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