diff options
author | eray orçunus <erayorcunus@gmail.com> | 2019-07-04 04:00:33 +0200 |
---|---|---|
committer | eray orçunus <erayorcunus@gmail.com> | 2019-07-04 04:00:33 +0200 |
commit | cc56292bc503d5aaa96c5146480ab8bd1b6b0488 (patch) | |
tree | 77949cc32155e844b34c75f856f79ff3f3ad9cec /src/patcher.h | |
parent | Even more CPed (diff) | |
parent | Merge pull request #107 from Nick007J/master (diff) | |
download | re3-cc56292bc503d5aaa96c5146480ab8bd1b6b0488.tar re3-cc56292bc503d5aaa96c5146480ab8bd1b6b0488.tar.gz re3-cc56292bc503d5aaa96c5146480ab8bd1b6b0488.tar.bz2 re3-cc56292bc503d5aaa96c5146480ab8bd1b6b0488.tar.lz re3-cc56292bc503d5aaa96c5146480ab8bd1b6b0488.tar.xz re3-cc56292bc503d5aaa96c5146480ab8bd1b6b0488.tar.zst re3-cc56292bc503d5aaa96c5146480ab8bd1b6b0488.zip |
Diffstat (limited to 'src/patcher.h')
-rw-r--r-- | src/patcher.h | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/src/patcher.h b/src/patcher.h index 43618b47..87a6bea4 100644 --- a/src/patcher.h +++ b/src/patcher.h @@ -9,6 +9,11 @@ #define NOVMT __declspec(novtable) #define SETVMT(a) *((DWORD_PTR*)this) = (DWORD_PTR)a +#include <algorithm> +#include <vector> + +#include "common.h" + enum { PATCH_CALL, @@ -28,6 +33,21 @@ enum extern int gtaversion; +class StaticPatcher +{ +private: + using Patcher = void(*)(); + + Patcher m_func; + StaticPatcher *m_next; + static StaticPatcher *ms_head; + + void Run() { m_func(); } +public: + StaticPatcher(Patcher func); + static void Apply(); +}; + template<typename T> inline T AddressByVersion(uint32_t addressIII10, uint32_t addressIII11, uint32_t addressIIISteam, uint32_t addressvc10, uint32_t addressvc11, uint32_t addressvcSteam) { @@ -110,9 +130,18 @@ ClearCC(AT address, unsigned int nCount) VirtualProtect((void*)address, nCount, dwProtect[0], &dwProtect[1]); } +extern std::vector<int32> usedAddresses; + template<typename AT, typename HT> inline void InjectHook(AT address, HT hook, unsigned int nType=PATCH_NOTHING) { + if(std::any_of(usedAddresses.begin(), usedAddresses.end(), + [address](AT value) { return (int32)value == address; })) { + debug("Used address %#06x twice when injecting hook\n", address); + } + + usedAddresses.push_back((int32)address); + DWORD dwProtect[2]; switch ( nType ) { @@ -159,22 +188,5 @@ inline void InterceptVmethod(void *dst, T func, uint32_t a) Patch(a, func); } - - -class StaticPatcher -{ -private: - using Patcher = void(*)(); - - Patcher m_func; - StaticPatcher *m_next; - static StaticPatcher *ms_head; - - void Run() { m_func(); } -public: - StaticPatcher(Patcher func); - static void Apply(); -}; - #define STARTPATCHES static StaticPatcher Patcher([](){ #define ENDPATCHES }); |