From c136b6fcac542a35b2782b8cd985f9480025d49b Mon Sep 17 00:00:00 2001 From: FutureRave Date: Tue, 22 Nov 2022 00:02:57 +0000 Subject: [PATCH] [Proxy]: Refactor some code --- src/Steam/Proxy.cpp | 14 ++++++++------ src/Steam/Steam.cpp | 9 ++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Steam/Proxy.cpp b/src/Steam/Proxy.cpp index 0df90ca1..4d352322 100644 --- a/src/Steam/Proxy.cpp +++ b/src/Steam/Proxy.cpp @@ -190,21 +190,23 @@ namespace Steam } else { +#ifdef _DEBUG OutputDebugStringA("Steam proxy was unable to match the arguments for SpawnProcess!\n"); +#endif } } void Proxy::RunMod() { const char* command = "-proc "; - char* parentProc = strstr(GetCommandLineA(), command); + auto* parentProc = std::strstr(GetCommandLineA(), command); if (parentProc) { FreeConsole(); parentProc += strlen(command); - int pid = atoi(parentProc); + const auto pid = std::strtol(parentProc, nullptr, 10); HANDLE processHandle = OpenProcess(SYNCHRONIZE, FALSE, pid); @@ -374,10 +376,10 @@ namespace Steam bool Proxy::Inititalize() { - std::string directoy = Proxy::GetSteamDirectory(); + const auto directoy = Proxy::GetSteamDirectory(); if (directoy.empty()) return false; - SetDllDirectoryA(Proxy::GetSteamDirectory().data()); + SetDllDirectoryA(directoy.data()); if (!Components::Dedicated::IsEnabled() && !Components::ZoneBuilder::IsEnabled()) { @@ -484,7 +486,7 @@ namespace Steam std::string Proxy::GetSteamDirectory() { HKEY hRegKey; - char SteamPath[MAX_PATH]; + char SteamPath[MAX_PATH]{}; if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, STEAM_REGISTRY_PATH, 0, KEY_QUERY_VALUE, &hRegKey) == ERROR_SUCCESS) { DWORD dwLength = sizeof(SteamPath); @@ -494,7 +496,7 @@ namespace Steam return SteamPath; } - return ""; + return {}; } uint32_t Proxy::GetActiveUser() diff --git a/src/Steam/Steam.cpp b/src/Steam/Steam.cpp index a03cec07..3d1ff85f 100644 --- a/src/Steam/Steam.cpp +++ b/src/Steam/Steam.cpp @@ -104,7 +104,14 @@ namespace Steam bool Enabled() { - return !Components::Flags::HasFlag("nosteam"); + static std::optional flag; + + if (!flag.has_value()) + { + flag = Components::Flags::HasFlag("nosteam"); + } + + return !flag.value(); } extern "C"