8 // TODO check which strings really should be engine strings
10 //============================================================================
13 const char *vm_m_extensions[] = {
20 "DP_GFX_FONTS_FREETYPE",
22 "DP_FONT_VARIABLEWIDTH",
23 "DP_MENU_EXTRESPONSEPACKET",
24 "DP_QC_ASINACOSATANATAN2TAN",
29 "DP_QC_CVAR_DESCRIPTION",
31 "DP_QC_DIGEST_SHA256",
32 "DP_QC_FINDCHAIN_TOFIELD",
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",
44 "DP_QC_TOKENIZEBYSEPARATOR",
45 "DP_QC_TOKENIZE_CONSOLE",
46 "DP_QC_UNLIMITEDTEMPSTRINGS",
59 setmousetarget(float target)
62 static void VM_M_setmousetarget(prvm_prog_t *prog)
64 VM_SAFEPARMCOUNT(1, VM_M_setmousetarget);
66 switch((int)PRVM_G_FLOAT(OFS_PARM0))
69 in_client_mouse = false;
72 in_client_mouse = true;
75 prog->error_cmd("VM_M_setmousetarget: wrong destination %f !",PRVM_G_FLOAT(OFS_PARM0));
86 static void VM_M_getmousetarget(prvm_prog_t *prog)
88 VM_SAFEPARMCOUNT(0,VM_M_getmousetarget);
91 PRVM_G_FLOAT(OFS_RETURN) = 2;
93 PRVM_G_FLOAT(OFS_RETURN) = 1;
102 setkeydest(float dest)
105 static void VM_M_setkeydest(prvm_prog_t *prog)
107 VM_SAFEPARMCOUNT(1,VM_M_setkeydest);
109 switch((int)PRVM_G_FLOAT(OFS_PARM0))
121 key_dest = key_menu_grabbed;
125 // key_dest = key_message
128 prog->error_cmd("VM_M_setkeydest: wrong destination %f !", PRVM_G_FLOAT(OFS_PARM0));
139 static void VM_M_getkeydest(prvm_prog_t *prog)
141 VM_SAFEPARMCOUNT(0,VM_M_getkeydest);
143 // key_game = 0, key_message = 1, key_menu = 2, key_menu_grabbed = 3, unknown = -1
147 PRVM_G_FLOAT(OFS_RETURN) = 0;
150 PRVM_G_FLOAT(OFS_RETURN) = 2;
152 case key_menu_grabbed:
153 PRVM_G_FLOAT(OFS_RETURN) = 3;
157 // PRVM_G_FLOAT(OFS_RETURN) = 1;
160 PRVM_G_FLOAT(OFS_RETURN) = -1;
169 vector getresolution(float number)
172 static void VM_M_getresolution(prvm_prog_t *prog)
175 VM_SAFEPARMCOUNTRANGE(1, 2, VM_M_getresolution);
177 nr = (int)PRVM_G_FLOAT(OFS_PARM0);
179 fs = ((prog->argc <= 1) || ((int)PRVM_G_FLOAT(OFS_PARM1)));
181 if(nr < -1 || nr >= (fs ? video_resolutions_count : video_resolutions_hardcoded_count))
183 PRVM_G_VECTOR(OFS_RETURN)[0] = 0;
184 PRVM_G_VECTOR(OFS_RETURN)[1] = 0;
185 PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
189 vid_mode_t *m = VID_GetDesktopMode();
192 PRVM_G_VECTOR(OFS_RETURN)[0] = m->width;
193 PRVM_G_VECTOR(OFS_RETURN)[1] = m->height;
194 PRVM_G_VECTOR(OFS_RETURN)[2] = m->pixelheight_num / (prvm_vec_t) m->pixelheight_denom;
198 PRVM_G_VECTOR(OFS_RETURN)[0] = 0;
199 PRVM_G_VECTOR(OFS_RETURN)[1] = 0;
200 PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
205 video_resolution_t *r = &((fs ? video_resolutions : video_resolutions_hardcoded)[nr]);
206 PRVM_G_VECTOR(OFS_RETURN)[0] = r->width;
207 PRVM_G_VECTOR(OFS_RETURN)[1] = r->height;
208 PRVM_G_VECTOR(OFS_RETURN)[2] = r->pixelheight;
212 static void VM_M_getgamedirinfo(prvm_prog_t *prog)
215 VM_SAFEPARMCOUNT(2, VM_getgamedirinfo);
217 nr = (int)PRVM_G_FLOAT(OFS_PARM0);
218 item = (int)PRVM_G_FLOAT(OFS_PARM1);
220 PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
222 if(nr >= 0 && nr < fs_all_gamedirs_count)
225 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, fs_all_gamedirs[nr].name );
227 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, fs_all_gamedirs[nr].description );
233 VM_M_getserverliststat
235 float getserverliststat(float type)
240 0 serverlist_viewcount
241 1 serverlist_totalcount
249 static void VM_M_getserverliststat(prvm_prog_t *prog)
252 VM_SAFEPARMCOUNT ( 1, VM_M_getserverliststat );
254 PRVM_G_FLOAT( OFS_RETURN ) = 0;
256 type = (int)PRVM_G_FLOAT( OFS_PARM0 );
260 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_viewcount;
263 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_cachecount;
266 PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount;
269 PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
272 PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
275 PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
278 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortbyfield;
281 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortflags;
284 VM_Warning(prog, "VM_M_getserverliststat: bad type %i!\n", type );
289 ========================
290 VM_M_resetserverlistmasks
292 resetserverlistmasks()
293 ========================
295 static void VM_M_resetserverlistmasks(prvm_prog_t *prog)
297 VM_SAFEPARMCOUNT(0, VM_M_resetserverlistmasks);
298 ServerList_ResetMasks();
303 ========================
304 VM_M_setserverlistmaskstring
306 setserverlistmaskstring(float mask, float fld, string str, float op)
309 ========================
311 static void VM_M_setserverlistmaskstring(prvm_prog_t *prog)
315 serverlist_mask_t *mask;
318 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmaskstring );
319 str = PRVM_G_STRING( OFS_PARM2 );
321 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
322 if( masknr >= 0 && masknr < SERVERLIST_ANDMASKCOUNT )
323 mask = &serverlist_andmasks[masknr];
324 else if( masknr >= 512 && masknr - 512 < SERVERLIST_ORMASKCOUNT )
325 mask = &serverlist_ormasks[masknr - 512 ];
328 VM_Warning(prog, "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
332 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
336 strlcpy( mask->info.cname, str, sizeof(mask->info.cname) );
339 strlcpy( mask->info.name, str, sizeof(mask->info.name) );
342 strlcpy( mask->info.qcstatus, str, sizeof(mask->info.qcstatus) );
345 strlcpy( mask->info.players, str, sizeof(mask->info.players) );
348 strlcpy( mask->info.map, str, sizeof(mask->info.map) );
351 strlcpy( mask->info.mod, str, sizeof(mask->info.mod) );
354 strlcpy( mask->info.game, str, sizeof(mask->info.game) );
357 VM_Warning(prog, "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
362 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
366 ========================
367 VM_M_setserverlistmasknumber
369 setserverlistmasknumber(float mask, float fld, float num, float op)
373 ========================
375 static void VM_M_setserverlistmasknumber(prvm_prog_t *prog)
378 serverlist_mask_t *mask;
381 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmasknumber );
383 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
384 if( masknr >= 0 && masknr < SERVERLIST_ANDMASKCOUNT )
385 mask = &serverlist_andmasks[masknr];
386 else if( masknr >= 512 && masknr - 512 < SERVERLIST_ORMASKCOUNT )
387 mask = &serverlist_ormasks[masknr - 512 ];
390 VM_Warning(prog, "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
394 number = (int)PRVM_G_FLOAT( OFS_PARM2 );
395 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
398 case SLIF_MAXPLAYERS:
399 mask->info.maxplayers = number;
401 case SLIF_NUMPLAYERS:
402 mask->info.numplayers = number;
405 mask->info.numbots = number;
408 mask->info.numhumans = number;
411 mask->info.ping = number;
414 mask->info.protocol = number;
417 mask->info.freeslots = number;
420 mask->info.category = number;
422 case SLIF_ISFAVORITE:
423 mask->info.isfavorite = number != 0;
426 VM_Warning(prog, "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
431 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
436 ========================
437 VM_M_resortserverlist
440 ========================
442 static void VM_M_resortserverlist(prvm_prog_t *prog)
444 VM_SAFEPARMCOUNT(0, VM_M_resortserverlist);
445 ServerList_RebuildViewList();
450 VM_M_getserverliststring
452 string getserverliststring(float field, float hostnr)
455 static void VM_M_getserverliststring(prvm_prog_t *prog)
457 const serverlist_entry_t *cache;
460 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
462 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
464 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
466 if(hostnr == -1 && serverlist_callbackentry)
468 cache = serverlist_callbackentry;
472 if(hostnr < 0 || hostnr >= serverlist_viewcount)
474 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
477 cache = ServerList_GetViewEntry(hostnr);
479 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
481 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.cname );
484 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.name );
487 PRVM_G_INT (OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.qcstatus );
490 PRVM_G_INT (OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.players );
493 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.game );
496 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.mod );
499 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.map );
501 // TODO remove this again
503 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->line1 );
506 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->line2 );
509 Con_Print("VM_M_getserverliststring: bad field number passed!\n");
515 VM_M_getserverlistnumber
517 float getserverlistnumber(float field, float hostnr)
520 static void VM_M_getserverlistnumber(prvm_prog_t *prog)
522 const serverlist_entry_t *cache;
525 VM_SAFEPARMCOUNT(2, VM_M_getserverlistnumber);
527 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
529 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
531 if(hostnr == -1 && serverlist_callbackentry)
533 cache = serverlist_callbackentry;
537 if(hostnr < 0 || hostnr >= serverlist_viewcount)
539 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
542 cache = ServerList_GetViewEntry(hostnr);
544 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
545 case SLIF_MAXPLAYERS:
546 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.maxplayers;
548 case SLIF_NUMPLAYERS:
549 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numplayers;
552 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numbots;
555 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numhumans;
558 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.freeslots;
561 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping;
564 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.protocol;
567 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.category;
569 case SLIF_ISFAVORITE:
570 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.isfavorite;
573 Con_Print("VM_M_getserverlistnumber: bad field number passed!\n");
578 ========================
579 VM_M_setserverlistsort
581 setserverlistsort(float field, float flags)
582 ========================
584 static void VM_M_setserverlistsort(prvm_prog_t *prog)
586 VM_SAFEPARMCOUNT( 2, VM_M_setserverlistsort );
588 serverlist_sortbyfield = (serverlist_infofield_t)((int)PRVM_G_FLOAT( OFS_PARM0 ));
589 serverlist_sortflags = (int) PRVM_G_FLOAT( OFS_PARM1 );
593 ========================
594 VM_M_refreshserverlist
597 ========================
599 static void VM_M_refreshserverlist(prvm_prog_t *prog)
601 qboolean do_reset = false;
602 VM_SAFEPARMCOUNTRANGE( 0, 1, VM_M_refreshserverlist );
603 if (prog->argc >= 1 && PRVM_G_FLOAT(OFS_PARM0))
605 ServerList_QueryList(do_reset, true, false, false);
609 ========================
610 VM_M_getserverlistindexforkey
612 float getserverlistindexforkey(string key)
613 ========================
615 static void VM_M_getserverlistindexforkey(prvm_prog_t *prog)
618 VM_SAFEPARMCOUNT( 1, VM_M_getserverlistindexforkey );
620 key = PRVM_G_STRING( OFS_PARM0 );
621 VM_CheckEmptyString( prog, key );
623 if( !strcmp( key, "cname" ) )
624 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CNAME;
625 else if( !strcmp( key, "ping" ) )
626 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PING;
627 else if( !strcmp( key, "game" ) )
628 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_GAME;
629 else if( !strcmp( key, "mod" ) )
630 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MOD;
631 else if( !strcmp( key, "map" ) )
632 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAP;
633 else if( !strcmp( key, "name" ) )
634 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NAME;
635 else if( !strcmp( key, "qcstatus" ) )
636 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_QCSTATUS;
637 else if( !strcmp( key, "players" ) )
638 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PLAYERS;
639 else if( !strcmp( key, "maxplayers" ) )
640 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS;
641 else if( !strcmp( key, "numplayers" ) )
642 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS;
643 else if( !strcmp( key, "numbots" ) )
644 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMBOTS;
645 else if( !strcmp( key, "numhumans" ) )
646 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMHUMANS;
647 else if( !strcmp( key, "freeslots" ) )
648 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_FREESLOTS;
649 else if( !strcmp( key, "protocol" ) )
650 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
651 else if( !strcmp( key, "category" ) )
652 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CATEGORY;
653 else if( !strcmp( key, "isfavorite" ) )
654 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_ISFAVORITE;
656 PRVM_G_FLOAT( OFS_RETURN ) = -1;
660 ========================
661 VM_M_addwantedserverlistkey
663 addwantedserverlistkey(string key)
664 ========================
666 static void VM_M_addwantedserverlistkey(prvm_prog_t *prog)
668 VM_SAFEPARMCOUNT( 1, VM_M_addwantedserverlistkey );
672 ===============================================================================
675 used only for client and menu
676 server uses VM_SV_...
678 Write*(* data, float type, float to)
680 ===============================================================================
683 #define MSG_BROADCAST 0 // unreliable to all
684 #define MSG_ONE 1 // reliable to one (msg_entity)
685 #define MSG_ALL 2 // reliable to all
686 #define MSG_INIT 3 // write to the init string
688 static sizebuf_t *VM_M_WriteDest (prvm_prog_t *prog)
694 prog->error_cmd("VM_M_WriteDest: game is not server (%s)", prog->name);
696 dest = (int)PRVM_G_FLOAT(OFS_PARM1);
703 destclient = (int) PRVM_G_FLOAT(OFS_PARM2);
704 if (destclient < 0 || destclient >= svs.maxclients || !svs.clients[destclient].active || !svs.clients[destclient].netconnection)
705 prog->error_cmd("VM_clientcommand: %s: invalid client !", prog->name);
707 return &svs.clients[destclient].netconnection->message;
710 return &sv.reliable_datagram;
716 prog->error_cmd("WriteDest: bad destination");
723 static void VM_M_WriteByte (prvm_prog_t *prog)
725 VM_SAFEPARMCOUNT(1, VM_M_WriteByte);
726 MSG_WriteByte (VM_M_WriteDest(prog), (int)PRVM_G_FLOAT(OFS_PARM0));
729 static void VM_M_WriteChar (prvm_prog_t *prog)
731 VM_SAFEPARMCOUNT(1, VM_M_WriteChar);
732 MSG_WriteChar (VM_M_WriteDest(prog), (int)PRVM_G_FLOAT(OFS_PARM0));
735 static void VM_M_WriteShort (prvm_prog_t *prog)
737 VM_SAFEPARMCOUNT(1, VM_M_WriteShort);
738 MSG_WriteShort (VM_M_WriteDest(prog), (int)PRVM_G_FLOAT(OFS_PARM0));
741 static void VM_M_WriteLong (prvm_prog_t *prog)
743 VM_SAFEPARMCOUNT(1, VM_M_WriteLong);
744 MSG_WriteLong (VM_M_WriteDest(prog), (int)PRVM_G_FLOAT(OFS_PARM0));
747 static void VM_M_WriteAngle (prvm_prog_t *prog)
749 VM_SAFEPARMCOUNT(1, VM_M_WriteAngle);
750 MSG_WriteAngle (VM_M_WriteDest(prog), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
753 static void VM_M_WriteCoord (prvm_prog_t *prog)
755 VM_SAFEPARMCOUNT(1, VM_M_WriteCoord);
756 MSG_WriteCoord (VM_M_WriteDest(prog), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
759 static void VM_M_WriteString (prvm_prog_t *prog)
761 VM_SAFEPARMCOUNT(1, VM_M_WriteString);
762 MSG_WriteString (VM_M_WriteDest(prog), PRVM_G_STRING(OFS_PARM0));
765 static void VM_M_WriteEntity (prvm_prog_t *prog)
767 VM_SAFEPARMCOUNT(1, VM_M_WriteEntity);
768 MSG_WriteShort (VM_M_WriteDest(prog), PRVM_G_EDICTNUM(OFS_PARM0));
775 copies data from one entity to another
777 copyentity(entity src, entity dst)
780 static void VM_M_copyentity (prvm_prog_t *prog)
782 prvm_edict_t *in, *out;
783 VM_SAFEPARMCOUNT(2,VM_M_copyentity);
784 in = PRVM_G_EDICT(OFS_PARM0);
785 out = PRVM_G_EDICT(OFS_PARM1);
786 memcpy(out->fields.fp, in->fields.fp, prog->entityfields * sizeof(prvm_vec_t));
789 //#66 vector() getmousepos (EXT_CSQC)
790 static void VM_M_getmousepos(prvm_prog_t *prog)
792 VM_SAFEPARMCOUNT(0,VM_M_getmousepos);
794 if (key_consoleactive || (key_dest != key_menu && key_dest != key_menu_grabbed))
795 VectorSet(PRVM_G_VECTOR(OFS_RETURN), 0, 0, 0);
796 else if (in_client_mouse)
797 VectorSet(PRVM_G_VECTOR(OFS_RETURN), in_windowmouse_x * vid_conwidth.integer / vid.width, in_windowmouse_y * vid_conheight.integer / vid.height, 0);
799 VectorSet(PRVM_G_VECTOR(OFS_RETURN), in_mouse_x * vid_conwidth.integer / vid.width, in_mouse_y * vid_conheight.integer / vid.height, 0);
802 static void VM_M_crypto_getkeyfp(prvm_prog_t *prog)
806 char keyfp[FP64_SIZE + 1];
808 VM_SAFEPARMCOUNT(1,VM_M_crypto_getkeyfp);
810 s = PRVM_G_STRING( OFS_PARM0 );
811 VM_CheckEmptyString( prog, s );
813 if(LHNETADDRESS_FromString(&addr, s, 26000) && Crypto_RetrieveHostKey(&addr, NULL, keyfp, sizeof(keyfp), NULL, 0, NULL, NULL))
814 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, keyfp );
816 PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
818 static void VM_M_crypto_getidfp(prvm_prog_t *prog)
822 char idfp[FP64_SIZE + 1];
824 VM_SAFEPARMCOUNT(1,VM_M_crypto_getidfp);
826 s = PRVM_G_STRING( OFS_PARM0 );
827 VM_CheckEmptyString( prog, s );
829 if(LHNETADDRESS_FromString(&addr, s, 26000) && Crypto_RetrieveHostKey(&addr, NULL, NULL, 0, idfp, sizeof(idfp), NULL, NULL))
830 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, idfp );
832 PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
834 static void VM_M_crypto_getidstatus(prvm_prog_t *prog)
840 VM_SAFEPARMCOUNT(1,VM_M_crypto_getidstatus);
842 s = PRVM_G_STRING( OFS_PARM0 );
843 VM_CheckEmptyString( prog, s );
845 if(LHNETADDRESS_FromString(&addr, s, 26000) && Crypto_RetrieveHostKey(&addr, NULL, NULL, 0, NULL, 0, NULL, &issigned))
846 PRVM_G_FLOAT( OFS_RETURN ) = issigned ? 2 : 1;
848 PRVM_G_FLOAT( OFS_RETURN ) = 0;
850 static void VM_M_crypto_getencryptlevel(prvm_prog_t *prog)
857 VM_SAFEPARMCOUNT(1,VM_M_crypto_getencryptlevel);
859 s = PRVM_G_STRING( OFS_PARM0 );
860 VM_CheckEmptyString( prog, s );
862 if(LHNETADDRESS_FromString(&addr, s, 26000) && Crypto_RetrieveHostKey(&addr, NULL, NULL, 0, NULL, 0, &aeslevel, NULL))
863 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, aeslevel ? va(vabuf, sizeof(vabuf), "%d AES128", aeslevel) : "0");
865 PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
867 static void VM_M_crypto_getmykeyfp(prvm_prog_t *prog)
870 char keyfp[FP64_SIZE + 1];
872 VM_SAFEPARMCOUNT(1, VM_M_crypto_getmykeyfp);
874 i = PRVM_G_FLOAT( OFS_PARM0 );
875 switch(Crypto_RetrieveLocalKey(i, keyfp, sizeof(keyfp), NULL, 0, NULL))
878 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, "");
881 PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
885 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, keyfp);
889 static void VM_M_crypto_getmyidfp(prvm_prog_t *prog)
892 char idfp[FP64_SIZE + 1];
894 VM_SAFEPARMCOUNT(1, VM_M_crypto_getmyidfp);
896 i = PRVM_G_FLOAT( OFS_PARM0 );
897 switch(Crypto_RetrieveLocalKey(i, NULL, 0, idfp, sizeof(idfp), NULL))
900 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, "");
903 PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
907 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, idfp);
911 static void VM_M_crypto_getmyidstatus(prvm_prog_t *prog)
916 VM_SAFEPARMCOUNT(1, VM_M_crypto_getmyidstatus);
918 i = PRVM_G_FLOAT( OFS_PARM0 );
919 switch(Crypto_RetrieveLocalKey(i, NULL, 0, NULL, 0, &issigned))
922 PRVM_G_FLOAT( OFS_RETURN ) = 0; // have no ID there
925 PRVM_G_FLOAT( OFS_RETURN ) = -1; // out of range
929 PRVM_G_FLOAT( OFS_RETURN ) = issigned ? 2 : 1;
934 prvm_builtin_t vm_m_builtins[] = {
935 NULL, // #0 NULL function (not callable)
936 VM_checkextension, // #1
942 VM_centerprint, // #7
946 VM_vectoangles, // #11
948 VM_localcmd_client, // #13
962 VM_findchainfloat, // #27
963 VM_precache_file, // #28
964 VM_precache_sound, // #29
977 VM_registercvar, // #42
982 VM_M_copyentity, // #47
996 VM_clientcount, // #61
997 VM_clientstate, // #62
999 VM_changelevel, // #64
1000 VM_localsound, // #65
1001 VM_M_getmousepos, // #66
1003 VM_loadfromdata, // #68
1004 VM_loadfromfile, // #69
1006 VM_cvar_string, // #71
1008 VM_stackdump, // #73
1009 VM_search_begin, // #74
1010 VM_search_end, // #75
1011 VM_search_getsize, // #76
1012 VM_search_getfilename, // #77
1016 VM_itof, // #81 isString
1017 VM_altstr_count, // #82
1018 VM_altstr_prepare, // #83
1019 VM_altstr_get, // #84
1020 VM_altstr_set, // #85
1021 VM_altstr_ins, // #86
1022 VM_findflags, // #87
1023 VM_findchainflags, // #88
1024 VM_cvar_defstring, // #89
1025 // deactivate support for model rendering in the menu until someone has time to do it right [3/2/2008 Andreas]
1027 VM_CL_setmodel, // #90 void(entity e, string m) setmodel (QUAKE)
1028 VM_CL_precache_model, // #91 void(string s) precache_model (QUAKE)
1029 VM_CL_setorigin, // #92 void(entity e, vector o) setorigin (QUAKE)
1163 VM_strstrofs, // #221 float(string str, string sub[, float startpos]) strstrofs (FTE_STRINGS)
1164 VM_str2chr, // #222 float(string str, float ofs) str2chr (FTE_STRINGS)
1165 VM_chr2str, // #223 string(float c, ...) chr2str (FTE_STRINGS)
1166 VM_strconv, // #224 string(float ccase, float calpha, float cnum, string s, ...) strconv (FTE_STRINGS)
1167 VM_strpad, // #225 string(float chars, string s, ...) strpad (FTE_STRINGS)
1168 VM_infoadd, // #226 string(string info, string key, string value, ...) infoadd (FTE_STRINGS)
1169 VM_infoget, // #227 string(string info, string key) infoget (FTE_STRINGS)
1170 VM_strncmp, // #228 float(string s1, string s2, float len) strncmp (FTE_STRINGS)
1171 VM_strncasecmp, // #229 float(string s1, string s2) strcasecmp (FTE_STRINGS)
1172 VM_strncasecmp, // #230 float(string s1, string s2, float len) strncasecmp (FTE_STRINGS)
1242 // deactivate support for model rendering in the menu until someone has time to do it right [3/2/2008 Andreas]
1244 // CSQC range #300-#399
1245 VM_CL_R_ClearScene, // #300 void() clearscene (DP_QC_RENDER_SCENE)
1246 VM_CL_R_AddEntities, // #301 void(float mask) addentities (DP_QC_RENDER_SCENE)
1247 VM_CL_R_AddEntity, // #302 void(entity ent) addentity (DP_QC_RENDER_SCENE)
1248 VM_CL_R_SetView, // #303 float(float property, ...) setproperty (DP_QC_RENDER_SCENE)
1249 VM_CL_R_RenderScene, // #304 void() renderscene (DP_QC_RENDER_SCENE)
1250 VM_CL_R_AddDynamicLight, // #305 void(vector org, float radius, vector lightcolours) adddynamiclight (DP_QC_RENDER_SCENE)
1251 VM_CL_R_PolygonBegin, // #306 void(string texturename, float flag[, float is2d, float lines]) R_BeginPolygon (DP_QC_RENDER_SCENE)
1252 VM_CL_R_PolygonVertex, // #307 void(vector org, vector texcoords, vector rgb, float alpha) R_PolygonVertex (DP_QC_RENDER_SCENE)
1253 VM_CL_R_PolygonEnd, // #308 void() R_EndPolygon
1254 NULL/*VM_CL_R_LoadWorldModel*/, // #309 void(string modelname) R_LoadWorldModel
1255 // TODO: rearrange and merge all builtin lists and share as many extensions as possible between all VM instances [1/27/2008 Andreas]
1256 VM_CL_setattachment, // #310 void(entity e, entity tagentity, string tagname) setattachment (DP_GFX_QUAKE3MODELTAGS) (DP_QC_RENDER_SCENE)
1257 VM_CL_gettagindex, // #311 float(entity ent, string tagname) gettagindex (DP_QC_GETTAGINFO) (DP_QC_RENDER_SCENE)
1258 VM_CL_gettaginfo, // #312 vector(entity ent, float tagindex) gettaginfo (DP_QC_GETTAGINFO) (DP_QC_RENDER_SCENE)
1260 // CSQC range #300-#399
1302 VM_keynumtostring, // #340 string keynumtostring(float keynum)
1303 VM_stringtokeynum, // #341 float stringtokeynum(string key)
1304 VM_getkeybind, // #342 string(float keynum[, float bindmap]) getkeybind (EXT_CSQC)
1311 VM_CL_isdemo, // #349
1315 VM_wasfreed, // #353 float(entity ent) wasfreed
1317 VM_CL_videoplaying, // #355
1318 VM_findfont, // #356 float(string fontname) loadfont (DP_GFX_FONTS)
1319 VM_loadfont, // #357 float(string fontname, string fontmaps, string sizes, float slot) loadfont (DP_GFX_FONTS)
1363 VM_M_WriteByte, // #401
1364 VM_M_WriteChar, // #402
1365 VM_M_WriteShort, // #403
1366 VM_M_WriteLong, // #404
1367 VM_M_WriteAngle, // #405
1368 VM_M_WriteCoord, // #406
1369 VM_M_WriteString, // #407
1370 VM_M_WriteEntity, // #408
1402 VM_buf_create, // #440 float() buf_create (DP_QC_STRINGBUFFERS)
1403 VM_buf_del, // #441 void(float bufhandle) buf_del (DP_QC_STRINGBUFFERS)
1404 VM_buf_getsize, // #442 float(float bufhandle) buf_getsize (DP_QC_STRINGBUFFERS)
1405 VM_buf_copy, // #443 void(float bufhandle_from, float bufhandle_to) buf_copy (DP_QC_STRINGBUFFERS)
1406 VM_buf_sort, // #444 void(float bufhandle, float sortpower, float backward) buf_sort (DP_QC_STRINGBUFFERS)
1407 VM_buf_implode, // #445 string(float bufhandle, string glue) buf_implode (DP_QC_STRINGBUFFERS)
1408 VM_bufstr_get, // #446 string(float bufhandle, float string_index) bufstr_get (DP_QC_STRINGBUFFERS)
1409 VM_bufstr_set, // #447 void(float bufhandle, float string_index, string str) bufstr_set (DP_QC_STRINGBUFFERS)
1410 VM_bufstr_add, // #448 float(float bufhandle, string str, float order) bufstr_add (DP_QC_STRINGBUFFERS)
1411 VM_bufstr_free, // #449 void(float bufhandle, float string_index) bufstr_free (DP_QC_STRINGBUFFERS)
1413 VM_iscachedpic, // #451 draw functions...
1414 VM_precache_pic, // #452
1416 VM_drawcharacter, // #454
1417 VM_drawstring, // #455
1419 VM_drawfill, // #457
1420 VM_drawsetcliparea, // #458
1421 VM_drawresetcliparea, // #459
1422 VM_getimagesize, // #460
1423 VM_cin_open, // #461
1424 VM_cin_close, // #462
1425 VM_cin_setstate, // #463
1426 VM_cin_getstate, // #464
1427 VM_cin_restart, // #465
1428 VM_drawline, // #466
1429 VM_drawcolorcodedstring, // #467
1430 VM_stringwidth, // #468
1431 VM_drawsubpic, // #469
1432 VM_drawrotpic, // #470
1433 VM_asin, // #471 float(float s) VM_asin (DP_QC_ASINACOSATANATAN2TAN)
1434 VM_acos, // #472 float(float c) VM_acos (DP_QC_ASINACOSATANATAN2TAN)
1435 VM_atan, // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
1436 VM_atan2, // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
1437 VM_tan, // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
1438 VM_strlennocol, // #476 float(string s) : DRESK - String Length (not counting color codes) (DP_QC_STRINGCOLORFUNCTIONS)
1439 VM_strdecolorize, // #477 string(string s) : DRESK - Decolorized String (DP_QC_STRINGCOLORFUNCTIONS)
1440 VM_strftime, // #478 string(float uselocaltime, string format, ...) (DP_QC_STRFTIME)
1441 VM_tokenizebyseparator, // #479 float(string s) tokenizebyseparator (DP_QC_TOKENIZEBYSEPARATOR)
1442 VM_strtolower, // #480 string(string s) VM_strtolower : DRESK - Return string as lowercase
1443 VM_strtoupper, // #481 string(string s) VM_strtoupper : DRESK - Return string as uppercase
1446 VM_strreplace, // #484 string(string search, string replace, string subject) strreplace (DP_QC_STRREPLACE)
1447 VM_strireplace, // #485 string(string search, string replace, string subject) strireplace (DP_QC_STRREPLACE)
1449 VM_gecko_create, // #487 float gecko_create( string name )
1450 VM_gecko_destroy, // #488 void gecko_destroy( string name )
1451 VM_gecko_navigate, // #489 void gecko_navigate( string name, string URI )
1452 VM_gecko_keyevent, // #490 float gecko_keyevent( string name, float key, float eventtype )
1453 VM_gecko_movemouse, // #491 void gecko_mousemove( string name, float x, float y )
1454 VM_gecko_resize, // #492 void gecko_resize( string name, float w, float h )
1455 VM_gecko_get_texture_extent, // #493 vector gecko_get_texture_extent( string name )
1456 VM_crc16, // #494 float(float caseinsensitive, string s, ...) crc16 = #494 (DP_QC_CRC16)
1457 VM_cvar_type, // #495 float(string name) cvar_type = #495; (DP_QC_CVAR_TYPE)
1458 VM_numentityfields, // #496 float() numentityfields = #496; (QP_QC_ENTITYDATA)
1459 VM_entityfieldname, // #497 string(float fieldnum) entityfieldname = #497; (DP_QC_ENTITYDATA)
1460 VM_entityfieldtype, // #498 float(float fieldnum) entityfieldtype = #498; (DP_QC_ENTITYDATA)
1461 VM_getentityfieldstring, // #499 string(float fieldnum, entity ent) getentityfieldstring = #499; (DP_QC_ENTITYDATA)
1462 VM_putentityfieldstring, // #500 float(float fieldnum, entity ent, string s) putentityfieldstring = #500; (DP_QC_ENTITYDATA)
1465 VM_whichpack, // #503 string(string) whichpack = #503;
1472 VM_uri_escape, // #510 string(string in) uri_escape = #510;
1473 VM_uri_unescape, // #511 string(string in) uri_unescape = #511;
1474 VM_etof, // #512 float(entity ent) num_for_edict = #512 (DP_QC_NUM_FOR_EDICT)
1475 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)
1476 VM_tokenize_console, // #514 float(string str) tokenize_console = #514; (DP_QC_TOKENIZE_CONSOLE)
1477 VM_argv_start_index, // #515 float(float idx) argv_start_index = #515; (DP_QC_TOKENIZE_CONSOLE)
1478 VM_argv_end_index, // #516 float(float idx) argv_end_index = #516; (DP_QC_TOKENIZE_CONSOLE)
1479 VM_buf_cvarlist, // #517 void(float buf, string prefix, string antiprefix) buf_cvarlist = #517; (DP_QC_STRINGBUFFERS_CVARLIST)
1480 VM_cvar_description, // #518 float(string name) cvar_description = #518; (DP_QC_CVAR_DESCRIPTION)
1495 VM_getsoundtime, // #533 float(entity e, float channel) getsoundtime = #533; (DP_SND_GETSOUNDTIME)
1496 VM_soundlength, // #534 float(string sample) soundlength = #534; (DP_SND_GETSOUNDTIME)
1497 VM_buf_loadfile, // #535 float(string filename, float bufhandle) buf_loadfile (DP_QC_STRINGBUFFERS_EXT_WIP)
1498 VM_buf_writefile, // #536 float(float filehandle, float bufhandle, float startpos, float numstrings) buf_writefile (DP_QC_STRINGBUFFERS_EXT_WIP)
1499 VM_bufstr_find, // #537 float(float bufhandle, string match, float matchrule, float startpos) bufstr_find (DP_QC_STRINGBUFFERS_EXT_WIP)
1500 VM_matchpattern, // #538 float(string s, string pattern, float matchrule) matchpattern (DP_QC_STRINGBUFFERS_EXT_WIP)
1563 VM_M_setkeydest, // #601 void setkeydest(float dest)
1564 VM_M_getkeydest, // #602 float getkeydest(void)
1565 VM_M_setmousetarget, // #603 void setmousetarget(float trg)
1566 VM_M_getmousetarget, // #604 float getmousetarget(void)
1567 VM_callfunction, // #605 void callfunction(...)
1568 VM_writetofile, // #606 void writetofile(float fhandle, entity ent)
1569 VM_isfunction, // #607 float isfunction(string function_name)
1570 VM_M_getresolution, // #608 vector getresolution(float number, [float forfullscreen])
1571 VM_keynumtostring, // #609 string keynumtostring(float keynum)
1572 VM_findkeysforcommand, // #610 string findkeysforcommand(string command[, float bindmap])
1573 VM_M_getserverliststat, // #611 float gethostcachevalue(float type)
1574 VM_M_getserverliststring, // #612 string gethostcachestring(float type, float hostnr)
1575 VM_parseentitydata, // #613 void parseentitydata(entity ent, string data)
1576 VM_stringtokeynum, // #614 float stringtokeynum(string key)
1577 VM_M_resetserverlistmasks, // #615 void resethostcachemasks(void)
1578 VM_M_setserverlistmaskstring, // #616 void sethostcachemaskstring(float mask, float fld, string str, float op)
1579 VM_M_setserverlistmasknumber, // #617 void sethostcachemasknumber(float mask, float fld, float num, float op)
1580 VM_M_resortserverlist, // #618 void resorthostcache(void)
1581 VM_M_setserverlistsort, // #619 void sethostcachesort(float fld, float descending)
1582 VM_M_refreshserverlist, // #620 void refreshhostcache(void)
1583 VM_M_getserverlistnumber, // #621 float gethostcachenumber(float fld, float hostnr)
1584 VM_M_getserverlistindexforkey,// #622 float gethostcacheindexforkey(string key)
1585 VM_M_addwantedserverlistkey, // #623 void addwantedhostcachekey(string key)
1586 VM_CL_getextresponse, // #624 string getextresponse(void)
1587 VM_netaddress_resolve, // #625 string netaddress_resolve(string, float)
1588 VM_M_getgamedirinfo, // #626 string getgamedirinfo(float n, float prop)
1589 VM_sprintf, // #627 string sprintf(string format, ...)
1592 VM_setkeybind, // #630 float(float key, string bind[, float bindmap]) setkeybind
1593 VM_getbindmaps, // #631 vector(void) getbindmap
1594 VM_setbindmaps, // #632 float(vector bm) setbindmap
1595 VM_M_crypto_getkeyfp, // #633 string(string addr) crypto_getkeyfp
1596 VM_M_crypto_getidfp, // #634 string(string addr) crypto_getidfp
1597 VM_M_crypto_getencryptlevel, // #635 string(string addr) crypto_getencryptlevel
1598 VM_M_crypto_getmykeyfp, // #636 string(float addr) crypto_getmykeyfp
1599 VM_M_crypto_getmyidfp, // #637 string(float addr) crypto_getmyidfp
1601 VM_digest_hex, // #639
1603 VM_M_crypto_getmyidstatus, // #641 float(float i) crypto_getmyidstatus
1604 VM_coverage, // #642
1605 VM_M_crypto_getidstatus, // #643 float(string addr) crypto_getidstatus
1609 const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);
1611 void MVM_init_cmd(prvm_prog_t *prog)
1613 r_refdef_scene_t *scene;
1616 prog->polygonbegin_model = NULL;
1617 prog->polygonbegin_guess2d = 0;
1619 scene = R_GetScenePointer( RST_MENU );
1621 memset (scene, 0, sizeof (*scene));
1623 scene->maxtempentities = 128;
1624 scene->tempentities = (entity_render_t*) Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t) * scene->maxtempentities);
1626 scene->maxentities = MAX_EDICTS + 256 + 512;
1627 scene->entities = (entity_render_t **)Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t *) * scene->maxentities);
1629 // LadyHavoc: what is this for?
1630 scene->ambientintensity = 32.0f;
1633 void MVM_reset_cmd(prvm_prog_t *prog)
1635 // note: the menu's render entities are automatically freed when the prog's pool is freed
1639 prog->polygonbegin_model = NULL;
1640 prog->polygonbegin_guess2d = 0;