summaryrefslogtreecommitdiffstats
path: root/src/core/re3.cpp
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2020-03-27 20:53:47 +0100
committeraap <aap@papnet.eu>2020-03-27 20:53:47 +0100
commite7c18fc17f82c40e937367726e07a58d5d4d7bce (patch)
tree56cb927424f601b27f0bc8821c7761f0e7468724 /src/core/re3.cpp
parentXInput (diff)
downloadre3-e7c18fc17f82c40e937367726e07a58d5d4d7bce.tar
re3-e7c18fc17f82c40e937367726e07a58d5d4d7bce.tar.gz
re3-e7c18fc17f82c40e937367726e07a58d5d4d7bce.tar.bz2
re3-e7c18fc17f82c40e937367726e07a58d5d4d7bce.tar.lz
re3-e7c18fc17f82c40e937367726e07a58d5d4d7bce.tar.xz
re3-e7c18fc17f82c40e937367726e07a58d5d4d7bce.tar.zst
re3-e7c18fc17f82c40e937367726e07a58d5d4d7bce.zip
Diffstat (limited to 'src/core/re3.cpp')
-rw-r--r--src/core/re3.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/core/re3.cpp b/src/core/re3.cpp
index 0301a98a..137a890c 100644
--- a/src/core/re3.cpp
+++ b/src/core/re3.cpp
@@ -22,11 +22,62 @@
#include "Console.h"
#include "Debug.h"
+#include <algorithm>
#include <vector>
#include <list>
std::vector<int32> 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 (int32)value == address; })) {
+ debug("Used address %#06x twice when injecting hook\n", address);
+ }
+
+ usedAddresses.push_back((int32)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*)((uint32)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]);
+}
+
void **rwengine = *(void***)0x5A10E1;
DebugMenuAPI gDebugMenuAPI;