From e829c407e3eb88f8c849aeb24e87dba1b60bb056 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 27 Jul 2023 02:05:35 +0200 Subject: [PATCH] fix: Writing behaving weirdly when using a custom base address --- lib/libimhex/source/providers/provider.cpp | 11 ++++++++++- plugins/builtin/source/content/views/view_patches.cpp | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/libimhex/source/providers/provider.cpp b/lib/libimhex/source/providers/provider.cpp index 44907f41f..ef5d722b7 100644 --- a/lib/libimhex/source/providers/provider.cpp +++ b/lib/libimhex/source/providers/provider.cpp @@ -143,6 +143,14 @@ namespace hex::prv { if (!this->isWritable()) return; + this->m_patches.emplace_back(); + + for (auto &[patchAddress, patch] : getPatches()) { + u8 value = 0x00; + this->readRaw(patchAddress - this->getBaseAddress(), &value, 1); + this->m_patches.back().insert({ patchAddress, value }); + } + for (auto &[patchAddress, patch] : getPatches()) { this->writeRaw(patchAddress - this->getBaseAddress(), &patch, 1); } @@ -150,6 +158,7 @@ namespace hex::prv { this->markDirty(); this->m_patches.emplace_back(); + this->m_currPatches = std::prev(this->m_patches.end()); } @@ -231,7 +240,7 @@ namespace hex::prv { for (u64 i = 0; i < size; i++) { u8 patch = reinterpret_cast(buffer)[i]; u8 originalValue = 0x00; - this->readRaw(offset + i, &originalValue, sizeof(u8)); + this->readRaw((offset + i) - this->getBaseAddress(), &originalValue, sizeof(u8)); if (patch == originalValue) getPatches().erase(offset + i); diff --git a/plugins/builtin/source/content/views/view_patches.cpp b/plugins/builtin/source/content/views/view_patches.cpp index 341810ae0..75c026a2d 100644 --- a/plugins/builtin/source/content/views/view_patches.cpp +++ b/plugins/builtin/source/content/views/view_patches.cpp @@ -47,6 +47,10 @@ namespace hex::plugin::builtin { else return std::nullopt; }); + + EventManager::subscribe([](auto *) { + EventManager::post(); + }); } void ViewPatches::drawContent() {