From d2732930504e1c6c3f968fb31fdf9791018eb776 Mon Sep 17 00:00:00 2001 From: ThirteenAG Date: Thu, 20 Jun 2024 23:28:25 +0800 Subject: [PATCH] dolphin plugin fix --- external/asmjit | 2 +- external/injector | 2 +- includes/dolphin/dolphin.h | 71 ++++++++++++++----- premake5.lua | 14 +++- .../dllmain.cpp | 2 +- 5 files changed, 70 insertions(+), 21 deletions(-) diff --git a/external/asmjit b/external/asmjit index 4a61c23ab..f5df7a2b1 160000 --- a/external/asmjit +++ b/external/asmjit @@ -1 +1 @@ -Subproject commit 4a61c23ab65a8feb58d1bcdb7cbe8c8bdc36b7d1 +Subproject commit f5df7a2b1bd942fc1169d0f563dacbe34e6a11ac diff --git a/external/injector b/external/injector index 9fb030def..898c53372 160000 --- a/external/injector +++ b/external/injector @@ -1 +1 @@ -Subproject commit 9fb030defbfdb24cb1beaac6b70c0785e4112c65 +Subproject commit 898c533729c4d6c16883acffeb9f6a58027d8b20 diff --git a/includes/dolphin/dolphin.h b/includes/dolphin/dolphin.h index e8c333cea..3f4fab554 100644 --- a/includes/dolphin/dolphin.h +++ b/includes/dolphin/dolphin.h @@ -1,6 +1,7 @@ #pragma once #include #include "ppc.hpp" +#include class Dolphin { @@ -13,18 +14,52 @@ class Dolphin static inline auto _MenuBarClearCache = (void(__fastcall*)())(nullptr); public: - static hook::pattern Pattern() - { - return hook::pattern("0F B6 C8 E8 ? ? ? ? 33 D2"); - } + //static hook::pattern Pattern() + //{ + // return hook::pattern("0F B6 C8 E8 ? ? ? ? 33 D2"); + //} static inline void SetIsThrottlerTempDisabled(bool disable) { if (!_SetIsThrottlerTempDisabled) { - auto pattern = hook::pattern("0F B6 C8 E8 ? ? ? ? 33 D2"); - if (!pattern.empty()) - _SetIsThrottlerTempDisabled = (void(__fastcall*)(bool disable))(injector::GetBranchDestination(pattern.get_first(3)).as_int()); + const auto current_module = GetModuleHandleW(NULL); + auto candidate_string = utility::scan_string(current_module, "Fog: {}"); + if (!candidate_string) candidate_string = utility::scan_string(current_module, "Copy EFB: {}"); + if (candidate_string) + { + auto candidate_stringref = utility::scan_displacement_reference(current_module, *candidate_string); + if (candidate_stringref) + { + for (size_t i = 0; i < 4000; ++i) + { + const auto mov = utility::scan_mnemonic(*candidate_stringref + i, 5, "MOV"); + if (mov) + { + if (injector::ReadMemory(*mov + 1, true) == 19) + { + const auto next_fn_call1 = utility::scan_mnemonic(*mov, 100, "CALL"); + if (next_fn_call1) + { + const auto next_fn_call2 = utility::scan_mnemonic(*next_fn_call1 + 5, 100, "CALL"); + if (next_fn_call2) + { + const auto next_mov = utility::scan_mnemonic(*next_fn_call2, 100, "MOV"); + if (next_mov) + { + if (injector::ReadMemory(*next_mov + 1, true) == 17) + { + _SetIsThrottlerTempDisabled = (void(__fastcall*)(bool disable))(injector::GetBranchDestination(*next_fn_call2).as_int()); + return _SetIsThrottlerTempDisabled(disable); + } + } + } + } + } + } + } + } + } } else return _SetIsThrottlerTempDisabled(disable); @@ -38,19 +73,21 @@ class Dolphin { if (!_MenuBarClearCache) { - auto pattern = hook::pattern("45 33 C9 45 33 C0 33 D2"); - if (!pattern.empty()) + const auto current_module = GetModuleHandleW(NULL); + const auto candidate_string = utility::scan_string(current_module, "Clear Cache"); + if (candidate_string) { - for (size_t i = 0; i < pattern.size(); i++) + auto candidate_stringref = utility::scan_displacement_reference(current_module, *candidate_string); + if (candidate_stringref) { - auto range_pattern = hook::pattern((uintptr_t)pattern.get(i).get(0), (uintptr_t)pattern.get(i).get(200), "45 ? ? ? 8D"); - if (!range_pattern.empty()) + *candidate_stringref -= 4; + for (size_t i = 0; i < 100; ++i) { - auto str = injector::ReadRelativeOffset(range_pattern.get(0).get(6)).get_raw(); - if (MemoryAddrValid(str) && std::string_view(str) == "Clear Cache") + const auto disp = utility::resolve_displacement(*candidate_stringref - i); + if (disp) { - _MenuBarClearCache = (void(__fastcall*)())(injector::ReadRelativeOffset(pattern.get(i).get(22)).as_int()); - break; + _MenuBarClearCache = (void(__fastcall*)())*disp; + return _MenuBarClearCache(); } } } @@ -60,7 +97,7 @@ class Dolphin return _MenuBarClearCache(); }(); } - __except ((GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) + __except (EXCEPTION_CONTINUE_SEARCH) { } } diff --git a/premake5.lua b/premake5.lua index 58a33500f..0503c76ff 100644 --- a/premake5.lua +++ b/premake5.lua @@ -188,7 +188,18 @@ workspace "WidescreenFixesPack" files { "external/asmjit/src/**.h", "external/asmjit/src/**.cpp" } includedirs { "external/asmjit/src/asmjit" } end - + + function add_kananlib() + defines { "BDDISASM_HAS_MEMSET", "BDDISASM_HAS_VSNPRINTF" } + files { "external/injector/kananlib/include/utility/*.hpp", "external/injector/kananlib/src/*.cpp" } + files { "external/injector/kananlib/include/utility/thirdparty/*.hpp" } + files { "external/injector/kananlib/include/utility/thirdparty/bddisasm/bddisasm/*.c" } + files { "external/injector/kananlib/include/utility/thirdparty/bddisasm/bdshemu/*.c" } + includedirs { "external/injector/kananlib/include" } + includedirs { "external/injector/kananlib/include/utility/thirdparty/bddisasm/inc" } + includedirs { "external/injector/kananlib/include/utility/thirdparty/bddisasm/bddisasm/include" } + end + function add_pspsdk() includedirs { "external/pspsdk/usr/local/pspdev/psp/sdk/include" } includedirs { "external/pspsdk/usr/local/pspdev/bin" } @@ -522,6 +533,7 @@ project "ResidentEvil0.FusionFix" project "ResidentEvil.FusionFix" setpaths("Z:/WFP/Games/ResidentEvil/", "bhd.exe", "scripts/") project "ResidentEvil2.RE3.Dolphin.FusionMod" + add_kananlib() platforms { "Win64" } architecture "x64" setpaths("Z:/WFP/Games/Dolphin-x64/", "Dolphin.exe", "scripts/") diff --git a/source/ResidentEvil2.RE3.Dolphin.FusionMod/dllmain.cpp b/source/ResidentEvil2.RE3.Dolphin.FusionMod/dllmain.cpp index 189a06834..492e4db5f 100644 --- a/source/ResidentEvil2.RE3.Dolphin.FusionMod/dllmain.cpp +++ b/source/ResidentEvil2.RE3.Dolphin.FusionMod/dllmain.cpp @@ -287,7 +287,7 @@ CEXP void InitializeASI() { std::call_once(CallbackHandler::flag, []() { - CallbackHandler::RegisterCallback(Init, Dolphin::Pattern()); + CallbackHandler::RegisterCallbackAtGetSystemTimeAsFileTime(Init); }); }