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