diff --git a/src/common/memory_patcher.cpp b/src/common/memory_patcher.cpp index 27cb6567..6aedc365 100644 --- a/src/common/memory_patcher.cpp +++ b/src/common/memory_patcher.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" +#include +#include #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, diff --git a/src/common/memory_patcher.h b/src/common/memory_patcher.h index 9e2da65f..c2c1d813 100644 --- a/src/common/memory_patcher.h +++ b/src/common/memory_patcher.h @@ -15,6 +15,7 @@ struct patchInfo { std::string offsetStr; std::string valueStr; bool isOffset; + bool littleEndian; }; extern std::vector 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 \ No newline at end of file diff --git a/src/qt_gui/cheats_patches.cpp b/src/qt_gui/cheats_patches.cpp index ce9c72c2..7791dd09 100644 --- a/src/qt_gui/cheats_patches.cpp +++ b/src/qt_gui/cheats_patches.cpp @@ -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); } } }