fix: Writing behaving weirdly when using a custom base address

This commit is contained in:
WerWolv
2023-07-27 02:05:35 +02:00
parent 94a02c4b6d
commit e829c407e3
2 changed files with 14 additions and 1 deletions

View File

@@ -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<const u8 *>(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);

View File

@@ -47,6 +47,10 @@ namespace hex::plugin::builtin {
else
return std::nullopt;
});
EventManager::subscribe<EventProviderSaved>([](auto *) {
EventManager::post<EventHighlightingChanged>();
});
}
void ViewPatches::drawContent() {