Merge pull request #5 from CrazyBloo/Cheats_Patches

fix issues with byte16, byte32, byte64 type patches
This commit is contained in:
DanielSvoboda 2024-08-24 00:08:52 -03:00 committed by GitHub
commit 14581b9e39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 7 deletions

View file

@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm>
#include <string>
#include "common/logging/log.h"
#include "memory_patcher.h"
@ -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) {
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;
@ -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;
@ -22,7 +23,7 @@ extern std::vector<patchInfo> pending_patches;
void AddPatchToQueue(patchInfo patchToAdd);
void ApplyPendingPatches();
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr,
bool isOffset);
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr, 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);
}
}
}