From 61b36d1f9a60fa9ead9c0f59047457ddef762597 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Thu, 6 Apr 2017 15:34:40 +0100 Subject: [PATCH 1/3] PatchEngine: Add Reload() function --- Source/Core/Core/ConfigManager.cpp | 3 +-- Source/Core/Core/PatchEngine.cpp | 6 ++++++ Source/Core/Core/PatchEngine.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 47a537e296..2a1cc18604 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -787,8 +787,7 @@ void SConfig::SetRunningGameMetadata(const std::string& game_id, u64 title_id, u CBoot::LoadMapFromFilename(); HLE::Clear(); HLE::PatchFunctions(); - PatchEngine::Shutdown(); - PatchEngine::LoadPatches(); + PatchEngine::Reload(); HiresTexture::Update(); } } diff --git a/Source/Core/Core/PatchEngine.cpp b/Source/Core/Core/PatchEngine.cpp index b2d9b17566..87c60e1f11 100644 --- a/Source/Core/Core/PatchEngine.cpp +++ b/Source/Core/Core/PatchEngine.cpp @@ -246,4 +246,10 @@ void Shutdown() Gecko::Shutdown(); } +void Reload() +{ + Shutdown(); + LoadPatches(); +} + } // namespace diff --git a/Source/Core/Core/PatchEngine.h b/Source/Core/Core/PatchEngine.h index 2d70bf4cf8..b1e7b2ba02 100644 --- a/Source/Core/Core/PatchEngine.h +++ b/Source/Core/Core/PatchEngine.h @@ -45,6 +45,7 @@ void LoadPatchSection(const std::string& section, std::vector& patches, I void LoadPatches(); bool ApplyFramePatches(); void Shutdown(); +void Reload(); inline int GetPatchTypeCharLength(PatchType type) { From 20a9c5b12d3596efc34df7df79817b297288008b Mon Sep 17 00:00:00 2001 From: Sepalani Date: Thu, 6 Apr 2017 15:39:52 +0100 Subject: [PATCH 2/3] HLE: Add PatchFixedFunctions() function --- Source/Core/Core/Boot/Boot.cpp | 16 +--------------- Source/Core/Core/HLE/HLE.cpp | 19 +++++++++++++++++++ Source/Core/Core/HLE/HLE.h | 1 + 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index ef5f460036..bec069bfdc 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -21,7 +21,6 @@ #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/Debugger/Debugger_SymbolMap.h" -#include "Core/GeckoCode.h" #include "Core/HLE/HLE.h" #include "Core/HW/DVD/DVDInterface.h" #include "Core/HW/EXI/EXI_DeviceIPL.h" @@ -479,19 +478,6 @@ bool CBoot::BootUp() } } - // HLE jump to loader (homebrew). Disabled when Gecko is active as it interferes with the code - // handler - if (!SConfig::GetInstance().bEnableCheats) - { - HLE::Patch(0x80001800, "HBReload"); - Memory::CopyToEmu(0x00001804, "STUBHAXX", 8); - } - - // Not part of the binary itself, but either we or Gecko OS might insert - // this, and it doesn't clear the icache properly. - HLE::Patch(Gecko::ENTRY_POINT, "GeckoCodehandler"); - // This has to always be installed even if cheats are not enabled because of the possiblity of - // loading a savestate where PC is inside the code handler while cheats are disabled. - HLE::Patch(Gecko::HLE_TRAMPOLINE_ADDRESS, "GeckoHandlerReturnTrampoline"); + HLE::PatchFixedFunctions(); return true; } diff --git a/Source/Core/Core/HLE/HLE.cpp b/Source/Core/Core/HLE/HLE.cpp index b32d269355..52cf570977 100644 --- a/Source/Core/Core/HLE/HLE.cpp +++ b/Source/Core/Core/HLE/HLE.cpp @@ -10,6 +10,7 @@ #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/Debugger/Debugger_SymbolMap.h" +#include "Core/GeckoCode.h" #include "Core/HLE/HLE.h" #include "Core/HLE/HLE_Misc.h" #include "Core/HLE/HLE_OS.h" @@ -88,6 +89,24 @@ void Patch(u32 addr, const char* hle_func_name) } } +void PatchFixedFunctions() +{ + // HLE jump to loader (homebrew). Disabled when Gecko is active as it interferes with the code + // handler + if (!SConfig::GetInstance().bEnableCheats) + { + Patch(0x80001800, "HBReload"); + Memory::CopyToEmu(0x00001804, "STUBHAXX", 8); + } + + // Not part of the binary itself, but either we or Gecko OS might insert + // this, and it doesn't clear the icache properly. + Patch(Gecko::ENTRY_POINT, "GeckoCodehandler"); + // This has to always be installed even if cheats are not enabled because of the possiblity of + // loading a savestate where PC is inside the code handler while cheats are disabled. + Patch(Gecko::HLE_TRAMPOLINE_ADDRESS, "GeckoHandlerReturnTrampoline"); +} + void PatchFunctions() { // Remove all hooks that aren't fixed address hooks diff --git a/Source/Core/Core/HLE/HLE.h b/Source/Core/Core/HLE/HLE.h index 61b50a8e72..dcd9c0d2b3 100644 --- a/Source/Core/Core/HLE/HLE.h +++ b/Source/Core/Core/HLE/HLE.h @@ -24,6 +24,7 @@ enum HookFlag HLE_TYPE_FIXED = 2, // An arbitrary hook mapped to a fixed address instead of a symbol }; +void PatchFixedFunctions(); void PatchFunctions(); void Clear(); From 5a1ebe232ed1c7a8d8de147c4ea95f3e04fdbdaa Mon Sep 17 00:00:00 2001 From: Sepalani Date: Thu, 6 Apr 2017 15:42:08 +0100 Subject: [PATCH 3/3] HLE: Add Reload() function --- Source/Core/Core/ConfigManager.cpp | 3 +-- Source/Core/Core/HLE/HLE.cpp | 7 +++++++ Source/Core/Core/HLE/HLE.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 2a1cc18604..ba10d0aeb8 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -785,8 +785,7 @@ void SConfig::SetRunningGameMetadata(const std::string& game_id, u64 title_id, u // TODO: have a callback mechanism for title changes? g_symbolDB.Clear(); CBoot::LoadMapFromFilename(); - HLE::Clear(); - HLE::PatchFunctions(); + HLE::Reload(); PatchEngine::Reload(); HiresTexture::Update(); } diff --git a/Source/Core/Core/HLE/HLE.cpp b/Source/Core/Core/HLE/HLE.cpp index 52cf570977..e2e2a20919 100644 --- a/Source/Core/Core/HLE/HLE.cpp +++ b/Source/Core/Core/HLE/HLE.cpp @@ -160,6 +160,13 @@ void Clear() s_original_instructions.clear(); } +void Reload() +{ + Clear(); + PatchFixedFunctions(); + PatchFunctions(); +} + void Execute(u32 _CurrentPC, u32 _Instruction) { unsigned int FunctionIndex = _Instruction & 0xFFFFF; diff --git a/Source/Core/Core/HLE/HLE.h b/Source/Core/Core/HLE/HLE.h index dcd9c0d2b3..8cc513124f 100644 --- a/Source/Core/Core/HLE/HLE.h +++ b/Source/Core/Core/HLE/HLE.h @@ -27,6 +27,7 @@ enum HookFlag void PatchFixedFunctions(); void PatchFunctions(); void Clear(); +void Reload(); void Patch(u32 pc, const char* func_name); u32 UnPatch(const std::string& patchName);