From 657e7321f68c3952ca6f783d26f7eb6bd1e0c93d Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 17 Dec 2018 13:38:23 -0500 Subject: [PATCH 1/7] Decouple execversion from MODVERSION; add scheme for MINORMODVERSION --- src/command.c | 12 ++++++++---- src/doomdef.h | 6 ++++++ src/m_misc.c | 8 ++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/command.c b/src/command.c index 47c6d2e5..3045c176 100644 --- a/src/command.c +++ b/src/command.c @@ -63,7 +63,7 @@ CV_PossibleValue_t CV_YesNo[] = {{0, "No"}, {1, "Yes"}, {0, NULL}}; CV_PossibleValue_t CV_Unsigned[] = {{0, "MIN"}, {999999999, "MAX"}, {0, NULL}}; CV_PossibleValue_t CV_Natural[] = {{1, "MIN"}, {999999999, "MAX"}, {0, NULL}}; -// Filter consvars by MODVERSION +// 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}; @@ -1589,7 +1589,7 @@ void CV_InitFilterVar(void) static boolean CV_FilterJoyAxisVars(consvar_t *v, const char *valstr) { // If ALL axis settings are previous defaults, set them to the new defaults - // MODVERSION < 26 (2.1.21) + // EXECVERSION < 26 (2.1.21) if (joyaxis_default) { @@ -1730,6 +1730,11 @@ static boolean CV_FilterJoyAxisVars(consvar_t *v, const char *valstr) static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr) { + INT32 majorexecversion = abs(cv_execversion.value) & 0xFFFF; +#if 0 // unused for now + INT32 minorexecversion = abs(cv_execversion.value) >> 16; +#endif + // True means allow the CV change, False means block it // We only care about CV_SAVE because this filters the user's config files @@ -1737,8 +1742,7 @@ static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr) if (!(v->flags & CV_SAVE)) return true; - // We go by MODVERSION here - if (cv_execversion.value < 26) // 26 = 2.1.21 + if (majorexecversion < 26) // 26 = 2.1.21 { // MOUSE SETTINGS // alwaysfreelook split between first and third person (chasefreelook) diff --git a/src/doomdef.h b/src/doomdef.h index 796221c9..0485698d 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -216,6 +216,12 @@ extern FILE *logstream; // Note that we use this to help keep internal testing in check; this is why v2.1.0 is not version "1". #define MODVERSION 26 +// To version config.cfg, EXECVERSION was originally equal to MODVERSION +// So keep it equal to MODVERSION, and increment MINOREXECVERSION whenever a config change +// is needed that does not correspond to an increment in MODVERSION +#define EXECVERSION 26 +#define MINOREXECVERSION 1 + // ========================================================================= // The maximum number of players, multiplayer/networking. diff --git a/src/m_misc.c b/src/m_misc.c index 1ab5f1fe..bb25c540 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -451,7 +451,7 @@ void Command_LoadConfig_f(void) COM_BufInsertText(va("exec \"%s\"\n", configfile)); // don't filter anymore vars and don't let this convsvar be changed - COM_BufInsertText(va("%s \"%d\"\n", cv_execversion.name, MODVERSION)); + COM_BufInsertText(va("%s \"%d\"\n", cv_execversion.name, EXECVERSION)); cv_execversion.flags |= CV_HIDEN; } @@ -503,7 +503,7 @@ void M_FirstLoadConfig(void) // no COM_BufExecute() needed; that does it right away // don't filter anymore vars and don't let this convsvar be changed - COM_BufInsertText(va("%s \"%d\"\n", cv_execversion.name, MODVERSION)); + COM_BufInsertText(va("%s \"%d\"\n", cv_execversion.name, EXECVERSION)); cv_execversion.flags |= CV_HIDEN; // make sure I_Quit() will write back the correct config @@ -562,8 +562,8 @@ void M_SaveConfig(const char *filename) fprintf(f, "// SRB2 configuration file.\n"); // print execversion FIRST, because subsequent consvars need to be filtered - // always print current MODVERSION - fprintf(f, "%s \"%d\"\n", cv_execversion.name, MODVERSION); + // always print current EXECVERSION + fprintf(f, "%s \"%d\"\n", cv_execversion.name, (EXECVERSION + (MINOREXECVERSION << 16))); // FIXME: save key aliases if ever implemented.. From b64dd82034e65e719465b8cd54ad5a223e6a7ecf Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 17 Dec 2018 13:39:24 -0500 Subject: [PATCH 2/7] Attempt to fix cv_execversion being accessible by console --- src/m_misc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/m_misc.c b/src/m_misc.c index bb25c540..556e56a2 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -443,7 +443,7 @@ void Command_LoadConfig_f(void) FIL_ForceExtension(configfile, ".cfg"); // temporarily reset execversion to default - cv_execversion.flags &= ~CV_HIDEN; + cv_execversion.flags = 0; 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_execversion.flags = CV_HIDEN; } /** 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 &= ~CV_HIDEN; + cv_execversion.flags = 0; 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_execversion.flags = CV_HIDEN; // make sure I_Quit() will write back the correct config // (do not write back the config if it crash before) From 969960a1ebbcd0c4907a9fa110d1b6cf5da2c5b3 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 20 Dec 2018 02:14:41 -0500 Subject: [PATCH 3/7] Adjust EXECVERSION define scheme* MAJOREXECVERSION and MINOREXECVERSION* GETEXECVERSION(major, minor) macro --- src/doomdef.h | 16 ++++++++++++---- src/m_misc.c | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 0485698d..0e059cd1 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -216,11 +216,19 @@ extern FILE *logstream; // Note that we use this to help keep internal testing in check; this is why v2.1.0 is not version "1". #define MODVERSION 26 -// To version config.cfg, EXECVERSION was originally equal to MODVERSION -// So keep it equal to MODVERSION, and increment MINOREXECVERSION whenever a config change -// is needed that does not correspond to an increment in MODVERSION -#define EXECVERSION 26 +// To version config.cfg, set MAJOREXECVERSION equal to MODVERSION +// and increment SUBEXECVERSION whenever a config change is needed +// that does not correspond to an increment in MODVERSION. +// If MAJOREXECVERSION increases, set MINOREXECVERSION to 0. +#define MAJOREXECVERSION 26 #define MINOREXECVERSION 1 +// (It would have been nice to use VERSION and SUBVERSION but those are different for DEVELOP builds) + +// Macros +#define GETMAJOREXECVERSION(v) (v & 0xFFFF) +#define GETMINOREXECVERSION(v) (v >> 16) +#define GETEXECVERSION(major,minor) (major + (minor << 16)) +#define EXECVERSION GETEXECVERSION(MAJOREXECVERSION, MINOREXECVERSION) // ========================================================================= diff --git a/src/m_misc.c b/src/m_misc.c index 556e56a2..1b92a8c4 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -563,7 +563,7 @@ void M_SaveConfig(const char *filename) // print execversion FIRST, because subsequent consvars need to be filtered // always print current EXECVERSION - fprintf(f, "%s \"%d\"\n", cv_execversion.name, (EXECVERSION + (MINOREXECVERSION << 16))); + fprintf(f, "%s \"%d\"\n", cv_execversion.name, EXECVERSION); // FIXME: save key aliases if ever implemented.. From 60bcf925253a1e24eebd221a02d284e48f19e58d Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 20 Dec 2018 02:18:59 -0500 Subject: [PATCH 4/7] Adjust execversion retrieval in CV_FilterVarByVersion --- src/command.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/command.c b/src/command.c index 3045c176..3bd80e1e 100644 --- a/src/command.c +++ b/src/command.c @@ -1730,11 +1730,6 @@ static boolean CV_FilterJoyAxisVars(consvar_t *v, const char *valstr) static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr) { - INT32 majorexecversion = abs(cv_execversion.value) & 0xFFFF; -#if 0 // unused for now - INT32 minorexecversion = abs(cv_execversion.value) >> 16; -#endif - // True means allow the CV change, False means block it // We only care about CV_SAVE because this filters the user's config files @@ -1742,7 +1737,7 @@ static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr) if (!(v->flags & CV_SAVE)) return true; - if (majorexecversion < 26) // 26 = 2.1.21 + if (GETMAJOREXECVERSION(cv_execversion.value) < 26) // 26 = 2.1.21 { // MOUSE SETTINGS // alwaysfreelook split between first and third person (chasefreelook) From 04916edc07396a1ba8605a871afad3e6ec818b5c Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 20 Dec 2018 04:03:35 -0500 Subject: [PATCH 5/7] Update EXECVERSION to MODVERSION 27 --- src/doomdef.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 0e059cd1..03f38098 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -214,14 +214,14 @@ extern FILE *logstream; // it's only for detection of the version the player is using so the MS can alert them of an update. // Only set it higher, not lower, obviously. // Note that we use this to help keep internal testing in check; this is why v2.1.0 is not version "1". -#define MODVERSION 26 +#define MODVERSION 27 // To version config.cfg, set MAJOREXECVERSION equal to MODVERSION // and increment SUBEXECVERSION whenever a config change is needed // that does not correspond to an increment in MODVERSION. // If MAJOREXECVERSION increases, set MINOREXECVERSION to 0. -#define MAJOREXECVERSION 26 -#define MINOREXECVERSION 1 +#define MAJOREXECVERSION 27 +#define MINOREXECVERSION 0 // (It would have been nice to use VERSION and SUBVERSION but those are different for DEVELOP builds) // Macros From 9be1ee4ac71c9292bd5a3e9e06db91ccbc2a2055 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 20 Dec 2018 17:16:04 -0500 Subject: [PATCH 6/7] Hardcode define MAJOREXECVERSION to MODVERSION --- src/doomdef.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 2b5c1ce3..02b156d6 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -216,13 +216,13 @@ extern FILE *logstream; // Note that we use this to help keep internal testing in check; this is why v2.1.0 is not version "1". #define MODVERSION 27 -// To version config.cfg, set MAJOREXECVERSION equal to MODVERSION -// and increment SUBEXECVERSION whenever a config change is needed +// 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. -#define MAJOREXECVERSION 27 +#define MAJOREXECVERSION MODVERSION #define MINOREXECVERSION 0 -// (It would have been nice to use VERSION and SUBVERSION but those are different for DEVELOP builds) +// (It would have been nice to use VERSION and SUBVERSION but those are zero'd out for DEVELOP builds) // Macros #define GETMAJOREXECVERSION(v) (v & 0xFFFF) From f1fea30045845df5092e12b2d20bdf4b1fa93f08 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 20 Dec 2018 17:56:51 -0500 Subject: [PATCH 7/7] Properly restrict EXECVERSION from cvar updates --- src/command.c | 15 ++++++++++++++- src/command.h | 1 + src/doomdef.h | 6 +++--- src/m_misc.c | 8 ++++---- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/command.c b/src/command.c index 3bd80e1e..c7ce2bd3 100644 --- a/src/command.c +++ b/src/command.c @@ -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 diff --git a/src/command.h b/src/command.h index 8dee1174..e6767825 100644 --- a/src/command.h +++ b/src/command.h @@ -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); diff --git a/src/doomdef.h b/src/doomdef.h index 02b156d6..1cbe97f2 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -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) diff --git a/src/m_misc.c b/src/m_misc.c index 1b92a8c4..1ef74dc7 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -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)