From c10386f3f660696bab89d7dfbed95b977d0f9ebf Mon Sep 17 00:00:00 2001 From: Orange Date: Fri, 3 Oct 2025 13:43:47 +0300 Subject: [PATCH 1/5] added rev_object --- include/omath/rev_eng/rev_object.hpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 include/omath/rev_eng/rev_object.hpp diff --git a/include/omath/rev_eng/rev_object.hpp b/include/omath/rev_eng/rev_object.hpp new file mode 100644 index 00000000..fe77b131 --- /dev/null +++ b/include/omath/rev_eng/rev_object.hpp @@ -0,0 +1,27 @@ +// +// Created by Vlad on 8/8/2025. +// + +#pragma once +#include +#include + +namespace omath::rev_eng +{ + class ReverseEngineeredObject + { + protected: + template + [[nodiscard]] Type& get_by_offset(const std::ptrdiff_t offset) const + { + return *reinterpret_cast(reinterpret_cast(this) + offset); + } + + template + ReturnType call_virtual_method(auto... arg_list) + { + using Func = ReturnType(__thiscall*)(void*, decltype(arg_list)...); + return (*static_cast(this))[id](this, arg_list...); + } + }; +} // namespace orev From 1ef7833bd9c1e1264fbe0eee73c243d3a26d0fd8 Mon Sep 17 00:00:00 2001 From: Orange Date: Fri, 3 Oct 2025 13:51:53 +0300 Subject: [PATCH 2/5] reordored omath headers --- include/omath/3d_primitives/box.hpp | 2 +- include/omath/3d_primitives/plane.hpp | 2 +- include/omath/collision/line_tracer.hpp | 2 +- include/omath/engines/iw_engine/constants.hpp | 4 ++-- include/omath/engines/opengl_engine/constants.hpp | 4 ++-- include/omath/engines/source_engine/constants.hpp | 4 ++-- include/omath/engines/unity_engine/constants.hpp | 4 ++-- include/omath/engines/unreal_engine/constants.hpp | 4 ++-- include/omath/{ => linear_algebra}/triangle.hpp | 2 +- include/omath/linear_algebra/vector3.hpp | 2 +- include/omath/omath.hpp | 10 +++++----- include/omath/projection/camera.hpp | 2 +- include/omath/{ => trigonometry}/angle.hpp | 2 +- include/omath/{ => trigonometry}/angles.hpp | 0 include/omath/{ => trigonometry}/view_angles.hpp | 0 include/omath/{ => utility}/color.hpp | 2 +- tests/general/unit_test_angle.cpp | 2 +- tests/general/unit_test_angles.cpp | 2 +- tests/general/unit_test_color.cpp | 3 +-- tests/general/unit_test_line_trace.cpp | 4 ++-- tests/general/unit_test_triangle.cpp | 2 +- tests/general/unit_test_view_angles.cpp | 2 +- 22 files changed, 30 insertions(+), 31 deletions(-) rename include/omath/{ => linear_algebra}/triangle.hpp (98%) rename include/omath/{ => trigonometry}/angle.hpp (99%) rename include/omath/{ => trigonometry}/angles.hpp (100%) rename include/omath/{ => trigonometry}/view_angles.hpp (100%) rename include/omath/{ => utility}/color.hpp (99%) diff --git a/include/omath/3d_primitives/box.hpp b/include/omath/3d_primitives/box.hpp index 3abb9a44..b039825f 100644 --- a/include/omath/3d_primitives/box.hpp +++ b/include/omath/3d_primitives/box.hpp @@ -3,8 +3,8 @@ // #pragma once +#include "omath/linear_algebra/triangle.hpp" #include "omath/linear_algebra/vector3.hpp" -#include "omath/triangle.hpp" #include namespace omath::primitives diff --git a/include/omath/3d_primitives/plane.hpp b/include/omath/3d_primitives/plane.hpp index 39c0f2c4..26f5871d 100644 --- a/include/omath/3d_primitives/plane.hpp +++ b/include/omath/3d_primitives/plane.hpp @@ -3,8 +3,8 @@ // #pragma once +#include "omath/linear_algebra/triangle.hpp" #include "omath/linear_algebra/vector3.hpp" -#include "omath/triangle.hpp" #include namespace omath::primitives diff --git a/include/omath/collision/line_tracer.hpp b/include/omath/collision/line_tracer.hpp index f2c16275..fb40f24a 100644 --- a/include/omath/collision/line_tracer.hpp +++ b/include/omath/collision/line_tracer.hpp @@ -3,8 +3,8 @@ // #pragma once +#include "omath/linear_algebra/triangle.hpp" #include "omath/linear_algebra/vector3.hpp" -#include "omath/triangle.hpp" namespace omath::collision { diff --git a/include/omath/engines/iw_engine/constants.hpp b/include/omath/engines/iw_engine/constants.hpp index 63d1177d..a9183fcf 100644 --- a/include/omath/engines/iw_engine/constants.hpp +++ b/include/omath/engines/iw_engine/constants.hpp @@ -5,8 +5,8 @@ #pragma once #include "omath/linear_algebra/mat.hpp" #include "omath/linear_algebra/vector3.hpp" -#include -#include +#include +#include namespace omath::iw_engine { diff --git a/include/omath/engines/opengl_engine/constants.hpp b/include/omath/engines/opengl_engine/constants.hpp index 4f5a955a..a4faa0da 100644 --- a/include/omath/engines/opengl_engine/constants.hpp +++ b/include/omath/engines/opengl_engine/constants.hpp @@ -5,8 +5,8 @@ #include "omath/linear_algebra/mat.hpp" #include "omath/linear_algebra/vector3.hpp" -#include -#include +#include +#include namespace omath::opengl_engine { diff --git a/include/omath/engines/source_engine/constants.hpp b/include/omath/engines/source_engine/constants.hpp index 33df18ba..743be74a 100644 --- a/include/omath/engines/source_engine/constants.hpp +++ b/include/omath/engines/source_engine/constants.hpp @@ -5,8 +5,8 @@ #include "omath/linear_algebra/mat.hpp" #include "omath/linear_algebra/vector3.hpp" -#include -#include +#include +#include namespace omath::source_engine { diff --git a/include/omath/engines/unity_engine/constants.hpp b/include/omath/engines/unity_engine/constants.hpp index 81151bc6..a938c1cc 100644 --- a/include/omath/engines/unity_engine/constants.hpp +++ b/include/omath/engines/unity_engine/constants.hpp @@ -6,8 +6,8 @@ #include "omath/linear_algebra/mat.hpp" #include "omath/linear_algebra/vector3.hpp" -#include -#include +#include +#include namespace omath::unity_engine { diff --git a/include/omath/engines/unreal_engine/constants.hpp b/include/omath/engines/unreal_engine/constants.hpp index e2e0eb7e..98ecf049 100644 --- a/include/omath/engines/unreal_engine/constants.hpp +++ b/include/omath/engines/unreal_engine/constants.hpp @@ -6,8 +6,8 @@ #include "omath/linear_algebra/mat.hpp" #include "omath/linear_algebra/vector3.hpp" -#include -#include +#include +#include namespace omath::unreal_engine { diff --git a/include/omath/triangle.hpp b/include/omath/linear_algebra/triangle.hpp similarity index 98% rename from include/omath/triangle.hpp rename to include/omath/linear_algebra/triangle.hpp index 519c48cb..b8a877c2 100644 --- a/include/omath/triangle.hpp +++ b/include/omath/linear_algebra/triangle.hpp @@ -2,7 +2,7 @@ // Created by Orange on 11/13/2024. // #pragma once -#include "linear_algebra/vector3.hpp" +#include "vector3.hpp" namespace omath { diff --git a/include/omath/linear_algebra/vector3.hpp b/include/omath/linear_algebra/vector3.hpp index 63e731e3..7228d817 100644 --- a/include/omath/linear_algebra/vector3.hpp +++ b/include/omath/linear_algebra/vector3.hpp @@ -4,7 +4,7 @@ #pragma once -#include "omath/angle.hpp" +#include "omath/trigonometry/angle.hpp" #include "omath/linear_algebra/vector2.hpp" #include #include diff --git a/include/omath/omath.hpp b/include/omath/omath.hpp index 474f927f..b2e62c5d 100644 --- a/include/omath/omath.hpp +++ b/include/omath/omath.hpp @@ -6,8 +6,8 @@ #pragma once // Basic math utilities -#include "omath/angles.hpp" -#include "omath/angle.hpp" +#include "omath/trigonometry/angles.hpp" +#include "omath/trigonometry/angle.hpp" // Vector classes (in dependency order) #include "omath/linear_algebra/vector2.hpp" @@ -18,11 +18,11 @@ #include "omath/linear_algebra/mat.hpp" // Color functionality -#include "omath/color.hpp" +#include "omath/utility/color.hpp" // Geometric primitives -#include "omath/triangle.hpp" -#include "omath/view_angles.hpp" +#include "omath/linear_algebra/triangle.hpp" +#include "omath/trigonometry/view_angles.hpp" // 3D primitives #include "omath/3d_primitives/box.hpp" diff --git a/include/omath/projection/camera.hpp b/include/omath/projection/camera.hpp index 7d7feb14..2e835dae 100644 --- a/include/omath/projection/camera.hpp +++ b/include/omath/projection/camera.hpp @@ -7,8 +7,8 @@ #include "omath/linear_algebra/mat.hpp" #include "omath/linear_algebra/vector3.hpp" #include "omath/projection/error_codes.hpp" +#include #include -#include #include #ifdef OMATH_BUILD_TESTS diff --git a/include/omath/angle.hpp b/include/omath/trigonometry/angle.hpp similarity index 99% rename from include/omath/angle.hpp rename to include/omath/trigonometry/angle.hpp index 993ddaee..ba785969 100644 --- a/include/omath/angle.hpp +++ b/include/omath/trigonometry/angle.hpp @@ -3,7 +3,7 @@ // #pragma once -#include "omath/angles.hpp" +#include "omath/trigonometry/angles.hpp" #include #include #include diff --git a/include/omath/angles.hpp b/include/omath/trigonometry/angles.hpp similarity index 100% rename from include/omath/angles.hpp rename to include/omath/trigonometry/angles.hpp diff --git a/include/omath/view_angles.hpp b/include/omath/trigonometry/view_angles.hpp similarity index 100% rename from include/omath/view_angles.hpp rename to include/omath/trigonometry/view_angles.hpp diff --git a/include/omath/color.hpp b/include/omath/utility/color.hpp similarity index 99% rename from include/omath/color.hpp rename to include/omath/utility/color.hpp index 7d720366..cfacee80 100644 --- a/include/omath/color.hpp +++ b/include/omath/utility/color.hpp @@ -4,7 +4,7 @@ #pragma once -#include "linear_algebra/vector4.hpp" +#include "omath/linear_algebra/vector4.hpp" #include namespace omath diff --git a/tests/general/unit_test_angle.cpp b/tests/general/unit_test_angle.cpp index 3fafd24e..0e4c7ba0 100644 --- a/tests/general/unit_test_angle.cpp +++ b/tests/general/unit_test_angle.cpp @@ -2,10 +2,10 @@ // Created by Orange on 11/30/2024. // +#include #include #include #include -#include using namespace omath; diff --git a/tests/general/unit_test_angles.cpp b/tests/general/unit_test_angles.cpp index 94ba0eff..42f81741 100644 --- a/tests/general/unit_test_angles.cpp +++ b/tests/general/unit_test_angles.cpp @@ -1,8 +1,8 @@ // // Created by Orange on 11/30/2024. // +#include #include -#include TEST(unit_test_angles, radians_to_deg) { diff --git a/tests/general/unit_test_color.cpp b/tests/general/unit_test_color.cpp index 0f0d332b..0112fd12 100644 --- a/tests/general/unit_test_color.cpp +++ b/tests/general/unit_test_color.cpp @@ -1,9 +1,8 @@ // // Created by Vlad on 01.09.2024. // +#include #include -#include - using namespace omath; diff --git a/tests/general/unit_test_line_trace.cpp b/tests/general/unit_test_line_trace.cpp index 31cb6a79..8387c4cb 100644 --- a/tests/general/unit_test_line_trace.cpp +++ b/tests/general/unit_test_line_trace.cpp @@ -2,9 +2,9 @@ // Revised unit‑test suite for LineTracer (segment‑based Möller–Trumbore) // Pure ASCII: avoids non‑standard characters that MSVC rejects. // -#include "omath/linear_algebra/vector3.hpp" +#include "omath/linear_algebra/triangle.hpp" #include "omath/collision/line_tracer.hpp" -#include "omath/triangle.hpp" +#include "omath/linear_algebra/vector3.hpp" #include "gtest/gtest.h" #include diff --git a/tests/general/unit_test_triangle.cpp b/tests/general/unit_test_triangle.cpp index 643ecdc2..a4e4b912 100644 --- a/tests/general/unit_test_triangle.cpp +++ b/tests/general/unit_test_triangle.cpp @@ -1,7 +1,7 @@ // // Created by Orange on 1/6/2025. // -#include "omath/triangle.hpp" +#include "omath/linear_algebra/triangle.hpp" #include "omath/linear_algebra/vector3.hpp" #include // For std::sqrt, std::isinf, std::isnan #include diff --git a/tests/general/unit_test_view_angles.cpp b/tests/general/unit_test_view_angles.cpp index 28605456..ed45c11c 100644 --- a/tests/general/unit_test_view_angles.cpp +++ b/tests/general/unit_test_view_angles.cpp @@ -1,4 +1,4 @@ // // Created by Orange on 11/30/2024. // -#include \ No newline at end of file +#include \ No newline at end of file From 74381eda5cb11f34fe197f2aac13df3d3a2dde2b Mon Sep 17 00:00:00 2001 From: Orange Date: Sat, 4 Oct 2025 09:47:48 +0300 Subject: [PATCH 3/5] added external class --- include/omath/rev_eng/external_rev_object.hpp | 35 +++++++++++++++++++ include/omath/rev_eng/internal_rev_object.hpp | 33 +++++++++++++++++ include/omath/rev_eng/rev_object.hpp | 27 -------------- 3 files changed, 68 insertions(+), 27 deletions(-) create mode 100644 include/omath/rev_eng/external_rev_object.hpp create mode 100644 include/omath/rev_eng/internal_rev_object.hpp delete mode 100644 include/omath/rev_eng/rev_object.hpp diff --git a/include/omath/rev_eng/external_rev_object.hpp b/include/omath/rev_eng/external_rev_object.hpp new file mode 100644 index 00000000..9d42b72e --- /dev/null +++ b/include/omath/rev_eng/external_rev_object.hpp @@ -0,0 +1,35 @@ +// +// Created by Vlad on 10/4/2025. +// + +#pragma once +#include +#include + +namespace omath::rev_eng +{ + template + class ExternalReverseEngineeredObject + { + public: + explicit ExternalReverseEngineeredObject(const std::uintptr_t addr): m_object_address(addr) + { + } + private: + std::uintptr_t m_object_address{}; + + protected: + template + [[nodiscard]] + Type get_by_offset(const std::ptrdiff_t offset) const + { + return ExternalMemoryManagementTrait::read_memory(m_object_address+offset); + } + + template + void set_by_offset(const std::ptrdiff_t offset, const Type& value) const + { + return ExternalMemoryManagementTrait::write_memory(m_object_address+offset, value); + } + }; +} // namespace omath::rev_eng \ No newline at end of file diff --git a/include/omath/rev_eng/internal_rev_object.hpp b/include/omath/rev_eng/internal_rev_object.hpp new file mode 100644 index 00000000..f7c19ad4 --- /dev/null +++ b/include/omath/rev_eng/internal_rev_object.hpp @@ -0,0 +1,33 @@ +// +// Created by Vlad on 8/8/2025. +// + +#pragma once +#include +#include + +namespace omath::rev_eng +{ + class InternalReverseEngineeredObject + { + protected: + template + [[nodiscard]] Type& get_by_offset(const std::ptrdiff_t offset) + { + return *reinterpret_cast(reinterpret_cast(this) + offset); + } + + template + [[nodiscard]] const Type& get_by_offset(const std::ptrdiff_t offset) const + { + return *reinterpret_cast(reinterpret_cast(this) + offset); + } + + template + ReturnType call_virtual_method(auto&&... arg_list) + { + using VirtualMethodType = ReturnType(__thiscall*)(void*, decltype(arg_list)...); + return (*static_cast(this))[id](this, arg_list...); + } + }; +} // namespace omath::rev_eng diff --git a/include/omath/rev_eng/rev_object.hpp b/include/omath/rev_eng/rev_object.hpp deleted file mode 100644 index fe77b131..00000000 --- a/include/omath/rev_eng/rev_object.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// -// Created by Vlad on 8/8/2025. -// - -#pragma once -#include -#include - -namespace omath::rev_eng -{ - class ReverseEngineeredObject - { - protected: - template - [[nodiscard]] Type& get_by_offset(const std::ptrdiff_t offset) const - { - return *reinterpret_cast(reinterpret_cast(this) + offset); - } - - template - ReturnType call_virtual_method(auto... arg_list) - { - using Func = ReturnType(__thiscall*)(void*, decltype(arg_list)...); - return (*static_cast(this))[id](this, arg_list...); - } - }; -} // namespace orev From dc6edbb67f23fdf1f5e193321338626b6e154010 Mon Sep 17 00:00:00 2001 From: Orange Date: Sat, 4 Oct 2025 09:52:14 +0300 Subject: [PATCH 4/5] update global header --- include/omath/omath.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/omath/omath.hpp b/include/omath/omath.hpp index b2e62c5d..04273175 100644 --- a/include/omath/omath.hpp +++ b/include/omath/omath.hpp @@ -82,3 +82,7 @@ #include "omath/engines/unreal_engine/camera.hpp" #include "omath/engines/unreal_engine/traits/camera_trait.hpp" #include "omath/engines/unreal_engine/traits/pred_engine_trait.hpp" + +// Reverse Engineering +#include "omath/rev_eng/external_rev_object.hpp" +#include "omath/rev_eng/internal_rev_object.hpp" \ No newline at end of file From cbee8c2c955c6525bff30a7b35c8a4639de14922 Mon Sep 17 00:00:00 2001 From: Orange Date: Sat, 4 Oct 2025 10:04:34 +0300 Subject: [PATCH 5/5] finished test --- include/omath/rev_eng/internal_rev_object.hpp | 4 +- .../general/unit_test_reverse_enineering.cpp | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 tests/general/unit_test_reverse_enineering.cpp diff --git a/include/omath/rev_eng/internal_rev_object.hpp b/include/omath/rev_eng/internal_rev_object.hpp index f7c19ad4..63249fbb 100644 --- a/include/omath/rev_eng/internal_rev_object.hpp +++ b/include/omath/rev_eng/internal_rev_object.hpp @@ -24,10 +24,10 @@ namespace omath::rev_eng } template - ReturnType call_virtual_method(auto&&... arg_list) + ReturnType call_virtual_method(auto... arg_list) { using VirtualMethodType = ReturnType(__thiscall*)(void*, decltype(arg_list)...); - return (*static_cast(this))[id](this, arg_list...); + return (*reinterpret_cast(this))[id](this, arg_list...); } }; } // namespace omath::rev_eng diff --git a/tests/general/unit_test_reverse_enineering.cpp b/tests/general/unit_test_reverse_enineering.cpp new file mode 100644 index 00000000..a7ddbda1 --- /dev/null +++ b/tests/general/unit_test_reverse_enineering.cpp @@ -0,0 +1,50 @@ +// +// Created by Vlad on 10/4/2025. +// +#include "omath/linear_algebra/vector3.hpp" +#include +#include + +class Player final +{ +public: + virtual int foo() {return 1;} + virtual int bar() {return 2;} + omath::Vector3 m_origin{1.f, 2.f, 3.f}; + int m_health{123}; +}; + +class RevPlayer : omath::rev_eng::InternalReverseEngineeredObject +{ +public: + omath::Vector3 get_origin() + { + return get_by_offset>(sizeof(std::uintptr_t)); + } + int get_health() + { + return get_by_offset(sizeof(std::uintptr_t)+sizeof(omath::Vector3)); + } + + int rev_foo() + { + return call_virtual_method<0, int>(); + } + int rev_bar() + { + return call_virtual_method<1, int>(); + } +}; + + +TEST(unit_test_reverse_enineering, read_test) +{ + Player player_original; + const auto player_reversed = reinterpret_cast(&player_original); + + EXPECT_EQ(player_original.m_origin, player_reversed->get_origin()); + EXPECT_EQ(player_original.m_health, player_reversed->get_health()); + + EXPECT_EQ(player_original.bar(), player_reversed->rev_bar()); + EXPECT_EQ(player_original.foo(), player_reversed->rev_foo()); +} \ No newline at end of file