Skip to content

Commit

Permalink
Remove copy-paste
Browse files Browse the repository at this point in the history
  • Loading branch information
Smertig committed Mar 20, 2023
1 parent e2d154b commit 65c8d0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
7 changes: 2 additions & 5 deletions include/rcmp/detail/hook_policy/indirect_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ template <auto IndirectFunctionAddress, class Signature, class F>
void hook_indirect_function(F&& hook) {
static_assert(std::is_constructible_v<rcmp::address_t, decltype(IndirectFunctionAddress)>);

using wrapped_policy_t = detail::WithGlobalState<
detail::HookIndirectPolicy,
std::integral_constant<decltype(IndirectFunctionAddress), IndirectFunctionAddress>
>;
rcmp::generic_hook_function<wrapped_policy_t::template Policy, Signature>(IndirectFunctionAddress, std::forward<F>(hook));
using Tag = std::integral_constant<decltype(IndirectFunctionAddress), IndirectFunctionAddress>;
rcmp::hook_indirect_function<Tag, Signature>(IndirectFunctionAddress, std::forward<F>(hook));
}

template <class Signature, class F>
Expand Down
15 changes: 4 additions & 11 deletions include/rcmp/detail/hook_policy/prolog_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ struct HookPrologPolicy {

#if defined(RCMP_HAS_HOOK_PROLOG_POLICY)

// TODO: cleanup copy-paste
template <class Tag, class Signature, class F>
void hook_function(rcmp::address_t function_address, F&& hook) {
using wrapped_policy_t = detail::WithGlobalState<
Expand All @@ -43,11 +42,8 @@ template <auto FunctionAddress, class Signature, class F>
void hook_function(F&& hook) {
static_assert(std::is_constructible_v<rcmp::address_t, decltype(FunctionAddress)>);

using wrapped_policy_t = detail::WithGlobalState<
detail::HookPrologPolicy,
std::integral_constant<decltype(FunctionAddress), FunctionAddress>
>;
rcmp::generic_hook_function<wrapped_policy_t::template Policy, Signature>(FunctionAddress, std::forward<F>(hook));
using Tag = std::integral_constant<decltype(FunctionAddress), FunctionAddress>;
rcmp::hook_function<Tag, Signature>(FunctionAddress, std::forward<F>(hook));
}

template <auto Function, class F>
Expand All @@ -57,11 +53,8 @@ void hook_function(F&& hook) {
static_assert(std::is_pointer_v<Signature>, "Function is not a pointer to function. Did you forget to specify signature? (rcmp::hook_function<.., Signature>(..) overload)");
static_assert(std::is_function_v<std::remove_pointer_t<Signature>>, "Function is not a pointer to function. Did you forget to specify signature? (rcmp::hook_function<.., Signature>(..) overload)");

using wrapped_policy_t = detail::WithGlobalState<
detail::HookPrologPolicy,
std::integral_constant<Signature, Function>
>;
rcmp::generic_hook_function<wrapped_policy_t::template Policy, Signature>(rcmp::bit_cast<const void*>(Function), std::forward<F>(hook));
using Tag = std::integral_constant<Signature, Function>;
rcmp::hook_function<Tag, Signature>(rcmp::bit_cast<const void*>(Function), std::forward<F>(hook));
}

template <class Signature, class F>
Expand Down

0 comments on commit 65c8d0d

Please sign in to comment.