From 281addc68e290967e6068b20d215bc3c32cee050 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 31 Jan 2023 21:48:42 +0100 Subject: [PATCH] Fix crash whitelist not working on client.dll Unregister gamesdk's crash handler if -noworkerdll is passed. This is required as both crashhandlers will be called during an exception, and on one, the whitelist wouldn't work. --- r5dev/core/dllmain.cpp | 6 ++++++ r5dev/public/utility/crashhandler.cpp | 24 ++++++++++++++++++++++-- r5dev/public/utility/crashhandler.h | 3 +++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/r5dev/core/dllmain.cpp b/r5dev/core/dllmain.cpp index 9e01af20..c5674abf 100644 --- a/r5dev/core/dllmain.cpp +++ b/r5dev/core/dllmain.cpp @@ -11,6 +11,7 @@ #include "windows/system.h" #include "mathlib/mathlib.h" #include "launcher/launcher.h" +#include "public/utility/crashhandler.h" //############################################################################# // INITIALIZATION @@ -109,6 +110,11 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) { SDK_Init(); } + else // Destroy crash handler. + { + g_CrashHandler->~CCrashHandler(); + g_CrashHandler = nullptr; + } break; } diff --git a/r5dev/public/utility/crashhandler.cpp b/r5dev/public/utility/crashhandler.cpp index 9fe49940..f7201448 100644 --- a/r5dev/public/utility/crashhandler.cpp +++ b/r5dev/public/utility/crashhandler.cpp @@ -581,6 +581,26 @@ long __stdcall BottomLevelExceptionFilter(EXCEPTION_POINTERS* pExceptionInfo) return EXCEPTION_EXECUTE_HANDLER; } +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CCrashHandler::Init() +{ + m_hExceptionHandler = AddVectoredExceptionHandler(TRUE, BottomLevelExceptionFilter); +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CCrashHandler::Shutdown() +{ + if (m_hExceptionHandler) + { + RemoveVectoredExceptionHandler(m_hExceptionHandler); + m_hExceptionHandler = nullptr; + } +} + //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- @@ -593,7 +613,7 @@ CCrashHandler::CCrashHandler() , m_bExceptionHandled(false) , m_bCrashMsgCreated(false) { - m_hExceptionHandler = AddVectoredExceptionHandler(TRUE, BottomLevelExceptionFilter); + Init(); } //----------------------------------------------------------------------------- @@ -601,7 +621,7 @@ CCrashHandler::CCrashHandler() //----------------------------------------------------------------------------- CCrashHandler::~CCrashHandler() { - RemoveVectoredExceptionHandler(m_hExceptionHandler); + Shutdown(); } CCrashHandler* g_CrashHandler = new CCrashHandler(); \ No newline at end of file diff --git a/r5dev/public/utility/crashhandler.h b/r5dev/public/utility/crashhandler.h index fb2264a2..3588c340 100644 --- a/r5dev/public/utility/crashhandler.h +++ b/r5dev/public/utility/crashhandler.h @@ -10,6 +10,9 @@ public: CCrashHandler(); ~CCrashHandler(); + void Init(); + void Shutdown(); + //------------------------------------------------------------------------- // Inlines: //-------------------------------------------------------------------------