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