fix bytes16, bytes32, bytes64 type patches

If a patch is any of these types we convert it from little endian to big endian
This commit is contained in:
CrazyBloo 2024-08-23 23:00:54 -04:00
parent 5aa1fac987
commit 632c8727ff
3 changed files with 24 additions and 5 deletions

View file

@ -2,6 +2,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/logging/log.h"
#include <algorithm>
#include <string>
#include "memory_patcher.h"
namespace MemoryPatcher {
@ -19,14 +21,14 @@ void ApplyPendingPatches() {
for (size_t i = 0; i < pending_patches.size(); ++i) {
patchInfo currentPatch = pending_patches[i];
PatchMemory(currentPatch.modNameStr, currentPatch.offsetStr, currentPatch.valueStr,
currentPatch.isOffset);
currentPatch.isOffset, currentPatch.littleEndian);
}
pending_patches.clear();
}
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr,
bool isOffset) {
bool isOffset, bool littleEndian) {
// Send a request to modify the process memory.
void* cheatAddress = nullptr;
@ -45,6 +47,11 @@ void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valu
bytePatch.push_back(byte);
}
if (littleEndian) {
std::reverse(bytePatch.begin(), bytePatch.end());
}
std::memcpy(cheatAddress, bytePatch.data(), bytePatch.size());
LOG_INFO(Loader, "Applied patch:{}, Offset:{}, Value:{}", modNameStr, (uintptr_t)cheatAddress,

View file

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

View file

@ -860,7 +860,7 @@ void CheatsPatches::applyCheat(const QString& modName, bool enabled) {
continue;
}
MemoryPatcher::PatchMemory(modNameStr, offsetStr, valueStr, true);
MemoryPatcher::PatchMemory(modNameStr, offsetStr, valueStr, true, false);
}
}
@ -876,19 +876,30 @@ void CheatsPatches::applyPatch(const QString& patchName, bool enabled) {
patchValue = convertValueToHex(type, patchValue);
bool littleEndian = false;
if (type.toStdString() == "bytes16") {
littleEndian = true;
} else if (type.toStdString() == "bytes32") {
littleEndian = true;
} else if (type.toStdString() == "bytes64") {
littleEndian = true;
}
if (MemoryPatcher::g_eboot_address == 0) {
MemoryPatcher::patchInfo addingPatch;
addingPatch.modNameStr = patchName.toStdString();
addingPatch.offsetStr = address.toStdString();
addingPatch.valueStr = patchValue.toStdString();
addingPatch.isOffset = false;
addingPatch.littleEndian = littleEndian;
MemoryPatcher::AddPatchToQueue(addingPatch);
continue;
}
MemoryPatcher::PatchMemory(patchName.toStdString(), address.toStdString(),
patchValue.toStdString(), false);
patchValue.toStdString(), false, littleEndian);
}
}
}