From 4017a6d864b6fa4a97c4c6e8013c99169ccc4d3b Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 26 Dec 2014 17:21:57 -0600 Subject: [PATCH] Retry setting unknown cvars after CVARINFOs are processed. - Fixed: Using +set cvarname and +cvarname on the command line would not work if cvarname was defined in CVARINFO. This should be the proper way to fix it. Rather than move all command line execution after loading CVARINFO, keep command line execution before wads are loaded. If an attempt is made to set an unknown cvar or to run an unknown command (which could potentially be shorthand for setting an unknown cvar), save it and try running it again after all CVARINFOs have been handled. --- src/c_dispatch.cpp | 50 ++++++++++++++++++++++++++++++++++++++++------ src/c_dispatch.h | 1 + src/d_main.cpp | 3 +++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/c_dispatch.cpp b/src/c_dispatch.cpp index 65e017bdc3..0719f5a902 100644 --- a/src/c_dispatch.cpp +++ b/src/c_dispatch.cpp @@ -185,6 +185,9 @@ static const char *KeyConfCommands[] = "clearplayerclasses" }; +static TArray StoredStartupSets; +static bool RunningStoredStartups; + // CODE -------------------------------------------------------------------- IMPLEMENT_CLASS (DWaitingCommand) @@ -537,6 +540,18 @@ void ResetButtonStates () } } +void C_ExecStoredSets() +{ + assert(!RunningStoredStartups); + RunningStoredStartups = true; + for (unsigned i = 0; i < StoredStartupSets.Size(); ++i) + { + C_DoCommand(StoredStartupSets[i]); + } + StoredStartupSets.Clear(); + RunningStoredStartups = false; +} + void C_DoCommand (const char *cmd, int keynum) { FConsoleCommand *com; @@ -612,7 +627,22 @@ void C_DoCommand (const char *cmd, int keynum) if ( (com = FindNameInHashTable (Commands, beg, len)) ) { - if (gamestate != GS_STARTUP || ParsingKeyConf || + if (gamestate == GS_STARTUP && !RunningStoredStartups && + len == 3 && strnicmp(beg, "set", 3) == 0) + { + // Save setting of unknown cvars for later, in case a loaded wad has a + // CVARINFO that defines it. + FCommandLine args(beg); + if (args.argc() > 1 && FindCVar(args[1], NULL) == NULL) + { + StoredStartupSets.Push(beg); + } + else + { + com->Run(args, players[consoleplayer].mo, keynum); + } + } + else if (gamestate != GS_STARTUP || ParsingKeyConf || (len == 3 && strnicmp (beg, "set", 3) == 0) || (len == 7 && strnicmp (beg, "logfile", 7) == 0) || (len == 9 && strnicmp (beg, "unbindall", 9) == 0) || @@ -657,12 +687,20 @@ void C_DoCommand (const char *cmd, int keynum) } else { // We don't know how to handle this command - char cmdname[64]; - size_t minlen = MIN (len, 63); + if (gamestate == GS_STARTUP && !RunningStoredStartups) + { + // Save it for later, in case a CVARINFO defines it. + StoredStartupSets.Push(beg); + } + else + { + char cmdname[64]; + size_t minlen = MIN (len, 63); - memcpy (cmdname, beg, minlen); - cmdname[len] = 0; - Printf ("Unknown command \"%s\"\n", cmdname); + memcpy (cmdname, beg, minlen); + cmdname[len] = 0; + Printf ("Unknown command \"%s\"\n", cmdname); + } } } } diff --git a/src/c_dispatch.h b/src/c_dispatch.h index f4518608df..b494005c72 100644 --- a/src/c_dispatch.h +++ b/src/c_dispatch.h @@ -42,6 +42,7 @@ class APlayerPawn; extern bool CheckCheatmode (bool printmsg = true); void C_ExecCmdLineParams (); +void C_ExecStoredSets(); // Add commands to the console as if they were typed in. Can handle wait // and semicolon-separated commands. This function may modify the source diff --git a/src/d_main.cpp b/src/d_main.cpp index 11a8c4ff0d..817d3b9ecc 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2290,6 +2290,9 @@ void D_DoomMain (void) // Now that wads are loaded, define mod-specific cvars. ParseCVarInfo(); + // Try setting previously unknown cvars again, as a CVARINFO may have made them known. + C_ExecStoredSets(); + // [RH] Initialize localizable strings. GStrings.LoadStrings (false);