This commit is contained in:
CrazyBloo 2024-08-22 20:11:53 -04:00
parent 06f6082bc1
commit fbe7f6d388
3 changed files with 20 additions and 24 deletions

View File

@ -1,8 +1,7 @@
#include "memory_patcher.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "memory_patcher.h"
namespace MemoryPatcher namespace MemoryPatcher {
{
uintptr_t g_eboot_address; uintptr_t g_eboot_address;
@ -25,8 +24,7 @@ void ApplyPendingPatches() {
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr) { void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr) {
// Send a request to modify the process memory. // Send a request to modify the process memory.
void* cheatAddress = void* cheatAddress = reinterpret_cast<void*>(g_eboot_address + std::stoi(offsetStr, 0, 16));
reinterpret_cast<void*>(g_eboot_address + std::stoi(offsetStr, 0, 16));
std::vector<unsigned char> bytePatch; std::vector<unsigned char> bytePatch;
@ -38,7 +36,8 @@ void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valu
} }
std::memcpy(cheatAddress, bytePatch.data(), bytePatch.size()); std::memcpy(cheatAddress, bytePatch.data(), bytePatch.size());
LOG_INFO(Loader, "Applied patch:{}, Offset:{}, Value:{}", modNameStr, (uintptr_t)cheatAddress, valueStr); LOG_INFO(Loader, "Applied patch:{}, Offset:{}, Value:{}", modNameStr, (uintptr_t)cheatAddress,
valueStr);
} }
} } // namespace MemoryPatcher

View File

@ -1,24 +1,23 @@
#pragma once #pragma once
#include <cstring> #include <cstring>
#include <vector>
#include <string> #include <string>
#include <vector>
namespace MemoryPatcher namespace MemoryPatcher {
{
extern uintptr_t g_eboot_address;
struct patchInfo { extern uintptr_t g_eboot_address;
std::string modNameStr;
std::string offsetStr;
std::string valueStr;
};
extern std::vector<patchInfo> pending_patches; struct patchInfo {
std::string modNameStr;
std::string offsetStr;
std::string valueStr;
};
void AddPatchToQueue(patchInfo patchToAdd); extern std::vector<patchInfo> pending_patches;
void ApplyPendingPatches();
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr); void AddPatchToQueue(patchInfo patchToAdd);
void ApplyPendingPatches();
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr);
} } // namespace MemoryPatcher

View File

@ -5,13 +5,13 @@
#include "common/alignment.h" #include "common/alignment.h"
#include "common/assert.h" #include "common/assert.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/memory_patcher.h"
#include "common/string_util.h" #include "common/string_util.h"
#include "core/aerolib/aerolib.h" #include "core/aerolib/aerolib.h"
#include "core/cpu_patches.h" #include "core/cpu_patches.h"
#include "core/loader/dwarf.h" #include "core/loader/dwarf.h"
#include "core/memory.h" #include "core/memory.h"
#include "core/module.h" #include "core/module.h"
#include "common/memory_patcher.h"
namespace Core { namespace Core {
@ -197,11 +197,9 @@ void Module::LoadModuleToMemory(u32& max_tls_index) {
if (MemoryPatcher::g_eboot_address == 0) { if (MemoryPatcher::g_eboot_address == 0) {
if (name == "eboot") { if (name == "eboot") {
MemoryPatcher::g_eboot_address = base_virtual_addr; MemoryPatcher::g_eboot_address = base_virtual_addr;
MemoryPatcher::ApplyPendingPatches(); MemoryPatcher::ApplyPendingPatches();
} }
} }
} }
void Module::LoadDynamicInfo() { void Module::LoadDynamicInfo() {