From ade281cdd22f4d457c2eaa4bcee8d9717651428d Mon Sep 17 00:00:00 2001 From: Orange Date: Sat, 1 Nov 2025 13:28:34 +0300 Subject: [PATCH] Adds const version of rev_bar method Adds a const overload for the `rev_bar` virtual method. This allows calling the method on const instances of the reverse engineered class. --- include/omath/rev_eng/internal_rev_object.hpp | 20 +++++++++++++++---- .../general/unit_test_reverse_enineering.cpp | 5 +++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/include/omath/rev_eng/internal_rev_object.hpp b/include/omath/rev_eng/internal_rev_object.hpp index fc293d2..0f05d41 100644 --- a/include/omath/rev_eng/internal_rev_object.hpp +++ b/include/omath/rev_eng/internal_rev_object.hpp @@ -23,15 +23,27 @@ namespace omath::rev_eng return *reinterpret_cast(reinterpret_cast(this) + offset); } - template - ReturnType call_virtual_method(auto... arg_list) + template + ReturnType call_virtual_method(Args&&... arg_list) { #ifdef _MSC_VER using VirtualMethodType = ReturnType(__thiscall*)(void*, decltype(arg_list)...); #else - using VirtualMethodType = ReturnType(*)(void*, decltype(arg_list)...); + using VirtualMethodType = ReturnType (*)(void*, decltype(arg_list)...); #endif - return (*reinterpret_cast(this))[id](this, arg_list...); + return (*reinterpret_cast(this))[id](this, std::forward(arg_list)...); + } + template + ReturnType call_virtual_method(Args&&... arg_list) const + { + using This = std::remove_cv_t>; +#ifdef _MSC_VER + using VirtualMethodType = ReturnType(__thiscall*)(const void*, decltype(arg_list)...); +#else + using VirtualMethodType = ReturnType (*)(void*, decltype(arg_list)...); +#endif + return (*reinterpret_cast(const_cast(this)))[id]( + this, std::forward(arg_list)...); } }; } // namespace omath::rev_eng diff --git a/tests/general/unit_test_reverse_enineering.cpp b/tests/general/unit_test_reverse_enineering.cpp index a7ddbda..a2c5ddd 100644 --- a/tests/general/unit_test_reverse_enineering.cpp +++ b/tests/general/unit_test_reverse_enineering.cpp @@ -34,6 +34,10 @@ public: { return call_virtual_method<1, int>(); } + [[nodiscard]] int rev_bar_const() const + { + return call_virtual_method<1, int>(); + } }; @@ -47,4 +51,5 @@ TEST(unit_test_reverse_enineering, read_test) EXPECT_EQ(player_original.bar(), player_reversed->rev_bar()); EXPECT_EQ(player_original.foo(), player_reversed->rev_foo()); + EXPECT_EQ(player_original.bar(), player_reversed->rev_bar_const()); } \ No newline at end of file