diff options
author | Sergeanur <s.anureev@yandex.ua> | 2020-07-22 02:23:12 +0200 |
---|---|---|
committer | Sergeanur <s.anureev@yandex.ua> | 2020-07-22 02:32:46 +0200 |
commit | 7d51995640c6ad822c983249acf7aa765aa055b8 (patch) | |
tree | bee1ed6834c3f548469b330c649b93d28b5b5ffa /src/core/patcher.cpp | |
parent | Merge branch 'master' of https://github.com/GTAmodding/re3 into erorcun (diff) | |
download | re3-7d51995640c6ad822c983249acf7aa765aa055b8.tar re3-7d51995640c6ad822c983249acf7aa765aa055b8.tar.gz re3-7d51995640c6ad822c983249acf7aa765aa055b8.tar.bz2 re3-7d51995640c6ad822c983249acf7aa765aa055b8.tar.lz re3-7d51995640c6ad822c983249acf7aa765aa055b8.tar.xz re3-7d51995640c6ad822c983249acf7aa765aa055b8.tar.zst re3-7d51995640c6ad822c983249acf7aa765aa055b8.zip |
Diffstat (limited to 'src/core/patcher.cpp')
-rw-r--r-- | src/core/patcher.cpp | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/src/core/patcher.cpp b/src/core/patcher.cpp deleted file mode 100644 index 83e06886..00000000 --- a/src/core/patcher.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#define WITHWINDOWS -#include "common.h" -#include "patcher.h" - -#include <algorithm> -#include <vector> - -StaticPatcher *StaticPatcher::ms_head; - -StaticPatcher::StaticPatcher(Patcher func) - : m_func(func) -{ - m_next = ms_head; - ms_head = this; -} - -void -StaticPatcher::Apply() -{ - StaticPatcher *current = ms_head; - while(current){ - current->Run(); - current = current->m_next; - } - ms_head = nil; -} -#ifdef _WIN32 -std::vector<uint32> usedAddresses; - -static DWORD protect[2]; -static uint32 protect_address; -static uint32 protect_size; - -void -Protect_internal(uint32 address, uint32 size) -{ - protect_address = address; - protect_size = size; - VirtualProtect((void*)address, size, PAGE_EXECUTE_READWRITE, &protect[0]); -} - -void -Unprotect_internal(void) -{ - VirtualProtect((void*)protect_address, protect_size, protect[0], &protect[1]); -} - -void -InjectHook_internal(uint32 address, uint32 hook, int type) -{ - if(std::any_of(usedAddresses.begin(), usedAddresses.end(), - [address](uint32 value) { return value == address; })) { - debug("Used address %#06x twice when injecting hook\n", address); - } - - usedAddresses.push_back(address); - - - switch(type){ - case PATCH_JUMP: - VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &protect[0]); - *(uint8*)address = 0xE9; - break; - case PATCH_CALL: - VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &protect[0]); - *(uint8*)address = 0xE8; - break; - default: - VirtualProtect((void*)(address + 1), 4, PAGE_EXECUTE_READWRITE, &protect[0]); - break; - } - - *(ptrdiff_t*)(address + 1) = hook - address - 5; - if(type == PATCH_NOTHING) - VirtualProtect((void*)(address + 1), 4, protect[0], &protect[1]); - else - VirtualProtect((void*)address, 5, protect[0], &protect[1]); -} -#else -void -Protect_internal(uint32 address, uint32 size) -{ -} - -void -Unprotect_internal(void) -{ -} - -void -InjectHook_internal(uint32 address, uint32 hook, int type) -{ -} -#endif |