[Proxy] Watch if steam crashes
This commit is contained in:
parent
04d09b39e0
commit
0fcf3ea014
@ -18,6 +18,10 @@ namespace Steam
|
|||||||
Utils* Proxy::SteamUtils = nullptr;
|
Utils* Proxy::SteamUtils = nullptr;
|
||||||
User* Proxy::SteamUser_ = nullptr;
|
User* Proxy::SteamUser_ = nullptr;
|
||||||
|
|
||||||
|
HANDLE Proxy::Process = nullptr;
|
||||||
|
HANDLE Proxy::CancelHandle = nullptr;
|
||||||
|
std::thread Proxy::WatchGuard;
|
||||||
|
|
||||||
uint32_t Proxy::AppId = 0;
|
uint32_t Proxy::AppId = 0;
|
||||||
|
|
||||||
std::recursive_mutex Proxy::CallMutex;
|
std::recursive_mutex Proxy::CallMutex;
|
||||||
@ -325,6 +329,41 @@ namespace Steam
|
|||||||
Proxy::UnregisterCalls();
|
Proxy::UnregisterCalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Proxy::LaunchWatchGuard()
|
||||||
|
{
|
||||||
|
if (Proxy::WatchGuard.joinable()) return;
|
||||||
|
|
||||||
|
HKEY hRegKey;
|
||||||
|
DWORD pid = 0;
|
||||||
|
if (RegOpenKeyExA(HKEY_CURRENT_USER, STEAM_REGISTRY_PROCESS_PATH, 0, KEY_QUERY_VALUE, &hRegKey) != ERROR_SUCCESS) return;
|
||||||
|
|
||||||
|
DWORD dwLength = sizeof(pid);
|
||||||
|
RegQueryValueExA(hRegKey, "pid", nullptr, nullptr, reinterpret_cast<BYTE*>(&pid), &dwLength);
|
||||||
|
RegCloseKey(hRegKey);
|
||||||
|
|
||||||
|
Proxy::CancelHandle = CreateEventA(nullptr, TRUE, FALSE, "CancelEvent");
|
||||||
|
if (!Proxy::CancelHandle) return;
|
||||||
|
|
||||||
|
Proxy::Process = OpenProcess(SYNCHRONIZE, FALSE, pid);
|
||||||
|
if (!Proxy::Process) return;
|
||||||
|
|
||||||
|
Proxy::WatchGuard = std::thread([]()
|
||||||
|
{
|
||||||
|
HANDLE handles[] = { Proxy::Process, Proxy::CancelHandle };
|
||||||
|
|
||||||
|
DWORD result = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
|
||||||
|
CloseHandle(Proxy::Process);
|
||||||
|
CloseHandle(Proxy::CancelHandle);
|
||||||
|
|
||||||
|
if (result == WAIT_OBJECT_0)
|
||||||
|
{
|
||||||
|
Proxy::SteamPipe = nullptr;
|
||||||
|
Proxy::SteamUser = nullptr;
|
||||||
|
Proxy::Uninititalize();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void Proxy::StartSteamIfNecessary()
|
void Proxy::StartSteamIfNecessary()
|
||||||
{
|
{
|
||||||
if (Proxy::GetSteamDirectory().empty() || !Steam::Enabled()) return;
|
if (Proxy::GetSteamDirectory().empty() || !Steam::Enabled()) return;
|
||||||
@ -348,6 +387,11 @@ namespace Steam
|
|||||||
CloseHandle(hProcess);
|
CloseHandle(hProcess);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
allocator.reference(allocator.allocate(1), [](void*)
|
||||||
|
{
|
||||||
|
Proxy::LaunchWatchGuard();
|
||||||
|
});
|
||||||
|
|
||||||
DWORD exitCode;
|
DWORD exitCode;
|
||||||
if (!GetExitCodeProcess(process, &exitCode)) return;
|
if (!GetExitCodeProcess(process, &exitCode)) return;
|
||||||
if (exitCode == STILL_ACTIVE) return;
|
if (exitCode == STILL_ACTIVE) return;
|
||||||
@ -375,6 +419,8 @@ namespace Steam
|
|||||||
while (!interval.elapsed(15s) && !Proxy::GetActiveUser()) std::this_thread::sleep_for(10ms);
|
while (!interval.elapsed(15s) && !Proxy::GetActiveUser()) std::this_thread::sleep_for(10ms);
|
||||||
std::this_thread::sleep_for(1s);
|
std::this_thread::sleep_for(1s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Proxy::LaunchWatchGuard();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Proxy::Inititalize()
|
bool Proxy::Inititalize()
|
||||||
@ -442,6 +488,30 @@ namespace Steam
|
|||||||
|
|
||||||
void Proxy::Uninititalize()
|
void Proxy::Uninititalize()
|
||||||
{
|
{
|
||||||
|
if(Proxy::WatchGuard.get_id() != std::this_thread::get_id() && Proxy::WatchGuard.joinable())
|
||||||
|
{
|
||||||
|
if (Proxy::CancelHandle)
|
||||||
|
{
|
||||||
|
SetEvent(Proxy::CancelHandle);
|
||||||
|
Proxy::WatchGuard.join();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Proxy::WatchGuard.detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Proxy::Process = nullptr;
|
||||||
|
Proxy::CancelHandle = nullptr;
|
||||||
|
|
||||||
|
Proxy::ClientEngine = nullptr;
|
||||||
|
Proxy::ClientUser = nullptr;
|
||||||
|
Proxy::ClientFriends = nullptr;
|
||||||
|
Proxy::SteamApps = nullptr;
|
||||||
|
Proxy::SteamFriends = nullptr;
|
||||||
|
Proxy::SteamUtils = nullptr;
|
||||||
|
Proxy::SteamUser_ = nullptr;
|
||||||
|
|
||||||
if (Proxy::SteamClient && Proxy::SteamPipe)
|
if (Proxy::SteamClient && Proxy::SteamPipe)
|
||||||
{
|
{
|
||||||
if (Proxy::SteamUser)
|
if (Proxy::SteamUser)
|
||||||
@ -452,6 +522,9 @@ namespace Steam
|
|||||||
Proxy::SteamClient->ReleaseSteamPipe(Proxy::SteamPipe);
|
Proxy::SteamClient->ReleaseSteamPipe(Proxy::SteamPipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Proxy::SteamPipe = nullptr;
|
||||||
|
Proxy::SteamUser = nullptr;
|
||||||
|
Proxy::SteamClient = nullptr;
|
||||||
Proxy::Client = ::Utils::Library();
|
Proxy::Client = ::Utils::Library();
|
||||||
Proxy::Overlay = ::Utils::Library();
|
Proxy::Overlay = ::Utils::Library();
|
||||||
}
|
}
|
||||||
|
@ -302,6 +302,10 @@ namespace Steam
|
|||||||
static void* SteamPipe;
|
static void* SteamPipe;
|
||||||
static void* SteamUser;
|
static void* SteamUser;
|
||||||
|
|
||||||
|
static HANDLE Process;
|
||||||
|
static HANDLE CancelHandle;
|
||||||
|
static std::thread WatchGuard;
|
||||||
|
|
||||||
static std::recursive_mutex CallMutex;
|
static std::recursive_mutex CallMutex;
|
||||||
static std::vector<CallContainer> Calls;
|
static std::vector<CallContainer> Calls;
|
||||||
static std::unordered_map<int32_t, void*> Callbacks;
|
static std::unordered_map<int32_t, void*> Callbacks;
|
||||||
@ -314,6 +318,7 @@ namespace Steam
|
|||||||
|
|
||||||
static void UnregisterCalls();
|
static void UnregisterCalls();
|
||||||
static void StartSteamIfNecessary();
|
static void StartSteamIfNecessary();
|
||||||
|
static void LaunchWatchGuard();
|
||||||
|
|
||||||
static void ResetActiveUser();
|
static void ResetActiveUser();
|
||||||
static uint32_t GetActiveUser();
|
static uint32_t GetActiveUser();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user