From f8cdd53561dc5bb37b5387f9ad3b966de8aa2a58 Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Thu, 26 Aug 2021 02:13:08 +0100 Subject: fix cleanup after injection --- GameInjector/dllmain.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/GameInjector/dllmain.cpp b/GameInjector/dllmain.cpp index 38e262cc..69ea748a 100644 --- a/GameInjector/dllmain.cpp +++ b/GameInjector/dllmain.cpp @@ -81,10 +81,14 @@ BOOL WINAPI CreateProcessWHook( CreateProcessA((tf2DirPath / "InjectionProxy64.exe").string().c_str(), (LPSTR)(argStr.str().c_str()), 0, 0, false, 0, 0, tf2DirPath.string().c_str(), (LPSTARTUPINFOA)&si, &pi); WaitForSingleObject(pi.hThread, INFINITE); - if (!alreadySuspended) - ResumeThread(lpProcessInformation->hThread); + // this doesn't seem to work super well + //if (!alreadySuspended) + ResumeThread(lpProcessInformation->hThread); + MH_DisableHook(&CreateProcessW); MH_RemoveHook(&CreateProcessW); + MH_Uninitialize(); + FreeLibrary(ownHModule); } @@ -101,14 +105,14 @@ BOOL APIENTRY DllMain(HMODULE hModule, { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: - //DisableThreadLibraryCalls(hModule); + DisableThreadLibraryCalls(hModule); case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } - //AllocConsole(); - //freopen("CONOUT$", "w", stdout); + AllocConsole(); + freopen("CONOUT$", "w", stdout); ownHModule = hModule; char ownDllPath[MAX_PATH]; @@ -116,9 +120,6 @@ BOOL APIENTRY DllMain(HMODULE hModule, tf2DirPath = std::filesystem::path(ownDllPath).parent_path(); - //AllocConsole(); - //freopen("CONOUT$", "w", stdout); - // hook CreateProcessW if (MH_Initialize() > MH_ERROR_ALREADY_INITIALIZED) // MH_ERROR_ALREADY_INITIALIZED = 1, MH_OK = 0, these are the only results we should expect return TRUE; -- cgit v1.2.3