Skip to content

Commit

Permalink
NativeHookManager: Add more "explicit" hook macros (#303)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Th3Fanbus authored Nov 9, 2024
1 parent a5773db commit aeb0ae6
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Mods/SML/Source/SML/Public/Patching/NativeHookManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,18 @@ using CallScope = TCallScope<T>;
return HookInvoker<decltype(&MethodReference), &MethodReference>::AddHandlerAfter(Handler); \
} )

#define SUBSCRIBE_METHOD_EXPLICIT(MethodSignature, MethodReference, Handler) \
Invoke( [&]() { \
HookInvoker<MethodSignature, &MethodReference>::InstallHook(TEXT(#MethodReference)); \
return HookInvoker<MethodSignature, &MethodReference>::AddHandlerBefore(Handler); \
} )

#define SUBSCRIBE_METHOD_EXPLICIT_AFTER(MethodSignature, MethodReference, Handler) \
Invoke( [&]() { \
HookInvoker<MethodSignature, &MethodReference>::InstallHook(TEXT(#MethodReference)); \
return HookInvoker<MethodSignature, &MethodReference>::AddHandlerAfter(Handler); \
} )

#define SUBSCRIBE_METHOD_VIRTUAL(MethodReference, SampleObjectInstance, Handler) \
Invoke( [&]() { \
HookInvoker<decltype(&MethodReference), &MethodReference>::InstallHook(TEXT(#MethodReference), SampleObjectInstance); \
Expand All @@ -598,6 +610,12 @@ using CallScope = TCallScope<T>;
return HookInvoker<decltype(&MethodReference), &MethodReference>::AddHandlerAfter(Handler); \
} )

#define SUBSCRIBE_METHOD_EXPLICIT_VIRTUAL(MethodSignature, MethodReference, SampleObjectInstance, Handler) \
Invoke( [&]() { \
HookInvoker<MethodSignature, &MethodReference>::InstallHook(TEXT(#MethodReference), SampleObjectInstance); \
return HookInvoker<MethodSignature, &MethodReference>::AddHandlerBefore(Handler); \
} )

#define SUBSCRIBE_METHOD_EXPLICIT_VIRTUAL_AFTER(MethodSignature, MethodReference, SampleObjectInstance, Handler) \
Invoke( [&]() { \
HookInvoker<MethodSignature, &MethodReference>::InstallHook(TEXT(#MethodReference), SampleObjectInstance); \
Expand All @@ -616,8 +634,26 @@ using CallScope = TCallScope<T>;
return HookInvoker<decltype(&ObjectClass::MethodName), &ObjectClass::MethodName>::AddHandlerAfter(Handler); \
} )

#define SUBSCRIBE_UOBJECT_METHOD_EXPLICIT(MethodSignature, ObjectClass, MethodName, Handler) \
Invoke( [&]() { \
HookInvoker<MethodSignature, &ObjectClass::MethodName>::InstallHook(TEXT(#ObjectClass "::" #MethodName), GetDefault<ObjectClass>()); \
return HookInvoker<MethodSignature, &ObjectClass::MethodName>::AddHandlerBefore(Handler); \
} )

#define SUBSCRIBE_UOBJECT_METHOD_EXPLICIT_AFTER(MethodSignature, ObjectClass, MethodName, Handler) \
Invoke( [&]() { \
HookInvoker<MethodSignature, &ObjectClass::MethodName>::InstallHook(TEXT(#ObjectClass "::" #MethodName), GetDefault<ObjectClass>()); \
return HookInvoker<MethodSignature, &ObjectClass::MethodName>::AddHandlerAfter(Handler); \
} )

#define UNSUBSCRIBE_METHOD(MethodReference, HandlerHandle) \
HookInvoker<decltype(&MethodReference), &MethodReference>::RemoveHandler(TEXT(#MethodReference), HandlerHandle )

#define UNSUBSCRIBE_METHOD_EXPLICIT(MethodSignature, MethodReference, HandlerHandle) \
HookInvoker<MethodSignature, &MethodReference>::RemoveHandler(TEXT(#MethodReference), HandlerHandle )

#define UNSUBSCRIBE_UOBJECT_METHOD(ObjectClass, MethodName, HandlerHandle) \
HookInvoker<decltype(&ObjectClass::MethodName), &ObjectClass::MethodName>::RemoveHandler(TEXT(#ObjectClass "::" #MethodName), HandlerHandle )

#define UNSUBSCRIBE_UOBJECT_METHOD_EXPLICIT(MethodSignature, ObjectClass, MethodName, HandlerHandle) \
HookInvoker<MethodSignature, &ObjectClass::MethodName>::RemoveHandler(TEXT(#ObjectClass "::" #MethodName), HandlerHandle )

0 comments on commit aeb0ae6

Please sign in to comment.