mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-12-19 01:51:29 +00:00
MemoryPatcher namespace, activate cheats on start
This commit is contained in:
44
src/common/memory_patcher.cpp
Normal file
44
src/common/memory_patcher.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "memory_patcher.h"
|
||||
#include "common/logging/log.h"
|
||||
|
||||
namespace MemoryPatcher
|
||||
{
|
||||
|
||||
uintptr_t g_eboot_address;
|
||||
|
||||
std::vector<patchInfo> pending_patches;
|
||||
|
||||
void AddPatchToQueue(patchInfo patchToAdd) {
|
||||
pending_patches.push_back(patchToAdd);
|
||||
}
|
||||
|
||||
void ApplyPendingPatches() {
|
||||
|
||||
for (size_t i = 0; i < pending_patches.size(); ++i) {
|
||||
patchInfo currentPatch = pending_patches[i];
|
||||
LOG_INFO(Loader, "loading patch {}", i);
|
||||
PatchMemory(currentPatch.modNameStr, currentPatch.offsetStr, currentPatch.valueStr);
|
||||
}
|
||||
|
||||
pending_patches.clear();
|
||||
}
|
||||
|
||||
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr) {
|
||||
// Send a request to modify the process memory.
|
||||
void* cheatAddress =
|
||||
reinterpret_cast<void*>(g_eboot_address + std::stoi(offsetStr, 0, 16));
|
||||
|
||||
std::vector<unsigned char> bytePatch;
|
||||
|
||||
for (size_t i = 0; i < valueStr.length(); i += 2) {
|
||||
unsigned char byte =
|
||||
static_cast<unsigned char>(std::strtol(valueStr.substr(i, 2).c_str(), nullptr, 16));
|
||||
|
||||
bytePatch.push_back(byte);
|
||||
}
|
||||
std::memcpy(cheatAddress, bytePatch.data(), bytePatch.size());
|
||||
|
||||
LOG_INFO(Loader, "Applied patch:{}, Offset:{}, Value:{}", modNameStr, (uintptr_t)cheatAddress, valueStr);
|
||||
}
|
||||
|
||||
}
|
||||
24
src/common/memory_patcher.h
Normal file
24
src/common/memory_patcher.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace MemoryPatcher
|
||||
{
|
||||
extern uintptr_t g_eboot_address;
|
||||
|
||||
struct patchInfo {
|
||||
std::string modNameStr;
|
||||
std::string offsetStr;
|
||||
std::string valueStr;
|
||||
};
|
||||
|
||||
extern std::vector<patchInfo> pending_patches;
|
||||
|
||||
void AddPatchToQueue(patchInfo patchToAdd);
|
||||
void ApplyPendingPatches();
|
||||
|
||||
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr);
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user