Index: source/ps/ConfigDB.h =================================================================== --- source/ps/ConfigDB.h +++ source/ps/ConfigDB.h @@ -41,6 +41,7 @@ CFG_MOD, CFG_USER, CFG_COMMAND, + CFG_SANITIZE, CFG_LAST }; @@ -59,7 +60,7 @@ /** * Attempt to retrieve the value of a config variable with the given name; - * will search CFG_COMMAND first, and then all namespaces from the specified + * will search CFG_SANITIZE first, and then all namespaces from the specified * namespace down. */ void GetValue(EConfigNamespace ns, const CStr& name, bool& value); @@ -81,7 +82,7 @@ /** * Attempt to retrieve a vector of values corresponding to the given setting; - * will search CFG_COMMAND first, and then all namespaces from the specified + * will search CFG_SANITIZE first, and then all namespaces from the specified * namespace down. */ void GetValues(EConfigNamespace ns, const CStr& name, CConfigValueSet& values) const; @@ -107,6 +108,10 @@ void SetValueBool(EConfigNamespace ns, const CStr& name, const bool value); + void SetValueInt(EConfigNamespace ns, const CStr& name, const int value); + + void SetValueDouble(EConfigNamespace ns, const CStr& name, const double value); + /** * Remove a config value in the specified namespace. */ Index: source/ps/ConfigDB.cpp =================================================================== --- source/ps/ConfigDB.cpp +++ source/ps/ConfigDB.cpp @@ -92,8 +92,8 @@ {\ CHECK_NS(;);\ CScopeLock s(&cfgdb_mutex);\ - TConfigMap::iterator it = m_Map[CFG_COMMAND].find(name);\ - if (it != m_Map[CFG_COMMAND].end())\ + TConfigMap::iterator it = m_Map[CFG_SANITIZE].find(name);\ + if (it != m_Map[CFG_SANITIZE].end())\ {\ Get(it->second[0], value);\ return;\ @@ -136,8 +136,8 @@ CHECK_NS(;); CScopeLock s(&cfgdb_mutex); - TConfigMap::iterator it = m_Map[CFG_COMMAND].find(name); - if (it != m_Map[CFG_COMMAND].end()) + TConfigMap::iterator it = m_Map[CFG_SANITIZE].find(name); + if (it != m_Map[CFG_SANITIZE].end()) { values = it->second; return; @@ -159,9 +159,9 @@ CHECK_NS(CFG_LAST); CScopeLock s(&cfgdb_mutex); - TConfigMap::iterator it = m_Map[CFG_COMMAND].find(name); - if (it != m_Map[CFG_COMMAND].end()) - return CFG_COMMAND; + TConfigMap::iterator it = m_Map[CFG_SANITIZE].find(name); + if (it != m_Map[CFG_SANITIZE].end()) + return CFG_SANITIZE; for (int search_ns = ns; search_ns >= 0; --search_ns) { @@ -187,7 +187,7 @@ if (boost::algorithm::starts_with(p.first, prefix)) ret[p.first] = p.second; - for (const std::pair& p : m_Map[CFG_COMMAND]) + for (const std::pair& p : m_Map[CFG_SANITIZE]) if (boost::algorithm::starts_with(p.first, prefix)) ret[p.first] = p.second; @@ -212,6 +212,18 @@ SetValueString(ns, name, valueString); } +void CConfigDB::SetValueInt(EConfigNamespace ns, const CStr& name, const int value) +{ + CStr valueString = CStr::FromInt(value); + SetValueString(ns, name, valueString); +} + +void CConfigDB::SetValueDouble(EConfigNamespace ns, const CStr& name, const double value) +{ + CStr valueString = CStr::FromDouble(value); + SetValueString(ns, name, valueString); +} + void CConfigDB::RemoveValue(EConfigNamespace ns, const CStr& name) { CHECK_NS(;); Index: source/ps/GameSetup/Config.cpp =================================================================== --- source/ps/GameSetup/Config.cpp +++ source/ps/GameSetup/Config.cpp @@ -24,6 +24,7 @@ #include "ps/CLogger.h" #include "ps/ConfigDB.h" #include "ps/GameSetup/CmdLineArgs.h" +#include "ps/VideoMode.h" // (these variables are documented in the header.) @@ -64,6 +65,7 @@ int g_xres, g_yres; float g_GuiScale = 1.0f; bool g_VSync = false; +bool g_Windowed = true; bool g_Quickstart = false; bool g_DisableAudio = false; @@ -111,6 +113,7 @@ CFG_GET_VAL("postproc", g_PostProc); CFG_GET_VAL("smoothlos", g_SmoothLOS); CFG_GET_VAL("gui.scale", g_GuiScale); + CFG_GET_VAL("windowed", g_Windowed); } @@ -135,8 +138,6 @@ if (args.Has("g")) { g_Gamma = args.Get("g").ToFloat(); - if (g_Gamma == 0.0f) - g_Gamma = 1.0f; } // if (args.Has("listfiles")) @@ -177,6 +178,39 @@ } +static void SanitizeConfig() +{ + if (g_Gamma <= 0.0) + { + g_Gamma = 1.0; + } + + if (g_GuiScale <= 0.0) + { + g_GuiScale = 1.0; + g_ConfigDB.SetValueDouble(CFG_SANITIZE, "gui.scale", 1.0); + } + + if (g_xres <= 0) + { + if(g_Windowed) + g_xres = DEFAULT_WINDOW_W; + else + g_xres = DEFAULT_FULLSCREEN_W; + g_ConfigDB.SetValueInt(CFG_SANITIZE, "xres", g_xres); + } + + if (g_yres <= 0) + { + if(g_Windowed) + g_yres = DEFAULT_WINDOW_H; + else + g_yres = DEFAULT_FULLSCREEN_H; + g_ConfigDB.SetValueInt(CFG_SANITIZE, "yres", g_yres); + } +} + + void CONFIG_Init(const CmdLineArgs& args) { TIMER(L"CONFIG_Init"); @@ -208,4 +242,7 @@ // Collect information from system.cfg, the profile file, // and any command-line overrides to fill in the globals. LoadGlobals(); // 64ms + + // Check for invalid values and sanitize them + SanitizeConfig(); } Index: source/ps/VideoMode.h =================================================================== --- source/ps/VideoMode.h +++ source/ps/VideoMode.h @@ -127,4 +127,10 @@ extern CVideoMode g_VideoMode; +extern const int DEFAULT_WINDOW_W; +extern const int DEFAULT_WINDOW_H; + +extern const int DEFAULT_FULLSCREEN_W; +extern const int DEFAULT_FULLSCREEN_H; + #endif // INCLUDED_VIDEOMODE Index: source/ps/VideoMode.cpp =================================================================== --- source/ps/VideoMode.cpp +++ source/ps/VideoMode.cpp @@ -38,11 +38,11 @@ #endif -static int DEFAULT_WINDOW_W = 1024; -static int DEFAULT_WINDOW_H = 768; +const int DEFAULT_WINDOW_W = 1024; +const int DEFAULT_WINDOW_H = 768; -static int DEFAULT_FULLSCREEN_W = 1024; -static int DEFAULT_FULLSCREEN_H = 768; +const int DEFAULT_FULLSCREEN_W = 1024; +const int DEFAULT_FULLSCREEN_H = 768; CVideoMode g_VideoMode;