#pragma once namespace memory { class byte_patch { public: virtual ~byte_patch(); void apply() const; void restore() const; void remove() const; template static const std::unique_ptr& make(TAddr address, std::remove_pointer_t> value) { return m_patches.emplace_back( std::unique_ptr(new byte_patch(address, value))); } static void restore_all(); private: template byte_patch(TAddr address, std::remove_pointer_t> value) : m_address(address) { m_size = sizeof(std::remove_pointer_t>); m_original_bytes = std::make_unique(m_size); m_value = std::make_unique(m_size); memcpy(m_original_bytes.get(), m_address, m_size); memcpy(m_value.get(), &value, m_size); } protected: static inline std::vector> m_patches; private: void* m_address; std::unique_ptr m_value; std::unique_ptr m_original_bytes; std::size_t m_size; friend bool operator== (const std::unique_ptr& a, const byte_patch* b); }; }