Skip to content

Commit

Permalink
dolphin plugin fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenAG committed Jun 20, 2024
1 parent 008c44e commit d273293
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 21 deletions.
2 changes: 1 addition & 1 deletion external/asmjit
2 changes: 1 addition & 1 deletion external/injector
Submodule injector updated 496 files
71 changes: 54 additions & 17 deletions includes/dolphin/dolphin.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <stdafx.h>
#include "ppc.hpp"
#include <utility/Scan.hpp>

class Dolphin
{
Expand All @@ -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<uint32_t>(*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<uint32_t>(*next_mov + 1, true) == 17)
{
_SetIsThrottlerTempDisabled = (void(__fastcall*)(bool disable))(injector::GetBranchDestination(*next_fn_call2).as_int());
return _SetIsThrottlerTempDisabled(disable);
}
}
}
}
}
}
}
}
}
}
else
return _SetIsThrottlerTempDisabled(disable);
Expand All @@ -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<uintptr_t>(0), (uintptr_t)pattern.get(i).get<uintptr_t>(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<uintptr_t>(6)).get_raw<char>();
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<uintptr_t>(22)).as_int());
break;
_MenuBarClearCache = (void(__fastcall*)())*disp;
return _MenuBarClearCache();
}
}
}
Expand All @@ -60,7 +97,7 @@ class Dolphin
return _MenuBarClearCache();
}();
}
__except ((GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
__except (EXCEPTION_CONTINUE_SEARCH)
{
}
}
Expand Down
14 changes: 13 additions & 1 deletion premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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/")
Expand Down
2 changes: 1 addition & 1 deletion source/ResidentEvil2.RE3.Dolphin.FusionMod/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ CEXP void InitializeASI()
{
std::call_once(CallbackHandler::flag, []()
{
CallbackHandler::RegisterCallback(Init, Dolphin::Pattern());
CallbackHandler::RegisterCallbackAtGetSystemTimeAsFileTime(Init);
});
}

Expand Down

0 comments on commit d273293

Please sign in to comment.