mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-02 07:22:24 +00:00
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:
parent
5aa1fac987
commit
632c8727ff
@ -2,6 +2,8 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <string>
|
||||||
#include "memory_patcher.h"
|
#include "memory_patcher.h"
|
||||||
|
|
||||||
namespace MemoryPatcher {
|
namespace MemoryPatcher {
|
||||||
@ -19,14 +21,14 @@ void ApplyPendingPatches() {
|
|||||||
for (size_t i = 0; i < pending_patches.size(); ++i) {
|
for (size_t i = 0; i < pending_patches.size(); ++i) {
|
||||||
patchInfo currentPatch = pending_patches[i];
|
patchInfo currentPatch = pending_patches[i];
|
||||||
PatchMemory(currentPatch.modNameStr, currentPatch.offsetStr, currentPatch.valueStr,
|
PatchMemory(currentPatch.modNameStr, currentPatch.offsetStr, currentPatch.valueStr,
|
||||||
currentPatch.isOffset);
|
currentPatch.isOffset, currentPatch.littleEndian);
|
||||||
}
|
}
|
||||||
|
|
||||||
pending_patches.clear();
|
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) {
|
bool isOffset, bool littleEndian) {
|
||||||
// Send a request to modify the process memory.
|
// Send a request to modify the process memory.
|
||||||
void* cheatAddress = nullptr;
|
void* cheatAddress = nullptr;
|
||||||
|
|
||||||
@ -45,6 +47,11 @@ void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valu
|
|||||||
|
|
||||||
bytePatch.push_back(byte);
|
bytePatch.push_back(byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (littleEndian) {
|
||||||
|
std::reverse(bytePatch.begin(), bytePatch.end());
|
||||||
|
}
|
||||||
|
|
||||||
std::memcpy(cheatAddress, bytePatch.data(), bytePatch.size());
|
std::memcpy(cheatAddress, bytePatch.data(), bytePatch.size());
|
||||||
|
|
||||||
LOG_INFO(Loader, "Applied patch:{}, Offset:{}, Value:{}", modNameStr, (uintptr_t)cheatAddress,
|
LOG_INFO(Loader, "Applied patch:{}, Offset:{}, Value:{}", modNameStr, (uintptr_t)cheatAddress,
|
||||||
|
@ -15,6 +15,7 @@ struct patchInfo {
|
|||||||
std::string offsetStr;
|
std::string offsetStr;
|
||||||
std::string valueStr;
|
std::string valueStr;
|
||||||
bool isOffset;
|
bool isOffset;
|
||||||
|
bool littleEndian;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::vector<patchInfo> pending_patches;
|
extern std::vector<patchInfo> pending_patches;
|
||||||
@ -23,6 +24,6 @@ void AddPatchToQueue(patchInfo patchToAdd);
|
|||||||
void ApplyPendingPatches();
|
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);
|
bool isOffset, bool littleEndian);
|
||||||
|
|
||||||
} // namespace MemoryPatcher
|
} // namespace MemoryPatcher
|
@ -860,7 +860,7 @@ void CheatsPatches::applyCheat(const QString& modName, bool enabled) {
|
|||||||
continue;
|
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);
|
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) {
|
if (MemoryPatcher::g_eboot_address == 0) {
|
||||||
MemoryPatcher::patchInfo addingPatch;
|
MemoryPatcher::patchInfo addingPatch;
|
||||||
addingPatch.modNameStr = patchName.toStdString();
|
addingPatch.modNameStr = patchName.toStdString();
|
||||||
addingPatch.offsetStr = address.toStdString();
|
addingPatch.offsetStr = address.toStdString();
|
||||||
addingPatch.valueStr = patchValue.toStdString();
|
addingPatch.valueStr = patchValue.toStdString();
|
||||||
addingPatch.isOffset = false;
|
addingPatch.isOffset = false;
|
||||||
|
addingPatch.littleEndian = littleEndian;
|
||||||
|
|
||||||
MemoryPatcher::AddPatchToQueue(addingPatch);
|
MemoryPatcher::AddPatchToQueue(addingPatch);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryPatcher::PatchMemory(patchName.toStdString(), address.toStdString(),
|
MemoryPatcher::PatchMemory(patchName.toStdString(), address.toStdString(),
|
||||||
patchValue.toStdString(), false);
|
patchValue.toStdString(), false, littleEndian);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user