From 3112ad4cfeae595830076d95a891f696d59f8d3b Mon Sep 17 00:00:00 2001 From: "Quentin E. / iDeath" Date: Sun, 30 Oct 2022 19:14:19 +0100 Subject: [PATCH] fix byte patch class being only usable in a single unit (#542) --- BigBaseV2/src/memory/byte_patch.cpp | 38 +++++++++++++++++++++++++++++ BigBaseV2/src/memory/byte_patch.hpp | 33 ++++--------------------- 2 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 BigBaseV2/src/memory/byte_patch.cpp diff --git a/BigBaseV2/src/memory/byte_patch.cpp b/BigBaseV2/src/memory/byte_patch.cpp new file mode 100644 index 00000000..c79bbc02 --- /dev/null +++ b/BigBaseV2/src/memory/byte_patch.cpp @@ -0,0 +1,38 @@ +#include "byte_patch.hpp" + +namespace memory +{ + byte_patch::~byte_patch() + { + restore(); + } + + void byte_patch::apply() const + { + memcpy(m_address, m_value.get(), m_size); + } + + void byte_patch::restore() const + { + memcpy(m_address, m_original_bytes.get(), m_size); + } + + void byte_patch::remove() const + { + if (const auto it = std::find(m_patches.begin(), m_patches.end(), this); it != m_patches.end()) + { + m_patches.erase(it); + } + } + + void byte_patch::restore_all() + { + m_patches.clear(); + } + + bool operator==(const std::unique_ptr& a, const byte_patch* b) + { + return a->m_address == b->m_address; + } +} + diff --git a/BigBaseV2/src/memory/byte_patch.hpp b/BigBaseV2/src/memory/byte_patch.hpp index 6865cbd2..7bcad2e4 100644 --- a/BigBaseV2/src/memory/byte_patch.hpp +++ b/BigBaseV2/src/memory/byte_patch.hpp @@ -5,28 +5,13 @@ namespace memory class byte_patch { public: - virtual ~byte_patch() - { - restore(); - } + virtual ~byte_patch(); - void apply() const - { - memcpy(m_address, m_value.get(), m_size); - } + void apply() const; - void restore() const - { - memcpy(m_address, m_original_bytes.get(), m_size); - } + void restore() const; - void remove() const - { - if (const auto it = std::find(m_patches.begin(), m_patches.end(), this); it != m_patches.end()) - { - m_patches.erase(it); - } - } + void remove() const; template static const std::unique_ptr& make(TAddr address, std::remove_pointer_t> value) @@ -35,10 +20,7 @@ namespace memory std::unique_ptr(new byte_patch(address, value))); } - static void restore_all() - { - m_patches.clear(); - } + static void restore_all(); private: template @@ -64,9 +46,4 @@ namespace memory friend bool operator== (const std::unique_ptr& a, const byte_patch* b); }; - - bool operator== (const std::unique_ptr& a, const byte_patch* b) - { - return a->m_address == b->m_address; - } }