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