From bf988fd1293ec6e558484ebce339d444eca8700a Mon Sep 17 00:00:00 2001 From: 11EJDE11 Date: Tue, 2 Dec 2025 01:54:31 +1300 Subject: [PATCH] Don't close Syringe immediately --- src/Phobos.Ext.cpp | 38 +++++++++++++++++++++++++++++++------- src/Phobos.cpp | 3 +-- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/Phobos.Ext.cpp b/src/Phobos.Ext.cpp index ac02d779bf..6877d59d9a 100644 --- a/src/Phobos.Ext.cpp +++ b/src/Phobos.Ext.cpp @@ -309,6 +309,35 @@ DEFINE_HOOK(0x67FDB1, LoadOptionsClass_GetFileInfo, 0x7) #include #include +/** + * Sets up to close Syringe when the game exits. + * We don't do it immediately so that the client doesn't think + * the game has exited once Syringe closes. + * + * Ported from Vinifera + * @author: ZivDero, secsome + */ +static DWORD DebuggerPID = 0; + +void _cdecl Kill_Debugger() +{ + if (DebuggerPID != 0) + { + HANDLE handle = OpenProcess(PROCESS_TERMINATE, FALSE, DebuggerPID); + if (handle) + { + TerminateProcess(handle, EXIT_SUCCESS); + CloseHandle(handle); + } + } +} + +void Setup_Kill_Debugger(DWORD pid) +{ + DebuggerPID = pid; + atexit(Kill_Debugger); +} + bool Phobos::DetachFromDebugger() { auto GetDebuggerProcessId = [](DWORD dwSelfProcessId) -> DWORD @@ -362,13 +391,8 @@ bool Phobos::DetachFromDebugger() status = NtRemoveProcessDebug(hCurrentProcess, hDebug); if (0 <= status) { - HANDLE hDbgProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); - if (INVALID_HANDLE_VALUE != hDbgProcess) - { - BOOL ret = TerminateProcess(hDbgProcess, EXIT_SUCCESS); - CloseHandle(hDbgProcess); - return ret; - } + Setup_Kill_Debugger(pid); + return true; } } NtClose(hDebug); diff --git a/src/Phobos.cpp b/src/Phobos.cpp index c061b50170..17de549101 100644 --- a/src/Phobos.cpp +++ b/src/Phobos.cpp @@ -145,8 +145,7 @@ void Phobos::ExeRun() L"To attach a debugger find the YR process in Process Hacker " L"/ Visual Studio processes window and detach debuggers from it, " - L"then you can attach your own debugger. After this you should " - L"terminate Syringe.exe because it won't automatically exit when YR is closed.\n\n" + L"then you can attach your own debugger.\n\n" L"Press OK to continue YR execution.", L"Debugger Notice", MB_OK);