mirror of
https://github.com/orange-cpp/omath.git
synced 2026-08-08 14:02:06 +00:00
Compare commits
6 Commits
8a591ce769
...
6a5771e57d
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a5771e57d | |||
| 58c082d399 | |||
| 11e6f67e23 | |||
| d7f9ab6e85 | |||
| ceecdde9dc | |||
| a546c1a6d1 |
@@ -265,13 +265,14 @@ namespace omath
|
|||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
|
||||||
template<> struct std::hash<omath::Vector2<float>>
|
template<class Type>
|
||||||
|
struct std::hash<omath::Vector2<Type>> // NOLINT(*-dcl58-cpp)
|
||||||
{
|
{
|
||||||
[[nodiscard("You must use hash value")]]
|
[[nodiscard("You must use hash value")]]
|
||||||
std::size_t operator()(const omath::Vector2<float>& vec) const noexcept
|
std::size_t operator()(const omath::Vector2<Type>& vec) const noexcept
|
||||||
{
|
{
|
||||||
std::size_t hash = 0;
|
std::size_t hash = 0;
|
||||||
constexpr std::hash<float> hasher;
|
constexpr std::hash<Type> hasher;
|
||||||
|
|
||||||
hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
@@ -284,7 +285,7 @@ template<class Type>
|
|||||||
struct std::formatter<omath::Vector2<Type>> // NOLINT(*-dcl58-cpp)
|
struct std::formatter<omath::Vector2<Type>> // NOLINT(*-dcl58-cpp)
|
||||||
{
|
{
|
||||||
[[nodiscard("You must use parse iterator")]]
|
[[nodiscard("You must use parse iterator")]]
|
||||||
static constexpr auto parse(std::format_parse_context& ctx)
|
static constexpr auto parse(std::format_parse_context& ctx) noexcept
|
||||||
{
|
{
|
||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -318,14 +318,15 @@ namespace omath
|
|||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
|
||||||
template<> struct std::hash<omath::Vector3<float>>
|
template<class Type>
|
||||||
|
struct std::hash<omath::Vector3<Type>> // NOLINT(*-dcl58-cpp)
|
||||||
{
|
{
|
||||||
// NOTE: Cannot be constexpr because of MSVC
|
// NOTE: Cannot be constexpr because of MSVC
|
||||||
[[nodiscard("You must use hash value")]]
|
[[nodiscard("You must use hash value")]]
|
||||||
std::size_t operator()(const omath::Vector3<float>& vec) const noexcept
|
std::size_t operator()(const omath::Vector3<Type>& vec) const noexcept
|
||||||
{
|
{
|
||||||
std::size_t hash = 0;
|
std::size_t hash = 0;
|
||||||
constexpr std::hash<float> hasher;
|
constexpr std::hash<Type> hasher;
|
||||||
|
|
||||||
hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
@@ -339,7 +340,7 @@ template<class Type>
|
|||||||
struct std::formatter<omath::Vector3<Type>> // NOLINT(*-dcl58-cpp)
|
struct std::formatter<omath::Vector3<Type>> // NOLINT(*-dcl58-cpp)
|
||||||
{
|
{
|
||||||
[[nodiscard("You must use parse iterator")]]
|
[[nodiscard("You must use parse iterator")]]
|
||||||
static constexpr auto parse(std::format_parse_context& ctx)
|
static constexpr auto parse(std::format_parse_context& ctx) noexcept
|
||||||
{
|
{
|
||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,13 +225,14 @@ namespace omath
|
|||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
|
||||||
template<> struct std::hash<omath::Vector4<float>>
|
template<class Type>
|
||||||
|
struct std::hash<omath::Vector4<Type>> // NOLINT(*-dcl58-cpp)
|
||||||
{
|
{
|
||||||
[[nodiscard("You must use hash value")]]
|
[[nodiscard("You must use hash value")]]
|
||||||
std::size_t operator()(const omath::Vector4<float>& vec) const noexcept
|
std::size_t operator()(const omath::Vector4<Type>& vec) const noexcept
|
||||||
{
|
{
|
||||||
std::size_t hash = 0;
|
std::size_t hash = 0;
|
||||||
constexpr std::hash<float> hasher;
|
constexpr std::hash<Type> hasher;
|
||||||
|
|
||||||
hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
|
||||||
@@ -240,12 +241,11 @@ template<> struct std::hash<omath::Vector4<float>>
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
struct std::formatter<omath::Vector4<Type>> // NOLINT(*-dcl58-cpp)
|
struct std::formatter<omath::Vector4<Type>> // NOLINT(*-dcl58-cpp)
|
||||||
{
|
{
|
||||||
[[nodiscard("You must use parse iterator")]]
|
[[nodiscard("You must use parse iterator")]]
|
||||||
static constexpr auto parse(std::format_parse_context& ctx)
|
static constexpr auto parse(std::format_parse_context& ctx) noexcept
|
||||||
{
|
{
|
||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,7 +238,8 @@ namespace omath::projection
|
|||||||
return m_view_projection_matrix.value();
|
return m_view_projection_matrix.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard("You must use view matrix")]] constexpr const Mat4X4Type& get_view_matrix() const noexcept
|
[[nodiscard("You must use view matrix")]]
|
||||||
|
constexpr const Mat4X4Type& get_view_matrix() const noexcept
|
||||||
{
|
{
|
||||||
if (!m_view_matrix.has_value())
|
if (!m_view_matrix.has_value())
|
||||||
m_view_matrix = calc_view_matrix();
|
m_view_matrix = calc_view_matrix();
|
||||||
@@ -295,27 +296,32 @@ namespace omath::projection
|
|||||||
m_projection_matrix = std::nullopt;
|
m_projection_matrix = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard("You must use field of view")]] constexpr const FieldOfView& get_field_of_view() const noexcept
|
[[nodiscard("You must use field of view")]]
|
||||||
|
constexpr const FieldOfView& get_field_of_view() const noexcept
|
||||||
{
|
{
|
||||||
return m_field_of_view;
|
return m_field_of_view;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard("You must use near plane")]] constexpr const NumericType& get_near_plane() const noexcept
|
[[nodiscard("You must use near plane")]]
|
||||||
|
constexpr const NumericType& get_near_plane() const noexcept
|
||||||
{
|
{
|
||||||
return m_near_plane_distance;
|
return m_near_plane_distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard("You must use far plane")]] constexpr const NumericType& get_far_plane() const noexcept
|
[[nodiscard("You must use far plane")]]
|
||||||
|
constexpr const NumericType& get_far_plane() const noexcept
|
||||||
{
|
{
|
||||||
return m_far_plane_distance;
|
return m_far_plane_distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard("You must use view angles")]] constexpr const ViewAnglesType& get_view_angles() const noexcept
|
[[nodiscard("You must use view angles")]]
|
||||||
|
constexpr const ViewAnglesType& get_view_angles() const noexcept
|
||||||
{
|
{
|
||||||
return m_view_angles;
|
return m_view_angles;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard("You must use origin")]] constexpr const Vector3<NumericType>& get_origin() const noexcept
|
[[nodiscard("You must use origin")]]
|
||||||
|
constexpr const Vector3<NumericType>& get_origin() const noexcept
|
||||||
{
|
{
|
||||||
return m_origin;
|
return m_origin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,36 +21,20 @@
|
|||||||
|
|
||||||
namespace omath::rev_eng
|
namespace omath::rev_eng
|
||||||
{
|
{
|
||||||
template<std::size_t N>
|
|
||||||
struct FixedString final
|
|
||||||
{
|
|
||||||
char data[N]{};
|
|
||||||
// ReSharper disable once CppNonExplicitConvertingConstructor
|
|
||||||
constexpr FixedString(const char (&str)[N]) noexcept // NOLINT(*-explicit-constructor)
|
|
||||||
{
|
|
||||||
for (std::size_t i = 0; i < N; ++i)
|
|
||||||
data[i] = str[i];
|
|
||||||
}
|
|
||||||
// ReSharper disable once CppNonExplicitConversionOperator
|
|
||||||
constexpr operator std::string_view() const noexcept // NOLINT(*-explicit-constructor)
|
|
||||||
{
|
|
||||||
return {data, N - 1};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
template<std::size_t N>
|
|
||||||
FixedString(const char (&)[N]) -> FixedString<N>;
|
|
||||||
|
|
||||||
class InternalReverseEngineeredObject
|
class InternalReverseEngineeredObject
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
template<class Type>
|
template<class Type>
|
||||||
[[nodiscard]] Type& get_by_offset(const std::ptrdiff_t offset)
|
[[nodiscard("You must use value")]]
|
||||||
|
Type& get_by_offset(const std::ptrdiff_t offset) noexcept
|
||||||
{
|
{
|
||||||
return *reinterpret_cast<Type*>(reinterpret_cast<std::uintptr_t>(this) + offset);
|
return *reinterpret_cast<Type*>(reinterpret_cast<std::uintptr_t>(this) + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
[[nodiscard]] const Type& get_by_offset(const std::ptrdiff_t offset) const
|
[[nodiscard("You must use value")]]
|
||||||
|
const Type& get_by_offset(const std::ptrdiff_t offset) const noexcept
|
||||||
{
|
{
|
||||||
return *reinterpret_cast<Type*>(reinterpret_cast<std::uintptr_t>(this) + offset);
|
return *reinterpret_cast<Type*>(reinterpret_cast<std::uintptr_t>(this) + offset);
|
||||||
}
|
}
|
||||||
@@ -76,14 +60,16 @@ namespace omath::rev_eng
|
|||||||
return reinterpret_cast<MethodType>(const_cast<void*>(ptr))(this, arg_list...);
|
return reinterpret_cast<MethodType>(const_cast<void*>(ptr))(this, arg_list...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<FixedString ModuleName, FixedString Pattern, class ReturnType>
|
template<PatternScanner::ConstevalPattern ModuleName, PatternScanner::ConstevalPattern Pattern,
|
||||||
|
class ReturnType>
|
||||||
ReturnType call_method(auto... arg_list)
|
ReturnType call_method(auto... arg_list)
|
||||||
{
|
{
|
||||||
static const auto* address = resolve_pattern(ModuleName, Pattern);
|
static const auto* address = resolve_pattern(ModuleName, Pattern);
|
||||||
return call_method<ReturnType>(address, arg_list...);
|
return call_method<ReturnType>(address, arg_list...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<FixedString ModuleName, FixedString Pattern, class ReturnType>
|
template<PatternScanner::ConstevalPattern ModuleName, PatternScanner::ConstevalPattern Pattern,
|
||||||
|
class ReturnType>
|
||||||
ReturnType call_method(auto... arg_list) const
|
ReturnType call_method(auto... arg_list) const
|
||||||
{
|
{
|
||||||
static const auto* address = resolve_pattern(ModuleName, Pattern);
|
static const auto* address = resolve_pattern(ModuleName, Pattern);
|
||||||
@@ -98,7 +84,8 @@ namespace omath::rev_eng
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class ReturnType>
|
template<class ReturnType>
|
||||||
ReturnType call_method(const std::string_view& module_name,const std::string_view& pattern, auto... arg_list) const
|
ReturnType call_method(const std::string_view& module_name, const std::string_view& pattern,
|
||||||
|
auto... arg_list) const
|
||||||
{
|
{
|
||||||
static const auto* address = resolve_pattern(module_name, pattern);
|
static const auto* address = resolve_pattern(module_name, pattern);
|
||||||
return call_method<ReturnType>(address, arg_list...);
|
return call_method<ReturnType>(address, arg_list...);
|
||||||
@@ -119,8 +106,7 @@ namespace omath::rev_eng
|
|||||||
template<std::ptrdiff_t TableOffset, std::size_t Id, class ReturnType>
|
template<std::ptrdiff_t TableOffset, std::size_t Id, class ReturnType>
|
||||||
ReturnType call_virtual_method(auto... arg_list)
|
ReturnType call_virtual_method(auto... arg_list)
|
||||||
{
|
{
|
||||||
auto sub_this = reinterpret_cast<void*>(
|
auto sub_this = reinterpret_cast<void*>(reinterpret_cast<std::uintptr_t>(this) + TableOffset);
|
||||||
reinterpret_cast<std::uintptr_t>(this) + TableOffset);
|
|
||||||
const auto vtable = *reinterpret_cast<void***>(sub_this);
|
const auto vtable = *reinterpret_cast<void***>(sub_this);
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
using Fn = ReturnType(__thiscall*)(void*, decltype(arg_list)...);
|
using Fn = ReturnType(__thiscall*)(void*, decltype(arg_list)...);
|
||||||
@@ -132,8 +118,7 @@ namespace omath::rev_eng
|
|||||||
template<std::ptrdiff_t TableOffset, 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
|
ReturnType call_virtual_method(auto... arg_list) const
|
||||||
{
|
{
|
||||||
auto sub_this = reinterpret_cast<const void*>(
|
auto sub_this = reinterpret_cast<const void*>(reinterpret_cast<std::uintptr_t>(this) + TableOffset);
|
||||||
reinterpret_cast<std::uintptr_t>(this) + TableOffset);
|
|
||||||
const auto vtable = *reinterpret_cast<void* const* const*>(sub_this);
|
const auto vtable = *reinterpret_cast<void* const* const*>(sub_this);
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
using Fn = ReturnType(__thiscall*)(const void*, decltype(arg_list)...);
|
using Fn = ReturnType(__thiscall*)(const void*, decltype(arg_list)...);
|
||||||
@@ -161,8 +146,8 @@ namespace omath::rev_eng
|
|||||||
return reinterpret_cast<const void*>(*result);
|
return reinterpret_cast<const void*>(*result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard("You forgot to use module base address")]]
|
||||||
static const void* get_module_base(const std::string_view module_name)
|
static const void* get_module_base(const std::string_view module_name) noexcept
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return GetModuleHandleA(module_name.data());
|
return GetModuleHandleA(module_name.data());
|
||||||
|
|||||||
@@ -38,17 +38,24 @@ namespace omath
|
|||||||
friend unit_test_pattern_scan_consteval_spacing_and_case_Test;
|
friend unit_test_pattern_scan_consteval_spacing_and_case_Test;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template<std::size_t N>
|
template<std::size_t Length>
|
||||||
struct ConstevalPattern final
|
struct ConstevalPattern final
|
||||||
{
|
{
|
||||||
char value[N]{};
|
char value[Length]{};
|
||||||
|
|
||||||
// ReSharper disable once CppNonExplicitConvertingConstructor
|
// ReSharper disable once CppNonExplicitConvertingConstructor
|
||||||
constexpr ConstevalPattern(const char (&text)[N]) // NOLINT(*-explicit-constructor)
|
constexpr ConstevalPattern(const char (&text)[Length]) // NOLINT(*-explicit-constructor)
|
||||||
{
|
{
|
||||||
std::ranges::copy(text, value);
|
std::ranges::copy(text, value);
|
||||||
}
|
}
|
||||||
|
[[nodiscard("You forgot to use string")]]
|
||||||
|
constexpr operator std::string_view() const noexcept // NOLINT(*-explicit-constructor)
|
||||||
|
{
|
||||||
|
return {value, Length - 1};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
template<std::size_t N>
|
||||||
|
ConstevalPattern(const char (&)[N]) -> ConstevalPattern<N>;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static std::span<std::byte>::iterator scan_for_pattern(const std::span<std::byte>& range,
|
static std::span<std::byte>::iterator scan_for_pattern(const std::span<std::byte>& range,
|
||||||
|
|||||||
Reference in New Issue
Block a user