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