From 5b3a1e0c55604fcf588cce5b7e4e40a81e921f46 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 06:28:34 -0500 Subject: [PATCH 1/5] Implement EXECVERSION consvar to invalidate previous versions' default config values --- src/command.c | 212 +++++++++++++++++++++++++++++++++++++++++++++++++- src/command.h | 6 ++ src/m_misc.c | 26 +++++++ 3 files changed, 242 insertions(+), 2 deletions(-) diff --git a/src/command.c b/src/command.c index 5d028d36..454bc76d 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 boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr); static boolean CV_Command(void); static consvar_t *CV_FindVar(const char *name); static const char *CV_StringValue(const char *var_name); @@ -62,6 +63,17 @@ 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 +// 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",CV_SAVE,CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; + +// for default joyaxis detection +static boolean joyaxis_default = false; +static boolean joyaxis2_default = false; +static INT32 joyaxis_count = 0; +static INT32 joyaxis2_count = 0; + #define COM_BUF_SIZE 8192 // command buffer size #define MAX_ALIAS_RECURSION 100 // max recursion allowed for aliases @@ -1568,6 +1580,199 @@ void CV_AddValue(consvar_t *var, INT32 increment) var->changed = 1; // user has changed it now } +void CV_InitFilterVar(void) +{ + joyaxis_default = joyaxis2_default = true; + joyaxis_count = joyaxis2_count = 0; +} + +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) + + if (joyaxis_default) + { +#if !defined (_WII) && !defined (WMINPUT) + if (!stricmp(v->name, "joyaxis_turn")) + { + if (joyaxis_count > 6) return false; + // we're currently setting the new defaults, don't interfere + else if (joyaxis_count == 6) return true; + + if (!stricmp(valstr, "X-Axis")) joyaxis_count++; + else joyaxis_default = false; + } +#if !defined (PSP) + if (!stricmp(v->name, "joyaxis_move")) + { + if (joyaxis_count > 6) return false; + else if (joyaxis_count == 6) return true; + + if (!stricmp(valstr, "Y-Axis")) joyaxis_count++; + else joyaxis_default = false; + } +#endif +#if !defined (_arch_dreamcast) && !defined (_XBOX) && !defined (PSP) + if (!stricmp(v->name, "joyaxis_side")) + { + if (joyaxis_count > 6) return false; + else if (joyaxis_count == 6) return true; + + if (!stricmp(valstr, "Z-Axis")) joyaxis_count++; + else joyaxis_default = false; + } +#endif +#if !defined (_XBOX) && !defined (PSP) + if (!stricmp(v->name, "joyaxis_look")) + { + if (joyaxis_count > 6) return false; + else if (joyaxis_count == 6) return true; + + if (!stricmp(valstr, "None")) joyaxis_count++; + else joyaxis_default = false; + } +#endif + if (!stricmp(v->name, "joyaxis_fire") + || !stricmp(v->name, "joyaxis_firenormal")) + { + if (joyaxis_count > 6) return false; + else if (joyaxis_count == 6) return true; + + if (!stricmp(valstr, "None")) joyaxis_count++; + else joyaxis_default = false; + } +#endif + // reset all axis settings to defaults + if (joyaxis_count == 6) + { + COM_BufInsertText(va("%s \"%s\"\n", cv_turnaxis.name, cv_turnaxis.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_moveaxis.name, cv_moveaxis.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_sideaxis.name, cv_sideaxis.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_lookaxis.name, cv_lookaxis.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_fireaxis.name, cv_fireaxis.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_firenaxis.name, cv_firenaxis.defaultvalue)); + joyaxis_count++; + return false; + } + } + + if (joyaxis2_default) + { +#if !defined (_WII) && !defined (WMINPUT) + if (!stricmp(v->name, "joyaxis2_turn")) + { + if (joyaxis2_count > 6) return false; + // we're currently setting the new defaults, don't interfere + else if (joyaxis2_count == 6) return true; + + if (!stricmp(valstr, "X-Axis")) joyaxis2_count++; + else joyaxis2_default = false; + } +// #if !defined (PSP) + if (!stricmp(v->name, "joyaxis2_move")) + { + if (joyaxis2_count > 6) return false; + else if (joyaxis2_count == 6) return true; + + if (!stricmp(valstr, "Y-Axis")) joyaxis2_count++; + else joyaxis2_default = false; + } +// #endif +#if !defined (_arch_dreamcast) && !defined (_XBOX) && !defined (PSP) + if (!stricmp(v->name, "joyaxis2_side")) + { + if (joyaxis2_count > 6) return false; + else if (joyaxis2_count == 6) return true; + + if (!stricmp(valstr, "Z-Axis")) joyaxis2_count++; + else joyaxis2_default = false; + } +#endif +#if !defined (_XBOX) // && !defined (PSP) + if (!stricmp(v->name, "joyaxis2_look")) + { + if (joyaxis2_count > 6) return false; + else if (joyaxis2_count == 6) return true; + + if (!stricmp(valstr, "None")) joyaxis2_count++; + else joyaxis2_default = false; + } +#endif + if (!stricmp(v->name, "joyaxis2_fire") + || !stricmp(v->name, "joyaxis2_firenormal")) + { + if (joyaxis2_count > 6) return false; + else if (joyaxis2_count == 6) return true; + + if (!stricmp(valstr, "None")) joyaxis2_count++; + else joyaxis2_default = false; + } +#endif + + // reset all axis settings to defaults + if (joyaxis2_count == 6) + { + COM_BufInsertText(va("%s \"%s\"\n", cv_turnaxis2.name, cv_turnaxis2.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_moveaxis2.name, cv_moveaxis2.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_sideaxis2.name, cv_sideaxis2.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_lookaxis2.name, cv_lookaxis2.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_fireaxis2.name, cv_fireaxis2.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_firenaxis2.name, cv_firenaxis2.defaultvalue)); + joyaxis2_count++; + return false; + } + } + + // we haven't reached our counts yet, or we're not default + return true; +} + +static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr) +{ + // True means allow the CV change, False means block it + + // We only care about CV_SAVE because this filters the user's config files + // We do this same check in CV_Command + if (!(v->flags & CV_SAVE)) + return true; + + // We go by MODVERSION here + if (cv_execversion.value < 26) // 26 = 2.1.21 + { + // MOUSE SETTINGS + // alwaysfreelook split between first and third person (chasefreelook) + // mousemove was on by default, which invalidates the current approach + if (!stricmp(v->name, "alwaysfreelook")) + return false; + if (!stricmp(v->name, "mousemove")) + return false; + + // mousesens was changed from 35 to 20 due to oversensitivity + if ((!stricmp(v->name, "mousesens") + || !stricmp(v->name, "mousesens2") + || !stricmp(v->name, "mouseysens") + || !stricmp(v->name, "mouseysens2")) + && atoi(valstr) == 35) + return false; + + // JOYSTICK DEFAULTS + // use_joystick was changed from 0 to 1 to automatically use a joystick if available +#if defined(HAVE_SDL) || defined(_WINDOWS) + if ((!stricmp(v->name, "use_joystick") + || !stricmp(v->name, "use_joystick2")) + && atoi(valstr) == 0) + return false; +#endif + + // axis defaults were changed to be friendly to 360 controllers + // if ALL axis settings are defaults, then change them to new values + if (!CV_FilterJoyAxisVars(v, valstr)) + return false; + } + return true; +} + /** Displays or changes a variable from the console. * Since the user is presumed to have been directly responsible * for this change, the variable is marked as changed this game. @@ -1592,8 +1797,11 @@ static boolean CV_Command(void) return true; } - CV_Set(v, COM_Argv(1)); - v->changed = 1; // now it's been changed by (presumably) the user + if (!(v->flags & CV_SAVE) || CV_FilterVarByVersion(v, COM_Argv(1))) + { + CV_Set(v, COM_Argv(1)); + v->changed = 1; // now it's been changed by (presumably) the user + } return true; } diff --git a/src/command.h b/src/command.h index 7420c210..8dee1174 100644 --- a/src/command.h +++ b/src/command.h @@ -125,6 +125,12 @@ extern CV_PossibleValue_t CV_OnOff[]; extern CV_PossibleValue_t CV_YesNo[]; extern CV_PossibleValue_t CV_Unsigned[]; extern CV_PossibleValue_t CV_Natural[]; + +// Filter consvars by version +extern consvar_t cv_execversion; + +void CV_InitFilterVar(void); + // register a variable for use at the console void CV_RegisterVar(consvar_t *variable); diff --git a/src/m_misc.c b/src/m_misc.c index f8014104..760894a6 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -37,6 +37,7 @@ #include "d_main.h" #include "m_argv.h" #include "i_system.h" +#include "command.h" // cv_execversion #include "m_anigif.h" @@ -440,7 +441,18 @@ void Command_LoadConfig_f(void) strcpy(configfile, COM_Argv(1)); FIL_ForceExtension(configfile, ".cfg"); + + // temporarily reset execversion to default + cv_execversion.flags &= ~CV_HIDEN; + COM_BufInsertText(va("%s \"%s\"\n", cv_execversion.name, cv_execversion.defaultvalue)); + CV_InitFilterVar(); + + // exec the config 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)); + cv_execversion.flags |= CV_HIDEN; } /** Saves the current configuration and loads another. @@ -477,10 +489,20 @@ void M_FirstLoadConfig(void) // load default control G_Controldefault(); + // temporarily reset execversion to default + // we shouldn't need to do this, but JUST in case... + cv_execversion.flags &= ~CV_HIDEN; + COM_BufInsertText(va("%s \"%s\"\n", cv_execversion.name, cv_execversion.defaultvalue)); + CV_InitFilterVar(); + // load config, make sure those commands doesnt require the screen... COM_BufInsertText(va("exec \"%s\"\n", configfile)); // 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)); + 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) gameconfig_loaded = true; @@ -536,6 +558,10 @@ void M_SaveConfig(const char *filename) // header message 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); + // FIXME: save key aliases if ever implemented.. CV_SaveVariables(f); From 70aa4ce18e9c52dd7ef8627abd66dea0a5f640ee Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 11:59:34 -0500 Subject: [PATCH 2/5] Add alwaysfreelook2 and mousemove2 to config versioning * Change alwaysfreelook2 to be consistent with alwaysfreelook (the only one that wasn't the same) --- src/command.c | 7 +++++-- src/g_game.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/command.c b/src/command.c index 454bc76d..cc208e94 100644 --- a/src/command.c +++ b/src/command.c @@ -1743,9 +1743,12 @@ static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr) // MOUSE SETTINGS // alwaysfreelook split between first and third person (chasefreelook) // mousemove was on by default, which invalidates the current approach - if (!stricmp(v->name, "alwaysfreelook")) + if (!stricmp(v->name, "alwaysfreelook") + || !stricmp(v->name, "alwaysfreelook2") + || !stricmp(v->name, "mousemove") + || !stricmp(v->name, "mousemove2")) return false; - if (!stricmp(v->name, "mousemove")) + if () return false; // mousesens was changed from 35 to 20 due to oversensitivity diff --git a/src/g_game.c b/src/g_game.c index 67f482e3..1b782a68 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -352,7 +352,7 @@ consvar_t cv_crosshair2 = {"crosshair2", "Cross", CV_SAVE, crosshair_cons_t, NUL consvar_t cv_invertmouse = {"invertmouse", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_invertmouse2 = {"invertmouse2", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_alwaysfreelook = {"alwaysmlook", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_alwaysfreelook2 = {"alwaysmlook2", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_alwaysfreelook2 = {"alwaysmlook2", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_chasefreelook = {"chasemlook", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_chasefreelook2 = {"chasemlook2", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_mousemove = {"mousemove", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; From a5eb62b73e0adaf5fb2475ce4a2f33ce9ba3d4d7 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 12:02:45 -0500 Subject: [PATCH 3/5] alwaysfreelook -> alwaysmlook string --- src/command.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command.c b/src/command.c index cc208e94..1acde820 100644 --- a/src/command.c +++ b/src/command.c @@ -1743,8 +1743,8 @@ static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr) // MOUSE SETTINGS // alwaysfreelook split between first and third person (chasefreelook) // mousemove was on by default, which invalidates the current approach - if (!stricmp(v->name, "alwaysfreelook") - || !stricmp(v->name, "alwaysfreelook2") + if (!stricmp(v->name, "alwaysmlook") + || !stricmp(v->name, "alwaysmlook2") || !stricmp(v->name, "mousemove") || !stricmp(v->name, "mousemove2")) return false; From 0be61e8830913bea46525e2ccf34468080f47278 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 12:03:53 -0500 Subject: [PATCH 4/5] a stray if block --- src/command.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/command.c b/src/command.c index 1acde820..c3f5140f 100644 --- a/src/command.c +++ b/src/command.c @@ -1748,8 +1748,6 @@ static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr) || !stricmp(v->name, "mousemove") || !stricmp(v->name, "mousemove2")) return false; - if () - return false; // mousesens was changed from 35 to 20 due to oversensitivity if ((!stricmp(v->name, "mousesens") From 3ceeb6a20582315efb37bd05b916bc3b943841ef Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 12:28:30 -0500 Subject: [PATCH 5/5] Register execversion and remove CV_SAVE because we write manually --- src/command.c | 2 +- src/m_misc.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/command.c b/src/command.c index c3f5140f..47c6d2e5 100644 --- a/src/command.c +++ b/src/command.c @@ -66,7 +66,7 @@ CV_PossibleValue_t CV_Natural[] = {{1, "MIN"}, {999999999, "MAX"}, {0, NULL}}; // Filter consvars by MODVERSION // 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",CV_SAVE,CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_execversion = {"execversion","25",0,CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; // for default joyaxis detection static boolean joyaxis_default = false; diff --git a/src/m_misc.c b/src/m_misc.c index 760894a6..1ab5f1fe 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -489,6 +489,9 @@ void M_FirstLoadConfig(void) // load default control G_Controldefault(); + // register execversion here before we load any configs + CV_RegisterVar(&cv_execversion); + // temporarily reset execversion to default // we shouldn't need to do this, but JUST in case... cv_execversion.flags &= ~CV_HIDEN;