|
5 | 5 |
|
6 | 6 | namespace SFSE::stl |
7 | 7 | { |
8 | | - template <class T, std::size_t Size = 5> |
| 8 | + template <class T, std::size_t N = 5> |
9 | 9 | constexpr void write_thunk_call(const std::uintptr_t a_address) noexcept |
10 | 10 | { |
11 | | - AllocTrampoline(14); |
12 | | - auto& trampoline = GetTrampoline(); |
13 | | - T::func = trampoline.write_call<Size>(a_address, T::thunk); |
| 11 | + T::func = GetTrampoline().write_call<N>(a_address, T::thunk); |
14 | 12 | } |
15 | 13 |
|
16 | | - template <class T, std::size_t Size = 5> |
| 14 | + template <class T, std::size_t N = 5, class U> |
| 15 | + constexpr void write_thunk_call(const U a_id) noexcept |
| 16 | + requires(std::is_same_v<U, REL::ID> || std::is_same_v<U, REL::Offset>) |
| 17 | + { |
| 18 | + T::func = GetTrampoline().write_call<N>(a_id.address(), T::thunk); |
| 19 | + } |
| 20 | + |
| 21 | + template <class T, std::size_t N = 5, class U> |
| 22 | + constexpr void write_thunk_call(const REL::Relocation<U> a_id) noexcept |
| 23 | + requires(std::is_same_v<typename REL::Relocation<U>::value_type, std::uintptr_t>) |
| 24 | + { |
| 25 | + T::func = GetTrampoline().write_call<N>(a_id.address(), T::thunk); |
| 26 | + } |
| 27 | + |
| 28 | + template <class T, std::size_t N = 5> |
17 | 29 | constexpr void write_thunk_call() noexcept |
18 | 30 | { |
19 | | - write_thunk_call<T, Size>(T::address); |
| 31 | + write_thunk_call<T, N>(T::address); |
| 32 | + } |
| 33 | + |
| 34 | + template <class T, std::size_t N = 5> |
| 35 | + constexpr void write_thunk_jump(const std::uintptr_t a_address) noexcept |
| 36 | + { |
| 37 | + T::func = GetTrampoline().write_branch<N>(a_address, T::thunk); |
| 38 | + } |
| 39 | + |
| 40 | + template <class T, std::size_t N = 5, class U> |
| 41 | + constexpr void write_thunk_jump(const U a_id) noexcept |
| 42 | + requires(std::is_same_v<U, REL::ID> || std::is_same_v<U, REL::Offset>) |
| 43 | + { |
| 44 | + T::func = GetTrampoline().write_branch<N>(a_id.address(), T::thunk); |
| 45 | + } |
| 46 | + |
| 47 | + template <class T, std::size_t N = 5, class U> |
| 48 | + constexpr void write_thunk_jump(const REL::Relocation<U> a_id) noexcept |
| 49 | + requires(std::is_same_v<typename REL::Relocation<U>::value_type, std::uintptr_t>) |
| 50 | + { |
| 51 | + T::func = GetTrampoline().write_branch<N>(a_id.address(), T::thunk); |
| 52 | + } |
| 53 | + |
| 54 | + template <class T, std::size_t N = 5> |
| 55 | + constexpr void write_thunk_jump() noexcept |
| 56 | + { |
| 57 | + write_thunk_jump<T, N>(T::address); |
20 | 58 | } |
21 | 59 |
|
22 | 60 | template <class T> |
23 | | - constexpr void write_vfunc(const REL::ID a_id) noexcept |
| 61 | + constexpr void write_vfunc(const std::uintptr_t a_address) noexcept |
24 | 62 | { |
25 | | - static REL::Relocation<std::uintptr_t> vtbl{ a_id }; |
| 63 | + static REL::Relocation vtbl{ REL::Offset(a_address) }; |
26 | 64 | T::func = vtbl.write_vfunc(T::idx, T::thunk); |
27 | 65 | } |
28 | 66 |
|
29 | | - template <class To, class From> |
30 | | - constexpr void write_vfunc(const std::size_t a_vtableIdx = 0) noexcept |
| 67 | + template <class T, class U> |
| 68 | + constexpr void write_vfunc(const U a_id) noexcept |
| 69 | + requires(std::is_same_v<U, REL::ID> || std::is_same_v<U, REL::Offset>) |
31 | 70 | { |
32 | | - write_vfunc<From>(To::VTABLE[a_vtableIdx]); |
| 71 | + static REL::Relocation vtbl{ a_id }; |
| 72 | + T::func = vtbl.write_vfunc(T::idx, T::thunk); |
33 | 73 | } |
34 | 74 |
|
35 | | - template <class T, std::size_t Size = 5> |
36 | | - constexpr void write_thunk_jump(const std::uintptr_t a_src) noexcept |
| 75 | + template <class T, class U> |
| 76 | + constexpr void write_vfunc(const REL::Relocation<U> a_id) noexcept |
| 77 | + requires(std::is_same_v<typename REL::Relocation<U>::value_type, std::uintptr_t>) |
37 | 78 | { |
38 | | - AllocTrampoline(14); |
39 | | - auto& trampoline = GetTrampoline(); |
40 | | - T::func = trampoline.write_branch<Size>(a_src, T::thunk); |
| 79 | + T::func = a_id.write_vfunc(T::idx, T::thunk); |
| 80 | + } |
| 81 | + |
| 82 | + template <class To, class From> |
| 83 | + constexpr void write_vfunc(const std::size_t a_vtableIdx = 0) noexcept |
| 84 | + { |
| 85 | + write_vfunc<From>(To::VTABLE[a_vtableIdx]); |
41 | 86 | } |
42 | 87 |
|
43 | 88 | namespace detail |
|
0 commit comments