Skip to content

What to do with references? #19

@RedHolms

Description

@RedHolms

I might be stupid, but this code doesn't work:

class UFunction : ... {
public:
  // Note the reference here
  void Invoke(UObject* obj, FFrame& stack, void* Z_Param__Result);
};

// Results with an address
#define GET_ADDR(...) ...

kthook::kthook_simple<decltype(&UFunction::Invoke)> FuncInvokeHook;

static void Foo() {
  FuncInvokeHook.set_dest(GET_ADDR("?Invoke@UFunction@@QEAAXPEAVUObject@@AEAUFFrame@@QEAX@Z"));
  FuncInvokeHook.set_cb(
    // !!! The problem is here. Neither "FFrame*" nor "FFrame&" doesn't work
    [](auto& hk, UFunction* _this, UObject* obj, FFrame* stack, void* Z_Param__Result) {
      hk.get_trampoline()(_this, obj, *stack, Z_Param__Result);
    }
  );
}

When trying to compile "FFrame*":

In file included from D:\votv-mp\Source\Client\Main.cpp:4:
In file included from D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook/kthook.hpp:54:
D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook\x86_64/kthook_x86_64_detail.hpp(502,16): error: no matching function for call to object of type 'std::function<void (const kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)> &, UFunction *&, UObject *&, FFrame *&, void *&)>'
  502 |         return cb(*this_hook, args...);
      |                ^~
D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook\x64/kthook_detail.hpp(157,16): note: in instantiation of function template specialization 'kthook::detail::common_relay<std::function<void (const kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)> &, UFunction *&, UObject *&, FFrame *&, void *&)> &, kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)>, void, UFunction *, UObject *, FFrame &, void *>' requested here
  157 |         return common_relay<decltype(cb), HookType, Ret, Args...>(cb, this_hook, head_args..., tail_args...);
      |                ^
D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook\x64/kthook_impl.hpp(545,112): note: in instantiation of member function 'kthook::detail::common_relay_generator<kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)>, void, std::tuple<UFunction *, UObject *, FFrame &, void *>, std::tuple<>, std::tuple<UFunction *, UObject *, FFrame &, void *>>::relay' requested here
  545 |                 reinterpret_cast<void*>(&detail::common_relay_generator<kthook_simple, Ret, head, tail, Args>::relay);
      |                                                                                                                ^
D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook\x64/kthook_impl.hpp(635,36): note: in instantiation of member function 'kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)>::generate_relay_jump' requested here
  635 |                 this->relay_jump = generate_relay_jump();
      |                                    ^
D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook\x64/kthook_impl.hpp(409,22): note: in instantiation of member function 'kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)>::patch_hook' requested here
  409 |         installed = !patch_hook(false);
      |                      ^
D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook\x64/kthook_impl.hpp(392,24): note: in instantiation of member function 'kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)>::remove' requested here
  392 |     ~kthook_simple() { remove(); }
      |                        ^
