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