From e3278840e9ddd15865e7d690b0398e46c4c91ecd Mon Sep 17 00:00:00 2001 From: FutureRave Date: Thu, 10 Feb 2022 12:14:43 +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 d94fd884..32946382 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 @@ -90,6 +116,7 @@ namespace Components } }*/ + Exception::CopyMessageToClipboard(errorStr); MessageBoxA(nullptr, errorStr.data(), "ERROR", MB_ICONERROR); if (doFullDump) 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;