Fix default CFG file loading

After the CMake refactor, this became broken as the 'DEDICATED' define does not work in tier0 headers. These were the last ones; moved to the DLL project instead. This commit also fixes a bug where the command line file gets parsed twice, while there was already a global containing the args (initialized on DLL init).
This commit is contained in:
Kawe Mazidjatari 2023-06-01 23:44:55 +02:00
parent aac74c11b2
commit a8f7336d78
4 changed files with 25 additions and 25 deletions

View File

@ -3,6 +3,7 @@
#include "core/init.h"
#include "core/logdef.h"
#include "core/logger.h"
#include "tier0/basetypes.h"
#include "tier0/crashhandler.h"
/*****************************************************************************/
#ifndef DEDICATED
@ -14,6 +15,12 @@
#include "mathlib/mathlib.h"
#include "launcher/launcher.h"
#ifndef DEDICATED
#define SDK_DEFAULT_CFG "cfg/startup_default.cfg"
#else
#define SDK_DEFAULT_CFG "cfg/startup_dedi_default.cfg"
#endif
//#############################################################################
// INITIALIZATION
//#############################################################################

View File

@ -19,12 +19,7 @@ int HWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int
// programatically (has to be after 'CommandLine()->CreateCmdLine()', but before 'SetPriorityClass()')
// For S0 and S1 we should modify the command line buffer passed to the entry point instead (here).
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
string svCmdLine = lpCmdLine;
if (!strstr(GetCommandLineA(), "-launcher"))
{
svCmdLine = LoadConfigFile(SDK_DEFAULT_CFG);
}
return v_WinMain(hInstance, hPrevInstance, const_cast<LPSTR>(svCmdLine.c_str()), nShowCmd);
return v_WinMain(hInstance, hPrevInstance, const_cast<LPSTR>(g_svCmdLine.c_str()), nShowCmd);
#else
return v_WinMain(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
#endif
@ -75,7 +70,8 @@ void RemoveSpuriousGameParameters()
// as all there are required to run the game with the game sdk.
void AppendSDKParametersPreInit()
{
if (*s_bIsDedicated)
const bool bDedicated = IsDedicated();
if (bDedicated)
{
CommandLine()->AppendParm("-collate", "");
CommandLine()->AppendParm("-multiple", "");
@ -94,30 +90,32 @@ void AppendSDKParametersPreInit()
// Assume default configs if the game isn't launched with the SDKLauncher.
if (!CommandLine()->FindParm("-launcher"))
{
string svArguments = LoadConfigFile(SDK_DEFAULT_CFG);
ParseAndApplyConfigFile(svArguments);
ParseAndApplyConfigFile(g_svCmdLine);
}
}
string LoadConfigFile(const string& svConfig)
string LoadConfigFile(const char* svConfig)
{
fs::path cfgPath = fs::current_path() /= svConfig; // Get cfg path for default startup.
ifstream cfgFile(cfgPath);
string svArguments;
if (cfgFile.good() && cfgFile)
if (!FileExists(cfgPath))
{
stringstream ss;
ss << cfgFile.rdbuf();
svArguments = ss.str();
// Load it from PLATFORM.
cfgPath = fs::current_path() /= string("platform/") + svConfig;
}
else
ifstream cfgFile(cfgPath);
if (!cfgFile)
{
spdlog::error("{:s}: '{:s}' does not exist!\n", __FUNCTION__, svConfig);
cfgFile.close();
return "";
}
cfgFile.close();
string svArguments;
stringstream ss;
ss << cfgFile.rdbuf();
svArguments = ss.str();
return svArguments;
}

View File

@ -16,7 +16,7 @@ inline auto v_RemoveSpuriousGameParameters = p_RemoveSpuriousGameParameters.RCas
#endif // !GAMEDLL_S0 || !GAMEDLL_S1
void AppendSDKParametersPreInit();
string LoadConfigFile(const string& svConfig);
string LoadConfigFile(const char* svConfig);
void ParseAndApplyConfigFile(const string& svConfig);
const char* ExitCodeToString(int nCode);

View File

@ -149,11 +149,6 @@
#define SDK_VERSION "VGameSDK008" // Increment this with every /breaking/ SDK change (i.e. security/backend changes breaking compatibility).
#define SDK_ARRAYSIZE(arr) ((sizeof(arr) / sizeof(*arr))) // Name due to IMGUI implementation and NT implementation that we shouldn't share across everywhere.
#ifndef DEDICATED
#define SDK_DEFAULT_CFG "platform/cfg/startup_default.cfg"
#else
#define SDK_DEFAULT_CFG "platform/cfg/startup_dedi_default.cfg"
#endif
#define SDK_SYSTEM_CFG_PATH "cfg/system/"
#define VALID_CHARSTAR(star) (star && star[0]) // Check if char* is valid and not empty.