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