mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-21 12:04:45 +00:00
initial implementation of cheat functionality
This commit is contained in:
parent
1be30f6b6c
commit
b017b303b2
3 changed files with 28 additions and 1 deletions
|
@ -11,6 +11,7 @@
|
|||
#include "core/loader/dwarf.h"
|
||||
#include "core/memory.h"
|
||||
#include "core/module.h"
|
||||
#include "qt_gui/cheats_patches.h"
|
||||
|
||||
namespace Core {
|
||||
|
||||
|
@ -90,6 +91,12 @@ void Module::LoadModuleToMemory(u32& max_tls_index) {
|
|||
LoadOffset += CODE_BASE_INCR * (1 + aligned_base_size / CODE_BASE_INCR);
|
||||
LOG_INFO(Core_Linker, "Loading module {} to {}", name, fmt::ptr(*out_addr));
|
||||
|
||||
if (cheats_eboot_address == 0) {
|
||||
if (name == "eboot") {
|
||||
cheats_eboot_address = base_virtual_addr;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize trampoline generator.
|
||||
void* trampoline_addr = std::bit_cast<void*>(base_virtual_addr + aligned_base_size);
|
||||
Xbyak::CodeGenerator c(TrampolineSize, trampoline_addr);
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include "cheats_patches.h"
|
||||
#include "common/path_util.h"
|
||||
|
||||
uintptr_t cheats_eboot_address = 0;
|
||||
|
||||
CheatsPatches::CheatsPatches(const QString& gameName, const QString& gameSerial,
|
||||
const QString& gameVersion, const QString& gameSize,
|
||||
const QPixmap& gameImage, QWidget* parent)
|
||||
|
@ -234,7 +236,23 @@ void CheatsPatches::applyCheat(const QString& modName, bool enabled) {
|
|||
|
||||
LOG_INFO(Loader, "Cheat applied:{}, Offset:{}, Value:{}", modNameStr, offsetStr, valueStr);
|
||||
|
||||
// Implement
|
||||
// Send a request to modify the process memory.
|
||||
if (cheats_eboot_address == 0) {
|
||||
LOG_INFO(Loader, "Can't apply mod until a game has been started");
|
||||
return;
|
||||
}
|
||||
|
||||
void* cheatAddress = reinterpret_cast<void*>(cheats_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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#include <QVector>
|
||||
#include <QWidget>
|
||||
|
||||
extern uintptr_t cheats_eboot_address;
|
||||
|
||||
class CheatsPatches : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue