From 61ff5c43b207849ab1613f046b089f061c8afeca Mon Sep 17 00:00:00 2001 From: is-this-c <87069698+is-this-c@users.noreply.github.com> Date: Sat, 29 Nov 2025 01:25:32 +1300 Subject: [PATCH] Update CodeInjection.h (#193) * Update CodeInjection.h * Update CodeInjection.h --- .../include/patch_common/CodeInjection.h | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/patch_common/include/patch_common/CodeInjection.h b/patch_common/include/patch_common/CodeInjection.h index 9388043f1..d7dad1474 100644 --- a/patch_common/include/patch_common/CodeInjection.h +++ b/patch_common/include/patch_common/CodeInjection.h @@ -234,7 +234,7 @@ class CodeInjection2()(std::declval(&wrapper), needs_trampoline), - m_functor(handler) + m_functor(std::move(handler)) {} private: @@ -253,8 +253,8 @@ class BaseCodeInjectionWithoutRegsAccess : public BaseCodeInjection WrapperPtr m_wrapper_ptr; - BaseCodeInjectionWithoutRegsAccess(uintptr_t addr, WrapperPtr wrapper_ptr, bool needs_trampoline) : - BaseCodeInjection(addr, needs_trampoline), m_wrapper_ptr(wrapper_ptr) + BaseCodeInjectionWithoutRegsAccess(uintptr_t addr, WrapperPtr wrapper_ptr) : + BaseCodeInjection(addr, true), m_wrapper_ptr(wrapper_ptr) {} void emit_code(AsmWriter& asm_writter, void* trampoline) override; @@ -266,9 +266,9 @@ class CodeInjection2()())> : public BaseCodeInjectio T m_functor; public: - CodeInjection2(uintptr_t addr, T handler, bool needs_trampoline) : - BaseCodeInjectionWithoutRegsAccess(addr, reinterpret_cast(&wrapper), needs_trampoline), - m_functor(handler) + CodeInjection2(uintptr_t addr, T handler) : + BaseCodeInjectionWithoutRegsAccess(addr, reinterpret_cast(&wrapper)), + m_functor(std::move(handler)) {} private: @@ -278,11 +278,20 @@ class CodeInjection2()())> : public BaseCodeInjectio } }; -template -class CodeInjection : public CodeInjection2 -{ +template +class CodeInjection : public CodeInjection2 { public: - CodeInjection(uintptr_t addr, T handler, bool needs_trampoline = true) : - CodeInjection2(addr, handler, needs_trampoline) - {} + CodeInjection(const uintptr_t addr, T handler) + requires std::invocable + : CodeInjection2(addr, std::move(handler)) { + } + + CodeInjection( + const uintptr_t addr, + T handler, + const bool needs_trampoline = true + ) + requires std::invocable + : CodeInjection2(addr, std::move(handler), needs_trampoline) { + } };