initial patch implementation
This commit is contained in:
parent
fbe7f6d388
commit
90f1d2c08f
|
@ -15,16 +15,23 @@ 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);
|
||||
PatchMemory(currentPatch.modNameStr, currentPatch.offsetStr, currentPatch.valueStr,
|
||||
currentPatch.isOffset);
|
||||
}
|
||||
|
||||
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) {
|
||||
// Send a request to modify the process memory.
|
||||
void* cheatAddress = reinterpret_cast<void*>(g_eboot_address + std::stoi(offsetStr, 0, 16));
|
||||
void* cheatAddress = nullptr;
|
||||
|
||||
if (isOffset) {
|
||||
cheatAddress = reinterpret_cast<void*>(g_eboot_address + std::stoi(offsetStr, 0, 16));
|
||||
} else {
|
||||
cheatAddress =
|
||||
reinterpret_cast<void*>(g_eboot_address + (std::stoi(offsetStr, 0, 16) - 0x400000));
|
||||
}
|
||||
|
||||
std::vector<unsigned char> bytePatch;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ struct patchInfo {
|
|||
std::string modNameStr;
|
||||
std::string offsetStr;
|
||||
std::string valueStr;
|
||||
bool isOffset;
|
||||
};
|
||||
|
||||
extern std::vector<patchInfo> pending_patches;
|
||||
|
@ -18,6 +19,6 @@ extern std::vector<patchInfo> pending_patches;
|
|||
void AddPatchToQueue(patchInfo patchToAdd);
|
||||
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);
|
||||
|
||||
} // namespace MemoryPatcher
|
|
@ -580,6 +580,8 @@ void CheatsPatches::addPatchToLayout(const QString& name, const QString& author,
|
|||
|
||||
// Hook checkbox hover events
|
||||
patchCheckBox->installEventFilter(this);
|
||||
|
||||
connect(patchCheckBox, &QCheckBox::toggled, [=](bool checked) { applyPatch(name, checked); });
|
||||
}
|
||||
|
||||
void CheatsPatches::updateNoteTextEdit(const QString& patchName) {
|
||||
|
@ -641,12 +643,40 @@ void CheatsPatches::applyCheat(const QString& modName, bool enabled) {
|
|||
addingPatch.modNameStr = modNameStr;
|
||||
addingPatch.offsetStr = offsetStr;
|
||||
addingPatch.valueStr = valueStr;
|
||||
addingPatch.isOffset = true;
|
||||
|
||||
MemoryPatcher::AddPatchToQueue(addingPatch);
|
||||
continue;
|
||||
}
|
||||
|
||||
MemoryPatcher::PatchMemory(modNameStr, offsetStr, valueStr);
|
||||
MemoryPatcher::PatchMemory(modNameStr, offsetStr, valueStr, true);
|
||||
}
|
||||
}
|
||||
|
||||
void CheatsPatches::applyPatch(const QString& patchName, bool enabled) {
|
||||
if (m_patchInfos.contains(patchName)) {
|
||||
const PatchInfo& patchInfo = m_patchInfos[patchName];
|
||||
|
||||
foreach (const QJsonValue& value, patchInfo.linesArray) {
|
||||
QJsonObject lineObject = value.toObject();
|
||||
QString type = lineObject["Type"].toString();
|
||||
QString address = lineObject["Address"].toString();
|
||||
QString patchValue = lineObject["Value"].toString();
|
||||
|
||||
if (MemoryPatcher::g_eboot_address == 0) {
|
||||
MemoryPatcher::patchInfo addingPatch;
|
||||
addingPatch.modNameStr = patchName.toStdString();
|
||||
addingPatch.offsetStr = address.toStdString();
|
||||
addingPatch.valueStr = patchValue.toStdString();
|
||||
addingPatch.isOffset = false;
|
||||
|
||||
MemoryPatcher::AddPatchToQueue(addingPatch);
|
||||
continue;
|
||||
}
|
||||
|
||||
MemoryPatcher::PatchMemory(patchName.toStdString(), address.toStdString(),
|
||||
patchValue.toStdString(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ private:
|
|||
void createFilesJson();
|
||||
void uncheckAllCheatCheckBoxes();
|
||||
void applyCheat(const QString& modName, bool enabled);
|
||||
void applyPatch(const QString& patchName, bool enabled);
|
||||
|
||||
// Event Filtering
|
||||
bool eventFilter(QObject* obj, QEvent* event);
|
||||
|
|
Loading…
Reference in New Issue