initial patch implementation

This commit is contained in:
CrazyBloo
2024-08-23 02:37:39 -04:00
parent fbe7f6d388
commit 90f1d2c08f
4 changed files with 45 additions and 6 deletions

View File

@@ -15,16 +15,23 @@ void ApplyPendingPatches() {
for (size_t i = 0; i < pending_patches.size(); ++i) {
patchInfo currentPatch = pending_patches[i];
LOG_INFO(Loader, "loading patch {}", i);
PatchMemory(currentPatch.modNameStr, currentPatch.offsetStr, currentPatch.valueStr);
PatchMemory(currentPatch.modNameStr, currentPatch.offsetStr, currentPatch.valueStr,
currentPatch.isOffset);
}
pending_patches.clear();
}
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr) {
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr, bool isOffset) {
// Send a request to modify the process memory.
void* cheatAddress = reinterpret_cast<void*>(g_eboot_address + std::stoi(offsetStr, 0, 16));
void* cheatAddress = nullptr;
if (isOffset) {
cheatAddress = reinterpret_cast<void*>(g_eboot_address + std::stoi(offsetStr, 0, 16));
} else {
cheatAddress =
reinterpret_cast<void*>(g_eboot_address + (std::stoi(offsetStr, 0, 16) - 0x400000));
}
std::vector<unsigned char> bytePatch;

View File

@@ -11,6 +11,7 @@ struct patchInfo {
std::string modNameStr;
std::string offsetStr;
std::string valueStr;
bool isOffset;
};
extern std::vector<patchInfo> pending_patches;
@@ -18,6 +19,6 @@ extern std::vector<patchInfo> pending_patches;
void AddPatchToQueue(patchInfo patchToAdd);
void ApplyPendingPatches();
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr);
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr, bool isOffset);
} // namespace MemoryPatcher