From 3831058f81afb8c323edd26d1f9b4c8ca8f2f0af Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 26 Nov 2023 11:42:26 +0100 Subject: [PATCH] New method for IDetour This will deprecate IDetour::Attach and IDetour::Detatch. This should reduce the chances of potential errors caused by using the wrong function in the wrong method (e.g. using DetourAttach in IDetour::Detatch). --- r5dev/thirdparty/detours/include/idetour.h | 12 ++++++++++++ r5dev/thirdparty/detours/src/idetour.cpp | 2 ++ 2 files changed, 14 insertions(+) diff --git a/r5dev/thirdparty/detours/include/idetour.h b/r5dev/thirdparty/detours/include/idetour.h index 5c4b72f9..6f794679 100644 --- a/r5dev/thirdparty/detours/include/idetour.h +++ b/r5dev/thirdparty/detours/include/idetour.h @@ -15,6 +15,18 @@ public: virtual void Attach(void) const = 0; virtual void Detach(void) const = 0; + + //virtual void Detour(const bool bAttach) const = 0; + template< + typename T, + typename std::enable_if<DetoursIsFunctionPointer<T>::value, int>::type = 0> + LONG Setup(_Inout_ T* ppPointer, _In_ T pDetour, const bool bAttach) const + { + if (bAttach) + return DetourAttach(ppPointer, pDetour); + else + return DetourDetach(ppPointer, pDetour); + } }; extern std::vector<IDetour*> g_DetourVec; diff --git a/r5dev/thirdparty/detours/src/idetour.cpp b/r5dev/thirdparty/detours/src/idetour.cpp index 264ae8d3..bbd1de53 100644 --- a/r5dev/thirdparty/detours/src/idetour.cpp +++ b/r5dev/thirdparty/detours/src/idetour.cpp @@ -6,6 +6,8 @@ #include <cassert> #include <vector> #include <unordered_set> +#include <Windows.h> +#include "../include/detours.h" #include "../include/idetour.h" //-----------------------------------------------------------------------------