fix return value of FS_WhichPack to NOT include the -basedir
[divverent/darkplaces.git] / mvm_cmds.c
1 #include "quakedef.h"
2
3 #include "prvm_cmds.h"
4 #include "clvm_cmds.h"
5 #include "menu.h"
6
7 //============================================================================
8 // Menu
9
10 char *vm_m_extensions =
11 "BX_WAL_SUPPORT "
12 "DP_CINEMATIC_DPV "
13 "DP_FONT_VARIABLEWIDTH "
14 "DP_GECKO_SUPPORT "
15 "DP_MENU_EXTRESPONSEPACKET "
16 "DP_QC_ASINACOSATANATAN2TAN "
17 "DP_QC_CMD "
18 "DP_QC_CRC16 "
19 "DP_QC_CVAR_TYPE "
20 "DP_QC_RENDER_SCENE "
21 "DP_QC_STRFTIME "
22 "DP_QC_STRINGBUFFERS "
23 "DP_QC_STRINGCOLORFUNCTIONS "
24 "DP_QC_STRING_CASE_FUNCTIONS "
25 "DP_QC_STRREPLACE "
26 "DP_QC_TOKENIZEBYSEPARATOR "
27 "DP_QC_UNLIMITEDTEMPSTRINGS "
28 "DP_QC_URI_ESCAPE "
29 "DP_QC_WHICHPACK "
30 "FTE_STRINGS "
31 ;
32
33 /*
34 =========
35 VM_M_setmousetarget
36
37 setmousetarget(float target)
38 =========
39 */
40 void VM_M_setmousetarget(void)
41 {
42         VM_SAFEPARMCOUNT(1, VM_M_setmousetarget);
43
44         switch((int)PRVM_G_FLOAT(OFS_PARM0))
45         {
46         case 1:
47                 in_client_mouse = false;
48                 break;
49         case 2:
50                 in_client_mouse = true;
51                 break;
52         default:
53                 PRVM_ERROR("VM_M_setmousetarget: wrong destination %f !",PRVM_G_FLOAT(OFS_PARM0));
54         }
55 }
56
57 /*
58 =========
59 VM_M_getmousetarget
60
61 float   getmousetarget
62 =========
63 */
64 void VM_M_getmousetarget(void)
65 {
66         VM_SAFEPARMCOUNT(0,VM_M_getmousetarget);
67
68         if(in_client_mouse)
69                 PRVM_G_FLOAT(OFS_RETURN) = 2;
70         else
71                 PRVM_G_FLOAT(OFS_RETURN) = 1;
72 }
73
74
75
76 /*
77 =========
78 VM_M_setkeydest
79
80 setkeydest(float dest)
81 =========
82 */
83 void VM_M_setkeydest(void)
84 {
85         VM_SAFEPARMCOUNT(1,VM_M_setkeydest);
86
87         switch((int)PRVM_G_FLOAT(OFS_PARM0))
88         {
89         case 0:
90                 // key_game
91                 key_dest = key_game;
92                 break;
93         case 2:
94                 // key_menu
95                 key_dest = key_menu;
96                 break;
97         case 3:
98                 // key_menu_grabbed
99                 key_dest = key_menu_grabbed;
100                 break;
101         case 1:
102                 // key_message
103                 // key_dest = key_message
104                 // break;
105         default:
106                 PRVM_ERROR("VM_M_setkeydest: wrong destination %f !", PRVM_G_FLOAT(OFS_PARM0));
107         }
108 }
109
110 /*
111 =========
112 VM_M_getkeydest
113
114 float   getkeydest
115 =========
116 */
117 void VM_M_getkeydest(void)
118 {
119         VM_SAFEPARMCOUNT(0,VM_M_getkeydest);
120
121         // key_game = 0, key_message = 1, key_menu = 2, key_menu_grabbed = 3, unknown = -1
122         switch(key_dest)
123         {
124         case key_game:
125                 PRVM_G_FLOAT(OFS_RETURN) = 0;
126                 break;
127         case key_menu:
128                 PRVM_G_FLOAT(OFS_RETURN) = 2;
129                 break;
130         case key_menu_grabbed:
131                 PRVM_G_FLOAT(OFS_RETURN) = 3;
132                 break;
133         case key_message:
134                 // not supported
135                 // PRVM_G_FLOAT(OFS_RETURN) = 1;
136                 // break;
137         default:
138                 PRVM_G_FLOAT(OFS_RETURN) = -1;
139         }
140 }
141
142 /*
143 =========
144 VM_M_callfunction
145
146         callfunction(...,string function_name)
147 Extension: pass
148 =========
149 */
150 mfunction_t *PRVM_ED_FindFunction (const char *name);
151 void VM_M_callfunction(void)
152 {
153         mfunction_t *func;
154         const char *s;
155
156         VM_SAFEPARMCOUNTRANGE(1, 8, VM_M_callfunction);
157
158         s = PRVM_G_STRING(OFS_PARM0+(prog->argc - 1)*3);
159
160         VM_CheckEmptyString(s);
161
162         func = PRVM_ED_FindFunction(s);
163
164         if(!func)
165                 PRVM_ERROR("VM_M_callfunciton: function %s not found !", s);
166         else if (func->first_statement < 0)
167         {
168                 // negative statements are built in functions
169                 int builtinnumber = -func->first_statement;
170                 prog->xfunction->builtinsprofile++;
171                 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
172                         prog->builtins[builtinnumber]();
173                 else
174                         PRVM_ERROR("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, PRVM_NAME);
175         }
176         else if(func - prog->functions > 0)
177         {
178                 prog->argc--;
179                 PRVM_ExecuteProgram(func - prog->functions,"");
180                 prog->argc++;
181         }
182 }
183
184 /*
185 =========
186 VM_M_isfunction
187
188 float   isfunction(string function_name)
189 =========
190 */
191 mfunction_t *PRVM_ED_FindFunction (const char *name);
192 void VM_M_isfunction(void)
193 {
194         mfunction_t *func;
195         const char *s;
196
197         VM_SAFEPARMCOUNT(1, VM_M_isfunction);
198
199         s = PRVM_G_STRING(OFS_PARM0);
200
201         VM_CheckEmptyString(s);
202
203         func = PRVM_ED_FindFunction(s);
204
205         if(!func)
206                 PRVM_G_FLOAT(OFS_RETURN) = false;
207         else
208                 PRVM_G_FLOAT(OFS_RETURN) = true;
209 }
210
211 /*
212 =========
213 VM_M_getresolution
214
215 vector  getresolution(float number)
216 =========
217 */
218 void VM_M_getresolution(void)
219 {
220         int nr;
221         VM_SAFEPARMCOUNT(1, VM_getresolution);
222
223         nr = (int)PRVM_G_FLOAT(OFS_PARM0);
224
225         // FIXME bounds check
226         PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr].width;
227         PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr].height;
228         PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
229 }
230
231 /*
232 =========
233 VM_M_findkeysforcommand
234
235 string  findkeysforcommand(string command)
236
237 the returned string is an altstring
238 =========
239 */
240 #define NUMKEYS 5 // TODO: merge the constant in keys.c with this one somewhen
241
242 void M_FindKeysForCommand(const char *command, int *keys);
243 void VM_M_findkeysforcommand(void)
244 {
245         const char *cmd;
246         char ret[VM_STRINGTEMP_LENGTH];
247         int keys[NUMKEYS];
248         int i;
249
250         VM_SAFEPARMCOUNT(1, VM_M_findkeysforcommand);
251
252         cmd = PRVM_G_STRING(OFS_PARM0);
253
254         VM_CheckEmptyString(cmd);
255
256         M_FindKeysForCommand(cmd, keys);
257
258         ret[0] = 0;
259         for(i = 0; i < NUMKEYS; i++)
260                 strlcat(ret, va(" \'%i\'", keys[i]), sizeof(ret));
261
262         PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(ret);
263 }
264
265 /*
266 =========
267 VM_M_getserverliststat
268
269 float   getserverliststat(float type)
270 =========
271 */
272 /*
273         type:
274 0       serverlist_viewcount
275 1   serverlist_totalcount
276 2       masterquerycount
277 3       masterreplycount
278 4       serverquerycount
279 5       serverreplycount
280 6       sortfield
281 7       sortdescending
282 */
283 void VM_M_getserverliststat( void )
284 {
285         int type;
286         VM_SAFEPARMCOUNT ( 1, VM_M_getserverliststat );
287
288         PRVM_G_FLOAT( OFS_RETURN ) = 0;
289
290         type = (int)PRVM_G_FLOAT( OFS_PARM0 );
291         switch(type)
292         {
293         case 0:
294                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_viewcount;
295                 return;
296         case 1:
297                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_cachecount;
298         case 2:
299                 PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount;
300                 return;
301         case 3:
302                 PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
303                 return;
304         case 4:
305                 PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
306                 return;
307         case 5:
308                 PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
309                 return;
310         case 6:
311                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortbyfield;
312                 return;
313         case 7:
314                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortdescending;
315                 return;
316         default:
317                 VM_Warning( "VM_M_getserverliststat: bad type %i!\n", type );
318         }
319 }
320
321 /*
322 ========================
323 VM_M_resetserverlistmasks
324
325 resetserverlistmasks()
326 ========================
327 */
328 void VM_M_resetserverlistmasks( void )
329 {
330         VM_SAFEPARMCOUNT(0, VM_M_resetserverlistmasks);
331         ServerList_ResetMasks();
332 }
333
334
335 /*
336 ========================
337 VM_M_setserverlistmaskstring
338
339 setserverlistmaskstring(float mask, float fld, string str, float op)
340 0-511           and
341 512 - 1024      or
342 ========================
343 */
344 void VM_M_setserverlistmaskstring( void )
345 {
346         const char *str;
347         int masknr;
348         serverlist_mask_t *mask;
349         int field;
350
351         VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmaskstring );
352         str = PRVM_G_STRING( OFS_PARM2 );
353
354         masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
355         if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
356                 mask = &serverlist_andmasks[masknr];
357         else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
358                 mask = &serverlist_ormasks[masknr - 512 ];
359         else
360         {
361                 VM_Warning( "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
362                 return;
363         }
364
365         field = (int) PRVM_G_FLOAT( OFS_PARM1 );
366
367         switch( field ) {
368                 case SLIF_CNAME:
369                         strlcpy( mask->info.cname, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.cname) );
370                         break;
371                 case SLIF_NAME:
372                         strlcpy( mask->info.name, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.name)  );
373                         break;
374                 case SLIF_MAP:
375                         strlcpy( mask->info.map, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.map)  );
376                         break;
377                 case SLIF_MOD:
378                         strlcpy( mask->info.mod, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.mod)  );
379                         break;
380                 case SLIF_GAME:
381                         strlcpy( mask->info.game, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.game)  );
382                         break;
383                 default:
384                         VM_Warning( "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
385                         return;
386         }
387
388         mask->active = true;
389         mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
390 }
391
392 /*
393 ========================
394 VM_M_setserverlistmasknumber
395
396 setserverlistmasknumber(float mask, float fld, float num, float op)
397
398 0-511           and
399 512 - 1024      or
400 ========================
401 */
402 void VM_M_setserverlistmasknumber( void )
403 {
404         int number;
405         serverlist_mask_t *mask;
406         int     masknr;
407         int field;
408         VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmasknumber );
409
410         masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
411         if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
412                 mask = &serverlist_andmasks[masknr];
413         else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
414                 mask = &serverlist_ormasks[masknr - 512 ];
415         else
416         {
417                 VM_Warning( "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
418                 return;
419         }
420
421         number = (int)PRVM_G_FLOAT( OFS_PARM2 );
422         field = (int) PRVM_G_FLOAT( OFS_PARM1 );
423
424         switch( field ) {
425                 case SLIF_MAXPLAYERS:
426                         mask->info.maxplayers = number;
427                         break;
428                 case SLIF_NUMPLAYERS:
429                         mask->info.numplayers = number;
430                         break;
431                 case SLIF_NUMBOTS:
432                         mask->info.numbots = number;
433                         break;
434                 case SLIF_NUMHUMANS:
435                         mask->info.numhumans = number;
436                         break;
437                 case SLIF_PING:
438                         mask->info.ping = number;
439                         break;
440                 case SLIF_PROTOCOL:
441                         mask->info.protocol = number;
442                         break;
443                 case SLIF_FREESLOTS:
444                         mask->info.freeslots = number;
445                         break;
446                 default:
447                         VM_Warning( "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
448                         return;
449         }
450
451         mask->active = true;
452         mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
453 }
454
455
456 /*
457 ========================
458 VM_M_resortserverlist
459
460 resortserverlist
461 ========================
462 */
463 void VM_M_resortserverlist( void )
464 {
465         VM_SAFEPARMCOUNT(0, VM_M_resortserverlist);
466         ServerList_RebuildViewList();
467 }
468
469 /*
470 =========
471 VM_M_getserverliststring
472
473 string  getserverliststring(float field, float hostnr)
474 =========
475 */
476 void VM_M_getserverliststring(void)
477 {
478         serverlist_entry_t *cache;
479         int hostnr;
480
481         VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
482
483         PRVM_G_INT(OFS_RETURN) = OFS_NULL;
484
485         hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
486
487         if(hostnr < 0 || hostnr >= serverlist_viewcount)
488         {
489                 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
490                 return;
491         }
492         cache = serverlist_viewlist[hostnr];
493         switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
494                 case SLIF_CNAME:
495                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.cname );
496                         break;
497                 case SLIF_NAME:
498                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.name );
499                         break;
500                 case SLIF_GAME:
501                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.game );
502                         break;
503                 case SLIF_MOD:
504                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.mod );
505                         break;
506                 case SLIF_MAP:
507                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->info.map );
508                         break;
509                 // TODO remove this again
510                 case 1024:
511                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line1 );
512                         break;
513                 case 1025:
514                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetEngineString( cache->line2 );
515                         break;
516                 default:
517                         Con_Print("VM_M_getserverliststring: bad field number passed!\n");
518         }
519 }
520
521 /*
522 =========
523 VM_M_getserverlistnumber
524
525 float   getserverlistnumber(float field, float hostnr)
526 =========
527 */
528 void VM_M_getserverlistnumber(void)
529 {
530         serverlist_entry_t *cache;
531         int hostnr;
532
533         VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
534
535         PRVM_G_INT(OFS_RETURN) = OFS_NULL;
536
537         hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
538
539         if(hostnr < 0 || hostnr >= serverlist_viewcount)
540         {
541                 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
542                 return;
543         }
544         cache = serverlist_viewlist[hostnr];
545         switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
546                 case SLIF_MAXPLAYERS:
547                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.maxplayers;
548                         break;
549                 case SLIF_NUMPLAYERS:
550                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numplayers;
551                         break;
552                 case SLIF_NUMBOTS:
553                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numbots;
554                         break;
555                 case SLIF_NUMHUMANS:
556                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numhumans;
557                         break;
558                 case SLIF_FREESLOTS:
559                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.freeslots;
560                         break;
561                 case SLIF_PING:
562                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping;
563                         break;
564                 case SLIF_PROTOCOL:
565                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.protocol;
566                         break;
567                 default:
568                         Con_Print("VM_M_getserverlistnumber: bad field number passed!\n");
569         }
570 }
571
572 /*
573 ========================
574 VM_M_setserverlistsort
575
576 setserverlistsort(float field, float descending)
577 ========================
578 */
579 void VM_M_setserverlistsort( void )
580 {
581         VM_SAFEPARMCOUNT( 2, VM_M_setserverlistsort );
582
583         serverlist_sortbyfield = (serverlist_infofield_t)((int)PRVM_G_FLOAT( OFS_PARM0 ));
584         serverlist_sortdescending = (qboolean) PRVM_G_FLOAT( OFS_PARM1 );
585 }
586
587 /*
588 ========================
589 VM_M_refreshserverlist
590
591 refreshserverlist()
592 ========================
593 */
594 void VM_M_refreshserverlist( void )
595 {
596         VM_SAFEPARMCOUNT( 0, VM_M_refreshserverlist );
597         ServerList_QueryList(false, true, false, false);
598 }
599
600 /*
601 ========================
602 VM_M_getserverlistindexforkey
603
604 float getserverlistindexforkey(string key)
605 ========================
606 */
607 void VM_M_getserverlistindexforkey( void )
608 {
609         const char *key;
610         VM_SAFEPARMCOUNT( 1, VM_M_getserverlistindexforkey );
611
612         key = PRVM_G_STRING( OFS_PARM0 );
613         VM_CheckEmptyString( key );
614
615         if( !strcmp( key, "cname" ) )
616                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CNAME;
617         else if( !strcmp( key, "ping" ) )
618                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PING;
619         else if( !strcmp( key, "game" ) )
620                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_GAME;
621         else if( !strcmp( key, "mod" ) )
622                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MOD;
623         else if( !strcmp( key, "map" ) )
624                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAP;
625         else if( !strcmp( key, "name" ) )
626                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NAME;
627         else if( !strcmp( key, "maxplayers" ) )
628                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS;
629         else if( !strcmp( key, "numplayers" ) )
630                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS;
631         else if( !strcmp( key, "numbots" ) )
632                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMBOTS;
633         else if( !strcmp( key, "numhumans" ) )
634                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMHUMANS;
635         else if( !strcmp( key, "freeslots" ) )
636                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_FREESLOTS;
637         else if( !strcmp( key, "protocol" ) )
638                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
639         else
640                 PRVM_G_FLOAT( OFS_RETURN ) = -1;
641 }
642
643 /*
644 ========================
645 VM_M_addwantedserverlistkey
646
647 addwantedserverlistkey(string key)
648 ========================
649 */
650 void VM_M_addwantedserverlistkey( void )
651 {
652         VM_SAFEPARMCOUNT( 1, VM_M_addwantedserverlistkey );
653 }
654
655 /*
656 ===============================================================================
657 MESSAGE WRITING
658
659 used only for client and menu
660 server uses VM_SV_...
661
662 Write*(* data, float type, float to)
663
664 ===============================================================================
665 */
666
667 #define MSG_BROADCAST   0               // unreliable to all
668 #define MSG_ONE                 1               // reliable to one (msg_entity)
669 #define MSG_ALL                 2               // reliable to all
670 #define MSG_INIT                3               // write to the init string
671
672 sizebuf_t *VM_M_WriteDest (void)
673 {
674         int             dest;
675         int             destclient;
676
677         if(!sv.active)
678                 PRVM_ERROR("VM_M_WriteDest: game is not server (%s)", PRVM_NAME);
679
680         dest = (int)PRVM_G_FLOAT(OFS_PARM1);
681         switch (dest)
682         {
683         case MSG_BROADCAST:
684                 return &sv.datagram;
685
686         case MSG_ONE:
687                 destclient = (int) PRVM_G_FLOAT(OFS_PARM2);
688                 if (destclient < 0 || destclient >= svs.maxclients || !svs.clients[destclient].active || !svs.clients[destclient].netconnection)
689                         PRVM_ERROR("VM_clientcommand: %s: invalid client !", PRVM_NAME);
690
691                 return &svs.clients[destclient].netconnection->message;
692
693         case MSG_ALL:
694                 return &sv.reliable_datagram;
695
696         case MSG_INIT:
697                 return &sv.signon;
698
699         default:
700                 PRVM_ERROR ("WriteDest: bad destination");
701                 break;
702         }
703
704         return NULL;
705 }
706
707 void VM_M_WriteByte (void)
708 {
709         VM_SAFEPARMCOUNT(1, VM_M_WriteByte);
710         MSG_WriteByte (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
711 }
712
713 void VM_M_WriteChar (void)
714 {
715         VM_SAFEPARMCOUNT(1, VM_M_WriteChar);
716         MSG_WriteChar (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
717 }
718
719 void VM_M_WriteShort (void)
720 {
721         VM_SAFEPARMCOUNT(1, VM_M_WriteShort);
722         MSG_WriteShort (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
723 }
724
725 void VM_M_WriteLong (void)
726 {
727         VM_SAFEPARMCOUNT(1, VM_M_WriteLong);
728         MSG_WriteLong (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
729 }
730
731 void VM_M_WriteAngle (void)
732 {
733         VM_SAFEPARMCOUNT(1, VM_M_WriteAngle);
734         MSG_WriteAngle (VM_M_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
735 }
736
737 void VM_M_WriteCoord (void)
738 {
739         VM_SAFEPARMCOUNT(1, VM_M_WriteCoord);
740         MSG_WriteCoord (VM_M_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
741 }
742
743 void VM_M_WriteString (void)
744 {
745         VM_SAFEPARMCOUNT(1, VM_M_WriteString);
746         MSG_WriteString (VM_M_WriteDest(), PRVM_G_STRING(OFS_PARM0));
747 }
748
749 void VM_M_WriteEntity (void)
750 {
751         VM_SAFEPARMCOUNT(1, VM_M_WriteEntity);
752         MSG_WriteShort (VM_M_WriteDest(), PRVM_G_EDICTNUM(OFS_PARM0));
753 }
754
755 //string(void) getextresponse = #624; // returns the next extResponse packet that was sent to this client
756 void VM_M_getextresponse (void)
757 {
758         VM_SAFEPARMCOUNT(0,VM_argv);
759
760         if (net_extresponse_count <= 0)
761                 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
762         else
763         {
764                 int first;
765                 --net_extresponse_count;
766                 first = (net_extresponse_last + NET_EXTRESPONSE_MAX - net_extresponse_count) % NET_EXTRESPONSE_MAX;
767                 PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(net_extresponse[first]);
768         }
769 }
770
771 /*
772 =================
773 VM_M_copyentity
774
775 copies data from one entity to another
776
777 copyentity(entity src, entity dst)
778 =================
779 */
780 static void VM_M_copyentity (void)
781 {
782         prvm_edict_t *in, *out;
783         VM_SAFEPARMCOUNT(2,VM_M_copyentity);
784         in = PRVM_G_EDICT(OFS_PARM0);
785         out = PRVM_G_EDICT(OFS_PARM1);
786         memcpy(out->fields.vp, in->fields.vp, prog->progs->entityfields * 4);
787 }
788
789 //#66 vector() getmousepos (EXT_CSQC)
790 static void VM_M_getmousepos(void)
791 {
792         VM_SAFEPARMCOUNT(0,VM_M_getmousepos);
793
794         if (key_consoleactive || (key_dest != key_menu && key_dest != key_menu_grabbed))
795                 VectorSet(PRVM_G_VECTOR(OFS_RETURN), 0, 0, 0);
796         else if (in_client_mouse)
797                 VectorSet(PRVM_G_VECTOR(OFS_RETURN), in_windowmouse_x * vid_conwidth.integer / vid.width, in_windowmouse_y * vid_conheight.integer / vid.height, 0);
798         else
799                 VectorSet(PRVM_G_VECTOR(OFS_RETURN), in_mouse_x * vid_conwidth.integer / vid.width, in_mouse_y * vid_conheight.integer / vid.height, 0);
800 }
801
802 prvm_builtin_t vm_m_builtins[] = {
803 NULL,                                                                   //   #0 NULL function (not callable)
804 VM_checkextension,                              //   #1
805 VM_error,                                                       //   #2
806 VM_objerror,                                            //   #3
807 VM_print,                                                       //   #4
808 VM_bprint,                                                      //   #5
809 VM_sprint,                                                      //   #6
810 VM_centerprint,                                 //   #7
811 VM_normalize,                                           //   #8
812 VM_vlen,                                                                //   #9
813 VM_vectoyaw,                                            //  #10
814 VM_vectoangles,                                 //  #11
815 VM_random,                                                      //  #12
816 VM_localcmd,                                            //  #13
817 VM_cvar,                                                                //  #14
818 VM_cvar_set,                                            //  #15
819 VM_dprint,                                                      //  #16
820 VM_ftos,                                                                //  #17
821 VM_fabs,                                                                //  #18
822 VM_vtos,                                                                //  #19
823 VM_etos,                                                                //  #20
824 VM_stof,                                                                //  #21
825 VM_spawn,                                                       //  #22
826 VM_remove,                                                      //  #23
827 VM_find,                                                                //  #24
828 VM_findfloat,                                           //  #25
829 VM_findchain,                                           //  #26
830 VM_findchainfloat,                              //  #27
831 VM_precache_file,                                       //  #28
832 VM_precache_sound,                              //  #29
833 VM_coredump,                                            //  #30
834 VM_traceon,                                                     //  #31
835 VM_traceoff,                                            //  #32
836 VM_eprint,                                                      //  #33
837 VM_rint,                                                                //  #34
838 VM_floor,                                                       //  #35
839 VM_ceil,                                                                //  #36
840 VM_nextent,                                                     //  #37
841 VM_sin,                                                         //  #38
842 VM_cos,                                                         //  #39
843 VM_sqrt,                                                                //  #40
844 VM_randomvec,                                           //  #41
845 VM_registercvar,                                        //  #42
846 VM_min,                                                         //  #43
847 VM_max,                                                         //  #44
848 VM_bound,                                                       //  #45
849 VM_pow,                                                         //  #46
850 VM_M_copyentity,                                        //  #47
851 VM_fopen,                                                       //  #48
852 VM_fclose,                                                      //  #49
853 VM_fgets,                                                       //  #50
854 VM_fputs,                                                       //  #51
855 VM_strlen,                                                      //  #52
856 VM_strcat,                                                      //  #53
857 VM_substring,                                           //  #54
858 VM_stov,                                                                //  #55
859 VM_strzone,                                                     //  #56
860 VM_strunzone,                                           //  #57
861 VM_tokenize,                                            //  #58
862 VM_argv,                                                                //  #59
863 VM_isserver,                                            //  #60
864 VM_clientcount,                                 //  #61
865 VM_clientstate,                                 //  #62
866 VM_clcommand,                                           //  #63
867 VM_changelevel,                                 //  #64
868 VM_localsound,                                          //  #65
869 VM_M_getmousepos,                                       //  #66
870 VM_gettime,                                                     //  #67
871 VM_loadfromdata,                                        //  #68
872 VM_loadfromfile,                                        //  #69
873 VM_modulo,                                                      //  #70
874 VM_cvar_string,                                 //  #71
875 VM_crash,                                                       //  #72
876 VM_stackdump,                                           //  #73
877 VM_search_begin,                                        //  #74
878 VM_search_end,                                          //  #75
879 VM_search_getsize,                              //  #76
880 VM_search_getfilename,                  //  #77
881 VM_chr,                                                         //  #78
882 VM_itof,                                                                //  #79
883 VM_ftoe,                                                                //  #80
884 VM_itof,                                                                //  #81 isString
885 VM_altstr_count,                                        //  #82
886 VM_altstr_prepare,                              //  #83
887 VM_altstr_get,                                          //  #84
888 VM_altstr_set,                                          //  #85
889 VM_altstr_ins,                                          //  #86
890 VM_findflags,                                           //  #87
891 VM_findchainflags,                              //  #88
892 VM_cvar_defstring,                              //  #89
893 // deactivate support for model rendering in the menu until someone has time to do it right [3/2/2008 Andreas]
894 #if 0
895 VM_CL_setmodel,                                 // #90 void(entity e, string m) setmodel (QUAKE)
896 VM_CL_precache_model,                   // #91 void(string s) precache_model (QUAKE)
897 VM_CL_setorigin,                                // #92 void(entity e, vector o) setorigin (QUAKE)
898 #else
899 NULL,
900 NULL,
901 NULL,
902 #endif
903 NULL,                                                                   //  #93
904 NULL,                                                                   //  #94
905 NULL,                                                                   //  #95
906 NULL,                                                                   //  #96
907 NULL,                                                                   //  #97
908 NULL,                                                                   //  #98
909 NULL,                                                                   //  #99
910 NULL,                                                                   // #100
911 NULL,                                                                   // #101
912 NULL,                                                                   // #102
913 NULL,                                                                   // #103
914 NULL,                                                                   // #104
915 NULL,                                                                   // #105
916 NULL,                                                                   // #106
917 NULL,                                                                   // #107
918 NULL,                                                                   // #108
919 NULL,                                                                   // #109
920 NULL,                                                                   // #110
921 NULL,                                                                   // #111
922 NULL,                                                                   // #112
923 NULL,                                                                   // #113
924 NULL,                                                                   // #114
925 NULL,                                                                   // #115
926 NULL,                                                                   // #116
927 NULL,                                                                   // #117
928 NULL,                                                                   // #118
929 NULL,                                                                   // #119
930 NULL,                                                                   // #120
931 NULL,                                                                   // #121
932 NULL,                                                                   // #122
933 NULL,                                                                   // #123
934 NULL,                                                                   // #124
935 NULL,                                                                   // #125
936 NULL,                                                                   // #126
937 NULL,                                                                   // #127
938 NULL,                                                                   // #128
939 NULL,                                                                   // #129
940 NULL,                                                                   // #130
941 NULL,                                                                   // #131
942 NULL,                                                                   // #132
943 NULL,                                                                   // #133
944 NULL,                                                                   // #134
945 NULL,                                                                   // #135
946 NULL,                                                                   // #136
947 NULL,                                                                   // #137
948 NULL,                                                                   // #138
949 NULL,                                                                   // #139
950 NULL,                                                                   // #140
951 NULL,                                                                   // #141
952 NULL,                                                                   // #142
953 NULL,                                                                   // #143
954 NULL,                                                                   // #144
955 NULL,                                                                   // #145
956 NULL,                                                                   // #146
957 NULL,                                                                   // #147
958 NULL,                                                                   // #148
959 NULL,                                                                   // #149
960 NULL,                                                                   // #150
961 NULL,                                                                   // #151
962 NULL,                                                                   // #152
963 NULL,                                                                   // #153
964 NULL,                                                                   // #154
965 NULL,                                                                   // #155
966 NULL,                                                                   // #156
967 NULL,                                                                   // #157
968 NULL,                                                                   // #158
969 NULL,                                                                   // #159
970 NULL,                                                                   // #160
971 NULL,                                                                   // #161
972 NULL,                                                                   // #162
973 NULL,                                                                   // #163
974 NULL,                                                                   // #164
975 NULL,                                                                   // #165
976 NULL,                                                                   // #166
977 NULL,                                                                   // #167
978 NULL,                                                                   // #168
979 NULL,                                                                   // #169
980 NULL,                                                                   // #170
981 NULL,                                                                   // #171
982 NULL,                                                                   // #172
983 NULL,                                                                   // #173
984 NULL,                                                                   // #174
985 NULL,                                                                   // #175
986 NULL,                                                                   // #176
987 NULL,                                                                   // #177
988 NULL,                                                                   // #178
989 NULL,                                                                   // #179
990 NULL,                                                                   // #180
991 NULL,                                                                   // #181
992 NULL,                                                                   // #182
993 NULL,                                                                   // #183
994 NULL,                                                                   // #184
995 NULL,                                                                   // #185
996 NULL,                                                                   // #186
997 NULL,                                                                   // #187
998 NULL,                                                                   // #188
999 NULL,                                                                   // #189
1000 NULL,                                                                   // #190
1001 NULL,                                                                   // #191
1002 NULL,                                                                   // #192
1003 NULL,                                                                   // #193
1004 NULL,                                                                   // #194
1005 NULL,                                                                   // #195
1006 NULL,                                                                   // #196
1007 NULL,                                                                   // #197
1008 NULL,                                                                   // #198
1009 NULL,                                                                   // #199
1010 NULL,                                                                   // #200
1011 NULL,                                                                   // #201
1012 NULL,                                                                   // #202
1013 NULL,                                                                   // #203
1014 NULL,                                                                   // #204
1015 NULL,                                                                   // #205
1016 NULL,                                                                   // #206
1017 NULL,                                                                   // #207
1018 NULL,                                                                   // #208
1019 NULL,                                                                   // #209
1020 NULL,                                                                   // #210
1021 NULL,                                                                   // #211
1022 NULL,                                                                   // #212
1023 NULL,                                                                   // #213
1024 NULL,                                                                   // #214
1025 NULL,                                                                   // #215
1026 NULL,                                                                   // #216
1027 NULL,                                                                   // #217
1028 NULL,                                                                   // #218
1029 NULL,                                                                   // #219
1030 NULL,                                                                   // #220
1031 VM_strstrofs,                                           // #221 float(string str, string sub[, float startpos]) strstrofs (FTE_STRINGS)
1032 VM_str2chr,                                             // #222 float(string str, float ofs) str2chr (FTE_STRINGS)
1033 VM_chr2str,                                             // #223 string(float c, ...) chr2str (FTE_STRINGS)
1034 VM_strconv,                                             // #224 string(float ccase, float calpha, float cnum, string s, ...) strconv (FTE_STRINGS)
1035 VM_strpad,                                              // #225 string(float chars, string s, ...) strpad (FTE_STRINGS)
1036 VM_infoadd,                                             // #226 string(string info, string key, string value, ...) infoadd (FTE_STRINGS)
1037 VM_infoget,                                             // #227 string(string info, string key) infoget (FTE_STRINGS)
1038 VM_strncmp,                                                     // #228 float(string s1, string s2, float len) strncmp (FTE_STRINGS)
1039 VM_strncasecmp,                                 // #229 float(string s1, string s2) strcasecmp (FTE_STRINGS)
1040 VM_strncasecmp,                                 // #230 float(string s1, string s2, float len) strncasecmp (FTE_STRINGS)
1041 NULL,                                                                   // #231
1042 NULL,                                                                   // #232
1043 NULL,                                                                   // #233
1044 NULL,                                                                   // #234
1045 NULL,                                                                   // #235
1046 NULL,                                                                   // #236
1047 NULL,                                                                   // #237
1048 NULL,                                                                   // #238
1049 NULL,                                                                   // #239
1050 NULL,                                                                   // #240
1051 NULL,                                                                   // #241
1052 NULL,                                                                   // #242
1053 NULL,                                                                   // #243
1054 NULL,                                                                   // #244
1055 NULL,                                                                   // #245
1056 NULL,                                                                   // #246
1057 NULL,                                                                   // #247
1058 NULL,                                                                   // #248
1059 NULL,                                                                   // #249
1060 NULL,                                                                   // #250
1061 NULL,                                                                   // #251
1062 NULL,                                                                   // #252
1063 NULL,                                                                   // #253
1064 NULL,                                                                   // #254
1065 NULL,                                                                   // #255
1066 NULL,                                                                   // #256
1067 NULL,                                                                   // #257
1068 NULL,                                                                   // #258
1069 NULL,                                                                   // #259
1070 NULL,                                                                   // #260
1071 NULL,                                                                   // #261
1072 NULL,                                                                   // #262
1073 NULL,                                                                   // #263
1074 NULL,                                                                   // #264
1075 NULL,                                                                   // #265
1076 NULL,                                                                   // #266
1077 NULL,                                                                   // #267
1078 NULL,                                                                   // #268
1079 NULL,                                                                   // #269
1080 NULL,                                                                   // #270
1081 NULL,                                                                   // #271
1082 NULL,                                                                   // #272
1083 NULL,                                                                   // #273
1084 NULL,                                                                   // #274
1085 NULL,                                                                   // #275
1086 NULL,                                                                   // #276
1087 NULL,                                                                   // #277
1088 NULL,                                                                   // #278
1089 NULL,                                                                   // #279
1090 NULL,                                                                   // #280
1091 NULL,                                                                   // #281
1092 NULL,                                                                   // #282
1093 NULL,                                                                   // #283
1094 NULL,                                                                   // #284
1095 NULL,                                                                   // #285
1096 NULL,                                                                   // #286
1097 NULL,                                                                   // #287
1098 NULL,                                                                   // #288
1099 NULL,                                                                   // #289
1100 NULL,                                                                   // #290
1101 NULL,                                                                   // #291
1102 NULL,                                                                   // #292
1103 NULL,                                                                   // #293
1104 NULL,                                                                   // #294
1105 NULL,                                                                   // #295
1106 NULL,                                                                   // #296
1107 NULL,                                                                   // #297
1108 NULL,                                                                   // #298
1109 NULL,                                                                   // #299
1110 // deactivate support for model rendering in the menu until someone has time to do it right [3/2/2008 Andreas]
1111 #if 0
1112 // CSQC range #300-#399
1113 VM_CL_R_ClearScene,                             // #300 void() clearscene (DP_QC_RENDER_SCENE)
1114 VM_CL_R_AddEntities,                    // #301 void(float mask) addentities (DP_QC_RENDER_SCENE)
1115 VM_CL_R_AddEntity,                              // #302 void(entity ent) addentity (DP_QC_RENDER_SCENE)
1116 VM_CL_R_SetView,                                // #303 float(float property, ...) setproperty (DP_QC_RENDER_SCENE)
1117 VM_CL_R_RenderScene,                    // #304 void() renderscene (DP_QC_RENDER_SCENE)
1118 VM_CL_R_AddDynamicLight,                // #305 void(vector org, float radius, vector lightcolours) adddynamiclight (DP_QC_RENDER_SCENE)
1119 VM_CL_R_PolygonBegin,                   // #306 void(string texturename, float flag[, float is2d, float lines]) R_BeginPolygon (DP_QC_RENDER_SCENE)
1120 VM_CL_R_PolygonVertex,                  // #307 void(vector org, vector texcoords, vector rgb, float alpha) R_PolygonVertex (DP_QC_RENDER_SCENE)
1121 VM_CL_R_PolygonEnd,                             // #308 void() R_EndPolygon
1122 NULL/*VM_CL_R_LoadWorldModel*/,                         // #309 void(string modelname) R_LoadWorldModel
1123 // TODO: rearrange and merge all builtin lists and share as many extensions as possible between all VM instances [1/27/2008 Andreas]
1124 VM_CL_setattachment,                            // #310 void(entity e, entity tagentity, string tagname) setattachment (DP_GFX_QUAKE3MODELTAGS) (DP_QC_RENDER_SCENE)
1125 VM_CL_gettagindex,                              // #311 float(entity ent, string tagname) gettagindex (DP_QC_GETTAGINFO) (DP_QC_RENDER_SCENE)
1126 VM_CL_gettaginfo,                                       // #312 vector(entity ent, float tagindex) gettaginfo (DP_QC_GETTAGINFO) (DP_QC_RENDER_SCENE)
1127 #else
1128 // CSQC range #300-#399
1129 NULL,           
1130 NULL,           
1131 NULL,           
1132 NULL,           
1133 NULL,           
1134 NULL,           
1135 NULL,           
1136 NULL,   
1137 NULL,   
1138 NULL,
1139 NULL,   
1140 NULL,   
1141 NULL,   
1142 #endif
1143 NULL,                                                                   // #313
1144 NULL,                                                                   // #314
1145 NULL,                                                                   // #315
1146 NULL,                                                                   // #316
1147 NULL,                                                                   // #317
1148 NULL,                                                                   // #318
1149 NULL,                                                                   // #319
1150 NULL,                                                                   // #320
1151 NULL,                                                                   // #321
1152 NULL,                                                                   // #322
1153 NULL,                                                                   // #323
1154 NULL,                                                                   // #324
1155 NULL,                                                                   // #325
1156 NULL,                                                                   // #326
1157 NULL,                                                                   // #327
1158 NULL,                                                                   // #328
1159 NULL,                                                                   // #329
1160 NULL,                                                                   // #330
1161 NULL,                                                                   // #331
1162 NULL,                                                                   // #332
1163 NULL,                                                                   // #333
1164 NULL,                                                                   // #334
1165 NULL,                                                                   // #335
1166 NULL,                                                                   // #336
1167 NULL,                                                                   // #337
1168 NULL,                                                                   // #338
1169 NULL,                                                                   // #339
1170 NULL,                                                                   // #340
1171 NULL,                                                                   // #341
1172 NULL,                                                                   // #342
1173 NULL,                                                                   // #343
1174 NULL,                                                                   // #344
1175 NULL,                                                                   // #345
1176 NULL,                                                                   // #346
1177 NULL,                                                                   // #347
1178 NULL,                                                                   // #348
1179 NULL,                                                                   // #349
1180 NULL,                                                                   // #350
1181 NULL,                                                                   // #351
1182 NULL,                                                                   // #352
1183 NULL,                                                                   // #353
1184 NULL,                                                                   // #354
1185 NULL,                                                                   // #355
1186 NULL,                                                                   // #356
1187 NULL,                                                                   // #357
1188 NULL,                                                                   // #358
1189 NULL,                                                                   // #359
1190 NULL,                                                                   // #360
1191 NULL,                                                                   // #361
1192 NULL,                                                                   // #362
1193 NULL,                                                                   // #363
1194 NULL,                                                                   // #364
1195 NULL,                                                                   // #365
1196 NULL,                                                                   // #366
1197 NULL,                                                                   // #367
1198 NULL,                                                                   // #368
1199 NULL,                                                                   // #369
1200 NULL,                                                                   // #370
1201 NULL,                                                                   // #371
1202 NULL,                                                                   // #372
1203 NULL,                                                                   // #373
1204 NULL,                                                                   // #374
1205 NULL,                                                                   // #375
1206 NULL,                                                                   // #376
1207 NULL,                                                                   // #377
1208 NULL,                                                                   // #378
1209 NULL,                                                                   // #379
1210 NULL,                                                                   // #380
1211 NULL,                                                                   // #381
1212 NULL,                                                                   // #382
1213 NULL,                                                                   // #383
1214 NULL,                                                                   // #384
1215 NULL,                                                                   // #385
1216 NULL,                                                                   // #386
1217 NULL,                                                                   // #387
1218 NULL,                                                                   // #388
1219 NULL,                                                                   // #389
1220 NULL,                                                                   // #390
1221 NULL,                                                                   // #391
1222 NULL,                                                                   // #392
1223 NULL,                                                                   // #393
1224 NULL,                                                                   // #394
1225 NULL,                                                                   // #395
1226 NULL,                                                                   // #396
1227 NULL,                                                                   // #397
1228 NULL,                                                                   // #398
1229 NULL,                                                                   // #399
1230 NULL,                                                                   // #400
1231 VM_M_WriteByte,                                 // #401
1232 VM_M_WriteChar,                                 // #402
1233 VM_M_WriteShort,                                        // #403
1234 VM_M_WriteLong,                                 // #404
1235 VM_M_WriteAngle,                                        // #405
1236 VM_M_WriteCoord,                                        // #406
1237 VM_M_WriteString,                                       // #407
1238 VM_M_WriteEntity,                                       // #408
1239 NULL,                                                                   // #409
1240 NULL,                                                                   // #410
1241 NULL,                                                                   // #411
1242 NULL,                                                                   // #412
1243 NULL,                                                                   // #413
1244 NULL,                                                                   // #414
1245 NULL,                                                                   // #415
1246 NULL,                                                                   // #416
1247 NULL,                                                                   // #417
1248 NULL,                                                                   // #418
1249 NULL,                                                                   // #419
1250 NULL,                                                                   // #420
1251 NULL,                                                                   // #421
1252 NULL,                                                                   // #422
1253 NULL,                                                                   // #423
1254 NULL,                                                                   // #424
1255 NULL,                                                                   // #425
1256 NULL,                                                                   // #426
1257 NULL,                                                                   // #427
1258 NULL,                                                                   // #428
1259 NULL,                                                                   // #429
1260 NULL,                                                                   // #430
1261 NULL,                                                                   // #431
1262 NULL,                                                                   // #432
1263 NULL,                                                                   // #433
1264 NULL,                                                                   // #434
1265 NULL,                                                                   // #435
1266 NULL,                                                                   // #436
1267 NULL,                                                                   // #437
1268 NULL,                                                                   // #438
1269 NULL,                                                                   // #439
1270 VM_buf_create,                                  // #440 float() buf_create (DP_QC_STRINGBUFFERS)
1271 VM_buf_del,                                             // #441 void(float bufhandle) buf_del (DP_QC_STRINGBUFFERS)
1272 VM_buf_getsize,                                 // #442 float(float bufhandle) buf_getsize (DP_QC_STRINGBUFFERS)
1273 VM_buf_copy,                                    // #443 void(float bufhandle_from, float bufhandle_to) buf_copy (DP_QC_STRINGBUFFERS)
1274 VM_buf_sort,                                    // #444 void(float bufhandle, float sortpower, float backward) buf_sort (DP_QC_STRINGBUFFERS)
1275 VM_buf_implode,                                 // #445 string(float bufhandle, string glue) buf_implode (DP_QC_STRINGBUFFERS)
1276 VM_bufstr_get,                                  // #446 string(float bufhandle, float string_index) bufstr_get (DP_QC_STRINGBUFFERS)
1277 VM_bufstr_set,                                  // #447 void(float bufhandle, float string_index, string str) bufstr_set (DP_QC_STRINGBUFFERS)
1278 VM_bufstr_add,                                  // #448 float(float bufhandle, string str, float order) bufstr_add (DP_QC_STRINGBUFFERS)
1279 VM_bufstr_free,                                 // #449 void(float bufhandle, float string_index) bufstr_free (DP_QC_STRINGBUFFERS)
1280 NULL,                                                                   // #450
1281 VM_iscachedpic,                                 // #451 draw functions...
1282 VM_precache_pic,                                        // #452
1283 VM_freepic,                                                     // #453
1284 VM_drawcharacter,                                       // #454
1285 VM_drawstring,                                          // #455
1286 VM_drawpic,                                                     // #456
1287 VM_drawfill,                                            // #457
1288 VM_drawsetcliparea,                             // #458
1289 VM_drawresetcliparea,                   // #459
1290 VM_getimagesize,                                        // #460
1291 VM_cin_open,                                            // #461
1292 VM_cin_close,                                           // #462
1293 VM_cin_setstate,                                        // #463
1294 VM_cin_getstate,                                        // #464
1295 VM_cin_restart,                                         // #465
1296 VM_drawline,                                            // #466
1297 VM_drawcolorcodedstring,                // #467
1298 VM_stringwidth,                                 // #468
1299 VM_drawsubpic,                                          // #469
1300 NULL,                                                                   // #470
1301 VM_asin,                                                                // #471 float(float s) VM_asin (DP_QC_ASINACOSATANATAN2TAN)
1302 VM_acos,                                                                // #472 float(float c) VM_acos (DP_QC_ASINACOSATANATAN2TAN)
1303 VM_atan,                                                                // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
1304 VM_atan2,                                                       // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
1305 VM_tan,                                                         // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
1306 VM_strlennocol,                                 // #476 float(string s) : DRESK - String Length (not counting color codes) (DP_QC_STRINGCOLORFUNCTIONS)
1307 VM_strdecolorize,                                       // #477 string(string s) : DRESK - Decolorized String (DP_QC_STRINGCOLORFUNCTIONS)
1308 VM_strftime,                                            // #478 string(float uselocaltime, string format, ...) (DP_QC_STRFTIME)
1309 VM_tokenizebyseparator,                 // #479 float(string s) tokenizebyseparator (DP_QC_TOKENIZEBYSEPARATOR)
1310 VM_strtolower,                                          // #480 string(string s) VM_strtolower : DRESK - Return string as lowercase
1311 VM_strtoupper,                                          // #481 string(string s) VM_strtoupper : DRESK - Return string as uppercase
1312 NULL,                                                                   // #482
1313 NULL,                                                                   // #483
1314 VM_strreplace,                                          // #484 string(string search, string replace, string subject) strreplace (DP_QC_STRREPLACE)
1315 VM_strireplace,                                 // #485 string(string search, string replace, string subject) strireplace (DP_QC_STRREPLACE)
1316 NULL,                                                                   // #486
1317 VM_gecko_create,                                        // #487 float gecko_create( string name )
1318 VM_gecko_destroy,                                       // #488 void gecko_destroy( string name )
1319 VM_gecko_navigate,                              // #489 void gecko_navigate( string name, string URI )
1320 VM_gecko_keyevent,                              // #490 float gecko_keyevent( string name, float key, float eventtype )
1321 VM_gecko_movemouse,                             // #491 void gecko_mousemove( string name, float x, float y )
1322 VM_gecko_resize,                                        // #492 void gecko_resize( string name, float w, float h )
1323 VM_gecko_get_texture_extent,    // #493 vector gecko_get_texture_extent( string name )
1324 VM_crc16,                                               // #494 float(float caseinsensitive, string s, ...) crc16 = #494 (DP_QC_CRC16)
1325 VM_cvar_type,                                   // #495 float(string name) cvar_type = #495; (DP_QC_CVAR_TYPE)
1326 NULL,                                                                   // #496
1327 NULL,                                                                   // #497
1328 NULL,                                                                   // #498
1329 NULL,                                                                   // #499
1330 NULL,                                                                   // #500
1331 NULL,                                                                   // #501
1332 NULL,                                                                   // #502
1333 VM_whichpack,                                   // #503 string(string) whichpack = #503;
1334 NULL,                                                                   // #504
1335 NULL,                                                                   // #505
1336 NULL,                                                                   // #506
1337 NULL,                                                                   // #507
1338 NULL,                                                                   // #508
1339 NULL,                                                                   // #509
1340 VM_uri_escape,                                  // #510 string(string in) uri_escape = #510;
1341 VM_uri_unescape,                                // #511 string(string in) uri_unescape = #511;
1342 VM_etof,                                        // #512 float(entity ent) num_for_edict = #512 (DP_QC_NUM_FOR_EDICT)
1343 NULL,                                                                   // #513
1344 NULL,                                                                   // #514
1345 NULL,                                                                   // #515
1346 NULL,                                                                   // #516
1347 NULL,                                                                   // #517
1348 NULL,                                                                   // #518
1349 NULL,                                                                   // #519
1350 NULL,                                                                   // #520
1351 NULL,                                                                   // #521
1352 NULL,                                                                   // #522
1353 NULL,                                                                   // #523
1354 NULL,                                                                   // #524
1355 NULL,                                                                   // #525
1356 NULL,                                                                   // #526
1357 NULL,                                                                   // #527
1358 NULL,                                                                   // #528
1359 NULL,                                                                   // #529
1360 NULL,                                                                   // #530
1361 NULL,                                                                   // #531
1362 NULL,                                                                   // #532
1363 NULL,                                                                   // #533
1364 NULL,                                                                   // #534
1365 NULL,                                                                   // #535
1366 NULL,                                                                   // #536
1367 NULL,                                                                   // #537
1368 NULL,                                                                   // #538
1369 NULL,                                                                   // #539
1370 NULL,                                                                   // #540
1371 NULL,                                                                   // #541
1372 NULL,                                                                   // #542
1373 NULL,                                                                   // #543
1374 NULL,                                                                   // #544
1375 NULL,                                                                   // #545
1376 NULL,                                                                   // #546
1377 NULL,                                                                   // #547
1378 NULL,                                                                   // #548
1379 NULL,                                                                   // #549
1380 NULL,                                                                   // #550
1381 NULL,                                                                   // #551
1382 NULL,                                                                   // #552
1383 NULL,                                                                   // #553
1384 NULL,                                                                   // #554
1385 NULL,                                                                   // #555
1386 NULL,                                                                   // #556
1387 NULL,                                                                   // #557
1388 NULL,                                                                   // #558
1389 NULL,                                                                   // #559
1390 NULL,                                                                   // #560
1391 NULL,                                                                   // #561
1392 NULL,                                                                   // #562
1393 NULL,                                                                   // #563
1394 NULL,                                                                   // #564
1395 NULL,                                                                   // #565
1396 NULL,                                                                   // #566
1397 NULL,                                                                   // #567
1398 NULL,                                                                   // #568
1399 NULL,                                                                   // #569
1400 NULL,                                                                   // #570
1401 NULL,                                                                   // #571
1402 NULL,                                                                   // #572
1403 NULL,                                                                   // #573
1404 NULL,                                                                   // #574
1405 NULL,                                                                   // #575
1406 NULL,                                                                   // #576
1407 NULL,                                                                   // #577
1408 NULL,                                                                   // #578
1409 NULL,                                                                   // #579
1410 NULL,                                                                   // #580
1411 NULL,                                                                   // #581
1412 NULL,                                                                   // #582
1413 NULL,                                                                   // #583
1414 NULL,                                                                   // #584
1415 NULL,                                                                   // #585
1416 NULL,                                                                   // #586
1417 NULL,                                                                   // #587
1418 NULL,                                                                   // #588
1419 NULL,                                                                   // #589
1420 NULL,                                                                   // #590
1421 NULL,                                                                   // #591
1422 NULL,                                                                   // #592
1423 NULL,                                                                   // #593
1424 NULL,                                                                   // #594
1425 NULL,                                                                   // #595
1426 NULL,                                                                   // #596
1427 NULL,                                                                   // #597
1428 NULL,                                                                   // #598
1429 NULL,                                                                   // #599
1430 NULL,                                                                   // #600
1431 VM_M_setkeydest,                                        // #601 void setkeydest(float dest)
1432 VM_M_getkeydest,                                        // #602 float getkeydest(void)
1433 VM_M_setmousetarget,                            // #603 void setmousetarget(float trg)
1434 VM_M_getmousetarget,                            // #604 float getmousetarget(void)
1435 VM_M_callfunction,                              // #605 void callfunction(...)
1436 VM_writetofile,                                 // #606 void writetofile(float fhandle, entity ent)
1437 VM_M_isfunction,                                        // #607 float isfunction(string function_name)
1438 VM_M_getresolution,                             // #608 vector getresolution(float number)
1439 VM_keynumtostring,                              // #609 string keynumtostring(float keynum)
1440 VM_M_findkeysforcommand,                // #610 string findkeysforcommand(string command)
1441 VM_M_getserverliststat,                 // #611 float gethostcachevalue(float type)
1442 VM_M_getserverliststring,               // #612 string gethostcachestring(float type, float hostnr)
1443 VM_parseentitydata,                             // #613 void parseentitydata(entity ent, string data)
1444 VM_stringtokeynum,                              // #614 float stringtokeynum(string key)
1445 VM_M_resetserverlistmasks,              // #615 void resethostcachemasks(void)
1446 VM_M_setserverlistmaskstring,   // #616 void sethostcachemaskstring(float mask, float fld, string str, float op)
1447 VM_M_setserverlistmasknumber,   // #617 void sethostcachemasknumber(float mask, float fld, float num, float op)
1448 VM_M_resortserverlist,                  // #618 void resorthostcache(void)
1449 VM_M_setserverlistsort,                 // #619 void sethostcachesort(float fld, float descending)
1450 VM_M_refreshserverlist,                 // #620 void refreshhostcache(void)
1451 VM_M_getserverlistnumber,               // #621 float gethostcachenumber(float fld, float hostnr)
1452 VM_M_getserverlistindexforkey,// #622 float gethostcacheindexforkey(string key)
1453 VM_M_addwantedserverlistkey,    // #623 void addwantedhostcachekey(string key)
1454 VM_M_getextresponse                             // #624 string getextresponse(void)
1455 };
1456
1457 const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);
1458
1459 void VM_M_Cmd_Init(void)
1460 {
1461         r_refdef_scene_t *scene;
1462
1463         VM_Cmd_Init();
1464         VM_Polygons_Reset();
1465
1466         scene = R_GetScenePointer( RST_MENU );
1467
1468         memset (scene, 0, sizeof (*scene));
1469
1470         scene->maxtempentities = 128;
1471         scene->tempentities = (entity_render_t*) Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t) * scene->maxtempentities);
1472
1473         scene->maxentities = MAX_EDICTS + 256 + 512;
1474         scene->entities = (entity_render_t **)Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t *) * scene->maxentities);
1475
1476         scene->ambient = 32.0f;
1477 }
1478
1479 void VM_M_Cmd_Reset(void)
1480 {
1481         // note: the menu's render entities are automatically freed when the prog's pool is freed
1482
1483         //VM_Cmd_Init();
1484         VM_Cmd_Reset();
1485         VM_Polygons_Reset();
1486 }