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