From 6b35320c12c491d283cec78a5e1fe0ba77fa6fff Mon Sep 17 00:00:00 2001 From: FutureRave Date: Thu, 10 Feb 2022 12:02:17 +0000 Subject: [PATCH] Copy exception message to clipboard for easy coby basting --- src/Components/Modules/Exception.cpp | 31 ++++++++++++++++++++++++++-- src/Components/Modules/Exception.hpp | 3 ++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Components/Modules/Exception.cpp b/src/Components/Modules/Exception.cpp index 677b8bb0..78b8e6b9 100644 --- a/src/Components/Modules/Exception.cpp +++ b/src/Components/Modules/Exception.cpp @@ -43,10 +43,10 @@ namespace Components Utils::Time::Interval interval; while (IsWindow(Window::GetWindow()) != FALSE && !interval.elapsed(2s)) { - if (PeekMessage(&msg, nullptr, NULL, NULL, PM_REMOVE)) + if (PeekMessageA(&msg, nullptr, NULL, NULL, PM_REMOVE)) { TranslateMessage(&msg); - DispatchMessage(&msg); + DispatchMessageA(&msg); } std::this_thread::sleep_for(10ms); @@ -57,6 +57,32 @@ namespace Components Game::Sys_SuspendOtherThreads(); } + void Exception::CopyMessageToClipboard(const std::string& error) + { + const auto hWndNewOwner = GetDesktopWindow(); + const auto result = OpenClipboard(hWndNewOwner); + + if (result == FALSE) + return; + + EmptyClipboard(); + auto* hMem = GlobalAlloc(GMEM_MOVEABLE, error.size() + 1); + + if (hMem != nullptr) + { + auto lock = reinterpret_cast(GlobalLock(hMem)); + + if (lock != nullptr) + { + std::strcpy(lock, error.data()); // Should be okay since we allocated size + 1 + GlobalUnlock(hMem); + SetClipboardData(1, hMem); + } + } + + CloseClipboard(); + } + LONG WINAPI Exception::ExceptionFilter(LPEXCEPTION_POINTERS ExceptionInfo) { // Pass on harmless errors @@ -78,6 +104,7 @@ namespace Components //Exception::SuspendProcess(); + Exception::CopyMessageToClipboard(errorStr); MessageBoxA(nullptr, errorStr.data(), "ERROR", MB_ICONERROR); if ( Flags::HasFlag("bigminidumps")) diff --git a/src/Components/Modules/Exception.hpp b/src/Components/Modules/Exception.hpp index 0b887af8..55a04c1f 100644 --- a/src/Components/Modules/Exception.hpp +++ b/src/Components/Modules/Exception.hpp @@ -18,7 +18,8 @@ namespace Components static LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilterStub(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter); static __declspec(noreturn) void ErrorLongJmp(jmp_buf _Buf, int _Value); static __declspec(noreturn) void LongJmp(jmp_buf _Buf, int _Value); - static void DebugMinidumpCommand(Command::Params*); + + static void CopyMessageToClipboard(const std::string& error); static int MiniDumpType; static Utils::Hook SetFilterHook;