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