Merge pull request #2 from CrazyBloo/Cheats_Patches

initial implementation of cheat functionality
This commit is contained in:
DanielSvoboda 2024-08-20 19:43:54 -03:00 committed by GitHub
commit f326173a46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 1 deletions

View file

@ -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);

View file

@ -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());
}
}

View file

@ -16,6 +16,8 @@
#include <QVector>
#include <QWidget>
extern uintptr_t cheats_eboot_address;
class CheatsPatches : public QWidget {
Q_OBJECT