Skip to content

Commit

Permalink
feat(hook): accept calling convention in make_hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Jun 20, 2024
1 parent 3df2b67 commit a9c06d8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.21)
project(lime LANGUAGES CXX VERSION 5.1)
project(lime LANGUAGES CXX VERSION 6.1)

# --------------------------------------------------------------------------------------------------------
# Library options
Expand Down
4 changes: 2 additions & 2 deletions include/lime/hooks/hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ namespace lime
static rtn_t<std::add_pointer_t> create(Source source, Callable &&target);
};

template <detail::function_pointer Signature, typename Callable>
template <detail::function_pointer Signature, convention Convention = convention::automatic, typename Callable>
auto make_hook(Signature source, Callable &&target);

template <typename Signature, typename Callable>
template <typename Signature, convention Convention = convention::automatic, typename Callable>
auto make_hook(detail::address auto source, Callable &&target);
} // namespace lime

Expand Down
8 changes: 4 additions & 4 deletions include/lime/hooks/hook.inl
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ namespace lime
return rtn;
}

template <detail::function_pointer Signature, typename Callable>
template <detail::function_pointer Signature, convention Convention, typename Callable>
auto make_hook(Signature source, Callable &&target)
{
return hook<std::remove_pointer_t<Signature>>::create(source, std::forward<Callable>(target));
return hook<std::remove_pointer_t<Signature>, Convention>::create(source, std::forward<Callable>(target));
}

template <typename Signature, typename Callable>
template <typename Signature, convention Convention, typename Callable>
auto make_hook(detail::address auto source, Callable &&target)
{
return hook<Signature>::create(source, std::forward<Callable>(target));
return hook<Signature, Convention>::create(source, std::forward<Callable>(target));
}
} // namespace lime
8 changes: 8 additions & 0 deletions tests/hook.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ suite<"Hooks"> hook_suite = []
delete hook;
return ret;
});

lime::make_hook<int(void *, int), lime::convention::automatic>(0xDEADBEEF,
[&](auto *hook, void *thiz, int param) -> int
{
auto ret = hook->original()(thiz, param);
delete hook;
return ret;
});
#endif

expect(eq(test_fn(10), 20));
Expand Down

0 comments on commit a9c06d8

Please sign in to comment.