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