From 632c8727ff5fe794858f5c9baa6630ffff2b4067 Mon Sep 17 00:00:00 2001 From: CrazyBloo Date: Fri, 23 Aug 2024 23:00:54 -0400 Subject: [PATCH 1/3] fix bytes16, bytes32, bytes64 type patches If a patch is any of these types we convert it from little endian to big endian --- src/common/memory_patcher.cpp | 11 +++++++++-- src/common/memory_patcher.h | 3 ++- src/qt_gui/cheats_patches.cpp | 15 +++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/common/memory_patcher.cpp b/src/common/memory_patcher.cpp index 27cb65670..6aedc365d 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 9e2da65f7..c2c1d813a 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 ce9c72c2c..7791dd095 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); } } } From c9551328bd9c10a5d998229023e9d7dcf402db55 Mon Sep 17 00:00:00 2001 From: CrazyBloo Date: Fri, 23 Aug 2024 23:03:22 -0400 Subject: [PATCH 2/3] format --- src/common/memory_patcher.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/memory_patcher.cpp b/src/common/memory_patcher.cpp index 6aedc365d..ba97d97d0 100644 --- a/src/common/memory_patcher.cpp +++ b/src/common/memory_patcher.cpp @@ -1,9 +1,9 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "common/logging/log.h" #include #include +#include "common/logging/log.h" #include "memory_patcher.h" namespace MemoryPatcher { @@ -27,8 +27,8 @@ void ApplyPendingPatches() { pending_patches.clear(); } -void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr, - bool isOffset, bool littleEndian) { +void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr, bool isOffset, + bool littleEndian) { // Send a request to modify the process memory. void* cheatAddress = nullptr; From 7564f195c3d804ab88ceea5c1844dd7f8ac60bb7 Mon Sep 17 00:00:00 2001 From: CrazyBloo Date: Fri, 23 Aug 2024 23:05:47 -0400 Subject: [PATCH 3/3] format again :( --- src/common/memory_patcher.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/memory_patcher.h b/src/common/memory_patcher.h index c2c1d813a..e6e220a17 100644 --- a/src/common/memory_patcher.h +++ b/src/common/memory_patcher.h @@ -23,7 +23,7 @@ extern std::vector pending_patches; void AddPatchToQueue(patchInfo patchToAdd); void ApplyPendingPatches(); -void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr, - bool isOffset, bool littleEndian); +void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr, bool isOffset, + bool littleEndian); } // namespace MemoryPatcher \ No newline at end of file