From 8290cadbe9260aa67b55749ff25ec308d6538c3f Mon Sep 17 00:00:00 2001 From: FutureRave Date: Thu, 10 Feb 2022 14:41:51 +0000 Subject: [PATCH] Add yes/no buttons to message box --- src/Components/Modules/Exception.cpp | 71 +++++++++++++++------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/src/Components/Modules/Exception.cpp b/src/Components/Modules/Exception.cpp index 5069bc91..803d06b8 100644 --- a/src/Components/Modules/Exception.cpp +++ b/src/Components/Modules/Exception.cpp @@ -73,7 +73,7 @@ namespace Components CloseClipboard(); return; } - + auto lock = GlobalLock(hMem); if (lock != nullptr) { @@ -102,15 +102,18 @@ namespace Components } else { - errorStr = Utils::String::VA("Fatal error (0x%08X) at 0x%08X.", ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress); + errorStr = Utils::String::VA("Fatal error (0x%08X) at 0x%08X.\n Copy exception address to keyboard?", ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress); } //Exception::SuspendProcess(); - Exception::CopyMessageToClipboard(Utils::String::VA("0x%08X", ExceptionInfo->ExceptionRecord->ExceptionAddress)); - MessageBoxA(nullptr, errorStr.data(), "ERROR", MB_ICONERROR); + // Message should be copied to the keyboard if no button is pressed + if (MessageBoxA(nullptr, errorStr.data(), nullptr, MB_YESNO | MB_ICONERROR) == IDYES) + { + Exception::CopyMessageToClipboard(Utils::String::VA("0x%08X", ExceptionInfo->ExceptionRecord->ExceptionAddress)); + } - if ( Flags::HasFlag("bigminidumps")) + if (Flags::HasFlag("bigminidumps")) { Exception::SetMiniDumpType(true, false); } @@ -201,20 +204,20 @@ namespace Components #ifdef DEBUG // Display DEBUG branding, so we know we're on a debug build Scheduler::OnFrame([]() - { - Game::Font_s* font = Game::R_RegisterFont("fonts/normalFont", 0); - float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; - - // Change the color when attaching a debugger - if (IsDebuggerPresent()) { - color[0] = 0.6588f; - color[1] = 1.0000f; - color[2] = 0.0000f; - } + Game::Font_s* font = Game::R_RegisterFont("fonts/normalFont", 0); + float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; - Game::R_AddCmdDrawText("DEBUG-BUILD", 0x7FFFFFFF, font, 15.0f, 10.0f + Game::R_TextHeight(font), 1.0f, 1.0f, 0.0f, color, Game::ITEM_TEXTSTYLE_SHADOWED); - }, true); + // Change the color when attaching a debugger + if (IsDebuggerPresent()) + { + color[0] = 0.6588f; + color[1] = 1.0000f; + color[2] = 0.0000f; + } + + Game::R_AddCmdDrawText("DEBUG-BUILD", 0x7FFFFFFF, font, 15.0f, 10.0f + Game::R_TextHeight(font), 1.0f, 1.0f, 0.0f, color, Game::ITEM_TEXTSTYLE_SHADOWED); + }, true); #endif #if !defined(DEBUG) || defined(FORCE_EXCEPTION_HANDLER) Exception::SetFilterHook.initialize(SetUnhandledExceptionFilter, Exception::SetUnhandledExceptionFilterStub, HOOK_JUMP); @@ -227,28 +230,28 @@ namespace Components Utils::Hook(0x6B8898, Exception::LongJmp, HOOK_JUMP).install()->quick(); Command::Add("mapTest", [](Command::Params* params) - { - Game::UI_UpdateArenas(); - - std::string command; - for (int i = 0; i < (params->length() >= 2 ? atoi(params->get(1)) : *Game::arenaCount); ++i) { - char* mapname = ArenaLength::NewArenas[i % *Game::arenaCount].mapName; + Game::UI_UpdateArenas(); - if (!(i % 2)) command.append(Utils::String::VA("wait 250;disconnect;wait 750;", mapname)); // Test a disconnect - else command.append(Utils::String::VA("wait 500;", mapname)); // Test direct map switch - command.append(Utils::String::VA("map %s;", mapname)); - } + std::string command; + for (int i = 0; i < (params->length() >= 2 ? atoi(params->get(1)) : *Game::arenaCount); ++i) + { + char* mapname = ArenaLength::NewArenas[i % *Game::arenaCount].mapName; - Command::Execute(command, false); - }); + if (!(i % 2)) command.append(Utils::String::VA("wait 250;disconnect;wait 750;", mapname)); // Test a disconnect + else command.append(Utils::String::VA("wait 500;", mapname)); // Test direct map switch + command.append(Utils::String::VA("map %s;", mapname)); + } + + Command::Execute(command, false); + }); Command::Add("debug_exceptionhandler", [](Command::Params*) - { - Logger::Print("Rerunning SetUnhandledExceptionHandler...\n"); - auto oldHandler = Exception::Hook(); - Logger::Print("Old exception handler was 0x%010X.\n", oldHandler); - }); + { + Logger::Print("Rerunning SetUnhandledExceptionHandler...\n"); + auto oldHandler = Exception::Hook(); + Logger::Print("Old exception handler was 0x%010X.\n", oldHandler); + }); } Exception::~Exception()