From 0bce0d12bc0b657675e3fa7ffd77a2706bb7a39b Mon Sep 17 00:00:00 2001 From: Kiyoshi Aman Date: Wed, 17 Jun 2020 23:46:54 -0600 Subject: [PATCH] src/exdeath.cc: truly a successful patcher --- src/exdeath.cc | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/exdeath.cc b/src/exdeath.cc index 522dfee..40f1371 100644 --- a/src/exdeath.cc +++ b/src/exdeath.cc @@ -103,8 +103,7 @@ void Exdeath::btnApply_clicked(bool trigger) { } target = new QFile(output); - target->open(QIODevice::WriteOnly | QIODevice::Append); - target->seek(0); + target->open(QIODevice::ReadWrite); for (int i = 0; i < patches.size(); i++) { applyPatch(target, patches[i]); @@ -116,22 +115,23 @@ void Exdeath::btnApply_clicked(bool trigger) { void Exdeath::applyPatch(QFile *file, QString patch) { QFile *data = new QFile(patch); data->open(QIODevice::ReadOnly); - char *temp = reinterpret_cast(malloc(65536)); - data->read(temp, 5); - - if (strncmp(temp, "PATCH", 5)) { - // not a patch - data->close(); - return; - } + // skipping header + data->seek(5); while (!data->atEnd()) { - unsigned int seek = 0, length = 0; + unsigned int seek = 0; + unsigned short length = 0; + char *temp = reinterpret_cast(malloc(65536)); + + data->read(temp, 3); if (!strncmp(temp, "EOF", 3)) { break; } + seek = ((temp[0] & 0xff) << 16) + ((temp[1] & 0xff) << 8) + (temp[2] & 0xff); + printf("Seeking to 0x%06x", seek); + file->seek(seek); data->read(temp, 2); length = ((temp[0] & 0xff) << 8) + (temp[1] & 0xff); @@ -140,15 +140,18 @@ void Exdeath::applyPatch(QFile *file, QString patch) { data->read(temp, 2); length = ((temp[0] & 0xff) << 8) + (temp[1] & 0xff); data->read(temp, 1); + printf(", now at 0x%08llx", file->pos()); + printf(" and writing 0x%04hx bytes of 0x%02hhx\n", length, temp[0]); - file->seek(seek); for (unsigned int i = 0; i < length; i++) { file->write(temp, 1); } + printf("position after write: 0x%08llx\n", file->pos()); } else { + printf(" and writing 0x%04hx bytes\n", length); data->read(temp, length); - file->seek(seek); file->write(temp, length); + printf("position after write: 0x%08llx\n", file->pos()); } }