D:\votv-mp\Source\Client\Main.cpp(9,53): note: in instantiation of member function 'kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)>::~kthook_simple' requested here
    9 | kthook::kthook_simple<decltype(&UFunction::Invoke)> FuncInvokeHook;
      |                                                     ^
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\functional(921,10): note: candidate function not viable: no known conversion from 'FFrame' to 'FFrame *&' for 4th argument
  921 |     _Ret operator()(_Types... _Args) const {
      |          ^          ~~~~~~~~~~~~~~~

When trying to compile with "FFrame&":

D:\votv-mp\Source\Client\Main.cpp(43,5): error: no viable conversion from '(lambda at D:\votv-mp\Source\Client\Main.cpp:43:5)' to 'cb_type' (aka 'function<void (const kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *), kthook::kNone> &, UFunction *&, UObject *&, FFrame *&, void *&)>')
   43 |     [](auto& hk, UFunction* _this, UObject* obj, FFrame& stack, void* Z_Param__Result) {
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   44 |       hk.get_trampoline()(_this, obj, stack, Z_Param__Result);
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   45 |     }
      |     ~
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\functional(1096,5): note: candidate constructor not viable: no known conversion from '(lambda at D:\votv-mp\Source\Client\Main.cpp:43:5)' to 'nullptr_t' (aka 'std::nullptr_t') for 1st argument
 1096 |     function(nullptr_t) noexcept {}
      |     ^        ~~~~~~~~~
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\functional(1098,5): note: candidate constructor not viable: no known conversion from '(lambda at D:\votv-mp\Source\Client\Main.cpp:43:5)' to 'const function<void (const kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)> &, UFunction *&, UObject *&, FFrame *&, void *&)> &' for 1st argument
 1098 |     function(const function& _Right) {
      |     ^        ~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\functional(1149,5): note: candidate constructor not viable: no known conversion from '(lambda at D:\votv-mp\Source\Client\Main.cpp:43:5)' to 'function<void (const kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)> &, UFunction *&, UObject *&, FFrame *&, void *&)> &&' for 1st argument
 1149 |     function(function&& _Right) noexcept {
      |     ^        ~~~~~~~~~~~~~~~~~
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\functional(1103,5): note: candidate template ignored: requirement 'conjunction_v<std::negation<std::is_same<(lambda at D:\votv-mp\Source\Client\Main.cpp:43:5), std::function<void (const kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *), kthook::kNone> &, UFunction *&, UObject *&, FFrame *&, void *&)>>>, std::_Is_invocable_r<void, (lambda at D:\votv-mp\Source\Client\Main.cpp:43:5) &, const kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *), kthook::kNone> &, UFunction *&, UObject *&, FFrame *&, void *&>>' was not satisfied [with _Fx = (lambda at D:\votv-mp\Source\Client\Main.cpp:43:5)]
 1103 |     function(_Fx&& _Func) {
      |     ^
D:\votv-mp\Source\Client\Main.cpp(43,5): note: candidate template ignored: could not match 'auto (*)(type-parameter-0-0 &, UFunction *, UObject *, FFrame &, void *)' against 'std::function<void (const kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)> &, UFunction *&, UObject *&, FFrame *&, void *&)>'
   43 |     [](auto& hk, UFunction* _this, UObject* obj, FFrame& stack, void* Z_Param__Result) {
      |     ^
D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook\x64/kthook_impl.hpp(425,25): note: passing argument to parameter 'callback_' here
  425 |     void set_cb(cb_type callback_) { callback = std::move(callback_); }
      |                         ^
In file included from D:\votv-mp\Source\Client\Main.cpp:4:
In file included from D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook/kthook.hpp:54:
D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook\x86_64/kthook_x86_64_detail.hpp(502,16): error: no matching function for call to object of type 'std::function<void (const kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)> &, UFunction *&, UObject *&, FFrame *&, void *&)>'
  502 |         return cb(*this_hook, args...);
      |                ^~
D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook\x64/kthook_detail.hpp(157,16): note: in instantiation of function template specialization 'kthook::detail::common_relay<std::function<void (const kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)> &, UFunction *&, UObject *&, FFrame *&, void *&)> &, kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)>, void, UFunction *, UObject *, FFrame &, void *>' requested here
  157 |         return common_relay<decltype(cb), HookType, Ret, Args...>(cb, this_hook, head_args..., tail_args...);
      |                ^
D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook\x64/kthook_impl.hpp(545,112): note: in instantiation of member function 'kthook::detail::common_relay_generator<kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)>, void, std::tuple<UFunction *, UObject *, FFrame &, void *>, std::tuple<>, std::tuple<UFunction *, UObject *, FFrame &, void *>>::relay' requested here
  545 |                 reinterpret_cast<void*>(&detail::common_relay_generator<kthook_simple, Ret, head, tail, Args>::relay);
      |                                                                                                                ^
D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook\x64/kthook_impl.hpp(635,36): note: in instantiation of member function 'kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)>::generate_relay_jump' requested here
  635 |                 this->relay_jump = generate_relay_jump();
      |                                    ^
D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook\x64/kthook_impl.hpp(409,22): note: in instantiation of member function 'kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)>::patch_hook' requested here
  409 |         installed = !patch_hook(false);
      |                      ^
D:\votv-mp\build\Debug\_deps\kthook-src\include\kthook\x64/kthook_impl.hpp(392,24): note: in instantiation of member function 'kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)>::remove' requested here
  392 |     ~kthook_simple() { remove(); }
      |                        ^
D:\votv-mp\Source\Client\Main.cpp(9,53): note: in instantiation of member function 'kthook::kthook_simple<void (UFunction::*)(UObject *, FFrame &, void *)>::~kthook_simple' requested here
    9 | kthook::kthook_simple<decltype(&UFunction::Invoke)> FuncInvokeHook;
      |                                                     ^
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\functional(921,10): note: candidate function not viable: no known conversion from 'FFrame' to 'FFrame *&' for 4th argument
  921 |     _Ret operator()(_Types... _Args) const {

I assume there's some issue with reference-to-pointer conversion:

// Here
using converted_args = typename detail::traits::add_refs_t<detail::traits::convert_refs_t<Args>>;

Or I can just do things wrong

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions