Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Utils/FileWatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string>
#include <vector>

namespace FileWatcher {
void Start(const std::vector<std::string>& directories);
void Stop();
}
namespace FileWatcher {
void Start(const std::vector<std::string>& directories);
void Stop();
}
46 changes: 27 additions & 19 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,30 @@ static DWORD WINAPI InitThread(LPVOID param) {
return 0;
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, PVOID pvReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hModule);
// Hand off all real work to a worker thread to avoid running file I/O,
// LoadLibrary, and detour transactions under the loader lock.
HANDLE h = CreateThread(nullptr, 0, InitThread, hModule, 0, nullptr);
if (h) CloseHandle(h);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
FileWatcher::Stop();
SteamUI::CoreUnhook();
SteamClient::CoreUnhook();
}

return TRUE;
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, PVOID pvReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hModule);
// Keep this module pinned so explicit FreeLibrary cannot unload code
// while hooks and worker threads may still reference it.
HMODULE pinnedModule = nullptr;
GetModuleHandleExA(
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN,
reinterpret_cast<LPCSTR>(&DllMain), &pinnedModule);
// Hand off all real work to a worker thread to avoid running file I/O,
// LoadLibrary, and detour transactions under the loader lock.
HANDLE h = CreateThread(nullptr, 0, InitThread, hModule, 0, nullptr);
if (h) CloseHandle(h);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
// During process termination, join watcher thread object so CRT static
// teardown does not hit std::thread's joinable-guard terminate.
if (pvReserved != nullptr) {
FileWatcher::Stop();
}
}

return TRUE;
}
Loading