From b6a70ecb315f2f4c361e33ed2803b1ebfd94f031 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Tue, 2 Jul 2019 20:28:20 +0200 Subject: [PATCH 1/2] Check if address is used twice --- src/patcher.h | 46 +++++++++++++++++++++++++++++----------------- src/re3.cpp | 4 ++++ 2 files changed, 33 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 +#include + +#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 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 usedAddresses; + template 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 }); diff --git a/src/re3.cpp b/src/re3.cpp index 87552214..9dc39d46 100644 --- a/src/re3.cpp +++ b/src/re3.cpp @@ -16,6 +16,10 @@ #include "Automobile.h" #include "debugmenu_public.h" +#include + +std::vector usedAddresses; + void **rwengine = *(void***)0x5A10E1; DebugMenuAPI gDebugMenuAPI; From 34e8fffcb4b41bb3049dfca9d42cea2e1da637f8 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Tue, 2 Jul 2019 21:31:12 +0200 Subject: [PATCH 2/2] Fix address of IsPedHeadAbovePos --- src/entities/Ped.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entities/Ped.cpp b/src/entities/Ped.cpp index 14aad60a..61d6d182 100644 --- a/src/entities/Ped.cpp +++ b/src/entities/Ped.cpp @@ -1696,7 +1696,7 @@ STARTPATCHES InjectHook(0x4D2BB0, &CPed::Avoid, PATCH_JUMP); InjectHook(0x4C6A50, &CPed::ClearAimFlag, PATCH_JUMP); InjectHook(0x4C64F0, &CPed::ClearLookFlag, PATCH_JUMP); - InjectHook(0x4E5BD0, &CPed::IsPedHeadAbovePos, PATCH_JUMP); + InjectHook(0x4EB670, &CPed::IsPedHeadAbovePos, PATCH_JUMP); InjectHook(0x4E68A0, &CPed::FinishedAttackCB, PATCH_JUMP); InjectHook(0x4E5BD0, &CheckForPedsOnGroundToAttack, PATCH_JUMP); InjectHook(0x4E6BA0, &CPed::Attack, PATCH_JUMP);