Added dp_waterscroll <scale> <speed> shader keyword as simple simulation of water...
[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 const char *vm_m_extensions =
13 "BX_WAL_SUPPORT "
14 "DP_CINEMATIC_DPV "
15 "DP_CSQC_BINDMAPS "
16 "DP_GFX_FONTS "
17 "DP_GFX_FONTS_FREETYPE "
18 "DP_UTF8 "
19 "DP_FONT_VARIABLEWIDTH "
20 "DP_GECKO_SUPPORT "
21 "DP_MENU_EXTRESPONSEPACKET "
22 "DP_QC_ASINACOSATANATAN2TAN "
23 "DP_QC_AUTOCVARS "
24 "DP_QC_CMD "
25 "DP_QC_CRC16 "
26 "DP_QC_CVAR_TYPE "
27 "DP_QC_CVAR_DESCRIPTION "
28 "DP_QC_FINDCHAIN_TOFIELD "
29 "DP_QC_LOG "
30 "DP_QC_RENDER_SCENE "
31 "DP_QC_SPRINTF "
32 "DP_QC_STRFTIME "
33 "DP_QC_STRINGBUFFERS "
34 "DP_QC_STRINGBUFFERS_CVARLIST "
35 "DP_QC_STRINGCOLORFUNCTIONS "
36 "DP_QC_STRING_CASE_FUNCTIONS "
37 "DP_QC_STRREPLACE "
38 "DP_QC_TOKENIZEBYSEPARATOR "
39 "DP_QC_TOKENIZE_CONSOLE "
40 "DP_QC_UNLIMITEDTEMPSTRINGS "
41 "DP_QC_URI_ESCAPE "
42 "DP_QC_URI_GET "
43 "DP_QC_WHICHPACK "
44 "FTE_STRINGS "
45 ;
46
47 /*
48 =========
49 VM_M_setmousetarget
50
51 setmousetarget(float target)
52 =========
53 */
54 void VM_M_setmousetarget(void)
55 {
56         VM_SAFEPARMCOUNT(1, VM_M_setmousetarget);
57
58         switch((int)PRVM_G_FLOAT(OFS_PARM0))
59         {
60         case 1:
61                 in_client_mouse = false;
62                 break;
63         case 2:
64                 in_client_mouse = true;
65                 break;
66         default:
67                 PRVM_ERROR("VM_M_setmousetarget: wrong destination %f !",PRVM_G_FLOAT(OFS_PARM0));
68         }
69 }
70
71 /*
72 =========
73 VM_M_getmousetarget
74
75 float   getmousetarget
76 =========
77 */
78 void VM_M_getmousetarget(void)
79 {
80         VM_SAFEPARMCOUNT(0,VM_M_getmousetarget);
81
82         if(in_client_mouse)
83                 PRVM_G_FLOAT(OFS_RETURN) = 2;
84         else
85                 PRVM_G_FLOAT(OFS_RETURN) = 1;
86 }
87
88
89
90 /*
91 =========
92 VM_M_setkeydest
93
94 setkeydest(float dest)
95 =========
96 */
97 void VM_M_setkeydest(void)
98 {
99         VM_SAFEPARMCOUNT(1,VM_M_setkeydest);
100
101         switch((int)PRVM_G_FLOAT(OFS_PARM0))
102         {
103         case 0:
104                 // key_game
105                 key_dest = key_game;
106                 break;
107         case 2:
108                 // key_menu
109                 key_dest = key_menu;
110                 break;
111         case 3:
112                 // key_menu_grabbed
113                 key_dest = key_menu_grabbed;
114                 break;
115         case 1:
116                 // key_message
117                 // key_dest = key_message
118                 // break;
119         default:
120                 PRVM_ERROR("VM_M_setkeydest: wrong destination %f !", PRVM_G_FLOAT(OFS_PARM0));
121         }
122 }
123
124 /*
125 =========
126 VM_M_getkeydest
127
128 float   getkeydest
129 =========
130 */
131 void VM_M_getkeydest(void)
132 {
133         VM_SAFEPARMCOUNT(0,VM_M_getkeydest);
134
135         // key_game = 0, key_message = 1, key_menu = 2, key_menu_grabbed = 3, unknown = -1
136         switch(key_dest)
137         {
138         case key_game:
139                 PRVM_G_FLOAT(OFS_RETURN) = 0;
140                 break;
141         case key_menu:
142                 PRVM_G_FLOAT(OFS_RETURN) = 2;
143                 break;
144         case key_menu_grabbed:
145                 PRVM_G_FLOAT(OFS_RETURN) = 3;
146                 break;
147         case key_message:
148                 // not supported
149                 // PRVM_G_FLOAT(OFS_RETURN) = 1;
150                 // break;
151         default:
152                 PRVM_G_FLOAT(OFS_RETURN) = -1;
153         }
154 }
155
156
157 /*
158 =========
159 VM_M_getresolution
160
161 vector  getresolution(float number)
162 =========
163 */
164 void VM_M_getresolution(void)
165 {
166         int nr, fs;
167         VM_SAFEPARMCOUNTRANGE(1, 2, VM_getresolution);
168
169         nr = (int)PRVM_G_FLOAT(OFS_PARM0);
170
171         fs = ((prog->argc <= 1) || ((int)PRVM_G_FLOAT(OFS_PARM1)));
172
173         if(nr < 0 || nr >= (fs ? video_resolutions_count : video_resolutions_hardcoded_count))
174         {
175                 PRVM_G_VECTOR(OFS_RETURN)[0] = 0;
176                 PRVM_G_VECTOR(OFS_RETURN)[1] = 0;
177                 PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
178         }
179         else
180         {
181                 video_resolution_t *r = &((fs ? video_resolutions : video_resolutions_hardcoded)[nr]);
182                 PRVM_G_VECTOR(OFS_RETURN)[0] = r->width;
183                 PRVM_G_VECTOR(OFS_RETURN)[1] = r->height;
184                 PRVM_G_VECTOR(OFS_RETURN)[2] = r->pixelheight;
185         }
186 }
187
188 void VM_M_getgamedirinfo(void)
189 {
190         int nr, item;
191         VM_SAFEPARMCOUNT(2, VM_getgamedirinfo);
192
193         nr = (int)PRVM_G_FLOAT(OFS_PARM0);
194         item = (int)PRVM_G_FLOAT(OFS_PARM1);
195
196         PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
197
198         if(nr >= 0 && nr < fs_all_gamedirs_count)
199         {
200                 if(item == 0)
201                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( fs_all_gamedirs[nr].name );
202                 else if(item == 1)
203                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( fs_all_gamedirs[nr].description );
204         }
205 }
206
207 /*
208 =========
209 VM_M_getserverliststat
210
211 float   getserverliststat(float type)
212 =========
213 */
214 /*
215         type:
216 0       serverlist_viewcount
217 1   serverlist_totalcount
218 2       masterquerycount
219 3       masterreplycount
220 4       serverquerycount
221 5       serverreplycount
222 6       sortfield
223 7       sortflags
224 */
225 void VM_M_getserverliststat( void )
226 {
227         int type;
228         VM_SAFEPARMCOUNT ( 1, VM_M_getserverliststat );
229
230         PRVM_G_FLOAT( OFS_RETURN ) = 0;
231
232         type = (int)PRVM_G_FLOAT( OFS_PARM0 );
233         switch(type)
234         {
235         case 0:
236                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_viewcount;
237                 return;
238         case 1:
239                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_cachecount;
240                 return;
241         case 2:
242                 PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount;
243                 return;
244         case 3:
245                 PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
246                 return;
247         case 4:
248                 PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
249                 return;
250         case 5:
251                 PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
252                 return;
253         case 6:
254                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortbyfield;
255                 return;
256         case 7:
257                 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortflags;
258                 return;
259         default:
260                 VM_Warning( "VM_M_getserverliststat: bad type %i!\n", type );
261         }
262 }
263
264 /*
265 ========================
266 VM_M_resetserverlistmasks
267
268 resetserverlistmasks()
269 ========================
270 */
271 void VM_M_resetserverlistmasks( void )
272 {
273         VM_SAFEPARMCOUNT(0, VM_M_resetserverlistmasks);
274         ServerList_ResetMasks();
275 }
276
277
278 /*
279 ========================
280 VM_M_setserverlistmaskstring
281
282 setserverlistmaskstring(float mask, float fld, string str, float op)
283 0-511           and
284 512 - 1024      or
285 ========================
286 */
287 void VM_M_setserverlistmaskstring( void )
288 {
289         const char *str;
290         int masknr;
291         serverlist_mask_t *mask;
292         int field;
293
294         VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmaskstring );
295         str = PRVM_G_STRING( OFS_PARM2 );
296
297         masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
298         if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
299                 mask = &serverlist_andmasks[masknr];
300         else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
301                 mask = &serverlist_ormasks[masknr - 512 ];
302         else
303         {
304                 VM_Warning( "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
305                 return;
306         }
307
308         field = (int) PRVM_G_FLOAT( OFS_PARM1 );
309
310         switch( field ) {
311                 case SLIF_CNAME:
312                         strlcpy( mask->info.cname, str, sizeof(mask->info.cname) );
313                         break;
314                 case SLIF_NAME:
315                         strlcpy( mask->info.name, str, sizeof(mask->info.name)  );
316                         break;
317                 case SLIF_QCSTATUS:
318                         strlcpy( mask->info.qcstatus, str, sizeof(mask->info.qcstatus)  );
319                         break;
320                 case SLIF_PLAYERS:
321                         strlcpy( mask->info.players, str, sizeof(mask->info.players)  );
322                         break;
323                 case SLIF_MAP:
324                         strlcpy( mask->info.map, str, sizeof(mask->info.map)  );
325                         break;
326                 case SLIF_MOD:
327                         strlcpy( mask->info.mod, str, sizeof(mask->info.mod)  );
328                         break;
329                 case SLIF_GAME:
330                         strlcpy( mask->info.game, str, sizeof(mask->info.game)  );
331                         break;
332                 default:
333                         VM_Warning( "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
334                         return;
335         }
336
337         mask->active = true;
338         mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
339 }
340
341 /*
342 ========================
343 VM_M_setserverlistmasknumber
344
345 setserverlistmasknumber(float mask, float fld, float num, float op)
346
347 0-511           and
348 512 - 1024      or
349 ========================
350 */
351 void VM_M_setserverlistmasknumber( void )
352 {
353         int number;
354         serverlist_mask_t *mask;
355         int     masknr;
356         int field;
357         VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmasknumber );
358
359         masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
360         if( masknr >= 0 && masknr <= SERVERLIST_ANDMASKCOUNT )
361                 mask = &serverlist_andmasks[masknr];
362         else if( masknr >= 512 && masknr - 512 <= SERVERLIST_ORMASKCOUNT )
363                 mask = &serverlist_ormasks[masknr - 512 ];
364         else
365         {
366                 VM_Warning( "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
367                 return;
368         }
369
370         number = (int)PRVM_G_FLOAT( OFS_PARM2 );
371         field = (int) PRVM_G_FLOAT( OFS_PARM1 );
372
373         switch( field ) {
374                 case SLIF_MAXPLAYERS:
375                         mask->info.maxplayers = number;
376                         break;
377                 case SLIF_NUMPLAYERS:
378                         mask->info.numplayers = number;
379                         break;
380                 case SLIF_NUMBOTS:
381                         mask->info.numbots = number;
382                         break;
383                 case SLIF_NUMHUMANS:
384                         mask->info.numhumans = number;
385                         break;
386                 case SLIF_PING:
387                         mask->info.ping = number;
388                         break;
389                 case SLIF_PROTOCOL:
390                         mask->info.protocol = number;
391                         break;
392                 case SLIF_FREESLOTS:
393                         mask->info.freeslots = number;
394                         break;
395                 case SLIF_ISFAVORITE:
396                         mask->info.isfavorite = number != 0;
397                         break;
398                 default:
399                         VM_Warning( "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
400                         return;
401         }
402
403         mask->active = true;
404         mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
405 }
406
407
408 /*
409 ========================
410 VM_M_resortserverlist
411
412 resortserverlist
413 ========================
414 */
415 void VM_M_resortserverlist( void )
416 {
417         VM_SAFEPARMCOUNT(0, VM_M_resortserverlist);
418         ServerList_RebuildViewList();
419 }
420
421 /*
422 =========
423 VM_M_getserverliststring
424
425 string  getserverliststring(float field, float hostnr)
426 =========
427 */
428 void VM_M_getserverliststring(void)
429 {
430         serverlist_entry_t *cache;
431         int hostnr;
432
433         VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
434
435         PRVM_G_INT(OFS_RETURN) = OFS_NULL;
436
437         hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
438
439         if(hostnr < 0 || hostnr >= serverlist_viewcount)
440         {
441                 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
442                 return;
443         }
444         cache = ServerList_GetViewEntry(hostnr);
445         switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
446                 case SLIF_CNAME:
447                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( cache->info.cname );
448                         break;
449                 case SLIF_NAME:
450                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( cache->info.name );
451                         break;
452                 case SLIF_QCSTATUS:
453                         PRVM_G_INT (OFS_RETURN ) = PRVM_SetTempString (cache->info.qcstatus );
454                         break;
455                 case SLIF_PLAYERS:
456                         PRVM_G_INT (OFS_RETURN ) = PRVM_SetTempString (cache->info.players );
457                         break;
458                 case SLIF_GAME:
459                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( cache->info.game );
460                         break;
461                 case SLIF_MOD:
462                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( cache->info.mod );
463                         break;
464                 case SLIF_MAP:
465                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( cache->info.map );
466                         break;
467                 // TODO remove this again
468                 case 1024:
469                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( cache->line1 );
470                         break;
471                 case 1025:
472                         PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( cache->line2 );
473                         break;
474                 default:
475                         Con_Print("VM_M_getserverliststring: bad field number passed!\n");
476         }
477 }
478
479 /*
480 =========
481 VM_M_getserverlistnumber
482
483 float   getserverlistnumber(float field, float hostnr)
484 =========
485 */
486 void VM_M_getserverlistnumber(void)
487 {
488         serverlist_entry_t *cache;
489         int hostnr;
490
491         VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
492
493         PRVM_G_INT(OFS_RETURN) = OFS_NULL;
494
495         hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
496
497         if(hostnr < 0 || hostnr >= serverlist_viewcount)
498         {
499                 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
500                 return;
501         }
502         cache = ServerList_GetViewEntry(hostnr);
503         switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
504                 case SLIF_MAXPLAYERS:
505                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.maxplayers;
506                         break;
507                 case SLIF_NUMPLAYERS:
508                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numplayers;
509                         break;
510                 case SLIF_NUMBOTS:
511                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numbots;
512                         break;
513                 case SLIF_NUMHUMANS:
514                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numhumans;
515                         break;
516                 case SLIF_FREESLOTS:
517                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.freeslots;
518                         break;
519                 case SLIF_PING:
520                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping;
521                         break;
522                 case SLIF_PROTOCOL:
523                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.protocol;
524                         break;
525                 case SLIF_ISFAVORITE:
526                         PRVM_G_FLOAT( OFS_RETURN ) = cache->info.isfavorite;
527                         break;
528                 default:
529                         Con_Print("VM_M_getserverlistnumber: bad field number passed!\n");
530         }
531 }
532
533 /*
534 ========================
535 VM_M_setserverlistsort
536
537 setserverlistsort(float field, float flags)
538 ========================
539 */
540 void VM_M_setserverlistsort( void )
541 {
542         VM_SAFEPARMCOUNT( 2, VM_M_setserverlistsort );
543
544         serverlist_sortbyfield = (serverlist_infofield_t)((int)PRVM_G_FLOAT( OFS_PARM0 ));
545         serverlist_sortflags = (int) PRVM_G_FLOAT( OFS_PARM1 );
546 }
547
548 /*
549 ========================
550 VM_M_refreshserverlist
551
552 refreshserverlist()
553 ========================
554 */
555 void VM_M_refreshserverlist( void )
556 {
557         VM_SAFEPARMCOUNT( 0, VM_M_refreshserverlist );
558         ServerList_QueryList(false, true, false, false);
559 }
560
561 /*
562 ========================
563 VM_M_getserverlistindexforkey
564
565 float getserverlistindexforkey(string key)
566 ========================
567 */
568 void VM_M_getserverlistindexforkey( void )
569 {
570         const char *key;
571         VM_SAFEPARMCOUNT( 1, VM_M_getserverlistindexforkey );
572
573         key = PRVM_G_STRING( OFS_PARM0 );
574         VM_CheckEmptyString( key );
575
576         if( !strcmp( key, "cname" ) )
577                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CNAME;
578         else if( !strcmp( key, "ping" ) )
579                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PING;
580         else if( !strcmp( key, "game" ) )
581                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_GAME;
582         else if( !strcmp( key, "mod" ) )
583                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MOD;
584         else if( !strcmp( key, "map" ) )
585                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAP;
586         else if( !strcmp( key, "name" ) )
587                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NAME;
588         else if( !strcmp( key, "qcstatus" ) )
589                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_QCSTATUS;
590         else if( !strcmp( key, "players" ) )
591                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PLAYERS;
592         else if( !strcmp( key, "maxplayers" ) )
593                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS;
594         else if( !strcmp( key, "numplayers" ) )
595                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS;
596         else if( !strcmp( key, "numbots" ) )
597                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMBOTS;
598         else if( !strcmp( key, "numhumans" ) )
599                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMHUMANS;
600         else if( !strcmp( key, "freeslots" ) )
601                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_FREESLOTS;
602         else if( !strcmp( key, "protocol" ) )
603                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
604         else if( !strcmp( key, "isfavorite" ) )
605                 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_ISFAVORITE;
606         else
607                 PRVM_G_FLOAT( OFS_RETURN ) = -1;
608 }
609
610 /*
611 ========================
612 VM_M_addwantedserverlistkey
613
614 addwantedserverlistkey(string key)
615 ========================
616 */
617 void VM_M_addwantedserverlistkey( void )
618 {
619         VM_SAFEPARMCOUNT( 1, VM_M_addwantedserverlistkey );
620 }
621
622 /*
623 ===============================================================================
624 MESSAGE WRITING
625
626 used only for client and menu
627 server uses VM_SV_...
628
629 Write*(* data, float type, float to)
630
631 ===============================================================================
632 */
633
634 #define MSG_BROADCAST   0               // unreliable to all
635 #define MSG_ONE                 1               // reliable to one (msg_entity)
636 #define MSG_ALL                 2               // reliable to all
637 #define MSG_INIT                3               // write to the init string
638
639 sizebuf_t *VM_M_WriteDest (void)
640 {
641         int             dest;
642         int             destclient;
643
644         if(!sv.active)
645                 PRVM_ERROR("VM_M_WriteDest: game is not server (%s)", PRVM_NAME);
646
647         dest = (int)PRVM_G_FLOAT(OFS_PARM1);
648         switch (dest)
649         {
650         case MSG_BROADCAST:
651                 return &sv.datagram;
652
653         case MSG_ONE:
654                 destclient = (int) PRVM_G_FLOAT(OFS_PARM2);
655                 if (destclient < 0 || destclient >= svs.maxclients || !svs.clients[destclient].active || !svs.clients[destclient].netconnection)
656                         PRVM_ERROR("VM_clientcommand: %s: invalid client !", PRVM_NAME);
657
658                 return &svs.clients[destclient].netconnection->message;
659
660         case MSG_ALL:
661                 return &sv.reliable_datagram;
662
663         case MSG_INIT:
664                 return &sv.signon;
665
666         default:
667                 PRVM_ERROR ("WriteDest: bad destination");
668                 break;
669         }
670
671         return NULL;
672 }
673
674 void VM_M_WriteByte (void)
675 {
676         VM_SAFEPARMCOUNT(1, VM_M_WriteByte);
677         MSG_WriteByte (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
678 }
679
680 void VM_M_WriteChar (void)
681 {
682         VM_SAFEPARMCOUNT(1, VM_M_WriteChar);
683         MSG_WriteChar (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
684 }
685
686 void VM_M_WriteShort (void)
687 {
688         VM_SAFEPARMCOUNT(1, VM_M_WriteShort);
689         MSG_WriteShort (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
690 }
691
692 void VM_M_WriteLong (void)
693 {
694         VM_SAFEPARMCOUNT(1, VM_M_WriteLong);
695         MSG_WriteLong (VM_M_WriteDest(), (int)PRVM_G_FLOAT(OFS_PARM0));
696 }
697
698 void VM_M_WriteAngle (void)
699 {
700         VM_SAFEPARMCOUNT(1, VM_M_WriteAngle);
701         MSG_WriteAngle (VM_M_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
702 }
703
704 void VM_M_WriteCoord (void)
705 {
706         VM_SAFEPARMCOUNT(1, VM_M_WriteCoord);
707         MSG_WriteCoord (VM_M_WriteDest(), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
708 }
709
710 void VM_M_WriteString (void)
711 {
712         VM_SAFEPARMCOUNT(1, VM_M_WriteString);
713         MSG_WriteString (VM_M_WriteDest(), PRVM_G_STRING(OFS_PARM0));
714 }
715
716 void VM_M_WriteEntity (void)
717 {
718         VM_SAFEPARMCOUNT(1, VM_M_WriteEntity);
719         MSG_WriteShort (VM_M_WriteDest(), PRVM_G_EDICTNUM(OFS_PARM0));
720 }
721
722 /*
723 =================
724 VM_M_copyentity
725
726 copies data from one entity to another
727
728 copyentity(entity src, entity dst)
729 =================
730 */
731 static void VM_M_copyentity (void)
732 {
733         prvm_edict_t *in, *out;
734         VM_SAFEPARMCOUNT(2,VM_M_copyentity);
735         in = PRVM_G_EDICT(OFS_PARM0);
736         out = PRVM_G_EDICT(OFS_PARM1);
737         memcpy(out->fields.vp, in->fields.vp, prog->progs->entityfields * 4);
738 }
739
740 //#66 vector() getmousepos (EXT_CSQC)
741 static void VM_M_getmousepos(void)
742 {
743         VM_SAFEPARMCOUNT(0,VM_M_getmousepos);
744
745         if (key_consoleactive || (key_dest != key_menu && key_dest != key_menu_grabbed))
746                 VectorSet(PRVM_G_VECTOR(OFS_RETURN), 0, 0, 0);
747         else if (in_client_mouse)
748                 VectorSet(PRVM_G_VECTOR(OFS_RETURN), in_windowmouse_x * vid_conwidth.integer / vid.width, in_windowmouse_y * vid_conheight.integer / vid.height, 0);
749         else
750                 VectorSet(PRVM_G_VECTOR(OFS_RETURN), in_mouse_x * vid_conwidth.integer / vid.width, in_mouse_y * vid_conheight.integer / vid.height, 0);
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 VM_keynumtostring,                              // #340 string keynumtostring(float keynum)
1122 VM_stringtokeynum,                              // #341 float stringtokeynum(string key)
1123 VM_getkeybind,                                                  // #342 string(float keynum[, float bindmap]) getkeybind (EXT_CSQC)
1124 NULL,                                                                   // #343
1125 NULL,                                                                   // #344
1126 NULL,                                                                   // #345
1127 NULL,                                                                   // #346
1128 NULL,                                                                   // #347
1129 NULL,                                                                   // #348
1130 VM_CL_isdemo,                                                   // #349
1131 NULL,                                                                   // #350
1132 NULL,                                                                   // #351
1133 NULL,                                                                   // #352
1134 NULL,                                                                   // #353
1135 NULL,                                                                   // #354
1136 VM_CL_videoplaying,                                             // #355
1137 VM_findfont,                                                    // #356 float(string fontname) loadfont (DP_GFX_FONTS)
1138 VM_loadfont,                                                    // #357 float(string fontname, string fontmaps, string sizes, float slot) loadfont (DP_GFX_FONTS)
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 VM_getsoundtime,                                                // #533 float(entity e, float channel) getsoundtime = #533; (DP_SND_GETSOUNDTIME)
1315 VM_soundlength,                                                 // #534 float(string sample) soundlength = #534; (DP_SND_GETSOUNDTIME)
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[, float bindmap])
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_CL_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 VM_sprintf,                     // #627 string sprintf(string format, ...)
1409 NULL, // #628
1410 NULL, // #629
1411 VM_setkeybind,                                          // #630 float(float key, string bind[, float bindmap]) setkeybind
1412 VM_getbindmaps,                                         // #631 vector(void) getbindmap
1413 VM_setbindmaps,                                         // #632 float(vector bm) setbindmap
1414 NULL
1415 };
1416
1417 const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);
1418
1419 void VM_M_Cmd_Init(void)
1420 {
1421         r_refdef_scene_t *scene;
1422
1423         VM_Cmd_Init();
1424         VM_Polygons_Reset();
1425
1426         scene = R_GetScenePointer( RST_MENU );
1427
1428         memset (scene, 0, sizeof (*scene));
1429
1430         scene->maxtempentities = 128;
1431         scene->tempentities = (entity_render_t*) Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t) * scene->maxtempentities);
1432
1433         scene->maxentities = MAX_EDICTS + 256 + 512;
1434         scene->entities = (entity_render_t **)Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t *) * scene->maxentities);
1435
1436         scene->ambient = 32.0f;
1437 }
1438
1439 void VM_M_Cmd_Reset(void)
1440 {
1441         // note: the menu's render entities are automatically freed when the prog's pool is freed
1442
1443         //VM_Cmd_Init();
1444         VM_Cmd_Reset();
1445         VM_Polygons_Reset();
1446 }