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