From 3a98f9c6212222255d19fb44d598368b5a7ad06c Mon Sep 17 00:00:00 2001 From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com> Date: Sun, 8 Oct 2023 16:27:39 +0200 Subject: [PATCH] add `enter_closed_door_crash` --- src/game_api/game_patches.cpp | 34 ++++++++++++++++++++++++++++++++++ src/game_api/game_patches.hpp | 1 + src/game_api/search.cpp | 8 ++++++++ src/game_api/state.cpp | 1 + 4 files changed, 44 insertions(+) diff --git a/src/game_api/game_patches.cpp b/src/game_api/game_patches.cpp index f71b096fd..c40919471 100644 --- a/src/game_api/game_patches.cpp +++ b/src/game_api/game_patches.cpp @@ -284,3 +284,37 @@ void set_skip_tiamat_cutscene(bool skip) else recover_mem("set_skip_tiamat_cutscene"); } + +void patch_entering_closed_door_crash() +{ + static bool once = false; + if (once) + return; + + size_t addr = get_address("enter_closed_door_crash"); + size_t return_addr; + { + auto memory = Memory::get(); + auto rva = find_inst(memory.exe(), "\x49\x39\xD4", addr - memory.exe_ptr, addr - memory.exe_ptr + 0x3F5, "patch_entering_closed_door_crash"); + if (rva == 0) + return; + size_t jump_addr = memory.at_exe(rva + 3); + size_t offset = memory_read(jump_addr + 2); + return_addr = jump_addr + 6 + offset; + } + std::string_view new_code{ + "\x48\x85\xC0"sv // test rax,rax + "\x74\x0D"sv // je + "\x48\x8B\x48\x08"sv // mov rcx,QWORD PTR [rax+0x8] // game code + "\x41\x8B\x47\x28"sv // mov eax,DWORD PTR [r15+0x28] // game code + "\xE9\x00\x00\x00\x00"sv // jmp (offset needs to be updated after we know the address) + }; + + auto new_code_addr = patch_and_redirect(addr, 8, new_code, true, return_addr); + if (new_code_addr == 0) + return; + + int32_t rel = static_cast((addr + 8) - (new_code_addr + 18)); + write_mem_prot(new_code_addr + 14, rel, true); + once = true; +} diff --git a/src/game_api/game_patches.hpp b/src/game_api/game_patches.hpp index 0adbc7548..78e5fd14b 100644 --- a/src/game_api/game_patches.hpp +++ b/src/game_api/game_patches.hpp @@ -6,3 +6,4 @@ void patch_liquid_OOB(); void set_skip_olmec_cutscene(bool skip); void patch_tiamat_kill_crash(); void set_skip_tiamat_cutscene(bool skip); +void patch_entering_closed_door_crash(); diff --git a/src/game_api/search.cpp b/src/game_api/search.cpp index 4459f4dec..1b5f2026f 100644 --- a/src/game_api/search.cpp +++ b/src/game_api/search.cpp @@ -2035,6 +2035,14 @@ std::unordered_map g_address_rules{ .decode_pc() .at_exe(), }, + { + "enter_closed_door_crash"sv, + // third virtual in behavior of the dog in walking state, the exact line crashing the game when pet tries to enter closed door (tiamat/hundun) + PatternCommandBuffer{} + .find_after_inst("FF 90 A8 00 00 00 48 89 F1"_gh) + .offset(0x5) + .at_exe(), + }, }; std::unordered_map g_cached_addresses; diff --git a/src/game_api/state.cpp b/src/game_api/state.cpp index 7a4dd4dc6..2cb5da1d0 100644 --- a/src/game_api/state.cpp +++ b/src/game_api/state.cpp @@ -300,6 +300,7 @@ State& State::get() patch_orbs_limit(); patch_olmec_kill_crash(); patch_liquid_OOB(); + patch_entering_closed_door_crash(); } else {