From 308d4a94648a25ee33b0d9a524ce9ad00465a12a Mon Sep 17 00:00:00 2001 From: rebtd7 <59185507+rebtd7@users.noreply.github.com> Date: Tue, 16 Mar 2021 12:00:04 -0300 Subject: [PATCH] Fix possible crash when exit after disabling messagebox --- d3d9ex/AutoFix.cpp | 27 ++++++++++++++++++++++++--- d3d9ex/Context.h | 6 +++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/d3d9ex/AutoFix.cpp b/d3d9ex/AutoFix.cpp index 99d4103..e3a3edd 100644 --- a/d3d9ex/AutoFix.cpp +++ b/d3d9ex/AutoFix.cpp @@ -198,6 +198,7 @@ void MainContext::FF13_InitializeGameAddresses() ff13_party_screen_scissor_scaling_factor_3 = baseAddr + 0x668E56; ff13_party_screen_scissor_scaling_factor_4 = baseAddr + 0x668E91; ff13_message_box_call_address = baseAddr + 0xA8A98F; + ff13_message_box_stack_push_address = baseAddr + 0xA8A982; } void MainContext::ForceWindowActivate(const HWND hWnd) { @@ -208,7 +209,7 @@ void MainContext::ForceWindowActivate(const HWND hWnd) { void MainContext::FF13_OneTimeFixes() { if (IsDXVK()) { - PatchMessageBox(ff13_message_box_call_address); + FF13_PatchMessageBox(); } ForceWindowActivate(hWndFF13); @@ -223,6 +224,17 @@ void MainContext::FF13_OneTimeFixes() { PrintLog("Finished FF13 One Time Fixes"); } +void MainContext::FF13_PatchMessageBox() +{ + PrintLog("Removing 'Quit game' textbox"); + + MemPatch::Nop(ff13_message_box_stack_push_address, 1); + MemPatch::Nop(ff13_message_box_stack_push_address + 1 * 4, 1); + MemPatch::Nop(ff13_message_box_stack_push_address + 2 * 4, 1); + MemPatch::Nop(ff13_message_box_stack_push_address + 3 * 4, 1); + PatchMessageBoxCall(ff13_message_box_call_address); +} + void MainContext::FF13_EnableControllerVibration() { if (!config.GetFFXIIIEnableControllerVibration()) { @@ -320,7 +332,7 @@ void MainContext::FF13_2_OneTimeFixes() { ForceWindowActivate(hWndFF13); if (IsDXVK()) { - PatchMessageBox(ff13_2_message_box_call_address); + FF13_2_PatchMessageBox(); } if (*ff13_2_frame_pacer_ptr_address) { @@ -338,9 +350,17 @@ void MainContext::FF13_2_OneTimeFixes() } } -void MainContext::PatchMessageBox(uint8_t* callInstructionAddress) +void MainContext::FF13_2_PatchMessageBox() { PrintLog("Removing 'Quit game' textbox"); + + // NOP push of registers to call MessageBox + MemPatch::Nop(ff13_2_message_box_stack_push_address, 5); + PatchMessageBoxCall(ff13_2_message_box_call_address); +} + +void MainContext::PatchMessageBoxCall(uint8_t* callInstructionAddress) +{ const int patchSize = 6; uint8_t patch[patchSize]; @@ -394,6 +414,7 @@ void MainContext::FF13_2_InitializeGameAddresses() ff13_2_internal_res_w = (uint32_t*)(baseAddr + 0x1FA864C); ff13_2_internal_res_h = ff13_2_internal_res_w + 1; ff13_2_message_box_call_address = baseAddr + 0x8047C0; + ff13_2_message_box_stack_push_address = baseAddr + 0x8047B4; } void MainContext::FF13_2_RemoveContinuousControllerScan() diff --git a/d3d9ex/Context.h b/d3d9ex/Context.h index 484fd32..8cfba47 100644 --- a/d3d9ex/Context.h +++ b/d3d9ex/Context.h @@ -93,6 +93,7 @@ private: uint8_t* ff13_party_screen_scissor_scaling_factor_2 = NULL; uint8_t* ff13_party_screen_scissor_scaling_factor_3 = NULL; uint8_t* ff13_party_screen_scissor_scaling_factor_4 = NULL; + uint8_t* ff13_message_box_stack_push_address = NULL; uint8_t* ff13_message_box_call_address = NULL; uint32_t* ff13_internal_res_w; uint32_t* ff13_internal_res_h; @@ -105,6 +106,7 @@ private: uint8_t** ff13_2_base_controller_input_address_ptr = NULL; uint8_t* ff13_2_vibration_high_set_zero_address = NULL; uint8_t* ff13_2_vibration_low_set_zero_address = NULL; + uint8_t* ff13_2_message_box_stack_push_address = NULL; uint8_t* ff13_2_message_box_call_address = NULL; uint32_t* ff13_2_internal_res_w; uint32_t* ff13_2_internal_res_h; @@ -143,6 +145,7 @@ private: void FF13_InitializeGameAddresses(); void FF13_OneTimeFixes(); + void FF13_PatchMessageBox(); void FF13_EnableControllerVibration(); void FF13_NOPIngameFrameRateLimitSetter(); void FF13_SetFrameRateVariables(); @@ -154,12 +157,13 @@ private: void FF13_2_RemoveContinuousControllerScan(); void FF13_2_AddHookIngameFrameRateLimitSetter(); void FF13_2_OneTimeFixes(); + void FF13_2_PatchMessageBox(); void FF13_2_EnableControllerVibration(); void AdjustVertexData(const uint32_t width, const uint32_t height); bool MatchesExpectedVertexStream(const float* pVertexStreamZeroData); void ForceWindowActivate(const HWND hWnd); - void PatchMessageBox(uint8_t* callInstructionAddress); + void PatchMessageBoxCall(uint8_t* callInstructionAddress); bool OneTimeFixInit(std::unique_ptr& className, HWND hWnd); std::atomic_bool otf_init = false;