Skip to content

Commit

Permalink
Replace game error handler with better dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Aug 17, 2024
1 parent 32aa34b commit 4a320be
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ project "TRAE-menu-hook"
language "C++"
cppdialect "C++17"

links { "d3d9.lib" }
links { "d3d9.lib", "Comctl32.lib" }

-- Source files
files "src/**"
Expand All @@ -29,6 +29,7 @@ project "TRAE-menu-hook"

-- Build configurations
symbols "On"
linkoptions [["/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'"]]

filter "configurations:Debug"
defines { "DEBUG", "_DEBUG" }
Expand Down
4 changes: 4 additions & 0 deletions src/modules/Patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "game/Game.h"
#include "MainMenu.h"
#include "patches/Reloc.h"
#include "patches/ErrorHandler.h"

// Instance of patches so we can get it in our hooks without calling GetModule<T> each call
static Patches* s_patches;
Expand Down Expand Up @@ -94,6 +95,9 @@ Patches::Patches()
MH_CreateHook((void*)GET_ADDRESS(0x4642F0, 0x467E60, 0x000000), MakePeHandle, nullptr);
#endif

// Insert error handler hook
MH_CreateHook((void*)GET_ADDRESS(0x401EE0, 0x401DF0, 0x478B00), MainG2_ErrorHandler, nullptr);

// Insert DeathState hooks
MH_CreateHook((void*)GET_ADDRESS(0x55DEC0, 0x5581D0, 0x75AA50), DeathState_Entry, (void**)&s_DeathState_Entry);
MH_CreateHook((void*)GET_ADDRESS(0x56EC70, 0x5699C0, 0x75AF90), DeathState_Process, (void**)&s_DeathState_Process);
Expand Down
42 changes: 42 additions & 0 deletions src/modules/patches/ErrorHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <Windows.h>
#include <Commctrl.h>

#include "ErrorHandler.h"
#include "cdc/render/PCDeviceManager.h"

static void HideWindow()
{
auto instance = cdc::PCDeviceManager::GetInstance();

if (instance)
{
ShowWindow(instance->GetWindow(), SW_MINIMIZE);
}
}

bool MainG2_ErrorHandler(const char* message)
{
// Hide the game window
HideWindow();

// Convert to wide string
wchar_t content[1024];
mbstowcs(content, message, 1024);

TASKDIALOGCONFIG config = { };
config.cbSize = sizeof(TASKDIALOGCONFIG);
config.hInstance = GetModuleHandleA(NULL);
config.dwFlags = TDF_EXPAND_FOOTER_AREA | TDF_EXPANDED_BY_DEFAULT;
config.dwCommonButtons = TDCBF_CLOSE_BUTTON;
config.pszMainIcon = TD_ERROR_ICON;
config.pszWindowTitle = L"Tomb Raider Error";
config.pszMainInstruction = L"Tomb Raider has encountered an error";
config.pszContent = L"A fatal error has occured while playing Tomb Raider. To resolve this error refer to the details below.";
config.pszExpandedInformation = content;

// Show the error dialog and exit the game after
TaskDialogIndirect(&config, NULL, NULL, NULL);
exit(1);

return true;
}
3 changes: 3 additions & 0 deletions src/modules/patches/ErrorHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

bool MainG2_ErrorHandler(const char* message);

0 comments on commit 4a320be

Please sign in to comment.