Properly restrict EXECVERSION from cvar updates

This commit is contained in:
mazmazz 2018-12-20 17:56:51 -05:00
parent 9be1ee4ac7
commit f1fea30045
4 changed files with 22 additions and 8 deletions

View file

@ -49,6 +49,7 @@ static void COM_Wait_f(void);
static void COM_Help_f(void);
static void COM_Toggle_f(void);
static void CV_EnforceExecVersion(void);
static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr);
static boolean CV_Command(void);
static consvar_t *CV_FindVar(const char *name);
@ -66,7 +67,8 @@ CV_PossibleValue_t CV_Natural[] = {{1, "MIN"}, {999999999, "MAX"}, {0, NULL}};
// Filter consvars by EXECVERSION
// First implementation is 26 (2.1.21), so earlier configs default at 25 (2.1.20)
// Also set CV_HIDEN during runtime, after config is loaded
consvar_t cv_execversion = {"execversion","25",0,CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL};
static boolean execversion_enabled = false;
consvar_t cv_execversion = {"execversion","25",CV_CALL,CV_Unsigned, CV_EnforceExecVersion, 0, NULL, NULL, 0, 0, NULL};
// for default joyaxis detection
static boolean joyaxis_default = false;
@ -1586,6 +1588,17 @@ void CV_InitFilterVar(void)
joyaxis_count = joyaxis2_count = 0;
}
void CV_ToggleExecVersion(boolean enable)
{
execversion_enabled = enable;
}
static void CV_EnforceExecVersion(void)
{
if (!execversion_enabled)
CV_StealthSetValue(&cv_execversion, EXECVERSION);
}
static boolean CV_FilterJoyAxisVars(consvar_t *v, const char *valstr)
{
// If ALL axis settings are previous defaults, set them to the new defaults

View file

@ -130,6 +130,7 @@ extern CV_PossibleValue_t CV_Natural[];
extern consvar_t cv_execversion;
void CV_InitFilterVar(void);
void CV_ToggleExecVersion(boolean enable);
// register a variable for use at the console
void CV_RegisterVar(consvar_t *variable);

View file

@ -217,9 +217,9 @@ extern FILE *logstream;
#define MODVERSION 27
// To version config.cfg, MAJOREXECVERSION is set equal to MODVERSION automatically.
// Increment SUBEXECVERSION whenever a config change is needed
// that does not correspond to an increment in MODVERSION.
// If MAJOREXECVERSION increases, set MINOREXECVERSION to 0.
// Increment MINOREXECVERSION whenever a config change is needed that does not correspond
// to an increment in MODVERSION. This might never happen in practice.
// If MODVERSION increases, set MINOREXECVERSION to 0.
#define MAJOREXECVERSION MODVERSION
#define MINOREXECVERSION 0
// (It would have been nice to use VERSION and SUBVERSION but those are zero'd out for DEVELOP builds)

View file

@ -443,7 +443,7 @@ void Command_LoadConfig_f(void)
FIL_ForceExtension(configfile, ".cfg");
// temporarily reset execversion to default
cv_execversion.flags = 0;
CV_ToggleExecVersion(true);
COM_BufInsertText(va("%s \"%s\"\n", cv_execversion.name, cv_execversion.defaultvalue));
CV_InitFilterVar();
@ -452,7 +452,7 @@ void Command_LoadConfig_f(void)
// don't filter anymore vars and don't let this convsvar be changed
COM_BufInsertText(va("%s \"%d\"\n", cv_execversion.name, EXECVERSION));
cv_execversion.flags = CV_HIDEN;
CV_ToggleExecVersion(false);
}
/** Saves the current configuration and loads another.
@ -494,7 +494,7 @@ void M_FirstLoadConfig(void)
// temporarily reset execversion to default
// we shouldn't need to do this, but JUST in case...
cv_execversion.flags = 0;
CV_ToggleExecVersion(true);
COM_BufInsertText(va("%s \"%s\"\n", cv_execversion.name, cv_execversion.defaultvalue));
CV_InitFilterVar();
@ -504,7 +504,7 @@ void M_FirstLoadConfig(void)
// don't filter anymore vars and don't let this convsvar be changed
COM_BufInsertText(va("%s \"%d\"\n", cv_execversion.name, EXECVERSION));
cv_execversion.flags = CV_HIDEN;
CV_ToggleExecVersion(false);
// make sure I_Quit() will write back the correct config
// (do not write back the config if it crash before)