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",
52 "DP_QC_FS_SEARCH_PACKFILE",
56 qbool MP_ConsoleCommand(const char *text)
58 prvm_prog_t *prog = MVM_prog;
59 return PRVM_ConsoleCommand(prog, text, &prog->funcoffsets.GameCommand, false, -1, 0, prog->loaded, "QC function GameCommand is missing");
66 setmousetarget(float target)
69 static void VM_M_setmousetarget(prvm_prog_t *prog)
71 VM_SAFEPARMCOUNT(1, VM_M_setmousetarget);
73 switch((int)PRVM_G_FLOAT(OFS_PARM0))
76 in_client_mouse = false;
79 in_client_mouse = true;
82 prog->error_cmd("VM_M_setmousetarget: wrong destination %f !",PRVM_G_FLOAT(OFS_PARM0));
93 static void VM_M_getmousetarget(prvm_prog_t *prog)
95 VM_SAFEPARMCOUNT(0,VM_M_getmousetarget);
98 PRVM_G_FLOAT(OFS_RETURN) = 2;
100 PRVM_G_FLOAT(OFS_RETURN) = 1;
109 setkeydest(float dest)
112 static void VM_M_setkeydest(prvm_prog_t *prog)
114 VM_SAFEPARMCOUNT(1,VM_M_setkeydest);
116 switch((int)PRVM_G_FLOAT(OFS_PARM0))
128 key_dest = key_menu_grabbed;
132 // key_dest = key_message
135 prog->error_cmd("VM_M_setkeydest: wrong destination %f !", PRVM_G_FLOAT(OFS_PARM0));
146 static void VM_M_getkeydest(prvm_prog_t *prog)
148 VM_SAFEPARMCOUNT(0,VM_M_getkeydest);
150 // key_game = 0, key_message = 1, key_menu = 2, key_menu_grabbed = 3, unknown = -1
154 PRVM_G_FLOAT(OFS_RETURN) = 0;
157 PRVM_G_FLOAT(OFS_RETURN) = 2;
159 case key_menu_grabbed:
160 PRVM_G_FLOAT(OFS_RETURN) = 3;
164 // PRVM_G_FLOAT(OFS_RETURN) = 1;
167 PRVM_G_FLOAT(OFS_RETURN) = -1;
176 vector getresolution(float number)
179 static void VM_M_getresolution(prvm_prog_t *prog)
182 VM_SAFEPARMCOUNTRANGE(1, 2, VM_M_getresolution);
184 nr = (int)PRVM_G_FLOAT(OFS_PARM0);
186 fs = ((prog->argc <= 1) || ((int)PRVM_G_FLOAT(OFS_PARM1)));
188 if(nr < -1 || nr >= (fs ? video_resolutions_count : video_resolutions_hardcoded_count))
190 PRVM_G_VECTOR(OFS_RETURN)[0] = 0;
191 PRVM_G_VECTOR(OFS_RETURN)[1] = 0;
192 PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
196 vid_mode_t m = VID_GetDesktopMode();
197 PRVM_G_VECTOR(OFS_RETURN)[0] = m.width;
198 PRVM_G_VECTOR(OFS_RETURN)[1] = m.height;
199 PRVM_G_VECTOR(OFS_RETURN)[2] = m.pixelheight_num / (prvm_vec_t) m.pixelheight_denom;
203 video_resolution_t *r = &((fs ? video_resolutions : video_resolutions_hardcoded)[nr]);
204 PRVM_G_VECTOR(OFS_RETURN)[0] = r->width;
205 PRVM_G_VECTOR(OFS_RETURN)[1] = r->height;
206 PRVM_G_VECTOR(OFS_RETURN)[2] = r->pixelheight;
210 static void VM_M_getgamedirinfo(prvm_prog_t *prog)
213 VM_SAFEPARMCOUNT(2, VM_getgamedirinfo);
215 nr = (int)PRVM_G_FLOAT(OFS_PARM0);
216 item = (int)PRVM_G_FLOAT(OFS_PARM1);
218 PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
220 if(nr >= 0 && nr < fs_all_gamedirs_count)
223 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, fs_all_gamedirs[nr].name );
225 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, fs_all_gamedirs[nr].description );
231 VM_M_getserverliststat
233 float getserverliststat(float type)
238 0 serverlist_viewcount
239 1 serverlist_totalcount
247 static void VM_M_getserverliststat(prvm_prog_t *prog)
250 VM_SAFEPARMCOUNT ( 1, VM_M_getserverliststat );
252 PRVM_G_FLOAT( OFS_RETURN ) = 0;
254 type = (int)PRVM_G_FLOAT( OFS_PARM0 );
258 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_viewcount;
261 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_cachecount;
264 PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount;
267 PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
270 PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
273 PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
276 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortbyfield;
279 PRVM_G_FLOAT ( OFS_RETURN ) = serverlist_sortflags;
282 VM_Warning(prog, "VM_M_getserverliststat: bad type %i!\n", type );
287 ========================
288 VM_M_resetserverlistmasks
290 resetserverlistmasks()
291 ========================
293 static void VM_M_resetserverlistmasks(prvm_prog_t *prog)
295 VM_SAFEPARMCOUNT(0, VM_M_resetserverlistmasks);
296 ServerList_ResetMasks();
301 ========================
302 VM_M_setserverlistmaskstring
304 setserverlistmaskstring(float mask, float fld, string str, float op)
307 ========================
309 static void VM_M_setserverlistmaskstring(prvm_prog_t *prog)
313 serverlist_mask_t *mask;
316 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmaskstring );
317 str = PRVM_G_STRING( OFS_PARM2 );
319 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
320 if( masknr >= 0 && masknr < SERVERLIST_ANDMASKCOUNT )
321 mask = &serverlist_andmasks[masknr];
322 else if( masknr >= 512 && masknr - 512 < SERVERLIST_ORMASKCOUNT )
323 mask = &serverlist_ormasks[masknr - 512 ];
326 VM_Warning(prog, "VM_M_setserverlistmaskstring: invalid mask number %i\n", masknr );
330 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
334 dp_strlcpy( mask->info.cname, str, sizeof(mask->info.cname) );
337 dp_strlcpy( mask->info.name, str, sizeof(mask->info.name) );
340 dp_strlcpy( mask->info.qcstatus, str, sizeof(mask->info.qcstatus) );
343 dp_strlcpy( mask->info.players, str, sizeof(mask->info.players) );
346 dp_strlcpy( mask->info.map, str, sizeof(mask->info.map) );
349 dp_strlcpy( mask->info.mod, str, sizeof(mask->info.mod) );
352 dp_strlcpy( mask->info.game, str, sizeof(mask->info.game) );
355 VM_Warning(prog, "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
360 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
364 ========================
365 VM_M_setserverlistmasknumber
367 setserverlistmasknumber(float mask, float fld, float num, float op)
371 ========================
373 static void VM_M_setserverlistmasknumber(prvm_prog_t *prog)
376 serverlist_mask_t *mask;
379 VM_SAFEPARMCOUNT( 4, VM_M_setserverlistmasknumber );
381 masknr = (int)PRVM_G_FLOAT( OFS_PARM0 );
382 if( masknr >= 0 && masknr < SERVERLIST_ANDMASKCOUNT )
383 mask = &serverlist_andmasks[masknr];
384 else if( masknr >= 512 && masknr - 512 < SERVERLIST_ORMASKCOUNT )
385 mask = &serverlist_ormasks[masknr - 512 ];
388 VM_Warning(prog, "VM_M_setserverlistmasknumber: invalid mask number %i\n", masknr );
392 number = (int)PRVM_G_FLOAT( OFS_PARM2 );
393 field = (int) PRVM_G_FLOAT( OFS_PARM1 );
396 case SLIF_MAXPLAYERS:
397 mask->info.maxplayers = number;
399 case SLIF_NUMPLAYERS:
400 mask->info.numplayers = number;
403 mask->info.numbots = number;
406 mask->info.numhumans = number;
409 mask->info.ping = number;
412 mask->info.protocol = number;
415 mask->info.freeslots = number;
418 mask->info.category = number;
420 case SLIF_ISFAVORITE:
421 mask->info.isfavorite = number != 0;
424 VM_Warning(prog, "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
429 mask->tests[field] = (serverlist_maskop_t)((int)PRVM_G_FLOAT( OFS_PARM3 ));
434 ========================
435 VM_M_resortserverlist
438 ========================
440 static void VM_M_resortserverlist(prvm_prog_t *prog)
442 VM_SAFEPARMCOUNT(0, VM_M_resortserverlist);
443 ServerList_RebuildViewList(NULL);
448 VM_M_getserverliststring
450 string getserverliststring(float field, float hostnr)
453 static void VM_M_getserverliststring(prvm_prog_t *prog)
455 const serverlist_entry_t *cache;
458 VM_SAFEPARMCOUNT(2, VM_M_getserverliststring);
460 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
462 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
464 if(hostnr == -1 && serverlist_callbackentry)
466 cache = serverlist_callbackentry;
470 if(hostnr < 0 || (unsigned)hostnr >= serverlist_viewcount)
472 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
475 cache = ServerList_GetViewEntry(hostnr);
477 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
479 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.cname );
482 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.name );
485 PRVM_G_INT (OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.qcstatus );
488 PRVM_G_INT (OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.players );
491 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.game );
494 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.mod );
497 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.map );
499 // TODO remove this again
501 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->line1 );
504 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->line2 );
507 Con_Print("VM_M_getserverliststring: bad field number passed!\n");
513 VM_M_getserverlistnumber
515 float getserverlistnumber(float field, float hostnr)
518 static void VM_M_getserverlistnumber(prvm_prog_t *prog)
520 const serverlist_entry_t *cache;
523 VM_SAFEPARMCOUNT(2, VM_M_getserverlistnumber);
525 PRVM_G_INT(OFS_RETURN) = OFS_NULL;
527 hostnr = (int)PRVM_G_FLOAT(OFS_PARM1);
529 if(hostnr == -1 && serverlist_callbackentry)
531 cache = serverlist_callbackentry;
535 if(hostnr < 0 || (unsigned)hostnr >= serverlist_viewcount)
537 Con_Print("VM_M_getserverliststring: bad hostnr passed!\n");
540 cache = ServerList_GetViewEntry(hostnr);
542 switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
543 case SLIF_MAXPLAYERS:
544 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.maxplayers;
546 case SLIF_NUMPLAYERS:
547 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numplayers;
550 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numbots;
553 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numhumans;
556 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.freeslots;
559 // display inf when a listed server times out and net_slist_pause blocks its removal
560 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping ?: INFINITY;
563 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.protocol;
566 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.category;
568 case SLIF_ISFAVORITE:
569 PRVM_G_FLOAT( OFS_RETURN ) = cache->info.isfavorite;
572 Con_Print("VM_M_getserverlistnumber: bad field number passed!\n");
577 ========================
578 VM_M_setserverlistsort
580 setserverlistsort(float field, float flags)
581 ========================
583 static void VM_M_setserverlistsort(prvm_prog_t *prog)
585 VM_SAFEPARMCOUNT( 2, VM_M_setserverlistsort );
587 serverlist_sortbyfield = (serverlist_infofield_t)((int)PRVM_G_FLOAT( OFS_PARM0 ));
588 serverlist_sortflags = (int) PRVM_G_FLOAT( OFS_PARM1 );
592 ========================
593 VM_M_refreshserverlist
596 ========================
598 static void VM_M_refreshserverlist(prvm_prog_t *prog)
600 qbool do_reset = false;
601 VM_SAFEPARMCOUNTRANGE( 0, 1, VM_M_refreshserverlist );
602 if (prog->argc >= 1 && PRVM_G_FLOAT(OFS_PARM0))
604 ServerList_QueryList(do_reset, true, false, false);
608 ========================
609 VM_M_getserverlistindexforkey
611 float getserverlistindexforkey(string key)
612 ========================
614 static void VM_M_getserverlistindexforkey(prvm_prog_t *prog)
617 VM_SAFEPARMCOUNT( 1, VM_M_getserverlistindexforkey );
619 key = PRVM_G_STRING( OFS_PARM0 );
620 VM_CheckEmptyString( prog, key );
622 if( !strcmp( key, "cname" ) )
623 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CNAME;
624 else if( !strcmp( key, "ping" ) )
625 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PING;
626 else if( !strcmp( key, "game" ) )
627 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_GAME;
628 else if( !strcmp( key, "mod" ) )
629 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MOD;
630 else if( !strcmp( key, "map" ) )
631 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAP;
632 else if( !strcmp( key, "name" ) )
633 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NAME;
634 else if( !strcmp( key, "qcstatus" ) )
635 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_QCSTATUS;
636 else if( !strcmp( key, "players" ) )
637 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PLAYERS;
638 else if( !strcmp( key, "maxplayers" ) )
639 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS;
640 else if( !strcmp( key, "numplayers" ) )
641 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS;
642 else if( !strcmp( key, "numbots" ) )
643 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMBOTS;
644 else if( !strcmp( key, "numhumans" ) )
645 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMHUMANS;
646 else if( !strcmp( key, "freeslots" ) )
647 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_FREESLOTS;
648 else if( !strcmp( key, "protocol" ) )
649 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
650 else if( !strcmp( key, "category" ) )
651 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_CATEGORY;
652 else if( !strcmp( key, "isfavorite" ) )
653 PRVM_G_FLOAT( OFS_RETURN ) = SLIF_ISFAVORITE;
655 PRVM_G_FLOAT( OFS_RETURN ) = -1;
659 ========================
660 VM_M_addwantedserverlistkey
662 addwantedserverlistkey(string key)
663 ========================
665 static void VM_M_addwantedserverlistkey(prvm_prog_t *prog)
667 VM_SAFEPARMCOUNT( 1, VM_M_addwantedserverlistkey );
671 ===============================================================================
674 used only for client and menu
675 server uses VM_SV_...
677 Write*(* data, float type, float to)
679 ===============================================================================
682 #define MSG_BROADCAST 0 // unreliable to all
683 #define MSG_ONE 1 // reliable to one (msg_entity)
684 #define MSG_ALL 2 // reliable to all
685 #define MSG_INIT 3 // write to the init string
687 static sizebuf_t *VM_M_WriteDest (prvm_prog_t *prog)
693 prog->error_cmd("VM_M_WriteDest: game is not server (%s)", prog->name);
695 dest = (int)PRVM_G_FLOAT(OFS_PARM1);
702 destclient = (int) PRVM_G_FLOAT(OFS_PARM2);
703 if (destclient < 0 || destclient >= svs.maxclients || !svs.clients[destclient].active || !svs.clients[destclient].netconnection)
704 prog->error_cmd("VM_clientcommand: %s: invalid client !", prog->name);
706 return &svs.clients[destclient].netconnection->message;
709 return &sv.reliable_datagram;
715 prog->error_cmd("WriteDest: bad destination");
722 static void VM_M_WriteByte (prvm_prog_t *prog)
724 VM_SAFEPARMCOUNT(1, VM_M_WriteByte);
725 MSG_WriteByte (VM_M_WriteDest(prog), (int)PRVM_G_FLOAT(OFS_PARM0));
728 static void VM_M_WriteChar (prvm_prog_t *prog)
730 VM_SAFEPARMCOUNT(1, VM_M_WriteChar);
731 MSG_WriteChar (VM_M_WriteDest(prog), (int)PRVM_G_FLOAT(OFS_PARM0));
734 static void VM_M_WriteShort (prvm_prog_t *prog)
736 VM_SAFEPARMCOUNT(1, VM_M_WriteShort);
737 MSG_WriteShort (VM_M_WriteDest(prog), (int)PRVM_G_FLOAT(OFS_PARM0));
740 static void VM_M_WriteLong (prvm_prog_t *prog)
742 VM_SAFEPARMCOUNT(1, VM_M_WriteLong);
743 MSG_WriteLong (VM_M_WriteDest(prog), (int)PRVM_G_FLOAT(OFS_PARM0));
746 static void VM_M_WriteAngle (prvm_prog_t *prog)
748 VM_SAFEPARMCOUNT(1, VM_M_WriteAngle);
749 MSG_WriteAngle (VM_M_WriteDest(prog), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
752 static void VM_M_WriteCoord (prvm_prog_t *prog)
754 VM_SAFEPARMCOUNT(1, VM_M_WriteCoord);
755 MSG_WriteCoord (VM_M_WriteDest(prog), PRVM_G_FLOAT(OFS_PARM0), sv.protocol);
758 static void VM_M_WriteString (prvm_prog_t *prog)
760 VM_SAFEPARMCOUNT(1, VM_M_WriteString);
761 MSG_WriteString (VM_M_WriteDest(prog), PRVM_G_STRING(OFS_PARM0));
764 static void VM_M_WriteEntity (prvm_prog_t *prog)
766 VM_SAFEPARMCOUNT(1, VM_M_WriteEntity);
767 MSG_WriteShort (VM_M_WriteDest(prog), PRVM_G_EDICTNUM(OFS_PARM0));
774 copies data from one entity to another
776 copyentity(entity src, entity dst)
779 static void VM_M_copyentity (prvm_prog_t *prog)
781 prvm_edict_t *in, *out;
782 VM_SAFEPARMCOUNT(2,VM_M_copyentity);
783 in = PRVM_G_EDICT(OFS_PARM0);
784 out = PRVM_G_EDICT(OFS_PARM1);
785 memcpy(out->fields.fp, in->fields.fp, prog->entityfields * sizeof(prvm_vec_t));
788 //#66 vector() getmousepos (EXT_CSQC)
789 static void VM_M_getmousepos(prvm_prog_t *prog)
791 VM_SAFEPARMCOUNT(0,VM_M_getmousepos);
793 if (key_consoleactive || (key_dest != key_menu && key_dest != key_menu_grabbed))
794 VectorSet(PRVM_G_VECTOR(OFS_RETURN), 0, 0, 0);
795 else if (in_client_mouse)
796 VectorSet(PRVM_G_VECTOR(OFS_RETURN), in_windowmouse_x * vid_conwidth.integer / vid.width, in_windowmouse_y * vid_conheight.integer / vid.height, 0);
798 VectorSet(PRVM_G_VECTOR(OFS_RETURN), in_mouse_x * vid_conwidth.integer / vid.width, in_mouse_y * vid_conheight.integer / vid.height, 0);
801 static void VM_M_crypto_getkeyfp(prvm_prog_t *prog)
805 char keyfp[FP64_SIZE + 1];
807 VM_SAFEPARMCOUNT(1,VM_M_crypto_getkeyfp);
809 s = PRVM_G_STRING( OFS_PARM0 );
810 VM_CheckEmptyString( prog, s );
812 if(LHNETADDRESS_FromString(&addr, s, 26000) && Crypto_RetrieveHostKey(&addr, NULL, keyfp, sizeof(keyfp), NULL, 0, NULL, NULL))
813 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, keyfp );
815 PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
817 static void VM_M_crypto_getidfp(prvm_prog_t *prog)
821 char idfp[FP64_SIZE + 1];
823 VM_SAFEPARMCOUNT(1,VM_M_crypto_getidfp);
825 s = PRVM_G_STRING( OFS_PARM0 );
826 VM_CheckEmptyString( prog, s );
828 if(LHNETADDRESS_FromString(&addr, s, 26000) && Crypto_RetrieveHostKey(&addr, NULL, NULL, 0, idfp, sizeof(idfp), NULL, NULL))
829 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, idfp );
831 PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
833 static void VM_M_crypto_getidstatus(prvm_prog_t *prog)
839 VM_SAFEPARMCOUNT(1,VM_M_crypto_getidstatus);
841 s = PRVM_G_STRING( OFS_PARM0 );
842 VM_CheckEmptyString( prog, s );
844 if(LHNETADDRESS_FromString(&addr, s, 26000) && Crypto_RetrieveHostKey(&addr, NULL, NULL, 0, NULL, 0, NULL, &issigned))
845 PRVM_G_FLOAT( OFS_RETURN ) = issigned ? 2 : 1;
847 PRVM_G_FLOAT( OFS_RETURN ) = 0;
849 static void VM_M_crypto_getencryptlevel(prvm_prog_t *prog)
856 VM_SAFEPARMCOUNT(1,VM_M_crypto_getencryptlevel);
858 s = PRVM_G_STRING( OFS_PARM0 );
859 VM_CheckEmptyString( prog, s );
861 if(LHNETADDRESS_FromString(&addr, s, 26000) && Crypto_RetrieveHostKey(&addr, NULL, NULL, 0, NULL, 0, &aeslevel, NULL))
862 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, aeslevel ? va(vabuf, sizeof(vabuf), "%d AES128", aeslevel) : "0");
864 PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
866 static void VM_M_crypto_getmykeyfp(prvm_prog_t *prog)
869 char keyfp[FP64_SIZE + 1];
871 VM_SAFEPARMCOUNT(1, VM_M_crypto_getmykeyfp);
873 i = PRVM_G_FLOAT( OFS_PARM0 );
874 switch(Crypto_RetrieveLocalKey(i, keyfp, sizeof(keyfp), NULL, 0, NULL))
877 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, "");
880 PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
884 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, keyfp);
888 static void VM_M_crypto_getmyidfp(prvm_prog_t *prog)
891 char idfp[FP64_SIZE + 1];
893 VM_SAFEPARMCOUNT(1, VM_M_crypto_getmyidfp);
895 i = PRVM_G_FLOAT( OFS_PARM0 );
896 switch(Crypto_RetrieveLocalKey(i, NULL, 0, idfp, sizeof(idfp), NULL))
899 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, "");
902 PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
906 PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, idfp);
910 static void VM_M_crypto_getmyidstatus(prvm_prog_t *prog)
915 VM_SAFEPARMCOUNT(1, VM_M_crypto_getmyidstatus);
917 i = PRVM_G_FLOAT( OFS_PARM0 );
918 switch(Crypto_RetrieveLocalKey(i, NULL, 0, NULL, 0, &issigned))
921 PRVM_G_FLOAT( OFS_RETURN ) = 0; // have no ID there
924 PRVM_G_FLOAT( OFS_RETURN ) = -1; // out of range
928 PRVM_G_FLOAT( OFS_RETURN ) = issigned ? 2 : 1;
933 // CL_Video interface functions
936 ========================
939 float cin_open(string file, string name)
940 ========================
942 void VM_cin_open(prvm_prog_t *prog)
947 VM_SAFEPARMCOUNT( 2, VM_cin_open );
949 file = PRVM_G_STRING( OFS_PARM0 );
950 name = PRVM_G_STRING( OFS_PARM1 );
952 VM_CheckEmptyString(prog, file );
953 VM_CheckEmptyString(prog, name );
955 if( CL_OpenVideo( file, name, MENUOWNER, "" ) )
956 PRVM_G_FLOAT( OFS_RETURN ) = 1;
958 PRVM_G_FLOAT( OFS_RETURN ) = 0;
962 ========================
965 void cin_close(string name)
966 ========================
968 void VM_cin_close(prvm_prog_t *prog)
972 VM_SAFEPARMCOUNT( 1, VM_cin_close );
974 name = PRVM_G_STRING( OFS_PARM0 );
975 VM_CheckEmptyString(prog, name );
977 CL_CloseVideo( CL_GetVideoByName( name ) );
981 ========================
983 void cin_setstate(string name, float type)
984 ========================
986 void VM_cin_setstate(prvm_prog_t *prog)
989 clvideostate_t state;
992 VM_SAFEPARMCOUNT( 2, VM_cin_setstate );
994 name = PRVM_G_STRING( OFS_PARM0 );
995 VM_CheckEmptyString(prog, name );
997 state = (clvideostate_t)((int)PRVM_G_FLOAT( OFS_PARM1 ));
999 video = CL_GetVideoByName( name );
1000 if( video && state > CLVIDEO_UNUSED && state < CLVIDEO_STATECOUNT )
1001 CL_SetVideoState( video, state );
1005 ========================
1008 float cin_getstate(string name)
1009 ========================
1011 void VM_cin_getstate(prvm_prog_t *prog)
1016 VM_SAFEPARMCOUNT( 1, VM_cin_getstate );
1018 name = PRVM_G_STRING( OFS_PARM0 );
1019 VM_CheckEmptyString(prog, name );
1021 video = CL_GetVideoByName( name );
1023 PRVM_G_FLOAT( OFS_RETURN ) = (int)video->state;
1025 PRVM_G_FLOAT( OFS_RETURN ) = 0;
1029 ========================
1032 void cin_restart(string name)
1033 ========================
1035 void VM_cin_restart(prvm_prog_t *prog)
1040 VM_SAFEPARMCOUNT( 1, VM_cin_restart );
1042 name = PRVM_G_STRING( OFS_PARM0 );
1043 VM_CheckEmptyString(prog, name );
1045 video = CL_GetVideoByName( name );
1047 CL_RestartVideo( video );
1050 static void VM_M_registercommand(prvm_prog_t *prog)
1052 VM_SAFEPARMCOUNT(1, VM_M_registercommand);
1053 Cmd_AddCommand(CF_CLIENT, PRVM_G_STRING(OFS_PARM0), NULL, "console command created by QuakeC");
1056 prvm_builtin_t vm_m_builtins[] = {
1057 NULL, // #0 NULL function (not callable)
1058 VM_checkextension, // #1
1064 VM_centerprint, // #7
1068 VM_vectoangles, // #11
1070 VM_localcmd_local, // #13
1082 VM_findfloat, // #25
1083 VM_findchain, // #26
1084 VM_findchainfloat, // #27
1085 VM_precache_file, // #28
1086 VM_precache_sound, // #29
1098 VM_randomvec, // #41
1099 VM_registercvar, // #42
1104 VM_M_copyentity, // #47
1111 VM_substring, // #54
1114 VM_strunzone, // #57
1118 VM_clientcount, // #61
1119 VM_clientstate, // #62
1121 VM_changelevel, // #64
1122 VM_localsound, // #65
1123 VM_M_getmousepos, // #66
1125 VM_loadfromdata, // #68
1126 VM_loadfromfile, // #69
1128 VM_cvar_string, // #71
1130 VM_stackdump, // #73
1131 VM_search_begin, // #74
1132 VM_search_end, // #75
1133 VM_search_getsize, // #76
1134 VM_search_getfilename, // #77
1138 VM_itof, // #81 isString
1139 VM_altstr_count, // #82
1140 VM_altstr_prepare, // #83
1141 VM_altstr_get, // #84
1142 VM_altstr_set, // #85
1143 VM_altstr_ins, // #86
1144 VM_findflags, // #87
1145 VM_findchainflags, // #88
1146 VM_cvar_defstring, // #89
1147 // deactivate support for model rendering in the menu until someone has time to do it right [3/2/2008 Andreas]
1149 VM_CL_setmodel, // #90 void(entity e, string m) setmodel (QUAKE)
1150 VM_CL_precache_model, // #91 void(string s) precache_model (QUAKE)
1151 VM_CL_setorigin, // #92 void(entity e, vector o) setorigin (QUAKE)
1285 VM_strstrofs, // #221 float(string str, string sub[, float startpos]) strstrofs (FTE_STRINGS)
1286 VM_str2chr, // #222 float(string str, float ofs) str2chr (FTE_STRINGS)
1287 VM_chr2str, // #223 string(float c, ...) chr2str (FTE_STRINGS)
1288 VM_strconv, // #224 string(float ccase, float calpha, float cnum, string s, ...) strconv (FTE_STRINGS)
1289 VM_strpad, // #225 string(float chars, string s, ...) strpad (FTE_STRINGS)
1290 VM_infoadd, // #226 string(string info, string key, string value, ...) infoadd (FTE_STRINGS)
1291 VM_infoget, // #227 string(string info, string key) infoget (FTE_STRINGS)
1292 VM_strncmp, // #228 float(string s1, string s2, float len) strncmp (FTE_STRINGS)
1293 VM_strncasecmp, // #229 float(string s1, string s2) strcasecmp (FTE_STRINGS)
1294 VM_strncasecmp, // #230 float(string s1, string s2, float len) strncasecmp (FTE_STRINGS)
1364 // deactivate support for model rendering in the menu until someone has time to do it right [3/2/2008 Andreas]
1366 // CSQC range #300-#399
1367 VM_CL_R_ClearScene, // #300 void() clearscene (DP_QC_RENDER_SCENE)
1368 VM_CL_R_AddEntities, // #301 void(float mask) addentities (DP_QC_RENDER_SCENE)
1369 VM_CL_R_AddEntity, // #302 void(entity ent) addentity (DP_QC_RENDER_SCENE)
1370 VM_CL_R_SetView, // #303 float(float property, ...) setproperty (DP_QC_RENDER_SCENE)
1371 VM_CL_R_RenderScene, // #304 void() renderscene (DP_QC_RENDER_SCENE)
1372 VM_CL_R_AddDynamicLight, // #305 void(vector org, float radius, vector lightcolours) adddynamiclight (DP_QC_RENDER_SCENE)
1373 VM_CL_R_PolygonBegin, // #306 void(string texturename, float flag[, float is2d, float lines]) R_BeginPolygon (DP_QC_RENDER_SCENE)
1374 VM_CL_R_PolygonVertex, // #307 void(vector org, vector texcoords, vector rgb, float alpha) R_PolygonVertex (DP_QC_RENDER_SCENE)
1375 VM_CL_R_PolygonEnd, // #308 void() R_EndPolygon
1376 NULL/*VM_CL_R_LoadWorldModel*/, // #309 void(string modelname) R_LoadWorldModel
1377 // TODO: rearrange and merge all builtin lists and share as many extensions as possible between all VM instances [1/27/2008 Andreas]
1378 VM_CL_setattachment, // #310 void(entity e, entity tagentity, string tagname) setattachment (DP_GFX_QUAKE3MODELTAGS) (DP_QC_RENDER_SCENE)
1379 VM_CL_gettagindex, // #311 float(entity ent, string tagname) gettagindex (DP_QC_GETTAGINFO) (DP_QC_RENDER_SCENE)
1380 VM_CL_gettaginfo, // #312 vector(entity ent, float tagindex) gettaginfo (DP_QC_GETTAGINFO) (DP_QC_RENDER_SCENE)
1382 // CSQC range #300-#399
1424 VM_keynumtostring, // #340 string keynumtostring(float keynum)
1425 VM_stringtokeynum, // #341 float stringtokeynum(string key)
1426 VM_getkeybind, // #342 string(float keynum[, float bindmap]) getkeybind (EXT_CSQC)
1433 VM_CL_isdemo, // #349
1436 VM_M_registercommand, // #352 void(string cmdname)
1437 VM_wasfreed, // #353 float(entity ent) wasfreed
1439 VM_CL_videoplaying, // #355
1440 VM_findfont, // #356 float(string fontname) loadfont (DP_GFX_FONTS)
1441 VM_loadfont, // #357 float(string fontname, string fontmaps, string sizes, float slot) loadfont (DP_GFX_FONTS)
1485 VM_M_WriteByte, // #401
1486 VM_M_WriteChar, // #402
1487 VM_M_WriteShort, // #403
1488 VM_M_WriteLong, // #404
1489 VM_M_WriteAngle, // #405
1490 VM_M_WriteCoord, // #406
1491 VM_M_WriteString, // #407
1492 VM_M_WriteEntity, // #408
1524 VM_buf_create, // #440 float() buf_create (DP_QC_STRINGBUFFERS)
1525 VM_buf_del, // #441 void(float bufhandle) buf_del (DP_QC_STRINGBUFFERS)
1526 VM_buf_getsize, // #442 float(float bufhandle) buf_getsize (DP_QC_STRINGBUFFERS)
1527 VM_buf_copy, // #443 void(float bufhandle_from, float bufhandle_to) buf_copy (DP_QC_STRINGBUFFERS)
1528 VM_buf_sort, // #444 void(float bufhandle, float sortpower, float backward) buf_sort (DP_QC_STRINGBUFFERS)
1529 VM_buf_implode, // #445 string(float bufhandle, string glue) buf_implode (DP_QC_STRINGBUFFERS)
1530 VM_bufstr_get, // #446 string(float bufhandle, float string_index) bufstr_get (DP_QC_STRINGBUFFERS)
1531 VM_bufstr_set, // #447 void(float bufhandle, float string_index, string str) bufstr_set (DP_QC_STRINGBUFFERS)
1532 VM_bufstr_add, // #448 float(float bufhandle, string str, float order) bufstr_add (DP_QC_STRINGBUFFERS)
1533 VM_bufstr_free, // #449 void(float bufhandle, float string_index) bufstr_free (DP_QC_STRINGBUFFERS)
1535 VM_iscachedpic, // #451 draw functions...
1536 VM_precache_pic, // #452
1538 VM_drawcharacter, // #454
1539 VM_drawstring, // #455
1541 VM_drawfill, // #457
1542 VM_drawsetcliparea, // #458
1543 VM_drawresetcliparea, // #459
1544 VM_getimagesize, // #460
1545 VM_cin_open, // #461
1546 VM_cin_close, // #462
1547 VM_cin_setstate, // #463
1548 VM_cin_getstate, // #464
1549 VM_cin_restart, // #465
1550 VM_drawline, // #466
1551 VM_drawcolorcodedstring, // #467
1552 VM_stringwidth, // #468
1553 VM_drawsubpic, // #469
1554 VM_drawrotpic, // #470
1555 VM_asin, // #471 float(float s) VM_asin (DP_QC_ASINACOSATANATAN2TAN)
1556 VM_acos, // #472 float(float c) VM_acos (DP_QC_ASINACOSATANATAN2TAN)
1557 VM_atan, // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN)
1558 VM_atan2, // #474 float(float c, float s) VM_atan2 (DP_QC_ASINACOSATANATAN2TAN)
1559 VM_tan, // #475 float(float a) VM_tan (DP_QC_ASINACOSATANATAN2TAN)
1560 VM_strlennocol, // #476 float(string s) : DRESK - String Length (not counting color codes) (DP_QC_STRINGCOLORFUNCTIONS)
1561 VM_strdecolorize, // #477 string(string s) : DRESK - Decolorized String (DP_QC_STRINGCOLORFUNCTIONS)
1562 VM_strftime, // #478 string(float uselocaltime, string format, ...) (DP_QC_STRFTIME)
1563 VM_tokenizebyseparator, // #479 float(string s) tokenizebyseparator (DP_QC_TOKENIZEBYSEPARATOR)
1564 VM_strtolower, // #480 string(string s) VM_strtolower : DRESK - Return string as lowercase
1565 VM_strtoupper, // #481 string(string s) VM_strtoupper : DRESK - Return string as uppercase
1568 VM_strreplace, // #484 string(string search, string replace, string subject) strreplace (DP_QC_STRREPLACE)
1569 VM_strireplace, // #485 string(string search, string replace, string subject) strireplace (DP_QC_STRREPLACE)
1571 VM_gecko_create, // #487 float gecko_create( string name )
1572 VM_gecko_destroy, // #488 void gecko_destroy( string name )
1573 VM_gecko_navigate, // #489 void gecko_navigate( string name, string URI )
1574 VM_gecko_keyevent, // #490 float gecko_keyevent( string name, float key, float eventtype )
1575 VM_gecko_movemouse, // #491 void gecko_mousemove( string name, float x, float y )
1576 VM_gecko_resize, // #492 void gecko_resize( string name, float w, float h )
1577 VM_gecko_get_texture_extent, // #493 vector gecko_get_texture_extent( string name )
1578 VM_crc16, // #494 float(float caseinsensitive, string s, ...) crc16 = #494 (DP_QC_CRC16)
1579 VM_cvar_type, // #495 float(string name) cvar_type = #495; (DP_QC_CVAR_TYPE)
1580 VM_numentityfields, // #496 float() numentityfields = #496; (QP_QC_ENTITYDATA)
1581 VM_entityfieldname, // #497 string(float fieldnum) entityfieldname = #497; (DP_QC_ENTITYDATA)
1582 VM_entityfieldtype, // #498 float(float fieldnum) entityfieldtype = #498; (DP_QC_ENTITYDATA)
1583 VM_getentityfieldstring, // #499 string(float fieldnum, entity ent) getentityfieldstring = #499; (DP_QC_ENTITYDATA)
1584 VM_putentityfieldstring, // #500 float(float fieldnum, entity ent, string s) putentityfieldstring = #500; (DP_QC_ENTITYDATA)
1587 VM_whichpack, // #503 string(string) whichpack = #503;
1594 VM_uri_escape, // #510 string(string in) uri_escape = #510;
1595 VM_uri_unescape, // #511 string(string in) uri_unescape = #511;
1596 VM_etof, // #512 float(entity ent) num_for_edict = #512 (DP_QC_NUM_FOR_EDICT)
1597 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)
1598 VM_tokenize_console, // #514 float(string str) tokenize_console = #514; (DP_QC_TOKENIZE_CONSOLE)
1599 VM_argv_start_index, // #515 float(float idx) argv_start_index = #515; (DP_QC_TOKENIZE_CONSOLE)
1600 VM_argv_end_index, // #516 float(float idx) argv_end_index = #516; (DP_QC_TOKENIZE_CONSOLE)
1601 VM_buf_cvarlist, // #517 void(float buf, string prefix, string antiprefix) buf_cvarlist = #517; (DP_QC_STRINGBUFFERS_CVARLIST)
1602 VM_cvar_description, // #518 float(string name) cvar_description = #518; (DP_QC_CVAR_DESCRIPTION)
1617 VM_getsoundtime, // #533 float(entity e, float channel) getsoundtime = #533; (DP_SND_GETSOUNDTIME)
1618 VM_soundlength, // #534 float(string sample) soundlength = #534; (DP_SND_GETSOUNDTIME)
1619 VM_buf_loadfile, // #535 float(string filename, float bufhandle) buf_loadfile (DP_QC_STRINGBUFFERS_EXT_WIP)
1620 VM_buf_writefile, // #536 float(float filehandle, float bufhandle, float startpos, float numstrings) buf_writefile (DP_QC_STRINGBUFFERS_EXT_WIP)
1621 VM_bufstr_find, // #537 float(float bufhandle, string match, float matchrule, float startpos) bufstr_find (DP_QC_STRINGBUFFERS_EXT_WIP)
1622 VM_matchpattern, // #538 float(string s, string pattern, float matchrule) matchpattern (DP_QC_STRINGBUFFERS_EXT_WIP)
1685 VM_M_setkeydest, // #601 void setkeydest(float dest)
1686 VM_M_getkeydest, // #602 float getkeydest(void)
1687 VM_M_setmousetarget, // #603 void setmousetarget(float trg)
1688 VM_M_getmousetarget, // #604 float getmousetarget(void)
1689 VM_callfunction, // #605 void callfunction(...)
1690 VM_writetofile, // #606 void writetofile(float fhandle, entity ent)
1691 VM_isfunction, // #607 float isfunction(string function_name)
1692 VM_M_getresolution, // #608 vector getresolution(float number, [float forfullscreen])
1693 VM_keynumtostring, // #609 string keynumtostring(float keynum)
1694 VM_findkeysforcommand, // #610 string findkeysforcommand(string command[, float bindmap])
1695 VM_M_getserverliststat, // #611 float gethostcachevalue(float type)
1696 VM_M_getserverliststring, // #612 string gethostcachestring(float type, float hostnr)
1697 VM_parseentitydata, // #613 void parseentitydata(entity ent, string data)
1698 VM_stringtokeynum, // #614 float stringtokeynum(string key)
1699 VM_M_resetserverlistmasks, // #615 void resethostcachemasks(void)
1700 VM_M_setserverlistmaskstring, // #616 void sethostcachemaskstring(float mask, float fld, string str, float op)
1701 VM_M_setserverlistmasknumber, // #617 void sethostcachemasknumber(float mask, float fld, float num, float op)
1702 VM_M_resortserverlist, // #618 void resorthostcache(void)
1703 VM_M_setserverlistsort, // #619 void sethostcachesort(float fld, float descending)
1704 VM_M_refreshserverlist, // #620 void refreshhostcache(void)
1705 VM_M_getserverlistnumber, // #621 float gethostcachenumber(float fld, float hostnr)
1706 VM_M_getserverlistindexforkey,// #622 float gethostcacheindexforkey(string key)
1707 VM_M_addwantedserverlistkey, // #623 void addwantedhostcachekey(string key)
1708 VM_CL_getextresponse, // #624 string getextresponse(void)
1709 VM_netaddress_resolve, // #625 string netaddress_resolve(string, float)
1710 VM_M_getgamedirinfo, // #626 string getgamedirinfo(float n, float prop)
1711 VM_sprintf, // #627 string sprintf(string format, ...)
1714 VM_setkeybind, // #630 float(float key, string bind[, float bindmap]) setkeybind
1715 VM_getbindmaps, // #631 vector(void) getbindmap
1716 VM_setbindmaps, // #632 float(vector bm) setbindmap
1717 VM_M_crypto_getkeyfp, // #633 string(string addr) crypto_getkeyfp
1718 VM_M_crypto_getidfp, // #634 string(string addr) crypto_getidfp
1719 VM_M_crypto_getencryptlevel, // #635 string(string addr) crypto_getencryptlevel
1720 VM_M_crypto_getmykeyfp, // #636 string(float addr) crypto_getmykeyfp
1721 VM_M_crypto_getmyidfp, // #637 string(float addr) crypto_getmyidfp
1723 VM_digest_hex, // #639
1725 VM_M_crypto_getmyidstatus, // #641 float(float i) crypto_getmyidstatus
1726 VM_coverage, // #642
1727 VM_M_crypto_getidstatus, // #643 float(string addr) crypto_getidstatus
1731 const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);
1733 void MVM_init_cmd(prvm_prog_t *prog)
1735 r_refdef_scene_t *scene;
1738 prog->polygonbegin_model = NULL;
1739 prog->polygonbegin_guess2d = 0;
1741 scene = R_GetScenePointer( RST_MENU );
1743 memset (scene, 0, sizeof (*scene));
1745 scene->maxtempentities = 128;
1746 scene->tempentities = (entity_render_t*) Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t) * scene->maxtempentities);
1748 scene->maxentities = MAX_EDICTS + 256 + 512;
1749 scene->entities = (entity_render_t **)Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t *) * scene->maxentities);
1751 // LadyHavoc: what is this for?
1752 scene->ambientintensity = 32.0f;
1755 void MVM_reset_cmd(prvm_prog_t *prog)
1757 // note: the menu's render entities are automatically freed when the prog's pool is freed
1761 prog->polygonbegin_model = NULL;
1762 prog->polygonbegin_guess2d = 0;