- PRVM_G_INT( OFS_RETURN ) = PRVM_SetString( outstr );
-}
-
-void VM_Cmd_Init(void)
-{
- // only init the stuff for the current prog
- VM_STRINGS_MEMPOOL = Mem_AllocPool(va("vm_stringsmempool[%s]",PRVM_NAME), 0, NULL);
- VM_Files_Init();
- VM_Search_Init();
-}
-
-void VM_Cmd_Reset(void)
-{
- //Mem_EmptyPool(VM_STRINGS_MEMPOOL);
- if( developer.integer >= 2 && VM_STRINGS_MEMPOOL ) {
- memheader_t *header;
- int i;
-
- for( i = 0, header = VM_STRINGS_MEMPOOL->chain ; header ; header = header->next, i++ )
- Con_DPrintf( "Leaked string %i (size: %i): %.*s\n", i, header->size, header->size, ((char*)header) + sizeof( memheader_t ) );
- }
-
- Mem_FreePool(&VM_STRINGS_MEMPOOL);
- CL_PurgeOwner( MENUOWNER );
- VM_Search_Reset();
- VM_Files_CloseAll();
-}
-
-//============================================================================
-// Server
-
-char *vm_sv_extensions =
-"";
-
-prvm_builtin_t vm_sv_builtins[] = {
-0 // to be consistent with the old vm
-};
-
-const int vm_sv_numbuiltins = sizeof(vm_sv_builtins) / sizeof(prvm_builtin_t);
-
-void VM_SV_Cmd_Init(void)
-{
-}
-
-void VM_SV_Cmd_Reset(void)
-{
-}
-
-//============================================================================
-// Client
-
-char *vm_cl_extensions =
-"";
-
-prvm_builtin_t vm_cl_builtins[] = {
-0 // to be consistent with the old vm
-};
-
-const int vm_cl_numbuiltins = sizeof(vm_cl_builtins) / sizeof(prvm_builtin_t);
-
-void VM_CL_Cmd_Init(void)
-{
-}
-
-void VM_CL_Cmd_Reset(void)
-{
-}
-
-//============================================================================
-// Menu
-
-char *vm_m_extensions =
-"DP_CINEMATIC_DPV";
-
-/*
-=========
-VM_M_setmousetarget
-
-setmousetarget(float target)
-=========
-*/
-void VM_M_setmousetarget(void)
-{
- VM_SAFEPARMCOUNT(1, VM_M_setmousetarget);
-
- switch((int)PRVM_G_FLOAT(OFS_PARM0))
- {
- case 1:
- in_client_mouse = false;
- break;
- case 2:
- in_client_mouse = true;
- break;
- default:
- PRVM_ERROR("VM_M_setmousetarget: wrong destination %i !\n",PRVM_G_FLOAT(OFS_PARM0));
- }
-}
-
-/*
-=========
-VM_M_getmousetarget
-
-float getmousetarget
-=========
-*/
-void VM_M_getmousetarget(void)
-{
- VM_SAFEPARMCOUNT(0,VM_M_getmousetarget);
-
- if(in_client_mouse)
- PRVM_G_FLOAT(OFS_RETURN) = 2;
- else
- PRVM_G_FLOAT(OFS_RETURN) = 1;
-}
-
-
-
-/*
-=========
-VM_M_setkeydest
-
-setkeydest(float dest)
-=========
-*/
-void VM_M_setkeydest(void)
-{
- VM_SAFEPARMCOUNT(1,VM_M_setkeydest);
-
- switch((int)PRVM_G_FLOAT(OFS_PARM0))
- {
- case 0:
- // key_game
- key_dest = key_game;
- break;
- case 2:
- // key_menu
- key_dest = key_menu;
- break;
- case 1:
- // key_message
- // key_dest = key_message
- // break;
- default:
- PRVM_ERROR("VM_M_setkeydest: wrong destination %i !\n",prog->globals[OFS_PARM0]);
- }
-}
-
-/*
-=========
-VM_M_getkeydest
-
-float getkeydest
-=========
-*/
-void VM_M_getkeydest(void)
-{
- VM_SAFEPARMCOUNT(0,VM_M_getkeydest);
-
- // key_game = 0, key_message = 1, key_menu = 2, unknown = 3
- switch(key_dest)
- {
- case key_game:
- PRVM_G_FLOAT(OFS_RETURN) = 0;
- break;
- case key_menu:
- PRVM_G_FLOAT(OFS_RETURN) = 2;
- break;
- case key_message:
- // not supported
- // PRVM_G_FLOAT(OFS_RETURN) = 1;
- // break;
- default:
- PRVM_G_FLOAT(OFS_RETURN) = 3;
- }
-}
-
-/*
-=========
-VM_M_callfunction
-
- callfunction(...,string function_name)
-Extension: pass
-=========
-*/
-mfunction_t *PRVM_ED_FindFunction (const char *name);
-void VM_M_callfunction(void)
-{
- mfunction_t *func;
- char *s;
-
- if(prog->argc == 0)
- PRVM_ERROR("VM_M_callfunction: 1 parameter is required !\n");
-
- s = PRVM_G_STRING(OFS_PARM0 + (prog->argc - 1));
-
- if(!s)
- PRVM_ERROR("VM_M_callfunction: null string !\n");
-
- VM_CheckEmptyString(s);
-
- func = PRVM_ED_FindFunction(s);
-
- if(!func)
- PRVM_ERROR("VM_M_callfunciton: function %s not found !\n", s);
- else if (func->first_statement < 0)
- {
- // negative statements are built in functions
- int builtinnumber = -func->first_statement;
- prog->xfunction->builtinsprofile++;
- if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
- prog->builtins[builtinnumber]();
- else
- PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME);
- }
- else if(func > 0)
- {
- prog->argc--;
- PRVM_ExecuteProgram(func - prog->functions,"");
- prog->argc++;
- }
-}
-
-/*
-=========
-VM_M_isfunction
-
-float isfunction(string function_name)
-=========
-*/
-mfunction_t *PRVM_ED_FindFunction (const char *name);
-void VM_M_isfunction(void)
-{
- mfunction_t *func;
- char *s;
-
- VM_SAFEPARMCOUNT(1, VM_M_isfunction);
-
- s = PRVM_G_STRING(OFS_PARM0);
-
- if(!s)
- PRVM_ERROR("VM_M_isfunction: null string !\n");
-
- VM_CheckEmptyString(s);
-
- func = PRVM_ED_FindFunction(s);
-
- if(!func)
- PRVM_G_FLOAT(OFS_RETURN) = false;
- else
- PRVM_G_FLOAT(OFS_RETURN) = true;
-}
-
-/*
-=========
-VM_M_writetofile
-
- writetofile(float fhandle, entity ent)
-=========
-*/
-void VM_M_writetofile(void)
-{
- prvm_edict_t * ent;
- int filenum;
-
- VM_SAFEPARMCOUNT(2, VM_M_writetofile);
-
- filenum = PRVM_G_FLOAT(OFS_PARM0);
- if (filenum < 0 || filenum >= MAX_VMFILES)
- {
- Con_Printf("VM_fputs: invalid file handle %i used in %s\n", filenum, PRVM_NAME);
- return;
- }
- if (VM_FILES[filenum] == NULL)
- {
- Con_Printf("VM_fputs: no such file handle %i (or file has been closed) in %s\n", filenum, PRVM_NAME);
- return;
- }
-
- ent = PRVM_G_EDICT(OFS_PARM1);
- if(ent->p.e->free)
- {
- Con_Printf("VM_M_writetofile: %s: entity %i is free !\n", PRVM_NAME, PRVM_EDICT_NUM(OFS_PARM1));
- return;
- }
-
- PRVM_ED_Write (VM_FILES[filenum], ent);
-}
-
-/*
-=========
-VM_M_getresolution
-
-vector getresolution(float number)
-=========
-*/
-extern unsigned short video_resolutions[][2];
-void VM_M_getresolution(void)
-{
- int nr;
- VM_SAFEPARMCOUNT(1, VM_getresolution);
-
- nr = PRVM_G_FLOAT(OFS_PARM0);
-
-
- PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr][0];
- PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr][1];
- PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
-}
-
-/*
-=========
-VM_M_keynumtostring
-
-string keynumtostring(float keynum)
-=========
-*/
-void VM_M_keynumtostring(void)
-{
- int keynum;
- char *tmp;
- VM_SAFEPARMCOUNT(1, VM_M_keynumtostring);
-
- keynum = PRVM_G_FLOAT(OFS_PARM0);
-
- tmp = VM_GetTempString();
-
- strcpy(tmp, Key_KeynumToString(keynum));
-
- PRVM_G_INT(OFS_RETURN) = PRVM_SetString(tmp);
-}
-
-/*
-=========
-VM_M_stringtokeynum
-
-float stringtokeynum(string key)
-=========
-*/
-void VM_M_stringtokeynum( void )
-{
- char *str;
- VM_SAFEPARMCOUNT( 1, VM_M_keynumtostring );
-
- str = PRVM_G_STRING( OFS_PARM0 );
-
- PRVM_G_INT(OFS_RETURN) = Key_StringToKeynum( str );
-}
-
-/*
-=========
-VM_M_findkeysforcommand
-
-string findkeysforcommand(string command)
-
-the returned string is an altstring
-=========
-*/
-#define NUMKEYS 5 // TODO: merge the constant in keys.c with this one somewhen
-
-void M_FindKeysForCommand(char *command, int *keys);
-void VM_M_findkeysforcommand(void)
-{
- char *cmd, *ret;
- int keys[NUMKEYS];
- int i;
-
- VM_SAFEPARMCOUNT(1, VM_M_findkeysforcommand);
-
- cmd = PRVM_G_STRING(OFS_PARM0);
-
- VM_CheckEmptyString(cmd);
-
- (ret = VM_GetTempString())[0] = 0;
-
- M_FindKeysForCommand(cmd, keys);
-
- for(i = 0; i < NUMKEYS; i++)
- ret = strcat(ret, va(" \'%i\'", keys[i]));
-
- PRVM_G_INT(OFS_RETURN) = PRVM_SetString(ret);
-}
-
-/*
-=========
-VM_M_gethostcachestat
-
-float gethostcachestat(float type)
-=========
-*/
-/*
- type:
-0 hostcache_viewcount
-1 hostcache_totalcount
-2 masterquerycount
-3 masterreplycount
-4 serverquerycount
-5 serverreplycount
-6 sortfield
-7 sortdescending
-*/
-void VM_M_gethostcachestat( void )
-{
- int type;
- VM_SAFEPARMCOUNT ( 1, VM_M_gethostcachestat );
-
- PRVM_G_FLOAT( OFS_RETURN ) = 0;
-
- type = PRVM_G_FLOAT( OFS_PARM0 );
- switch(type)
- {
- case 0:
- PRVM_G_FLOAT ( OFS_RETURN ) = hostcache_viewcount;
- return;
- case 1:
- PRVM_G_FLOAT ( OFS_RETURN ) = hostcache_cachecount;
- case 2:
- PRVM_G_FLOAT ( OFS_RETURN ) = masterquerycount;
- return;
- case 3:
- PRVM_G_FLOAT ( OFS_RETURN ) = masterreplycount;
- return;
- case 4:
- PRVM_G_FLOAT ( OFS_RETURN ) = serverquerycount;
- return;
- case 5:
- PRVM_G_FLOAT ( OFS_RETURN ) = serverreplycount;
- return;
- case 6:
- PRVM_G_FLOAT ( OFS_RETURN ) = hostcache_sortbyfield;
- return;
- case 7:
- PRVM_G_FLOAT ( OFS_RETURN ) = hostcache_sortdescending;
- return;
- default:
- Con_Printf( "VM_M_gethostcachestat: bad type %i!\n", type );
- }
-}
-
-/*
-========================
-VM_M_resethostcachemasks
-
-resethostcachemasks()
-========================
-*/
-void VM_M_resethostcachemasks( void )
-{
- HostCache_ResetMasks();
-}
-
-
-/*
-========================
-VM_M_sethostcachemaskstring
-
-sethostcachemaskstring(float mask, float fld, string str, float op)
-0-511 and
-512 - 1024 or
-========================
-*/
-void VM_M_sethostcachemaskstring( void )
-{
- char *str;
- int masknr;
- hostcache_mask_t *mask;
- int field;
-
- VM_SAFEPARMCOUNT( 4, VM_M_sethostcachemaskstring );
- str = PRVM_G_STRING( OFS_PARM1 );
- if( !str )
- PRVM_ERROR( "VM_M_sethostcachemaskstring: null string passed!" );
-
- masknr = PRVM_G_FLOAT( OFS_PARM0 );
- if( masknr >= 0 && masknr <= HOSTCACHE_ANDMASKCOUNT )
- mask = &hostcache_andmasks[masknr];
- else if( masknr >= 512 && masknr - 512 <= HOSTCACHE_ORMASKCOUNT )
- mask = &hostcache_ormasks[masknr - 512 ];
- else {
- Con_Printf( "VM_M_sethostcachemaskstring: invalid mask number %i\n", masknr );
- return;
- }
-
- field = (int) PRVM_G_FLOAT( OFS_PARM1 );
-
- switch( field ) {
- case HCIF_CNAME:
- strncpy( mask->info.cname, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.cname) );
- break;
- case HCIF_NAME:
- strncpy( mask->info.name, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.name) );
- break;
- case HCIF_MAP:
- strncpy( mask->info.map, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.map) );
- break;
- case HCIF_MOD:
- strncpy( mask->info.mod, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.mod) );
- break;
- case HCIF_GAME:
- strncpy( mask->info.game, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.game) );
- break;
- default:
- Con_Printf( "VM_M_sethostcachemaskstring: Bad field number %i passed!\n", field );
- return;
- }
-
- mask->active = true;
- mask->tests[field] = (int) PRVM_G_FLOAT( OFS_PARM3 );
-}
-
-/*
-========================
-VM_M_sethostcachemasknumber
-
-sethostcachemasknumber(float mask, float fld, float num, float op)
-
-0-511 and
-512 - 1024 or
-========================
-*/
-void VM_M_sethostcachemasknumber( void )
-{
- int number;
- hostcache_mask_t *mask;
- int masknr;
- int field;
- VM_SAFEPARMCOUNT( 4, VM_M_sethostcachemasknumber );
-
- masknr = PRVM_G_FLOAT( OFS_PARM0 );
- if( masknr >= 0 && masknr <= HOSTCACHE_ANDMASKCOUNT )
- mask = &hostcache_andmasks[masknr];
- else if( masknr >= 512 && masknr - 512 <= HOSTCACHE_ORMASKCOUNT )
- mask = &hostcache_ormasks[masknr - 512 ];
- else {
- Con_Printf( "VM_M_sethostcachemasknumber: invalid mask number %i\n", masknr );
- return;
- }
-
- number = PRVM_G_FLOAT( OFS_PARM2 );
- field = (int) PRVM_G_FLOAT( OFS_PARM1 );
-
- switch( field ) {
- case HCIF_MAXPLAYERS:
- mask->info.maxplayers = number;
- break;
- case HCIF_NUMPLAYERS:
- mask->info.numplayers = number;
- break;
- case HCIF_PING:
- mask->info.ping = number;
- break;
- case HCIF_PROTOCOL:
- mask->info.protocol = number;
- break;
- default:
- Con_Printf( "VM_M_sethostcachemasknumber: Bad field number %i passed!\n", field );
- return;
- }
-
- mask->active = true;
- mask->tests[field] = (int) PRVM_G_FLOAT( OFS_PARM3 );