[Proxy]: Refactor some code

This commit is contained in:
FutureRave 2022-11-22 00:02:57 +00:00
parent c23557ff9a
commit c136b6fcac
No known key found for this signature in database
GPG Key ID: 22F9079C86CFAB31
2 changed files with 16 additions and 7 deletions

View File

@ -190,21 +190,23 @@ namespace Steam
} }
else else
{ {
#ifdef _DEBUG
OutputDebugStringA("Steam proxy was unable to match the arguments for SpawnProcess!\n"); OutputDebugStringA("Steam proxy was unable to match the arguments for SpawnProcess!\n");
#endif
} }
} }
void Proxy::RunMod() void Proxy::RunMod()
{ {
const char* command = "-proc "; const char* command = "-proc ";
char* parentProc = strstr(GetCommandLineA(), command); auto* parentProc = std::strstr(GetCommandLineA(), command);
if (parentProc) if (parentProc)
{ {
FreeConsole(); FreeConsole();
parentProc += strlen(command); parentProc += strlen(command);
int pid = atoi(parentProc); const auto pid = std::strtol(parentProc, nullptr, 10);
HANDLE processHandle = OpenProcess(SYNCHRONIZE, FALSE, pid); HANDLE processHandle = OpenProcess(SYNCHRONIZE, FALSE, pid);
@ -374,10 +376,10 @@ namespace Steam
bool Proxy::Inititalize() bool Proxy::Inititalize()
{ {
std::string directoy = Proxy::GetSteamDirectory(); const auto directoy = Proxy::GetSteamDirectory();
if (directoy.empty()) return false; if (directoy.empty()) return false;
SetDllDirectoryA(Proxy::GetSteamDirectory().data()); SetDllDirectoryA(directoy.data());
if (!Components::Dedicated::IsEnabled() && !Components::ZoneBuilder::IsEnabled()) if (!Components::Dedicated::IsEnabled() && !Components::ZoneBuilder::IsEnabled())
{ {
@ -484,7 +486,7 @@ namespace Steam
std::string Proxy::GetSteamDirectory() std::string Proxy::GetSteamDirectory()
{ {
HKEY hRegKey; 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) if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, STEAM_REGISTRY_PATH, 0, KEY_QUERY_VALUE, &hRegKey) == ERROR_SUCCESS)
{ {
DWORD dwLength = sizeof(SteamPath); DWORD dwLength = sizeof(SteamPath);
@ -494,7 +496,7 @@ namespace Steam
return SteamPath; return SteamPath;
} }
return ""; return {};
} }
uint32_t Proxy::GetActiveUser() uint32_t Proxy::GetActiveUser()

View File

@ -104,7 +104,14 @@ namespace Steam
bool Enabled() bool Enabled()
{ {
return !Components::Flags::HasFlag("nosteam"); static std::optional<bool> flag;
if (!flag.has_value())
{
flag = Components::Flags::HasFlag("nosteam");
}
return !flag.value();
} }
extern "C" extern "C"