Skip to content

Commit

Permalink
feat: add overload support to hook
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Jan 31, 2024
1 parent 40f8c0a commit 98beff7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ll/api/event/player/PlayerSwingEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerSwingEventHook,
HookPriority::Normal,
ServerNetworkHandler,
"?handle@ServerNetworkHandler@@UEAAXAEBVNetworkIdentifier@@AEBVAnimatePacket@@@Z",
&ServerNetworkHandler::handle,
void,
NetworkIdentifier const& id,
AnimatePacket const& packet
Expand Down
15 changes: 9 additions & 6 deletions src/ll/api/memory/Hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ struct AddConstAtMemberFun<Ret (T::*)(Args...)> {
template <class T>
using AddConstAtMemberFunT = typename AddConstAtMemberFun<T>::type;

template <class T, class U>
using AddConstAtMemberFunIfOriginIs = std::conditional_t<IsConstMemberFunV<U>, AddConstAtMemberFunT<T>, T>;
template <class T, bool U>
using AddConstAtMemberFunIfOriginIs = std::conditional_t<U, AddConstAtMemberFunT<T>, T>;

/**
* @brief Hook priority enum.
Expand Down Expand Up @@ -166,8 +166,11 @@ class HookRegistrar {
struct DEF_TYPE TYPE { \
using FuncPtr = ::ll::memory::FuncPtr; \
using HookPriority = ::ll::memory::HookPriority; \
using OriginFuncType = \
::ll::memory::AddConstAtMemberFunIfOriginIs<RET_TYPE FUNC_PTR(__VA_ARGS__), decltype(IDENTIFIER)>; \
template <class T> \
static constexpr bool isConstMemberFunction = \
requires(T const&) { static_cast<RET_TYPE FUNC_PTR(__VA_ARGS__) const>(IDENTIFIER); }; \
using OriginFuncType = ::ll::memory:: \
AddConstAtMemberFunIfOriginIs<RET_TYPE FUNC_PTR(__VA_ARGS__), isConstMemberFunction<DEF_TYPE>>; \
\
inline static FuncPtr target__{}; \
inline static OriginFuncType originFunc__{}; \
Expand All @@ -177,10 +180,10 @@ class HookRegistrar {
template <class Arg> \
static consteval void detector() { \
if constexpr (requires { \
::ll::memory::virtualDetector<IDENTIFIER>(); \
::ll::memory::virtualDetector<static_cast<OriginFuncType>(IDENTIFIER)>(); \
ll::memory::resolveIdentifier<OriginFuncType>(IDENTIFIER); \
}) { \
if constexpr (::ll::memory::virtualDetector<IDENTIFIER>()) { \
if constexpr (::ll::memory::virtualDetector<static_cast<OriginFuncType>(IDENTIFIER)>()) { \
static_assert( \
::ll::concepts::always_false<Arg>, \
#IDENTIFIER " is a virtual function, for now you can't use function pointer to hook it." \
Expand Down

0 comments on commit 98beff7

Please sign in to comment.