From c9ab5be1a96680ef3782fa921537eecc574b2981 Mon Sep 17 00:00:00 2001 From: Angad <66992519+ThirdEyeSqueegee@users.noreply.github.com> Date: Wed, 13 Sep 2023 20:13:35 -0700 Subject: [PATCH] feat: add hook helpers (#44) --- CommonLibSF/include/SFSE/SFSE.h | 1 + CommonLibSF/include/SFSE/Utilities.h | 39 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 CommonLibSF/include/SFSE/Utilities.h diff --git a/CommonLibSF/include/SFSE/SFSE.h b/CommonLibSF/include/SFSE/SFSE.h index 94178045..89aa6e9d 100644 --- a/CommonLibSF/include/SFSE/SFSE.h +++ b/CommonLibSF/include/SFSE/SFSE.h @@ -8,4 +8,5 @@ #include "SFSE/Interfaces.h" #include "SFSE/Logger.h" #include "SFSE/Trampoline.h" +#include "SFSE/Utilities.h" #include "SFSE/Version.h" diff --git a/CommonLibSF/include/SFSE/Utilities.h b/CommonLibSF/include/SFSE/Utilities.h new file mode 100644 index 00000000..4a0656f7 --- /dev/null +++ b/CommonLibSF/include/SFSE/Utilities.h @@ -0,0 +1,39 @@ +#pragma once + +#include "REL/Relocation.h" +#include "SFSE/API.h" + +namespace SFSE +{ + namespace stl + { + template + constexpr void write_thunk_call() noexcept + { + SFSE::AllocTrampoline(14); + auto& trampoline = SFSE::GetTrampoline(); + T::func = trampoline.write_call(T::address, T::Thunk); + } + + template + constexpr void write_vfunc() noexcept + { + REL::Relocation vtbl{ To::VTABLE[0] }; + From::func = vtbl.write_vfunc(From::idx, From::Thunk); + } + + template + constexpr void write_vfunc(const std::size_t a_vtable_idx) noexcept + { + REL::Relocation vtbl{ To::VTABLE[a_vtable_idx] }; + From::func = vtbl.write_vfunc(From::idx, From::Thunk); + } + + template + constexpr void write_vfunc(const REL::Offset a_offset) noexcept + { + REL::Relocation vtbl{ a_offset }; + T::func = vtbl.write_vfunc(T::idx, T::Thunk); + } + } // namespace stl +} // namespace SFSE