Skip to content

Commit

Permalink
add enter_closed_door_crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Auto committed Oct 8, 2023
1 parent 099d40b commit 3a98f9c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/game_api/game_patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t>(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 <end>
"\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<int32_t>((addr + 8) - (new_code_addr + 18));
write_mem_prot(new_code_addr + 14, rel, true);
once = true;
}
1 change: 1 addition & 0 deletions src/game_api/game_patches.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
8 changes: 8 additions & 0 deletions src/game_api/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,14 @@ std::unordered_map<std::string_view, AddressRule> 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<std::string_view, size_t> g_cached_addresses;

Expand Down
1 change: 1 addition & 0 deletions src/game_api/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ State& State::get()
patch_orbs_limit();
patch_olmec_kill_crash();
patch_liquid_OOB();
patch_entering_closed_door_crash();
}
else
{
Expand Down

0 comments on commit 3a98f9c

Please sign in to comment.