diff --git a/src/console/c_cvars.cpp b/src/console/c_cvars.cpp index 103c8cf95..0b4bdd2ed 100644 --- a/src/console/c_cvars.cpp +++ b/src/console/c_cvars.cpp @@ -48,6 +48,8 @@ #include "menu/menu.h" #include "vm.h" +#include "version.h" + struct FLatchedValue { FBaseCVar *Variable; @@ -1745,3 +1747,55 @@ CCMD (archivecvar) } } } + +void C_GrabCVarDefaults () +{ + int lump, lastlump = 0; + int lumpversion, gamelastrunversion; + gamelastrunversion = atoi(LASTRUNVERSION); + + while ((lump = Wads.FindLump("DEFCVARS", &lastlump)) != -1) + { + FScanner sc(lump); + + sc.MustGetString(); + if (!sc.Compare("version")) + sc.ScriptError("Must declare version for defcvars!"); + sc.MustGetNumber(); + lumpversion = sc.Number; + if (lumpversion > gamelastrunversion) + sc.ScriptError("Unsupported version %i (%i supported)", lumpversion, gamelastrunversion); + if (lumpversion < 218) + sc.ScriptError("Version must be at least 218 (current version %i)", gamelastrunversion); + + FBaseCVar *var; + + while (sc.GetString()) + { + if (sc.Compare("set")) + { + sc.MustGetString(); + } + var = FindCVar (sc.String, NULL); + if (var != NULL) + { + if (var->GetFlags() & CVAR_ARCHIVE) + { + UCVarValue val; + + sc.MustGetString(); + val.String = const_cast(sc.String); + var->SetGenericRepDefault(val, CVAR_String); + } + else + { + sc.ScriptError("Cannot set cvar default for non-config cvar '%s'", sc.String); + } + } + else + { + sc.ScriptError("Unknown cvar '%s'", sc.String); + } + } + } +} diff --git a/src/d_main.cpp b/src/d_main.cpp index bc4b66dde..12ea85c47 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -145,6 +145,7 @@ void DrawFullscreenSubtitle(const char *text); void D_Cleanup(); void FreeSBarInfoScript(); void I_UpdateWindowTitle(); +void C_GrabCVarDefaults (); // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- @@ -2531,6 +2532,8 @@ static int D_DoomMain_Internal (void) allwads.ShrinkToFit(); SetMapxxFlag(); + C_GrabCVarDefaults(); //parse DEFCVARS + GameConfig->DoKeySetup(gameinfo.ConfigName); // Now that wads are loaded, define mod-specific cvars.