feat(BytePatch): add restore & apply methods (#524)
This commit is contained in:
parent
0188477573
commit
1549f157a6
@ -7,10 +7,20 @@ namespace memory
|
||||
public:
|
||||
virtual ~byte_patch()
|
||||
{
|
||||
memcpy(m_address, m_original_bytes.data(), m_original_bytes.size());
|
||||
restore();
|
||||
}
|
||||
|
||||
void apply() const
|
||||
{
|
||||
memcpy(m_address, m_value.get(), m_size);
|
||||
}
|
||||
|
||||
void restore() const
|
||||
{
|
||||
memcpy(m_address, m_original_bytes.get(), m_size);
|
||||
}
|
||||
|
||||
void remove() const
|
||||
{
|
||||
if (const auto it = std::find(m_patches.begin(), m_patches.end(), this); it != m_patches.end())
|
||||
{
|
||||
@ -35,11 +45,12 @@ namespace memory
|
||||
byte_patch(TAddr address, std::remove_pointer_t<std::remove_reference_t<TAddr>> value)
|
||||
: m_address(address)
|
||||
{
|
||||
constexpr auto size = sizeof(std::remove_pointer_t<std::remove_reference_t<TAddr>>);
|
||||
m_original_bytes.resize(size);
|
||||
memcpy(m_original_bytes.data(), m_address, size);
|
||||
m_size = sizeof(std::remove_pointer_t<std::remove_reference_t<TAddr>>);
|
||||
m_original_bytes = std::make_unique<uint8_t[]>(m_size);
|
||||
m_value = std::make_unique<uint8_t[]>(m_size);
|
||||
|
||||
*address = value;
|
||||
memcpy(m_original_bytes.get(), m_address, m_size);
|
||||
memcpy(m_value.get(), &value, m_size);
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -47,7 +58,9 @@ namespace memory
|
||||
|
||||
private:
|
||||
void* m_address;
|
||||
std::vector<uint8_t> m_original_bytes;
|
||||
std::unique_ptr<uint8_t[]> m_value;
|
||||
std::unique_ptr<uint8_t[]> m_original_bytes;
|
||||
std::size_t m_size;
|
||||
|
||||
friend bool operator== (const std::unique_ptr<byte_patch>& a, const byte_patch* b);
|
||||
};
|
||||
|
@ -203,7 +203,7 @@ namespace big
|
||||
// Request Control of Entity PATCH
|
||||
main_batch.add("RCOE-Patch", "48 89 5C 24 ? 57 48 83 EC 20 8B D9 E8 ? ? ? ? ? ? ? ? 8B CB", [this](memory::handle ptr)
|
||||
{
|
||||
memory::byte_patch::make(ptr.add(0x13).as<std::uint16_t*>(), 0x9090);
|
||||
memory::byte_patch::make(ptr.add(0x13).as<std::uint16_t*>(), 0x9090)->apply();
|
||||
});
|
||||
|
||||
// Replay Interface
|
||||
@ -418,28 +418,28 @@ namespace big
|
||||
*/
|
||||
if (auto pat1 = mem_region.scan("3b 0a 0f 83 ? ? ? ? 48 ff c7"))
|
||||
{
|
||||
memory::byte_patch::make(pat1.add(2).as<uint32_t*>(), 0xc9310272);
|
||||
memory::byte_patch::make(pat1.add(6).as<uint16_t*>(), 0x9090);
|
||||
memory::byte_patch::make(pat1.add(2).as<uint32_t*>(), 0xc9310272)->apply();
|
||||
memory::byte_patch::make(pat1.add(6).as<uint16_t*>(), 0x9090)->apply();
|
||||
}
|
||||
|
||||
if (auto pat2 = mem_region.scan("3b 0a 0f 83 ? ? ? ? 49 03 fa"))
|
||||
{
|
||||
memory::byte_patch::make(pat2.add(2).as<uint32_t*>(), 0xc9310272);
|
||||
memory::byte_patch::make(pat2.add(6).as<uint16_t*>(), 0x9090);
|
||||
memory::byte_patch::make(pat2.add(2).as<uint32_t*>(), 0xc9310272)->apply();
|
||||
memory::byte_patch::make(pat2.add(6).as<uint16_t*>(), 0x9090)->apply();
|
||||
}
|
||||
|
||||
auto pat3 = mem_region.scan_all("3b 11 0f 83 ? ? ? ? 48 ff c7");
|
||||
for (auto& handle : pat3)
|
||||
{
|
||||
memory::byte_patch::make(handle.add(2).as<uint32_t*>(), 0xd2310272);
|
||||
memory::byte_patch::make(handle.add(6).as<uint16_t*>(), 0x9090);
|
||||
memory::byte_patch::make(handle.add(2).as<uint32_t*>(), 0xd2310272)->apply();
|
||||
memory::byte_patch::make(handle.add(6).as<uint16_t*>(), 0x9090)->apply();
|
||||
}
|
||||
|
||||
auto pat4 = mem_region.scan_all("3b 11 0f 83 ? ? ? ? 49 03 fa");
|
||||
for (auto& handle : pat4)
|
||||
{
|
||||
memory::byte_patch::make(handle.add(2).as<uint32_t*>(), 0xd2310272);
|
||||
memory::byte_patch::make(handle.add(6).as<uint16_t*>(), 0x9090);
|
||||
memory::byte_patch::make(handle.add(2).as<uint32_t*>(), 0xd2310272)->apply();
|
||||
memory::byte_patch::make(handle.add(6).as<uint16_t*>(), 0x9090)->apply();
|
||||
}
|
||||
|
||||
m_hwnd = FindWindowW(L"grcWindow", nullptr);
|
||||
|
Reference in New Issue
Block a user