From aeb0ae61a9101ab0d6657bb4ae84550944cd9475 Mon Sep 17 00:00:00 2001 From: Angel Pons <22937129+Th3Fanbus@users.noreply.github.com> Date: Sat, 9 Nov 2024 11:32:48 +0000 Subject: [PATCH] NativeHookManager: Add more "explicit" hook macros (#303) For some reason, `SUBSCRIBE_METHOD_EXPLICIT_VIRTUAL_AFTER` was the only "explicit" macro in this header. Add the remaining macros, based on the corresponding "non-explicit" macros. Signed-off-by: Angel Pons --- .../SML/Public/Patching/NativeHookManager.h | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Mods/SML/Source/SML/Public/Patching/NativeHookManager.h b/Mods/SML/Source/SML/Public/Patching/NativeHookManager.h index 9bbbfb4a55..2dc95ef53f 100644 --- a/Mods/SML/Source/SML/Public/Patching/NativeHookManager.h +++ b/Mods/SML/Source/SML/Public/Patching/NativeHookManager.h @@ -586,6 +586,18 @@ using CallScope = TCallScope; return HookInvoker::AddHandlerAfter(Handler); \ } ) +#define SUBSCRIBE_METHOD_EXPLICIT(MethodSignature, MethodReference, Handler) \ + Invoke( [&]() { \ + HookInvoker::InstallHook(TEXT(#MethodReference)); \ + return HookInvoker::AddHandlerBefore(Handler); \ + } ) + +#define SUBSCRIBE_METHOD_EXPLICIT_AFTER(MethodSignature, MethodReference, Handler) \ + Invoke( [&]() { \ + HookInvoker::InstallHook(TEXT(#MethodReference)); \ + return HookInvoker::AddHandlerAfter(Handler); \ + } ) + #define SUBSCRIBE_METHOD_VIRTUAL(MethodReference, SampleObjectInstance, Handler) \ Invoke( [&]() { \ HookInvoker::InstallHook(TEXT(#MethodReference), SampleObjectInstance); \ @@ -598,6 +610,12 @@ using CallScope = TCallScope; return HookInvoker::AddHandlerAfter(Handler); \ } ) +#define SUBSCRIBE_METHOD_EXPLICIT_VIRTUAL(MethodSignature, MethodReference, SampleObjectInstance, Handler) \ + Invoke( [&]() { \ + HookInvoker::InstallHook(TEXT(#MethodReference), SampleObjectInstance); \ + return HookInvoker::AddHandlerBefore(Handler); \ + } ) + #define SUBSCRIBE_METHOD_EXPLICIT_VIRTUAL_AFTER(MethodSignature, MethodReference, SampleObjectInstance, Handler) \ Invoke( [&]() { \ HookInvoker::InstallHook(TEXT(#MethodReference), SampleObjectInstance); \ @@ -616,8 +634,26 @@ using CallScope = TCallScope; return HookInvoker::AddHandlerAfter(Handler); \ } ) +#define SUBSCRIBE_UOBJECT_METHOD_EXPLICIT(MethodSignature, ObjectClass, MethodName, Handler) \ + Invoke( [&]() { \ + HookInvoker::InstallHook(TEXT(#ObjectClass "::" #MethodName), GetDefault()); \ + return HookInvoker::AddHandlerBefore(Handler); \ + } ) + +#define SUBSCRIBE_UOBJECT_METHOD_EXPLICIT_AFTER(MethodSignature, ObjectClass, MethodName, Handler) \ + Invoke( [&]() { \ + HookInvoker::InstallHook(TEXT(#ObjectClass "::" #MethodName), GetDefault()); \ + return HookInvoker::AddHandlerAfter(Handler); \ + } ) + #define UNSUBSCRIBE_METHOD(MethodReference, HandlerHandle) \ HookInvoker::RemoveHandler(TEXT(#MethodReference), HandlerHandle ) +#define UNSUBSCRIBE_METHOD_EXPLICIT(MethodSignature, MethodReference, HandlerHandle) \ + HookInvoker::RemoveHandler(TEXT(#MethodReference), HandlerHandle ) + #define UNSUBSCRIBE_UOBJECT_METHOD(ObjectClass, MethodName, HandlerHandle) \ HookInvoker::RemoveHandler(TEXT(#ObjectClass "::" #MethodName), HandlerHandle ) + +#define UNSUBSCRIBE_UOBJECT_METHOD_EXPLICIT(MethodSignature, ObjectClass, MethodName, HandlerHandle) \ + HookInvoker::RemoveHandler(TEXT(#ObjectClass "::" #MethodName), HandlerHandle )