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