2004-08-21 01:25:48 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2005-07-03 15:16:20 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
// cvar.c -- dynamic variable tracking
|
|
|
|
|
|
|
|
#include "quakedef.h"
|
|
|
|
|
|
|
|
cvar_group_t *cvar_groups;
|
|
|
|
|
|
|
|
//cvar_t *cvar_vars;
|
|
|
|
char *cvar_null_string = "";
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_FindVar
|
|
|
|
============
|
|
|
|
*/
|
2005-03-28 00:11:59 +00:00
|
|
|
cvar_t *Cvar_FindVar (const char *var_name)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
cvar_group_t *grp;
|
|
|
|
cvar_t *var;
|
2005-07-03 15:16:20 +00:00
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
for (grp=cvar_groups ; grp ; grp=grp->next)
|
|
|
|
for (var=grp->cvars ; var ; var=var->next)
|
|
|
|
if (!Q_strcasecmp (var_name, var->name))
|
|
|
|
return var;
|
|
|
|
|
|
|
|
for (grp=cvar_groups ; grp ; grp=grp->next)
|
|
|
|
for (var=grp->cvars ; var ; var=var->next)
|
|
|
|
if (var->name2 && !Q_strcasecmp (var_name, var->name2))
|
|
|
|
return var;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
cvar_group_t *Cvar_FindGroup (const char *group_name)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
cvar_group_t *grp;
|
2005-07-03 15:16:20 +00:00
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
for (grp=cvar_groups ; grp ; grp=grp->next)
|
|
|
|
if (!Q_strcasecmp (group_name, grp->name))
|
|
|
|
return grp;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-03-28 00:11:59 +00:00
|
|
|
cvar_group_t *Cvar_GetGroup(const char *gname)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
cvar_group_t *g;
|
|
|
|
if (!gname)
|
|
|
|
gname = "Miscilaneous vars";
|
|
|
|
g = Cvar_FindGroup(gname);
|
|
|
|
if (g)
|
|
|
|
return g;
|
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
g = (cvar_group_t*)Z_Malloc(sizeof(cvar_group_t));
|
|
|
|
g->name = (char*)gname;
|
2004-08-21 01:25:48 +00:00
|
|
|
g->next = NULL;
|
|
|
|
g->next = cvar_groups;
|
|
|
|
cvar_groups = g;
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
2005-08-22 22:21:59 +00:00
|
|
|
// converts a given single cvar flag into a human readable string
|
|
|
|
char *Cvar_FlagToName(int flag)
|
|
|
|
{
|
|
|
|
switch (flag)
|
|
|
|
{
|
|
|
|
case CVAR_ARCHIVE:
|
|
|
|
return "archive";
|
|
|
|
case CVAR_USERINFO:
|
|
|
|
return "userinfo";
|
|
|
|
case CVAR_NOSET:
|
|
|
|
return "noset";
|
|
|
|
case CVAR_LATCH:
|
|
|
|
return "latch";
|
|
|
|
case CVAR_POINTER:
|
|
|
|
return "pointer";
|
|
|
|
case CVAR_NOTFROMSERVER:
|
|
|
|
return "noserver";
|
|
|
|
case CVAR_USERCREATED:
|
|
|
|
return "userset";
|
|
|
|
case CVAR_CHEAT:
|
|
|
|
return "cheat";
|
|
|
|
case CVAR_SEMICHEAT:
|
|
|
|
return "semicheat";
|
|
|
|
case CVAR_RENDERERLATCH:
|
|
|
|
return "renderlatch";
|
|
|
|
case CVAR_SERVEROVERRIDE:
|
|
|
|
return "serverlatch";
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
//lists commands, also prints restriction level
|
2005-08-22 22:21:59 +00:00
|
|
|
#define CLF_RAW 0x1
|
|
|
|
#define CLF_LEVEL 0x2
|
2005-08-23 03:25:22 +00:00
|
|
|
#define CLF_ALTNAME 0x4
|
2005-08-22 22:21:59 +00:00
|
|
|
#define CLF_VALUES 0x8
|
|
|
|
#define CLF_DEFAULT 0x10
|
|
|
|
#define CLF_LATCHES 0x20
|
|
|
|
#define CLF_FLAGS 0x40
|
|
|
|
#define CLF_FLAGMASK 0x80
|
2004-08-21 01:25:48 +00:00
|
|
|
void Cvar_List_f (void)
|
|
|
|
{
|
|
|
|
cvar_group_t *grp;
|
|
|
|
cvar_t *cmd;
|
2005-08-22 22:21:59 +00:00
|
|
|
char *var, *search, *gsearch;
|
|
|
|
int gnum, i, num = 0;
|
2005-08-23 03:25:22 +00:00
|
|
|
int listflags = 0, cvarflags = 0;
|
|
|
|
char strtmp[512];
|
2005-08-22 22:21:59 +00:00
|
|
|
|
|
|
|
gsearch = search = NULL;
|
|
|
|
for (i = 1; i < Cmd_Argc(); i++)
|
|
|
|
{
|
|
|
|
var = Cmd_Argv(i);
|
|
|
|
if (*var == '-')
|
|
|
|
{
|
|
|
|
// short options
|
|
|
|
for (var++; *var; var++)
|
|
|
|
{
|
2005-08-23 03:25:22 +00:00
|
|
|
switch (*var)
|
2005-08-22 22:21:59 +00:00
|
|
|
{
|
2005-08-23 03:25:22 +00:00
|
|
|
case 'g':
|
2005-08-22 22:21:59 +00:00
|
|
|
// fix this so we can search for multiple groups
|
|
|
|
i++;
|
|
|
|
if (i >= Cmd_Argc())
|
|
|
|
{
|
|
|
|
Con_Printf("Missing parameter for -g\nUse cvarlist -h for help\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gsearch = Cmd_Argv(i);
|
2005-08-23 03:25:22 +00:00
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
listflags |= CLF_ALTNAME;
|
|
|
|
break;
|
|
|
|
case 'l':
|
2005-08-22 22:21:59 +00:00
|
|
|
listflags |= CLF_LEVEL;
|
2005-08-23 03:25:22 +00:00
|
|
|
break;
|
|
|
|
case 'r':
|
2005-08-22 22:21:59 +00:00
|
|
|
listflags |= CLF_RAW;
|
2005-08-23 03:25:22 +00:00
|
|
|
break;
|
|
|
|
case 'v':
|
2005-08-22 22:21:59 +00:00
|
|
|
listflags |= CLF_VALUES;
|
2005-08-23 03:25:22 +00:00
|
|
|
break;
|
|
|
|
case 'd':
|
2005-08-22 22:21:59 +00:00
|
|
|
listflags |= CLF_DEFAULT;
|
2005-08-23 03:25:22 +00:00
|
|
|
break;
|
|
|
|
case 'L':
|
2005-08-22 22:21:59 +00:00
|
|
|
listflags |= CLF_LATCHES;
|
2005-08-23 03:25:22 +00:00
|
|
|
break;
|
|
|
|
case 'f':
|
2005-08-22 22:21:59 +00:00
|
|
|
{
|
|
|
|
char *tmpv;
|
|
|
|
|
2005-08-23 03:25:22 +00:00
|
|
|
listflags |= CLF_FLAGMASK;
|
2005-08-22 22:21:59 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
if (i >= Cmd_Argc())
|
|
|
|
{
|
|
|
|
Con_Printf("Missing parameter for -f\nUse cvarlist -h for help\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpv = Cmd_Argv(i);
|
|
|
|
|
|
|
|
for (num = 1; num <= CVAR_LASTFLAG; num <<= 1)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
tmp = Cvar_FlagToName(num);
|
|
|
|
|
|
|
|
if (tmp && !stricmp(tmp, tmpv))
|
|
|
|
{
|
|
|
|
cvarflags |= num;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num > CVAR_LASTFLAG)
|
|
|
|
{
|
|
|
|
Con_Printf("Invalid cvar flag name\nUse cvarlist -h for help\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2005-08-23 03:25:22 +00:00
|
|
|
break;
|
|
|
|
case 'F':
|
2005-08-22 22:21:59 +00:00
|
|
|
listflags |= CLF_FLAGS;
|
2005-08-23 03:25:22 +00:00
|
|
|
break;
|
|
|
|
case 'h':
|
2005-08-22 22:21:59 +00:00
|
|
|
// list options
|
2005-08-23 03:25:22 +00:00
|
|
|
Con_Printf("cvarlist list all cvars matching given parameters\n"
|
|
|
|
"Syntax: cvarlist [-FLdhlrv] [-f flag] [-g group] [cvar]\n"
|
2005-08-22 22:21:59 +00:00
|
|
|
" -F shows cvar flags\n"
|
|
|
|
" -L shows latched values\n"
|
2005-08-23 03:25:22 +00:00
|
|
|
" -a shows cvar alternate names\n"
|
2005-08-22 22:21:59 +00:00
|
|
|
" -d shows default cvar values\n"
|
|
|
|
" -f shows only cvars with a matching flag, more than one -f can be used\n"
|
2005-08-23 03:25:22 +00:00
|
|
|
" -g shows only cvar groups using wildcards in group\n"
|
2005-08-22 22:21:59 +00:00
|
|
|
" -h shows this help message\n"
|
|
|
|
" -l shows cvar restriction levels\n"
|
|
|
|
" -r removes group and list headers\n"
|
|
|
|
" -v shows current values\n"
|
2005-08-23 03:25:22 +00:00
|
|
|
" cvar indicates the cvar to show, wildcards (*,?) accepted\n"
|
2005-08-22 22:21:59 +00:00
|
|
|
"Cvar flags are:");
|
|
|
|
|
|
|
|
for (num = 1; num <= CVAR_LASTFLAG; num <<= 1)
|
|
|
|
{
|
|
|
|
// no point caring about the content of var at this point
|
|
|
|
var = Cvar_FlagToName(num);
|
|
|
|
|
|
|
|
if (var)
|
|
|
|
Con_Printf(" %s", var);
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf("\n\n");
|
|
|
|
return;
|
2005-08-23 03:25:22 +00:00
|
|
|
case '-':
|
|
|
|
break;
|
|
|
|
default:
|
2005-08-22 22:21:59 +00:00
|
|
|
Con_Printf("Invalid option for cvarlist\nUse cvarlist -h for help\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
search = var;
|
|
|
|
}
|
|
|
|
|
2005-08-23 03:25:22 +00:00
|
|
|
// this is sane.. hopefully
|
|
|
|
if (gsearch)
|
|
|
|
Q_strlwr(gsearch);
|
|
|
|
|
|
|
|
if (search)
|
|
|
|
Q_strlwr(search);
|
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
for (grp=cvar_groups ; grp ; grp=grp->next)
|
|
|
|
{
|
2005-08-22 22:21:59 +00:00
|
|
|
// list only cvars with group search substring
|
2005-08-23 03:25:22 +00:00
|
|
|
if (gsearch)
|
|
|
|
{
|
|
|
|
Q_strncpyz(strtmp, grp->name, 512);
|
|
|
|
Q_strlwr(strtmp);
|
|
|
|
if (!wildcmp(gsearch, strtmp))
|
|
|
|
continue;
|
|
|
|
}
|
2005-08-22 22:21:59 +00:00
|
|
|
|
|
|
|
gnum = 0;
|
|
|
|
for (cmd=grp->cvars ; cmd ; cmd=cmd->next)
|
|
|
|
{
|
|
|
|
// list only non-restricted cvars
|
|
|
|
if ((cmd->restriction?cmd->restriction:rcon_level.value) > Cmd_ExecLevel)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// list only cvars with search substring
|
2005-08-23 03:25:22 +00:00
|
|
|
if (search)
|
|
|
|
{
|
|
|
|
Q_strncpyz(strtmp, cmd->name, 512);
|
|
|
|
Q_strlwr(strtmp);
|
|
|
|
|
|
|
|
if (!wildcmp(search, strtmp))
|
|
|
|
{
|
|
|
|
if (cmd->name2)
|
|
|
|
{
|
|
|
|
Q_strncpyz(strtmp, cmd->name2, 512);
|
|
|
|
Q_strlwr(strtmp);
|
|
|
|
if (!wildcmp(search, strtmp))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2005-08-22 22:21:59 +00:00
|
|
|
|
|
|
|
// list only cvars with matching flags
|
2005-08-23 03:25:22 +00:00
|
|
|
if ((listflags & CLF_FLAGMASK) && !(cmd->flags & cvarflags))
|
2005-08-22 22:21:59 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// print cvar list header
|
|
|
|
if (!(listflags & CLF_RAW) && !num)
|
|
|
|
Con_TPrintf(TL_CVARLISTHEADER);
|
|
|
|
|
|
|
|
// print group header
|
|
|
|
if (!(listflags & CLF_RAW) && !gnum)
|
|
|
|
Con_Printf("%s --\n", grp->name);
|
|
|
|
|
|
|
|
// print restriction level
|
|
|
|
if (listflags & CLF_LEVEL)
|
|
|
|
Con_Printf("(%i) ", cmd->restriction);
|
|
|
|
|
|
|
|
// print cvar name
|
|
|
|
Con_Printf(cmd->name);
|
|
|
|
|
|
|
|
// print current value
|
|
|
|
if (listflags & CLF_VALUES)
|
|
|
|
{
|
|
|
|
if (*cmd->string)
|
|
|
|
Con_Printf(" %s", cmd->string);
|
|
|
|
}
|
|
|
|
|
|
|
|
// print default value
|
|
|
|
if (listflags & CLF_DEFAULT)
|
|
|
|
Con_Printf(", default \"%s\"", cmd->defaultstr);
|
|
|
|
|
2005-08-23 03:25:22 +00:00
|
|
|
// print alternate name
|
|
|
|
if ((listflags & CLF_ALTNAME) && cmd->name2)
|
|
|
|
Con_Printf(", alternate %s", cmd->name2);
|
|
|
|
|
2005-08-22 22:21:59 +00:00
|
|
|
// print cvar flags
|
|
|
|
if (listflags & CLF_FLAGS)
|
|
|
|
{
|
|
|
|
for (i = 1; i <= CVAR_LASTFLAG; i <<= 1)
|
|
|
|
{
|
|
|
|
if (i & cmd->flags)
|
|
|
|
{
|
|
|
|
var = Cvar_FlagToName(i);
|
|
|
|
if (var)
|
|
|
|
Con_Printf(" %s", var);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// print latched value
|
|
|
|
if (listflags & CLF_LATCHES)
|
|
|
|
{
|
|
|
|
if (cmd->latched_string)
|
|
|
|
Con_Printf(", latched as \"%s\"", cmd->latched_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
// print new line to finish individual cvar
|
|
|
|
Con_Printf("\n");
|
|
|
|
|
|
|
|
num++;
|
|
|
|
gnum++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// print new line to seperate groups
|
|
|
|
if (!(listflags & CLF_RAW) && gnum)
|
|
|
|
Con_Printf("\n");
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-23 03:25:22 +00:00
|
|
|
#define CRF_ALTNAME 0x1
|
|
|
|
void Cvar_Reset_f (void)
|
|
|
|
{
|
|
|
|
cvar_group_t *grp;
|
|
|
|
cvar_t *cmd;
|
|
|
|
int i, listflags;
|
|
|
|
char *var;
|
|
|
|
char *search, *gsearch;
|
|
|
|
char strtmp[512];
|
|
|
|
|
|
|
|
search = gsearch = NULL;
|
|
|
|
|
|
|
|
// parse command line options
|
|
|
|
for (i = 1; i < Cmd_Argc(); i++)
|
|
|
|
{
|
|
|
|
var = Cmd_Argv(i);
|
|
|
|
if (*var == '-')
|
|
|
|
{
|
|
|
|
// short options
|
|
|
|
for (var++; *var; var++)
|
|
|
|
{
|
|
|
|
switch (*var)
|
|
|
|
{
|
|
|
|
case 'a':
|
|
|
|
listflags |= CRF_ALTNAME;
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
// fix this so we can search for multiple groups
|
|
|
|
i++;
|
|
|
|
if (i >= Cmd_Argc())
|
|
|
|
{
|
|
|
|
Con_Printf("Missing parameter for -g\nUse cvarlist -h for help\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gsearch = Cmd_Argv(i);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
Con_Printf("cvarreset resets all cvars to default values matching given parameters\n"
|
|
|
|
"Syntax: cvarreset [-a] (-g group)/cvar\n"
|
|
|
|
" -a matches cvar against alternate cvar names\n"
|
|
|
|
" -g matches using wildcards in group\n"
|
|
|
|
" -h shows this help message\n"
|
|
|
|
" cvar indicates the cvars to reset, wildcards (*, ?) accepted\n"
|
|
|
|
"A -g or cvar is required\n");
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
Con_Printf("Invalid option for cvarreset\nUse cvarreset -h for help\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
search = var;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!search && !gsearch)
|
|
|
|
{
|
|
|
|
Con_Printf("No group or cvars given\nUse cvarreset -h for help\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this should be sane.. hopefully
|
|
|
|
if (search)
|
|
|
|
Q_strlwr(search);
|
|
|
|
if (gsearch)
|
|
|
|
Q_strlwr(gsearch);
|
|
|
|
|
|
|
|
for (grp=cvar_groups ; grp ; grp=grp->next)
|
|
|
|
{
|
|
|
|
if (gsearch)
|
|
|
|
{
|
|
|
|
Q_strncpyz(strtmp, grp->name, 512);
|
|
|
|
Q_strlwr(strtmp);
|
|
|
|
if (!wildcmp(gsearch, strtmp))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cmd=grp->cvars ; cmd ; cmd=cmd->next)
|
|
|
|
{
|
|
|
|
// reset only non-restricted cvars
|
|
|
|
if ((cmd->restriction?cmd->restriction:rcon_level.value) > Cmd_ExecLevel)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// reset only cvars with search substring
|
|
|
|
if (search)
|
|
|
|
{
|
|
|
|
Q_strncpyz(strtmp, cmd->name, 512);
|
|
|
|
Q_strlwr(strtmp);
|
|
|
|
|
|
|
|
if (!wildcmp(search, strtmp))
|
|
|
|
{
|
|
|
|
if ((listflags & CRF_ALTNAME) && cmd->name2)
|
|
|
|
{
|
|
|
|
Q_strncpyz(strtmp, cmd->name2, 512);
|
|
|
|
Q_strlwr(strtmp);
|
|
|
|
if (!wildcmp(search, strtmp))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// reset cvar to default
|
|
|
|
Cvar_Set(cmd, cmd->defaultstr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_VariableValue
|
|
|
|
============
|
|
|
|
*/
|
2005-03-28 00:11:59 +00:00
|
|
|
float Cvar_VariableValue (const char *var_name)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
cvar_t *var;
|
2005-07-03 15:16:20 +00:00
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
var = Cvar_FindVar (var_name);
|
|
|
|
if (!var)
|
|
|
|
return 0;
|
|
|
|
return Q_atof (var->string);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_VariableString
|
|
|
|
============
|
|
|
|
*/
|
2005-03-28 00:11:59 +00:00
|
|
|
char *Cvar_VariableString (const char *var_name)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
cvar_t *var;
|
2005-07-03 15:16:20 +00:00
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
var = Cvar_FindVar (var_name);
|
|
|
|
if (!var)
|
|
|
|
return cvar_null_string;
|
|
|
|
return var->string;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_CompleteVariable
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
/* moved to cmd_compleatevariable
|
|
|
|
char *Cvar_CompleteVariable (char *partial)
|
|
|
|
{
|
|
|
|
cvar_group_t *grp;
|
|
|
|
cvar_t *cvar;
|
|
|
|
int len;
|
2005-07-03 15:16:20 +00:00
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
len = Q_strlen(partial);
|
2005-07-03 15:16:20 +00:00
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
if (!len)
|
|
|
|
return NULL;
|
2005-07-03 15:16:20 +00:00
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
// check exact match
|
|
|
|
for (grp=cvar_groups ; grp ; grp=grp->next)
|
|
|
|
for (cvar=grp->cvars ; cvar ; cvar=cvar->next)
|
|
|
|
if (!strcmp (partial,cvar->name))
|
|
|
|
return cvar->name;
|
|
|
|
|
|
|
|
// check partial match
|
|
|
|
for (grp=cvar_groups ; grp ; grp=grp->next)
|
|
|
|
for (cvar=grp->cvars ; cvar ; cvar=cvar->next)
|
|
|
|
if (!Q_strncmp (partial,cvar->name, len))
|
|
|
|
return cvar->name;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_Set
|
|
|
|
============
|
|
|
|
*/
|
2005-03-28 00:11:59 +00:00
|
|
|
cvar_t *Cvar_SetCore (cvar_t *var, const char *value, qboolean force)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
char *latch=NULL;
|
2005-07-03 15:16:20 +00:00
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
if (!var)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((var->flags & CVAR_NOSET) && !force)
|
|
|
|
{
|
|
|
|
Con_Printf ("variable %s is readonly\n", var->name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var->flags & CVAR_SERVEROVERRIDE && !force)
|
|
|
|
latch = "variable %s is under server control - latched\n";
|
|
|
|
else if (var->flags & CVAR_LATCH)
|
|
|
|
latch = "variable %s is latched\n";
|
|
|
|
else if (var->flags & CVAR_RENDERERLATCH && qrenderer)
|
|
|
|
latch = "variable %s will be changed after a renderer restart\n";
|
|
|
|
#ifndef SERVERONLY
|
2004-12-21 04:37:14 +00:00
|
|
|
else if (var->flags & CVAR_CHEAT && !cls.allow_cheats && cls.state)
|
2004-08-21 01:25:48 +00:00
|
|
|
latch = "variable %s is a cheat variable - latched\n";
|
2004-12-21 04:37:14 +00:00
|
|
|
else if (var->flags & CVAR_SEMICHEAT && !cls.allow_semicheats && cls.state)
|
2004-08-21 01:25:48 +00:00
|
|
|
latch = "variable %s is a cheat variable - latched\n";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (latch && !force)
|
|
|
|
{
|
|
|
|
if (cl_warncmd.value)
|
2004-12-24 08:45:56 +00:00
|
|
|
{
|
|
|
|
if (var->latched_string)
|
|
|
|
{ //already latched
|
|
|
|
if (strcmp(var->latched_string, value))
|
|
|
|
Con_Printf (latch, var->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ //new latch
|
|
|
|
if (strcmp(var->string, value))
|
|
|
|
Con_Printf (latch, var->name);
|
|
|
|
}
|
|
|
|
}
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
if (var->latched_string && !strcmp(var->latched_string, value)) //no point, this would force the same
|
|
|
|
return NULL;
|
|
|
|
if (var->latched_string)
|
|
|
|
Z_Free(var->latched_string);
|
2005-07-28 15:52:31 +00:00
|
|
|
if (!strcmp(var->string, value)) //latch to the original value? remove the latch.
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
var->latched_string = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-03-28 00:11:59 +00:00
|
|
|
var->latched_string = (char*)Z_Malloc(strlen(value)+1);
|
2004-08-21 01:25:48 +00:00
|
|
|
strcpy(var->latched_string, value);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef CLIENTONLY
|
|
|
|
if (var->flags & CVAR_SERVERINFO)
|
|
|
|
{
|
|
|
|
Info_SetValueForKey (svs.info, var->name, value, MAX_SERVERINFO_STRING);
|
|
|
|
SV_SendServerInfoChange(var->name, value);
|
|
|
|
// SV_BroadcastCommand ("fullserverinfo \"%s\"\n", svs.info);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifndef SERVERONLY
|
|
|
|
if (var->flags & CVAR_USERINFO)
|
|
|
|
{
|
|
|
|
Info_SetValueForKey (cls.userinfo, var->name, value, MAX_INFO_STRING);
|
|
|
|
if (cls.state >= ca_connected)
|
|
|
|
{
|
|
|
|
#ifdef Q2CLIENT
|
2005-08-07 18:08:13 +00:00
|
|
|
if (cls.protocol == CP_QUAKE2 || cls.protocol == CP_QUAKE3) //q2 just resends the lot. Kinda bad...
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
cls.resendinfo = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2005-03-23 22:14:08 +00:00
|
|
|
CL_SendClientCommand(true, "setinfo \"%s\" \"%s\"\n", var->name, value);
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 16:21:27 +00:00
|
|
|
latch = var->string;
|
2005-07-03 15:16:20 +00:00
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
var->string = (char*)Z_Malloc (Q_strlen(value)+1);
|
2004-08-21 01:25:48 +00:00
|
|
|
Q_strcpy (var->string, value);
|
|
|
|
var->value = Q_atof (var->string);
|
|
|
|
|
2005-04-16 16:21:27 +00:00
|
|
|
if (latch)
|
|
|
|
{
|
|
|
|
if (strcmp(latch, value))
|
|
|
|
var->modified++; //only modified if it changed.
|
|
|
|
|
|
|
|
Z_Free (latch); // free the old value string
|
|
|
|
}
|
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
if (var->latched_string) //we may as well have this here.
|
|
|
|
{
|
|
|
|
Z_Free(var->latched_string);
|
|
|
|
var->latched_string = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cvar_ForceCheatVars(qboolean semicheats, qboolean absolutecheats)
|
|
|
|
{ //this either unlatches if the cheat type is allowed, or enforces a default for full cheats and blank for semicheats.
|
|
|
|
//this is clientside only.
|
|
|
|
//if a value is enforced, it is latched to the old value.
|
|
|
|
cvar_group_t *grp;
|
|
|
|
cvar_t *var;
|
|
|
|
|
|
|
|
char *latch;
|
|
|
|
|
|
|
|
for (grp=cvar_groups ; grp ; grp=grp->next)
|
|
|
|
for (var=grp->cvars ; var ; var=var->next)
|
|
|
|
{
|
|
|
|
if (!(var->flags & (CVAR_CHEAT|CVAR_SEMICHEAT)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
latch = var->latched_string;
|
|
|
|
var->latched_string = NULL;
|
|
|
|
if (!latch)
|
|
|
|
{
|
|
|
|
latch = var->string;
|
|
|
|
var->string = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var->flags & CVAR_CHEAT)
|
|
|
|
{
|
|
|
|
if (!absolutecheats)
|
|
|
|
Cvar_ForceSet(var, var->defaultstr);
|
|
|
|
else
|
|
|
|
Cvar_ForceSet(var, latch);
|
|
|
|
}
|
|
|
|
if (var->flags & CVAR_SEMICHEAT)
|
|
|
|
{
|
|
|
|
if (!semicheats)
|
|
|
|
Cvar_ForceSet(var, "");
|
|
|
|
else
|
|
|
|
Cvar_ForceSet(var, latch);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (latch)
|
|
|
|
{
|
|
|
|
if (!strcmp(var->string, latch))
|
|
|
|
Z_Free(latch);
|
|
|
|
else
|
|
|
|
var->latched_string = latch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cvar_ApplyLatches(int latchflag)
|
|
|
|
{
|
|
|
|
cvar_group_t *grp;
|
|
|
|
cvar_t *var;
|
2004-09-04 17:39:47 +00:00
|
|
|
int mask = ~0;
|
|
|
|
|
2004-10-10 06:32:29 +00:00
|
|
|
if (latchflag == CVAR_SERVEROVERRIDE) //these ones are cleared
|
2004-09-04 17:39:47 +00:00
|
|
|
mask = ~CVAR_SERVEROVERRIDE;
|
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
for (grp=cvar_groups ; grp ; grp=grp->next)
|
|
|
|
for (var=grp->cvars ; var ; var=var->next)
|
|
|
|
{
|
|
|
|
if (var->flags & latchflag)
|
|
|
|
{
|
|
|
|
if (var->latched_string)
|
|
|
|
{
|
|
|
|
Cvar_ForceSet(var, var->latched_string);
|
|
|
|
}
|
2004-09-04 17:39:47 +00:00
|
|
|
var->flags &= mask;
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
cvar_t *Cvar_Set (cvar_t *var, const char *value)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
return Cvar_SetCore(var, value, false);
|
|
|
|
}
|
2005-03-28 00:11:59 +00:00
|
|
|
cvar_t *Cvar_ForceSet (cvar_t *var, const char *value)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
return Cvar_SetCore(var, value, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_SetValue
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
void Cvar_SetValue (cvar_t *var, float value)
|
|
|
|
{
|
|
|
|
char val[32];
|
|
|
|
|
|
|
|
if (value == (int)value)
|
|
|
|
sprintf (val, "%i",(int)value); //make it look nicer.
|
|
|
|
else
|
|
|
|
sprintf (val, "%f",value);
|
|
|
|
Cvar_Set (var, val);
|
|
|
|
}
|
|
|
|
|
2005-01-07 02:46:54 +00:00
|
|
|
void Cvar_Free(cvar_t *tbf)
|
|
|
|
{
|
|
|
|
cvar_t *var;
|
|
|
|
cvar_group_t *grp;
|
|
|
|
if (!(tbf->flags & CVAR_POINTER))
|
|
|
|
return; //only freeable if it was a pointer to begin with.
|
|
|
|
|
|
|
|
for (grp=cvar_groups ; grp ; grp=grp->next)
|
|
|
|
{
|
|
|
|
if (grp->cvars == tbf)
|
|
|
|
{
|
|
|
|
grp->cvars = tbf->next;
|
|
|
|
goto unlinked;
|
|
|
|
}
|
|
|
|
for (var=grp->cvars ; var->next ; var=var->next)
|
|
|
|
{
|
|
|
|
if (var->next == tbf)
|
|
|
|
{
|
|
|
|
var->next = tbf->next;
|
|
|
|
goto unlinked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unlinked:
|
|
|
|
Z_Free(tbf->string);
|
|
|
|
Z_Free(tbf->defaultstr);
|
|
|
|
if (tbf->latched_string)
|
|
|
|
Z_Free(tbf->latched_string);
|
|
|
|
Z_Free(tbf);
|
|
|
|
}
|
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_RegisterVariable
|
|
|
|
|
|
|
|
Adds a freestanding variable to the variable list.
|
|
|
|
============
|
|
|
|
*/
|
2005-03-28 00:11:59 +00:00
|
|
|
void Cvar_Register (cvar_t *variable, const char *groupname)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
cvar_t *old;
|
|
|
|
cvar_group_t *group;
|
|
|
|
char value[512];
|
|
|
|
|
2005-01-07 02:46:54 +00:00
|
|
|
// copy the value off, because future sets will Z_Free it
|
|
|
|
strcpy (value, variable->string);
|
|
|
|
|
2005-07-28 15:22:15 +00:00
|
|
|
// check to see if it has already been defined
|
2004-08-21 01:25:48 +00:00
|
|
|
old = Cvar_FindVar (variable->name);
|
|
|
|
if (old)
|
|
|
|
{
|
|
|
|
if (old->flags & CVAR_POINTER)
|
|
|
|
{
|
|
|
|
group = Cvar_GetGroup(groupname);
|
|
|
|
|
|
|
|
variable->modified = old->modified;
|
2005-01-07 02:46:54 +00:00
|
|
|
variable->flags |= old->flags & CVAR_ARCHIVE;
|
|
|
|
|
|
|
|
// link the variable in
|
|
|
|
variable->next = group->cvars;
|
|
|
|
variable->restriction = old->restriction; //exe registered vars
|
|
|
|
group->cvars = variable;
|
|
|
|
|
|
|
|
// make sure it can be zfreed
|
2005-03-28 00:11:59 +00:00
|
|
|
variable->string = (char*)Z_Malloc (1);
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2005-01-07 02:46:54 +00:00
|
|
|
//cheat prevention - engine set default is the one that stays.
|
2005-03-28 00:11:59 +00:00
|
|
|
variable->defaultstr = (char*)Z_Malloc (strlen(value)+1); //give it it's default (for server controlled vars and things)
|
2005-01-07 02:46:54 +00:00
|
|
|
strcpy (variable->defaultstr, value);
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2005-01-07 02:46:54 +00:00
|
|
|
// set it through the function to be consistant
|
|
|
|
if (old->latched_string)
|
|
|
|
Cvar_SetCore (variable, old->latched_string, true);
|
2004-08-21 01:25:48 +00:00
|
|
|
else
|
2005-01-07 02:46:54 +00:00
|
|
|
Cvar_SetCore (variable, old->string, true);
|
|
|
|
|
|
|
|
Cvar_Free(old);
|
2004-08-21 01:25:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-07-03 15:16:20 +00:00
|
|
|
|
2005-07-28 15:22:15 +00:00
|
|
|
Con_Printf ("Can't register variable %s, already defined\n", variable->name);
|
2004-08-21 01:25:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for overlap with a command
|
|
|
|
if (Cmd_Exists (variable->name))
|
|
|
|
{
|
|
|
|
Con_Printf ("Cvar_RegisterVariable: %s is a command\n", variable->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
group = Cvar_GetGroup(groupname);
|
|
|
|
|
|
|
|
// link the variable in
|
|
|
|
variable->next = group->cvars;
|
|
|
|
variable->restriction = 0; //exe registered vars
|
|
|
|
group->cvars = variable;
|
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
variable->string = (char*)Z_Malloc (1);
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
variable->defaultstr = (char*)Z_Malloc (strlen(value)+1); //give it it's default (for server controlled vars and things)
|
2004-08-21 01:25:48 +00:00
|
|
|
strcpy (variable->defaultstr, value);
|
|
|
|
|
|
|
|
// set it through the function to be consistant
|
|
|
|
Cvar_SetCore (variable, value, true);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
void Cvar_RegisterVariable (cvar_t *variable)
|
2005-07-03 15:16:20 +00:00
|
|
|
{
|
2004-08-21 01:25:48 +00:00
|
|
|
Cvar_Register(variable, NULL);
|
|
|
|
}
|
|
|
|
*/
|
2005-03-28 00:11:59 +00:00
|
|
|
cvar_t *Cvar_Get(const char *name, const char *defaultvalue, int flags, const char *group)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
cvar_t *var;
|
|
|
|
var = Cvar_FindVar(name);
|
|
|
|
|
|
|
|
if (var)
|
|
|
|
{
|
|
|
|
//allow this to change all < cvar_latch values.
|
|
|
|
//this allows q2 dlls to apply different flags to a cvar without destroying our important ones (like cheat).
|
2005-06-04 04:20:20 +00:00
|
|
|
var->flags = (var->flags & ~(CVAR_NOSET)) | (flags & (CVAR_NOSET|CVAR_SERVERINFO|CVAR_USERINFO|CVAR_ARCHIVE));
|
2004-08-21 01:25:48 +00:00
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
var = (cvar_t*)Z_Malloc(sizeof(cvar_t)+strlen(name)+1);
|
2004-08-21 01:25:48 +00:00
|
|
|
var->name = (char *)(var+1);
|
|
|
|
strcpy(var->name, name);
|
2005-03-28 00:11:59 +00:00
|
|
|
var->string = (char*)defaultvalue;
|
2005-01-07 02:46:54 +00:00
|
|
|
var->flags = flags|CVAR_POINTER|CVAR_USERCREATED;
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
Cvar_Register(var, group);
|
|
|
|
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
|
|
|
//prevent the client from altering the cvar until they change map or the server resets the var to the default.
|
2005-03-28 00:11:59 +00:00
|
|
|
void Cvar_LockFromServer(cvar_t *var, const char *str)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
char *oldlatch;
|
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
Con_DPrintf("Server taking control of cvar %s (%s)\n", var->name, str);
|
2004-10-10 06:32:29 +00:00
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
var->flags |= CVAR_SERVEROVERRIDE;
|
|
|
|
|
|
|
|
oldlatch = var->latched_string;
|
|
|
|
if (oldlatch) //maintaining control
|
|
|
|
var->latched_string = NULL;
|
|
|
|
else //taking control
|
|
|
|
{
|
2005-03-28 00:11:59 +00:00
|
|
|
oldlatch = (char*)Z_Malloc(strlen(var->string)+1);
|
2004-08-21 01:25:48 +00:00
|
|
|
strcpy(oldlatch, var->string);
|
|
|
|
}
|
|
|
|
|
|
|
|
Cvar_SetCore (var, str, true); //will use all, quote included
|
|
|
|
|
2005-07-28 15:52:31 +00:00
|
|
|
var->latched_string = oldlatch; //keep track of the original value.
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_Command
|
|
|
|
|
|
|
|
Handles variable inspection and changing from the console
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
qboolean Cvar_Command (int level)
|
|
|
|
{
|
|
|
|
cvar_t *v;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
// check variables
|
|
|
|
v = Cvar_FindVar (Cmd_Argv(0));
|
|
|
|
if (!v)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((v->restriction?v->restriction:rcon_level.value) > level)
|
|
|
|
{
|
|
|
|
Con_Printf ("You do not have the priveledges for %s\n", v->name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:21:27 +00:00
|
|
|
if (v->flags & CVAR_NOTFROMSERVER && Cmd_FromGamecode())
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
Con_Printf ("Server tried setting %s cvar\n", v->name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// perform a variable print or set
|
|
|
|
if (Cmd_Argc() == 1)
|
|
|
|
{
|
|
|
|
Con_Printf ("\"%s\" is \"%s\"\n", v->name, v->string);
|
|
|
|
if (v->latched_string)
|
|
|
|
Con_Printf ("Latched as \"%s\"\n", v->latched_string);
|
2005-07-01 19:23:00 +00:00
|
|
|
Con_Printf("Default: \"%s\"\n", v->defaultstr);
|
2004-08-21 01:25:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Cmd_Argc() == 2)
|
|
|
|
str = Cmd_Argv(1);
|
|
|
|
else
|
|
|
|
str = Cmd_Args();
|
|
|
|
|
|
|
|
if (v->flags & CVAR_NOSET)
|
|
|
|
{
|
|
|
|
Con_Printf ("Cvar %s may not be set via the console\n", v->name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#ifndef SERVERONLY
|
|
|
|
if (Cmd_ExecLevel > RESTRICT_SERVER)
|
|
|
|
{ //directed at a secondary player.
|
2005-03-23 22:14:08 +00:00
|
|
|
CL_SendClientCommand(true, "%i setinfo %s \"%s\"", Cmd_ExecLevel - RESTRICT_SERVER-1, v->name, str);
|
2004-08-21 01:25:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v->flags & CVAR_SERVEROVERRIDE)
|
|
|
|
{
|
2005-04-16 16:21:27 +00:00
|
|
|
if (Cmd_FromGamecode())
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
if (!strcmp(v->defaultstr, str)) //returning to default
|
|
|
|
{
|
|
|
|
v->flags &= ~CVAR_SERVEROVERRIDE;
|
|
|
|
if (v->latched_string)
|
|
|
|
str = v->latched_string; //set to the latched
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Cvar_LockFromServer(v, str);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//let cvar_set latch if needed.
|
|
|
|
}
|
2005-04-16 16:21:27 +00:00
|
|
|
else if (Cmd_FromGamecode())
|
2005-07-03 15:16:20 +00:00
|
|
|
{//it's not latched yet
|
|
|
|
if (strcmp(v->defaultstr, str))
|
|
|
|
{ //lock the cvar, unless it's going to it's default value.
|
|
|
|
Cvar_LockFromServer(v, str);
|
|
|
|
return true;
|
|
|
|
}
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
Cvar_Set (v, str); //will use all, quote included
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cvar_WriteVariables
|
|
|
|
|
|
|
|
Writes lines containing "set variable value" for all variables
|
|
|
|
with the archive flag set to true.
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
void Cvar_WriteVariables (FILE *f, qboolean all)
|
|
|
|
{
|
|
|
|
qboolean writtengroupheader;
|
|
|
|
cvar_group_t *grp;
|
|
|
|
cvar_t *var;
|
|
|
|
char *val;
|
|
|
|
|
|
|
|
for (grp=cvar_groups ; grp ; grp=grp->next)
|
|
|
|
{
|
|
|
|
writtengroupheader = false;
|
|
|
|
for (var = grp->cvars ; var ; var = var->next)
|
|
|
|
if (var->flags & CVAR_ARCHIVE || all)
|
|
|
|
{
|
|
|
|
if (!writtengroupheader)
|
|
|
|
{
|
|
|
|
writtengroupheader = true;
|
|
|
|
fprintf(f, "\n// %s\n", grp->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
val = var->string; //latched vars should act differently.
|
|
|
|
if (var->latched_string)
|
|
|
|
val = var->latched_string;
|
|
|
|
|
|
|
|
if (var->flags & CVAR_USERCREATED)
|
|
|
|
{
|
|
|
|
if (var->flags & CVAR_ARCHIVE)
|
|
|
|
fprintf (f, "seta %s \"%s\"\n", var->name, val);
|
|
|
|
else
|
|
|
|
fprintf (f, "set %s \"%s\"\n", var->name, val);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fprintf (f, "%s \"%s\"\n", var->name, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cvar_Shutdown(void)
|
|
|
|
{
|
|
|
|
cvar_t *var;
|
|
|
|
cvar_group_t *grp;
|
|
|
|
while(cvar_groups)
|
|
|
|
{
|
|
|
|
while(cvar_groups->cvars)
|
|
|
|
{
|
|
|
|
var = cvar_groups->cvars;
|
|
|
|
cvar_groups->cvars = var->next;
|
|
|
|
|
|
|
|
Z_Free(var->string);
|
|
|
|
if (var->flags & CVAR_POINTER)
|
|
|
|
Z_Free(var);
|
|
|
|
}
|
|
|
|
|
|
|
|
grp = cvar_groups;
|
|
|
|
cvar_groups = grp->next;
|
|
|
|
Z_Free(grp);
|
|
|
|
}
|
|
|
|
}
|