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