mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-18 15:23:26 +00:00
replaced with table offset
This commit is contained in:
@@ -116,11 +116,11 @@ namespace omath::rev_eng
|
||||
return call_method<ReturnType>(vtable[Id], arg_list...);
|
||||
}
|
||||
|
||||
template<std::size_t TableIndex, std::size_t Id, class ReturnType>
|
||||
template<std::ptrdiff_t TableOffset, std::size_t Id, class ReturnType>
|
||||
ReturnType call_virtual_method(auto... arg_list)
|
||||
{
|
||||
auto sub_this = reinterpret_cast<void*>(
|
||||
reinterpret_cast<std::uintptr_t>(this) + TableIndex * sizeof(std::uintptr_t));
|
||||
reinterpret_cast<std::uintptr_t>(this) + TableOffset);
|
||||
const auto vtable = *reinterpret_cast<void***>(sub_this);
|
||||
#ifdef _MSC_VER
|
||||
using Fn = ReturnType(__thiscall*)(void*, decltype(arg_list)...);
|
||||
@@ -129,11 +129,11 @@ namespace omath::rev_eng
|
||||
#endif
|
||||
return reinterpret_cast<Fn>(vtable[Id])(sub_this, arg_list...);
|
||||
}
|
||||
template<std::size_t TableIndex, std::size_t Id, class ReturnType>
|
||||
template<std::ptrdiff_t TableOffset, std::size_t Id, class ReturnType>
|
||||
ReturnType call_virtual_method(auto... arg_list) const
|
||||
{
|
||||
auto sub_this = reinterpret_cast<const void*>(
|
||||
reinterpret_cast<std::uintptr_t>(this) + TableIndex * sizeof(std::uintptr_t));
|
||||
reinterpret_cast<std::uintptr_t>(this) + TableOffset);
|
||||
const auto vtable = *reinterpret_cast<void* const* const*>(sub_this);
|
||||
#ifdef _MSC_VER
|
||||
using Fn = ReturnType(__thiscall*)(const void*, decltype(arg_list)...);
|
||||
|
||||
@@ -52,18 +52,20 @@ public:
|
||||
|
||||
class RevMultiPlayer final : omath::rev_eng::InternalReverseEngineeredObject
|
||||
{
|
||||
static constexpr std::ptrdiff_t TABLE_A_OFFSET = 0;
|
||||
static constexpr std::ptrdiff_t TABLE_B_OFFSET = sizeof(void*);
|
||||
public:
|
||||
// Table 0 (BaseA vtable): index 0 = get_a, 1 = get_a2
|
||||
[[nodiscard]] int rev_get_a() const { return call_virtual_method<0, 0, int>(); }
|
||||
[[nodiscard]] int rev_get_a2() const { return call_virtual_method<0, 1, int>(); }
|
||||
// Table at offset 0 (BaseA vtable): index 0 = get_a, 1 = get_a2
|
||||
[[nodiscard]] int rev_get_a() const { return call_virtual_method<TABLE_A_OFFSET, 0, int>(); }
|
||||
[[nodiscard]] int rev_get_a2() const { return call_virtual_method<TABLE_A_OFFSET, 1, int>(); }
|
||||
|
||||
// Table 1 (BaseB vtable): index 0 = get_b, 1 = get_b2
|
||||
[[nodiscard]] int rev_get_b() const { return call_virtual_method<1, 0, int>(); }
|
||||
[[nodiscard]] int rev_get_b2() const { return call_virtual_method<1, 1, int>(); }
|
||||
// Table at offset sizeof(void*) (BaseB vtable): index 0 = get_b, 1 = get_b2
|
||||
[[nodiscard]] int rev_get_b() const { return call_virtual_method<TABLE_B_OFFSET, 0, int>(); }
|
||||
[[nodiscard]] int rev_get_b2() const { return call_virtual_method<TABLE_B_OFFSET, 1, int>(); }
|
||||
|
||||
// Non-const versions
|
||||
int rev_get_a_mut() { return call_virtual_method<0, 0, int>(); }
|
||||
int rev_get_b_mut() { return call_virtual_method<1, 0, int>(); }
|
||||
int rev_get_a_mut() { return call_virtual_method<TABLE_A_OFFSET, 0, int>(); }
|
||||
int rev_get_b_mut() { return call_virtual_method<TABLE_B_OFFSET, 0, int>(); }
|
||||
};
|
||||
|
||||
class RevPlayer final : omath::rev_eng::InternalReverseEngineeredObject
|
||||
|
||||
Reference in New Issue
Block a user