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