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() {