From 4bc074fa841908e180116289a1dd665270fe5fbd Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 30 Jan 2022 11:58:32 +0100 Subject: [PATCH] sys: Remove patched bytes when their value is the same as the original --- lib/libimhex/source/providers/provider.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/libimhex/source/providers/provider.cpp b/lib/libimhex/source/providers/provider.cpp index fa7109f94..189e4a301 100644 --- a/lib/libimhex/source/providers/provider.cpp +++ b/lib/libimhex/source/providers/provider.cpp @@ -154,8 +154,16 @@ namespace hex::prv { if (createUndo) createUndoPoint(); - for (u64 i = 0; i < size; i++) - getPatches()[offset + i] = reinterpret_cast(buffer)[i]; + for (u64 i = 0; i < size; i++) { + u8 patch = reinterpret_cast(buffer)[i]; + u8 originalValue = 0x00; + this->readRaw(offset + i, &originalValue, sizeof(u8)); + + if (patch == originalValue) + getPatches().erase(offset + i); + else + getPatches()[offset + i] = patch; + } } void Provider::createUndoPoint() {