2022-10-30 19:14:19 +01:00
|
|
|
#include "byte_patch.hpp"
|
|
|
|
|
|
|
|
namespace memory
|
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
byte_patch::~byte_patch()
|
|
|
|
{
|
|
|
|
restore();
|
|
|
|
}
|
2022-10-30 19:14:19 +01:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
void byte_patch::apply() const
|
|
|
|
{
|
|
|
|
memcpy(m_address, m_value.get(), m_size);
|
|
|
|
}
|
2022-10-30 19:14:19 +01:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
void byte_patch::restore() const
|
|
|
|
{
|
|
|
|
memcpy(m_address, m_original_bytes.get(), m_size);
|
|
|
|
}
|
2022-10-30 19:14:19 +01:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2022-10-30 19:14:19 +01:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
void byte_patch::restore_all()
|
|
|
|
{
|
|
|
|
m_patches.clear();
|
|
|
|
}
|
2022-10-30 19:14:19 +01:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
bool operator==(const std::unique_ptr<byte_patch>& a, const byte_patch* b)
|
|
|
|
{
|
|
|
|
return a->m_address == b->m_address;
|
|
|
|
}
|
2022-10-30 19:14:19 +01:00
|
|
|
}
|