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