From f2a5c8ac68b72e1fd9c90b8f06a643ec76487688 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 16 Apr 2022 00:30:46 +0200 Subject: [PATCH] See description * Renamed 'r5apexsdkd64.dll' to 'gamesdk.dll'. * Added required dedicated parameters to code instead. * Bug fixes around CCommandLine class (fixed misaligned VTable indexes). * SDK now supports being directly launched by the game executable. The SDK launcher will pass '-launcher' to the game, which indicated its being launched by the launcher. If the game does not receive '-launcher', it assumes its being launched directly from the game executable, which will instead load 'startup_(dedi_)default.cfg'. The sdk dll's are now added to the game's IAT by their dummy exports allowing for them to be loaded when the exe is loaded (the dll's do everything on init). --- r5dev/GameSDK.def | 2 +- r5dev/client/cdll_engine_int.cpp | 2 +- r5dev/common/opcodes.h | 3 +- r5dev/core/dllmain.cpp | 14 +- r5dev/core/init.cpp | 5 +- r5dev/core/logdef.cpp | 2 +- r5dev/core/termutil.cpp | 4 +- r5dev/core/termutil.h | 2 + r5dev/engine/host_state.cpp | 2 +- r5dev/engine/sys_dll2.cpp | 6 +- r5dev/gameui/IBrowser.cpp | 2 +- r5dev/gameui/IConsole.cpp | 3 +- r5dev/launcher/launcher.cpp | 178 ++++++++++++++++++++++++++ r5dev/launcher/launcher.h | 44 +++++++ r5dev/sdklauncher/sdklauncher.cpp | 66 +++++----- r5dev/tier0/basetypes.h | 8 +- r5dev/tier0/commandline.cpp | 12 +- r5dev/tier0/commandline.h | 4 +- r5dev/tier1/IConVar.cpp | 4 +- r5dev/tier1/cmd.cpp | 16 ++- r5dev/vproj/clientsdk.vcxproj | 2 + r5dev/vproj/clientsdk.vcxproj.filters | 6 + r5dev/vproj/dedicated.vcxproj | 2 + r5dev/vproj/dedicated.vcxproj.filters | 6 + r5dev/vproj/gamesdk.vcxproj | 10 +- r5dev/vproj/gamesdk.vcxproj.filters | 6 + r5dev/windows/console.cpp | 2 +- 27 files changed, 352 insertions(+), 61 deletions(-) create mode 100644 r5dev/launcher/launcher.cpp create mode 100644 r5dev/launcher/launcher.h diff --git a/r5dev/GameSDK.def b/r5dev/GameSDK.def index d3afbc7a..28983565 100644 --- a/r5dev/GameSDK.def +++ b/r5dev/GameSDK.def @@ -1,4 +1,4 @@ -LIBRARY r5apexsdkd64 +LIBRARY gamesdk EXPORTS DummyExport @1 diff --git a/r5dev/client/cdll_engine_int.cpp b/r5dev/client/cdll_engine_int.cpp index 9b4a16df..8f2cdc60 100644 --- a/r5dev/client/cdll_engine_int.cpp +++ b/r5dev/client/cdll_engine_int.cpp @@ -31,7 +31,7 @@ void CHLClient::FrameStageNotify(CHLClient* pHLClient, ClientFrameStage_t frameS { KeyValues::Init(); #if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2) // !TEMP UNTIL CHOSTSTATE IS BUILD AGNOSTIC! // - if (!g_pCmdLine->CheckParm("-devsdk")) + if (!CommandLine()->CheckParm("-devsdk")) { Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_server.cfg\"", cmd_source_t::kCommandSrcCode); Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_server.cfg\"", cmd_source_t::kCommandSrcCode); diff --git a/r5dev/common/opcodes.h b/r5dev/common/opcodes.h index 17fa9485..12e6ea38 100644 --- a/r5dev/common/opcodes.h +++ b/r5dev/common/opcodes.h @@ -2,14 +2,13 @@ #ifdef DEDICATED inline const char* g_szGameDll = "r5apex_ds.exe"; +void Dedicated_Init(); #else inline const char* g_szGameDll = "r5apex.exe"; #endif // DEDICATED -void Dedicated_Init(); void RuntimePtc_Init(); void RuntimePtc_Toggle(); - #ifdef GAMEDLL_S3 /* -------------- OTHER ------------------------------------------------------------------------------------------------------------------------------------------------- */ inline CMemory dst007 = /*0x14028F3B0*/ FindPatternSIMD(g_szGameDll, reinterpret_cast("\x48\x8B\xC4\x44\x89\x40\x18\x48\x89\x50\x10\x55\x53\x56\x57\x41"), "xxxxxxxxxxxxxxxx"); diff --git a/r5dev/core/dllmain.cpp b/r5dev/core/dllmain.cpp index 32ba5284..5f8d1cd2 100644 --- a/r5dev/core/dllmain.cpp +++ b/r5dev/core/dllmain.cpp @@ -9,6 +9,7 @@ #endif // !DEDICATED #include "windows/console.h" #include "windows/system.h" +#include "launcher/launcher.h" //############################################################################# // INITIALIZATION @@ -16,8 +17,19 @@ void R5Dev_Init() { + if (strstr(GetCommandLineA(), "-launcher")) + { + g_svCmdLine = GetCommandLineA(); + } + else + { + g_svCmdLine = LoadConfigFile(SDK_DEFAULT_CFG); + } #ifndef DEDICATED - if (strstr(GetCommandLineA(), "-wconsole")) { Console_Init(); } + if (strstr(g_svCmdLine.c_str(), "-wconsole")) + { + Console_Init(); + } #else Console_Init(); #endif // !DEDICATED diff --git a/r5dev/core/init.cpp b/r5dev/core/init.cpp index 4e7bb6c0..7f6975b8 100644 --- a/r5dev/core/init.cpp +++ b/r5dev/core/init.cpp @@ -21,8 +21,9 @@ #include "vstdlib/keyvaluessystem.h" #include "common/opcodes.h" #include "common/netmessages.h" -#include "launcher/IApplication.h" #include "launcher/prx.h" +#include "launcher/launcher.h" +#include "launcher/IApplication.h" #include "filesystem/basefilesystem.h" #include "filesystem/filesystem.h" #include "ebisusdk/EbisuSDK.h" @@ -132,6 +133,7 @@ void Systems_Init() DetourUpdateThread(GetCurrentThread()); // Hook functions + Launcher_Attatch(); IApplication_Attach(); #ifdef DEDICATED //PRX_Attach(); @@ -231,6 +233,7 @@ void Systems_Shutdown() DetourUpdateThread(GetCurrentThread()); // Unhook functions + Launcher_Detatch(); IApplication_Detach(); #ifdef DEDICATED //PRX_Detach(); diff --git a/r5dev/core/logdef.cpp b/r5dev/core/logdef.cpp index c086b92c..63e86c29 100644 --- a/r5dev/core/logdef.cpp +++ b/r5dev/core/logdef.cpp @@ -31,7 +31,7 @@ void SpdLog_Init(void) auto wconsole = spdlog::stdout_logger_mt("win_console"); // Determine if user wants ansi-color logging in the terminal. - if (strstr(GetCommandLineA(), "-ansiclr")) + if (strstr(g_svCmdLine.c_str(), "-ansiclr")) { wconsole->set_pattern("[%S.%e] %v\u001b[0m"); g_bSpdLog_UseAnsiClr = true; diff --git a/r5dev/core/termutil.cpp b/r5dev/core/termutil.cpp index d72ff891..2793ffdf 100644 --- a/r5dev/core/termutil.cpp +++ b/r5dev/core/termutil.cpp @@ -13,7 +13,9 @@ std::string g_svGreenB = ""; std::string g_svBlueB = ""; std::string g_svYellowB = ""; -std::string g_svReset = ""; +std::string g_svReset = ""; + +std::string g_svCmdLine; //----------------------------------------------------------------------------- // Purpose: sets the global ansi escape sequences. diff --git a/r5dev/core/termutil.h b/r5dev/core/termutil.h index ee05cfe6..324dbd96 100644 --- a/r5dev/core/termutil.h +++ b/r5dev/core/termutil.h @@ -13,4 +13,6 @@ extern std::string g_svYellowB; extern std::string g_svReset; +extern std::string g_svCmdLine; + void AnsiColors_Init(); diff --git a/r5dev/engine/host_state.cpp b/r5dev/engine/host_state.cpp index 1690c802..0c167100 100644 --- a/r5dev/engine/host_state.cpp +++ b/r5dev/engine/host_state.cpp @@ -256,7 +256,7 @@ FORCEINLINE void CHostState::Think(void) const //----------------------------------------------------------------------------- FORCEINLINE void CHostState::LoadConfig(void) const { - if (!g_pCmdLine->CheckParm("-devsdk")) + if (!CommandLine()->CheckParm("-devsdk")) { #ifndef CLIENT_DLL Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_server.cfg\"", cmd_source_t::kCommandSrcCode); diff --git a/r5dev/engine/sys_dll2.cpp b/r5dev/engine/sys_dll2.cpp index 827d45bc..4b0c2140 100644 --- a/r5dev/engine/sys_dll2.cpp +++ b/r5dev/engine/sys_dll2.cpp @@ -1,4 +1,4 @@ -//====== Copyright 1996-2005, Valve Corporation, All rights reserved. ======// +//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======// // // Purpose: // @@ -10,6 +10,7 @@ #include "tier1/cvar.h" #include "engine/sys_dll.h" #include "engine/sys_dll2.h" +#include "engine/sys_utils.h" #include "client/vengineclient_impl.h" //----------------------------------------------------------------------------- @@ -30,7 +31,8 @@ static bool IsValveMod(const char* pModName) //----------------------------------------------------------------------------- static bool IsRespawnMod(const char* pModName) { - return (_stricmp(pModName, "r1") == 0 || + return (_stricmp(pModName, "platform") == 0 || + _stricmp(pModName, "r1") == 0 || _stricmp(pModName, "r2") == 0 || _stricmp(pModName, "r5") == 0); } diff --git a/r5dev/gameui/IBrowser.cpp b/r5dev/gameui/IBrowser.cpp index 9166ca5c..62c0bb5d 100644 --- a/r5dev/gameui/IBrowser.cpp +++ b/r5dev/gameui/IBrowser.cpp @@ -734,7 +734,7 @@ void IBrowser::SetStyleVar(void) ImGuiStyle& style = ImGui::GetStyle(); ImVec4* colors = style.Colors; - if (!g_pCmdLine->CheckParm("-imgui_default_theme")) + if (!CommandLine()->CheckParm("-imgui_default_theme")) { colors[ImGuiCol_Text] = ImVec4(0.81f, 0.81f, 0.81f, 1.00f); colors[ImGuiCol_TextDisabled] = ImVec4(0.56f, 0.56f, 0.56f, 1.00f); diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index ac73586a..76feedf0 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -762,9 +762,8 @@ void CConsole::SetStyleVar(void) ImGuiStyle& style = ImGui::GetStyle(); ImVec4* colors = style.Colors; - if (!g_pCmdLine->CheckParm("-imgui_default_theme")) + if (!CommandLine()->CheckParm("-imgui_default_theme")) { - colors[ImGuiCol_Text] = ImVec4(0.81f, 0.81f, 0.81f, 1.00f); colors[ImGuiCol_TextDisabled] = ImVec4(0.56f, 0.56f, 0.56f, 1.00f); colors[ImGuiCol_WindowBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); diff --git a/r5dev/launcher/launcher.cpp b/r5dev/launcher/launcher.cpp new file mode 100644 index 00000000..107b2af6 --- /dev/null +++ b/r5dev/launcher/launcher.cpp @@ -0,0 +1,178 @@ +//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======// +// +// Purpose: Defines the entry point for the application. +// +// $NoKeywords: $ +//===========================================================================// +#include "core/stdafx.h" +#include "tier0/commandline.h" +#include "launcher/launcher.h" + +int HWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) +{ + // !TODO [AMOS]: 'RemoveSpuriousGameParameters()' is inline with 'LauncherMain()' in S0 and S1, + // and its the only function where we could append our own command line parameters early enough + // 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); +#else + return v_WinMain(hInstance, hPrevInstance, lpCmdLine, nShowCmd); +#endif +} + +int LauncherMain(HINSTANCE hInstance) +{ + int results = v_LauncherMain(hInstance); + printf("LauncherMain returned %s\n", ExitCodeToString(results)); + return results; +} + +#if !defined (GAMEDLL_S0) || !defined (GAMEDLL_S1) +// Remove all but the last -game parameter. +// This is for mods based off something other than Half-Life 2 (like HL2MP mods). +// The Steam UI does 'steam -applaunch 320 -game c:\steam\steamapps\sourcemods\modname', but applaunch inserts +// its own -game parameter, which would supercede the one we really want if we didn't intercede here. +void RemoveSpuriousGameParameters() +{ + AppendSDKParametersPreInit(); + + // Find the last -game parameter. + int nGameArgs = 0; + char lastGameArg[MAX_PATH]; + for (int i = 0; i < CommandLine()->ParmCount() - 1; i++) + { + if (_stricmp(CommandLine()->GetParm(i), "-game") == 0) + { + _snprintf(lastGameArg, sizeof(lastGameArg), "\"%s\"", CommandLine()->GetParm(i + 1)); + ++nGameArgs; + ++i; + } + } + + // We only care if > 1 was specified. + if (nGameArgs > 1) + { + CommandLine()->RemoveParm("-game"); + CommandLine()->AppendParm("-game", lastGameArg); + } +} +#endif + +// Append required command line parameters. +// This avoids having all these in the startup configuration files +// as all there are required to run the game with the game sdk. +void AppendSDKParametersPreInit() +{ +#ifdef DEDICATED + CommandLine()->AppendParm("-sw", ""); + CommandLine()->AppendParm("-lv", ""); + CommandLine()->AppendParm("-safe", ""); + CommandLine()->AppendParm("-high", ""); + CommandLine()->AppendParm("-rerun", ""); + CommandLine()->AppendParm("-collate", ""); + CommandLine()->AppendParm("-multiple", ""); + CommandLine()->AppendParm("-noorigin", ""); + CommandLine()->AppendParm("-novid", ""); + CommandLine()->AppendParm("-noshaderapi", ""); + CommandLine()->AppendParm("-nosound", ""); + CommandLine()->AppendParm("-nojoy", ""); + CommandLine()->AppendParm("-nomouse", ""); + CommandLine()->AppendParm("-nomenuvid", ""); + CommandLine()->AppendParm("-nosendtable", ""); + CommandLine()->AppendParm("-gamepad_ignore_local", ""); +#endif + // Assume default configs if the game isn't launched with the SDKLauncher. + if (!CommandLine()->FindParm("-launcher")) + { + string svArguments = LoadConfigFile(SDK_DEFAULT_CFG); + ParseAndApplyConfigFile(svArguments); + } +} + +string LoadConfigFile(const string& svConfig) +{ + fs::path cfgPath = fs::current_path() /= svConfig; // Get cfg path for default startup. + ifstream cfgFile(cfgPath); + string svArguments; + + if (cfgFile.good() && cfgFile) + { + stringstream ss; + ss << cfgFile.rdbuf(); + svArguments = ss.str(); + } + else + { + spdlog::error("%s: '%s' does not exist!\n", __FUNCTION__, svConfig.c_str()); + cfgFile.close(); + return ""; + } + cfgFile.close(); + + return svArguments; +} + +void ParseAndApplyConfigFile(const string& svConfig) +{ + stringstream ss(svConfig); + string svInput; + + if (strlen(svConfig.c_str()) > 0) + { + while (std::getline(ss, svInput, '\n')) + { + size_t nPos = svInput.find(" "); + if (!svInput.empty() + && nPos > 0 + && nPos < svInput.size() + && nPos != svInput.size()) + { + string svValue = svInput.substr(nPos + 1); + string svArgument = svInput.erase(svInput.find(" ")); + + CommandLine()->AppendParm(svArgument.c_str(), svValue.c_str()); + } + else + { + CommandLine()->AppendParm(svInput.c_str(), ""); + } + } + } +} + +const char* ExitCodeToString(int nCode) +{ + switch (nCode) + { + case EXIT_SUCCESS: + return "EXIT_SUCCESS"; + case EXIT_FAILURE: + return "EXIT_SUCCESS"; + default: + return ""; + } +} + +void Launcher_Attatch() +{ + DetourAttach((LPVOID*)&v_WinMain, &HWinMain); + DetourAttach((LPVOID*)&v_LauncherMain, &LauncherMain); +#if !defined (GAMEDLL_S0) || !defined (GAMEDLL_S1) + DetourAttach((LPVOID*)&v_RemoveSpuriousGameParameters, &RemoveSpuriousGameParameters); +#endif +} + +void Launcher_Detatch() +{ + DetourDetach((LPVOID*)&v_WinMain, &HWinMain); + DetourDetach((LPVOID*)&v_LauncherMain, &LauncherMain); +#if !defined (GAMEDLL_S0) || !defined (GAMEDLL_S1) + DetourDetach((LPVOID*)&v_RemoveSpuriousGameParameters, &RemoveSpuriousGameParameters); +#endif +} \ No newline at end of file diff --git a/r5dev/launcher/launcher.h b/r5dev/launcher/launcher.h new file mode 100644 index 00000000..a765f0fe --- /dev/null +++ b/r5dev/launcher/launcher.h @@ -0,0 +1,44 @@ +#ifndef LAUNCHER_H +#define LAUNCHER_H + +inline CMemory p_WinMain = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x20\x41\x8B\xD9\x49\x8B\xF8"), "xxxx?xxxx?xxxx?xxxxxxxxxxx"); +inline auto v_WinMain = p_WinMain.RCast(); + +inline CMemory p_LauncherMain = g_mGameDll.GetExportedFunction("LauncherMain"); +inline auto v_LauncherMain = p_LauncherMain.RCast(); + +#if !defined (GAMEDLL_S0) || !defined (GAMEDLL_S1) +inline CMemory p_RemoveSpuriousGameParameters = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x81\xEC\x00\x00\x00\x00\x33\xED\x48\x8D\x3D\x00\x00\x00\x00"), "xxxx?xxxx?xxxx?xxxx????xxxxx????"); +inline auto v_RemoveSpuriousGameParameters = p_RemoveSpuriousGameParameters.RCast(); +#endif // !GAMEDLL_S0 || !GAMEDLL_S1 + +void AppendSDKParametersPreInit(); +string LoadConfigFile(const string& svConfig); +void ParseAndApplyConfigFile(const string& svConfig); +const char* ExitCodeToString(int nCode); + +void Launcher_Attatch(); +void Launcher_Detatch(); + +/////////////////////////////////////////////////////////////////////////////// +class HLauncher : public IDetour +{ + virtual void GetAdr(void) const + { + std::cout << "| FUN: WinMain : 0x" << std::hex << std::uppercase << p_WinMain.GetPtr() << std::setw(nPad) << " |" << std::endl; + std::cout << "| FUN: LauncherMain : 0x" << std::hex << std::uppercase << p_LauncherMain.GetPtr() << std::setw(nPad) << " |" << std::endl; +#if !defined (GAMEDLL_S0) || !defined (GAMEDLL_S1) + std::cout << "| FUN: RemoveSpuriousGameParameters::Create : 0x" << std::hex << std::uppercase << p_RemoveSpuriousGameParameters.GetPtr() << std::setw(nPad) << " |" << std::endl; +#endif // !GAMEDLL_S0 || !GAMEDLL_S1 + std::cout << "+----------------------------------------------------------------+" << std::endl; + } + virtual void GetFun(void) const { } + virtual void GetVar(void) const { } + virtual void GetCon(void) const { } + virtual void Attach(void) const { } + virtual void Detach(void) const { } +}; +/////////////////////////////////////////////////////////////////////////////// + +REGISTER(HLauncher); +#endif // LAUNCHER_H \ No newline at end of file diff --git a/r5dev/sdklauncher/sdklauncher.cpp b/r5dev/sdklauncher/sdklauncher.cpp index 2983d24d..51e85eaa 100644 --- a/r5dev/sdklauncher/sdklauncher.cpp +++ b/r5dev/sdklauncher/sdklauncher.cpp @@ -11,11 +11,11 @@ bool LaunchR5Apex(eLaunchMode lMode, eLaunchState lState) { /////////////////////////////////////////////////////////////////////////// // Initialize strings. - std::string WorkerDll = std::string(); - std::string GameDirectory = std::string(); - std::string CommandLineArguments = std::string(); - std::string StartupCommandLine = std::string(); - std::string currentDirectory = std::filesystem::current_path().u8string(); + std::string svWorkerDll = std::string(); + std::string svGameDir = std::string(); + std::string svCmdLineArgs = std::string(); + std::string svStartCmdLine = std::string(); + std::string svCurrentDir = std::filesystem::current_path().u8string(); /////////////////////////////////////////////////////////////////////////// // Determine launch mode. @@ -28,8 +28,8 @@ bool LaunchR5Apex(eLaunchMode lMode, eLaunchState lState) if (cfgFile.good() && cfgFile) // Does the cfg file exist? { std::stringstream ss; - ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream. - CommandLineArguments = ss.str(); // Get all the contents of the cfg file. + ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream. + svCmdLineArgs = ss.str() + "-launcher"; // Get all the contents of the cfg file. } else { @@ -39,9 +39,9 @@ bool LaunchR5Apex(eLaunchMode lMode, eLaunchState lState) } cfgFile.close(); // Close cfg file. - WorkerDll = currentDirectory + "\\r5apexsdkd64.dll"; // Get path to worker dll. - GameDirectory = currentDirectory + "\\r5apex.exe"; // Get path to game executeable. - StartupCommandLine = currentDirectory + "\\r5apex.exe " + CommandLineArguments; // Setup startup command line string. + svWorkerDll = svCurrentDir + "\\gamesdk.dll"; // Get path to worker dll. + svGameDir = svCurrentDir + "\\r5apex.exe"; // Get path to game executeable. + svStartCmdLine = svCurrentDir + "\\r5apex.exe " + svCmdLineArgs; // Setup startup command line string. spdlog::info("*** LAUNCHING GAME [DEBUG] ***\n"); break; @@ -53,8 +53,8 @@ bool LaunchR5Apex(eLaunchMode lMode, eLaunchState lState) if (cfgFile.good() && cfgFile) // Does the cfg file exist? { std::stringstream ss; - ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream. - CommandLineArguments = ss.str(); // Get all the contents of the cfg file. + ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream. + svCmdLineArgs = ss.str() + "-launcher"; // Get all the contents of the cfg file. } else { @@ -64,9 +64,9 @@ bool LaunchR5Apex(eLaunchMode lMode, eLaunchState lState) } cfgFile.close(); // Close cfg file. - WorkerDll = currentDirectory + "\\r5apexsdkd64.dll"; // Get path to worker dll. - GameDirectory = currentDirectory + "\\r5apex.exe"; // Get path to game executeable. - StartupCommandLine = currentDirectory + "\\r5apex.exe " + CommandLineArguments; // Setup startup command line string. + svWorkerDll = svCurrentDir + "\\gamesdk.dll"; // Get path to worker dll. + svGameDir = svCurrentDir + "\\r5apex.exe"; // Get path to game executeable. + svStartCmdLine = svCurrentDir + "\\r5apex.exe " + svCmdLineArgs; // Setup startup command line string. spdlog::info("*** LAUNCHING GAME [RELEASE] ***\n"); break; @@ -78,8 +78,8 @@ bool LaunchR5Apex(eLaunchMode lMode, eLaunchState lState) if (cfgFile.good() && cfgFile) // Does the cfg file exist? { std::stringstream ss; - ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream. - CommandLineArguments = ss.str(); // Get all the contents of the cfg file. + ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream. + svCmdLineArgs = ss.str() + "-launcher"; // Get all the contents of the cfg file. } else { @@ -89,9 +89,9 @@ bool LaunchR5Apex(eLaunchMode lMode, eLaunchState lState) } cfgFile.close(); // Close cfg file. - WorkerDll = currentDirectory + "\\dedicated.dll"; // Get path to worker dll. - GameDirectory = currentDirectory + "\\r5apex_ds.exe"; // Get path to game executeable. - StartupCommandLine = currentDirectory + "\\r5apex_ds.exe " + CommandLineArguments; // Setup startup command line string. + svWorkerDll = svCurrentDir + "\\dedicated.dll"; // Get path to worker dll. + svGameDir = svCurrentDir + "\\r5apex_ds.exe"; // Get path to game executeable. + svStartCmdLine = svCurrentDir + "\\r5apex_ds.exe " + svCmdLineArgs; // Setup startup command line string. spdlog::info("*** LAUNCHING DEDICATED [DEBUG] ***\n"); break; @@ -103,8 +103,8 @@ bool LaunchR5Apex(eLaunchMode lMode, eLaunchState lState) if (cfgFile.good() && cfgFile) // Does the cfg file exist? { std::stringstream ss; - ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream. - CommandLineArguments = ss.str(); // Get all the contents of the cfg file. + ss << cfgFile.rdbuf(); // Read ifstream buffer into stringstream. + svCmdLineArgs = ss.str(); // Get all the contents of the cfg file. } else { @@ -114,9 +114,9 @@ bool LaunchR5Apex(eLaunchMode lMode, eLaunchState lState) } cfgFile.close(); // Close cfg file. - WorkerDll = currentDirectory + "\\dedicated.dll"; // Get path to worker dll. - GameDirectory = currentDirectory + "\\r5apex_ds.exe"; // Get path to game executeable. - StartupCommandLine = currentDirectory + "\\r5apex_ds.exe " + CommandLineArguments; // Setup startup command line string. + svWorkerDll = svCurrentDir + "\\dedicated.dll"; // Get path to worker dll. + svGameDir = svCurrentDir + "\\r5apex_ds.exe"; // Get path to game executeable. + svStartCmdLine = svCurrentDir + "\\r5apex_ds.exe " + svCmdLineArgs; // Setup startup command line string. spdlog::info("*** LAUNCHING DEDICATED [RELEASE] ***\n"); break; @@ -131,17 +131,17 @@ bool LaunchR5Apex(eLaunchMode lMode, eLaunchState lState) /////////////////////////////////////////////////////////////////////////// // Print the file paths and arguments. std::cout << "----------------------------------------------------------------------------------------------------------------------" << std::endl; - spdlog::debug("- CWD: {}\n", currentDirectory); - spdlog::debug("- EXE: {}\n", GameDirectory); - spdlog::debug("- DLL: {}\n", WorkerDll); - spdlog::debug("- CLI: {}\n", CommandLineArguments); + spdlog::debug("- CWD: {}\n", svCurrentDir); + spdlog::debug("- EXE: {}\n", svGameDir); + spdlog::debug("- DLL: {}\n", svWorkerDll); + spdlog::debug("- CLI: {}\n", svCmdLineArgs); std::cout << "----------------------------------------------------------------------------------------------------------------------" << std::endl; /////////////////////////////////////////////////////////////////////////// // Build our list of dlls to inject. LPCSTR DllsToInject[1] = { - WorkerDll.c_str() + svWorkerDll.c_str() }; STARTUPINFOA StartupInfo = { 0 }; @@ -154,14 +154,14 @@ bool LaunchR5Apex(eLaunchMode lMode, eLaunchState lState) // Create the game process in a suspended state with our dll. BOOL result = DetourCreateProcessWithDllsA ( - GameDirectory.c_str(), // lpApplicationName - (LPSTR)StartupCommandLine.c_str(), // lpCommandLine + svGameDir.c_str(), // lpApplicationName + (LPSTR)svStartCmdLine.c_str(), // lpCommandLine NULL, // lpProcessAttributes NULL, // lpThreadAttributes FALSE, // bInheritHandles CREATE_SUSPENDED, // dwCreationFlags NULL, // lpEnvironment - currentDirectory.c_str(), // lpCurrentDirectory + svCurrentDir.c_str(), // lpCurrentDirectory &StartupInfo, // lpStartupInfo &ProcInfo, // lpProcessInformation sizeof(DllsToInject) / sizeof(LPCSTR), // nDlls diff --git a/r5dev/tier0/basetypes.h b/r5dev/tier0/basetypes.h index 2f62060d..efe9d83d 100644 --- a/r5dev/tier0/basetypes.h +++ b/r5dev/tier0/basetypes.h @@ -16,7 +16,13 @@ #define MAX_PLAYERS 128 // Max R5 players. -#define SDK_VERSION "VGameSDK024" +#define SDK_VERSION "VGameSDK001" // Increment this with every /breaking/ SDK change (i.e. security/backend changes breaking compatibility). + +#ifndef DEDICATED +#define SDK_DEFAULT_CFG "platform\\cfg\\startup_default.cfg" +#else +#define SDK_DEFAULT_CFG "platform\\cfg\\startup_dedi_default.cfg" +#endif // #define COMPILETIME_MAX and COMPILETIME_MIN for max/min in constant expressions #define COMPILETIME_MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) ) diff --git a/r5dev/tier0/commandline.cpp b/r5dev/tier0/commandline.cpp index ba424cc1..bad139e8 100644 --- a/r5dev/tier0/commandline.cpp +++ b/r5dev/tier0/commandline.cpp @@ -88,13 +88,11 @@ const char* CCommandLine::ParmValue(const char* psz, const char* pDefaultVal) static int index = 7; return CallVFunc(index, this, psz, pDefaultVal); } - int CCommandLine::ParmValue(const char* psz, int nDefaultVal) { static int index = 8; return CallVFunc(index, this, psz, nDefaultVal); } - float CCommandLine::ParmValue(const char* psz, float flDefaultVal) { static int index = 9; @@ -124,9 +122,17 @@ const char* CCommandLine::GetParm(int nIndex) void CCommandLine::SetParm(int nIndex, char const* pParm) { - static int index = 13; + static int index = 14; CallVFunc(index, this, nIndex, pParm); } /////////////////////////////////////////////////////////////////////////////// CCommandLine* g_pCmdLine = reinterpret_cast(p_CCVar_GetCommandLineValue.FindPatternSelf("48 8D 0D", CMemory::Direction::DOWN, 250).ResolveRelativeAddressSelf(0x3, 0x7).GetPtr()); + +//----------------------------------------------------------------------------- +// Instance singleton and expose interface to rest of code +//----------------------------------------------------------------------------- +CCommandLine* CommandLine(void) +{ + return g_pCmdLine; +} diff --git a/r5dev/tier0/commandline.h b/r5dev/tier0/commandline.h index 60bf7590..ee587b69 100644 --- a/r5dev/tier0/commandline.h +++ b/r5dev/tier0/commandline.h @@ -18,14 +18,14 @@ public: const char* GetParm(int nIndex); void SetParm(int nIndex, char const* pParm); }; -extern CCommandLine* g_pCmdLine; +CCommandLine* CommandLine(void); /////////////////////////////////////////////////////////////////////////////// class HCommandLine : public IDetour { virtual void GetAdr(void) const { - std::cout << "| VAR: g_pCmdLine : 0x" << std::hex << std::uppercase << g_pCmdLine << std::setw(0) << " |" << std::endl; + std::cout << "| VAR: g_pCmdLine : 0x" << std::hex << std::uppercase << CommandLine() << std::setw(0) << " |" << std::endl; std::cout << "+----------------------------------------------------------------+" << std::endl; } virtual void GetFun(void) const { } diff --git a/r5dev/tier1/IConVar.cpp b/r5dev/tier1/IConVar.cpp index c8713f74..2add98c5 100644 --- a/r5dev/tier1/IConVar.cpp +++ b/r5dev/tier1/IConVar.cpp @@ -169,10 +169,11 @@ void ConVar::InitShipped(void) const } //----------------------------------------------------------------------------- -// Purpose: unregister/disable unused ConVar's for dedicated. +// Purpose: unregister/disable extraneous ConVar's. //----------------------------------------------------------------------------- void ConVar::PurgeShipped(void) const { +#ifdef DEDICATED const char* pszToPurge[] = { "bink_materials_enabled", @@ -191,6 +192,7 @@ void ConVar::PurgeShipped(void) const pCVar->SetValue(0); } } +#endif // DEDICATED } //----------------------------------------------------------------------------- diff --git a/r5dev/tier1/cmd.cpp b/r5dev/tier1/cmd.cpp index e7caba35..feb5e432 100644 --- a/r5dev/tier1/cmd.cpp +++ b/r5dev/tier1/cmd.cpp @@ -171,10 +171,11 @@ void ConCommand::InitShipped(void) } //----------------------------------------------------------------------------- -// Purpose: unregister unused ConCommand's for dedicated. +// Purpose: unregister extraneous ConCommand's. //----------------------------------------------------------------------------- void ConCommand::PurgeShipped(void) const { +#ifdef DEDICATED const char* pszCommandToRemove[] = { "bind", @@ -183,14 +184,24 @@ void ConCommand::PurgeShipped(void) const "bind_list_abilities", "bind_US_standard", "bind_held_US_standard", + "unbind", + "unbind_US_standard", + "unbindall", + "unbind_all_gamepad", + "unbindall_ignoreGamepad", + "unbind_batch", + "unbind_held", + "unbind_held_US_standard", + "getpos_bind", "connect", + "silent_connect", + "ping", "gameui_activate", "gameui_hide", "weaponSelectOrdnance", "weaponSelectPrimary0", "weaponSelectPrimary1", "weaponSelectPrimary2", - "silent_connect", "+scriptCommand1", "-scriptCommand1", "+scriptCommand2", @@ -220,6 +231,7 @@ void ConCommand::PurgeShipped(void) const g_pCVar->UnregisterConCommand(pCommandBase); } } +#endif // DEDICATED } //----------------------------------------------------------------------------- diff --git a/r5dev/vproj/clientsdk.vcxproj b/r5dev/vproj/clientsdk.vcxproj index 9b9c22ba..6fa4f264 100644 --- a/r5dev/vproj/clientsdk.vcxproj +++ b/r5dev/vproj/clientsdk.vcxproj @@ -46,6 +46,7 @@ + @@ -152,6 +153,7 @@ + diff --git a/r5dev/vproj/clientsdk.vcxproj.filters b/r5dev/vproj/clientsdk.vcxproj.filters index ace4a8de..68762bd3 100644 --- a/r5dev/vproj/clientsdk.vcxproj.filters +++ b/r5dev/vproj/clientsdk.vcxproj.filters @@ -417,6 +417,9 @@ sdk\vstdlib + + sdk\launcher + @@ -1190,6 +1193,9 @@ sdk\tier0 + + sdk\launcher + diff --git a/r5dev/vproj/dedicated.vcxproj b/r5dev/vproj/dedicated.vcxproj index 8b5d3d65..95994d9f 100644 --- a/r5dev/vproj/dedicated.vcxproj +++ b/r5dev/vproj/dedicated.vcxproj @@ -169,6 +169,7 @@ + @@ -395,6 +396,7 @@ + diff --git a/r5dev/vproj/dedicated.vcxproj.filters b/r5dev/vproj/dedicated.vcxproj.filters index 1c465913..b1f6c1d2 100644 --- a/r5dev/vproj/dedicated.vcxproj.filters +++ b/r5dev/vproj/dedicated.vcxproj.filters @@ -861,6 +861,9 @@ sdk\tier0 + + sdk\launcher + @@ -1085,6 +1088,9 @@ sdk\vstdlib + + sdk\launcher + diff --git a/r5dev/vproj/gamesdk.vcxproj b/r5dev/vproj/gamesdk.vcxproj index 1317557b..cea41e88 100644 --- a/r5dev/vproj/gamesdk.vcxproj +++ b/r5dev/vproj/gamesdk.vcxproj @@ -52,6 +52,7 @@ + @@ -169,6 +170,7 @@ + @@ -432,7 +434,7 @@ true $(SolutionDir)r5dev\;$(IncludePath);$(DXSDK_DIR)Include $(LibraryPath);$(DXSDK_DIR)Lib\x64 - r5apexsdkd64 + gamesdk $(SolutionDir)bin\$(Configuration)\ $(SolutionDir)build\$(ProjectName)\$(Configuration)\ $(VC_ReferencesPath_x64); @@ -441,7 +443,7 @@ false $(SolutionDir)r5dev\;$(IncludePath);$(DXSDK_DIR)Include $(LibraryPath);$(DXSDK_DIR)Lib\x64 - r5apexsdkd64 + gamesdk $(VC_ReferencesPath_x64); $(SolutionDir)bin\$(Configuration)\ $(SolutionDir)build\$(ProjectName)\$(Configuration)\ @@ -469,7 +471,7 @@ $(SolutionDir)lib\$(Configuration)\ - IF EXIST "$(SolutionDir)..\..\r5apex.exe" del "$(SolutionDir)..\..\r5apexsdkd64.dll" && copy /Y "$(TargetPath)" "$(SolutionDir)..\..\ + IF EXIST "$(SolutionDir)..\..\r5apex.exe" del "$(SolutionDir)..\..\gamesdk.dll" && copy /Y "$(TargetPath)" "$(SolutionDir)..\..\ @@ -511,7 +513,7 @@ $(SolutionDir)lib\$(Configuration)\ - IF EXIST "$(SolutionDir)..\..\r5apex.exe" del "$(SolutionDir)..\..\r5apexsdkd64.dll" && copy /Y "$(TargetPath)" "$(SolutionDir)..\..\ + IF EXIST "$(SolutionDir)..\..\r5apex.exe" del "$(SolutionDir)..\..\gamesdk.dll" && copy /Y "$(TargetPath)" "$(SolutionDir)..\..\ diff --git a/r5dev/vproj/gamesdk.vcxproj.filters b/r5dev/vproj/gamesdk.vcxproj.filters index 78d4dbc9..1c0e98b3 100644 --- a/r5dev/vproj/gamesdk.vcxproj.filters +++ b/r5dev/vproj/gamesdk.vcxproj.filters @@ -447,6 +447,9 @@ sdk\vstdlib + + sdk\launcher + @@ -1253,6 +1256,9 @@ sdk\tier0 + + sdk\launcher + diff --git a/r5dev/windows/console.cpp b/r5dev/windows/console.cpp index 8b1b5f93..b6b86cde 100644 --- a/r5dev/windows/console.cpp +++ b/r5dev/windows/console.cpp @@ -97,7 +97,7 @@ void Console_Init() CloseHandle(hThread); } - if (strstr(GetCommandLineA(), "-ansiclr")) + if (strstr(g_svCmdLine.c_str(), "-ansiclr")) { GetConsoleMode(hOutput, &dwMode); dwMode |= ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING;