fix byte patch class being only usable in a single unit (#542)
This commit is contained in:
parent
0bd683afca
commit
3112ad4cfe
38
BigBaseV2/src/memory/byte_patch.cpp
Normal file
38
BigBaseV2/src/memory/byte_patch.cpp
Normal file
@ -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<byte_patch>& a, const byte_patch* b)
|
||||||
|
{
|
||||||
|
return a->m_address == b->m_address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,28 +5,13 @@ namespace memory
|
|||||||
class byte_patch
|
class byte_patch
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~byte_patch()
|
virtual ~byte_patch();
|
||||||
{
|
|
||||||
restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
void apply() const
|
void apply() const;
|
||||||
{
|
|
||||||
memcpy(m_address, m_value.get(), m_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void restore() const
|
void restore() const;
|
||||||
{
|
|
||||||
memcpy(m_address, m_original_bytes.get(), m_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void remove() 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename TAddr>
|
template <typename TAddr>
|
||||||
static const std::unique_ptr<byte_patch>& make(TAddr address, std::remove_pointer_t<std::remove_reference_t<TAddr>> value)
|
static const std::unique_ptr<byte_patch>& make(TAddr address, std::remove_pointer_t<std::remove_reference_t<TAddr>> value)
|
||||||
@ -35,10 +20,7 @@ namespace memory
|
|||||||
std::unique_ptr<byte_patch>(new byte_patch(address, value)));
|
std::unique_ptr<byte_patch>(new byte_patch(address, value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void restore_all()
|
static void restore_all();
|
||||||
{
|
|
||||||
m_patches.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename TAddr>
|
template <typename TAddr>
|
||||||
@ -64,9 +46,4 @@ namespace memory
|
|||||||
|
|
||||||
friend bool operator== (const std::unique_ptr<byte_patch>& a, const byte_patch* b);
|
friend bool operator== (const std::unique_ptr<byte_patch>& a, const byte_patch* b);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator== (const std::unique_ptr<byte_patch>& a, const byte_patch* b)
|
|
||||||
{
|
|
||||||
return a->m_address == b->m_address;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user