Skip to content

Commit

Permalink
feat: add hook helpers (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirdEyeSqueegee authored Sep 14, 2023
1 parent 22bf4c9 commit c9ab5be
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CommonLibSF/include/SFSE/SFSE.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
#include "SFSE/Interfaces.h"
#include "SFSE/Logger.h"
#include "SFSE/Trampoline.h"
#include "SFSE/Utilities.h"
#include "SFSE/Version.h"
39 changes: 39 additions & 0 deletions CommonLibSF/include/SFSE/Utilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include "REL/Relocation.h"
#include "SFSE/API.h"

namespace SFSE
{
namespace stl
{
template <class T, std::size_t Size = 5>
constexpr void write_thunk_call() noexcept
{
SFSE::AllocTrampoline(14);
auto& trampoline = SFSE::GetTrampoline();
T::func = trampoline.write_call<Size>(T::address, T::Thunk);
}

template <class To, class From>
constexpr void write_vfunc() noexcept
{
REL::Relocation<std::uintptr_t> vtbl{ To::VTABLE[0] };
From::func = vtbl.write_vfunc(From::idx, From::Thunk);
}

template <class To, class From>
constexpr void write_vfunc(const std::size_t a_vtable_idx) noexcept
{
REL::Relocation<std::uintptr_t> vtbl{ To::VTABLE[a_vtable_idx] };
From::func = vtbl.write_vfunc(From::idx, From::Thunk);
}

template <class T>
constexpr void write_vfunc(const REL::Offset a_offset) noexcept
{
REL::Relocation<std::uintptr_t> vtbl{ a_offset };
T::func = vtbl.write_vfunc(T::idx, T::Thunk);
}
} // namespace stl
} // namespace SFSE

0 comments on commit c9ab5be

Please sign in to comment.