From a8f7336d78e72f3afaae796ef50bcea67523dd3d Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 1 Jun 2023 23:44:55 +0200 Subject: [PATCH] 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). --- r5dev/core/dllmain.cpp | 7 +++++++ r5dev/launcher/launcher.cpp | 36 ++++++++++++++++------------------ r5dev/launcher/launcher.h | 2 +- r5dev/public/tier0/basetypes.h | 5 ----- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/r5dev/core/dllmain.cpp b/r5dev/core/dllmain.cpp index 44e542ab..b5aa1b80 100644 --- a/r5dev/core/dllmain.cpp +++ b/r5dev/core/dllmain.cpp @@ -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 //############################################################################# diff --git a/r5dev/launcher/launcher.cpp b/r5dev/launcher/launcher.cpp index 1a1c072a..8a354896 100644 --- a/r5dev/launcher/launcher.cpp +++ b/r5dev/launcher/launcher.cpp @@ -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(svCmdLine.c_str()), nShowCmd); + return v_WinMain(hInstance, hPrevInstance, const_cast(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; } diff --git a/r5dev/launcher/launcher.h b/r5dev/launcher/launcher.h index 57346f5a..8426fafb 100644 --- a/r5dev/launcher/launcher.h +++ b/r5dev/launcher/launcher.h @@ -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); diff --git a/r5dev/public/tier0/basetypes.h b/r5dev/public/tier0/basetypes.h index c21e3b3d..11968fb7 100644 --- a/r5dev/public/tier0/basetypes.h +++ b/r5dev/public/tier0/basetypes.h @@ -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.