mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-20 02:43:27 +00:00
Compare commits
5 Commits
feature/vm
...
646a920e4c
| Author | SHA1 | Date | |
|---|---|---|---|
| 646a920e4c | |||
| 52687a70c7 | |||
| a9eff7d320 | |||
| 211e4c3d9b | |||
| 74dc2234f7 |
7
.idea/dictionaries/project.xml
generated
7
.idea/dictionaries/project.xml
generated
@@ -1,7 +0,0 @@
|
|||||||
<component name="ProjectDictionaryState">
|
|
||||||
<dictionary name="project">
|
|
||||||
<words>
|
|
||||||
<w>vmprotect</w>
|
|
||||||
</words>
|
|
||||||
</dictionary>
|
|
||||||
</component>
|
|
||||||
@@ -31,10 +31,6 @@ option(OMATH_SUPRESS_SAFETY_CHECKS
|
|||||||
option(OMATH_ENABLE_COVERAGE "Enable coverage" OFF)
|
option(OMATH_ENABLE_COVERAGE "Enable coverage" OFF)
|
||||||
option(OMATH_ENABLE_FORCE_INLINE
|
option(OMATH_ENABLE_FORCE_INLINE
|
||||||
"Will for compiler to make some functions to be force inlined no matter what" ON)
|
"Will for compiler to make some functions to be force inlined no matter what" ON)
|
||||||
option(OMATH_VMPROTECT_INTEGRATION
|
|
||||||
"omath will use vmprotect sdk to protect sensitive parts of code from reverse engineering"
|
|
||||||
OFF)
|
|
||||||
|
|
||||||
if(VCPKG_MANIFEST_FEATURES)
|
if(VCPKG_MANIFEST_FEATURES)
|
||||||
foreach(omath_feature IN LISTS VCPKG_MANIFEST_FEATURES)
|
foreach(omath_feature IN LISTS VCPKG_MANIFEST_FEATURES)
|
||||||
if(omath_feature STREQUAL "imgui")
|
if(omath_feature STREQUAL "imgui")
|
||||||
@@ -47,8 +43,6 @@ if(VCPKG_MANIFEST_FEATURES)
|
|||||||
set(OMATH_BUILD_BENCHMARK ON)
|
set(OMATH_BUILD_BENCHMARK ON)
|
||||||
elseif(omath_feature STREQUAL "examples")
|
elseif(omath_feature STREQUAL "examples")
|
||||||
set(OMATH_BUILD_EXAMPLES ON)
|
set(OMATH_BUILD_EXAMPLES ON)
|
||||||
elseif(omath_feature STREQUAL "vmprotect")
|
|
||||||
set(OMATH_VMPROTECT_INTEGRATION ON)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endforeach()
|
endforeach()
|
||||||
@@ -113,11 +107,6 @@ if(OMATH_IMGUI_INTEGRATION)
|
|||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(OMATH_VMPROTECT_INTEGRATION)
|
|
||||||
find_package(vmprotect_sdk CONFIG REQUIRED)
|
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC vmprotect_sdk::vmprotect_sdk)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(OMATH_USE_AVX2)
|
if(OMATH_USE_AVX2)
|
||||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_USE_AVX2)
|
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_USE_AVX2)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -145,7 +145,7 @@
|
|||||||
"hidden": true,
|
"hidden": true,
|
||||||
"inherits": ["linux-base", "vcpkg-base"],
|
"inherits": ["linux-base", "vcpkg-base"],
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
"VCPKG_MANIFEST_FEATURES": "tests;imgui;avx2;vmprotect;examples"
|
"VCPKG_MANIFEST_FEATURES": "tests;imgui;avx2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ add_subdirectory(example_barycentric)
|
|||||||
add_subdirectory(example_glfw3)
|
add_subdirectory(example_glfw3)
|
||||||
add_subdirectory(example_proj_mat_builder)
|
add_subdirectory(example_proj_mat_builder)
|
||||||
add_subdirectory(example_signature_scan)
|
add_subdirectory(example_signature_scan)
|
||||||
add_subdirectory(exmple_var_encryption)
|
|
||||||
if(OMATH_ENABLE_VALGRIND)
|
if(OMATH_ENABLE_VALGRIND)
|
||||||
omath_setup_valgrind(example_projection_matrix_builder)
|
omath_setup_valgrind(example_projection_matrix_builder)
|
||||||
omath_setup_valgrind(example_signature_scan)
|
omath_setup_valgrind(example_signature_scan)
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
project(example_var_encryption)
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} main.cpp)
|
|
||||||
set_target_properties(
|
|
||||||
${PROJECT_NAME}
|
|
||||||
PROPERTIES CXX_STANDARD 23
|
|
||||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
|
||||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
|
||||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}")
|
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE omath::omath)
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by orange on 24.02.2026.
|
|
||||||
//
|
|
||||||
#include "omath/containers/encrypted_variable.hpp"
|
|
||||||
#include <omath/omath.hpp>
|
|
||||||
#include <print>
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
OMATH_DEF_CRYPT_VAR(int, 64) var{5};
|
|
||||||
var.encrypt();
|
|
||||||
std::println("{}", var.value());
|
|
||||||
var.decrypt();
|
|
||||||
std::println("{}", var.value());
|
|
||||||
return var.value();
|
|
||||||
}
|
|
||||||
@@ -14,11 +14,15 @@ namespace omath::collision
|
|||||||
Simplex<VertexType> simplex; // valid only if hit == true and size==4
|
Simplex<VertexType> simplex; // valid only if hit == true and size==4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct GjkSettings final
|
||||||
|
{
|
||||||
|
float epsilon = 1e-6f;
|
||||||
|
std::size_t max_iterations = 64;
|
||||||
|
};
|
||||||
template<class ColliderInterfaceType>
|
template<class ColliderInterfaceType>
|
||||||
class GjkAlgorithm final
|
class GjkAlgorithm final
|
||||||
{
|
{
|
||||||
using VectorType = ColliderInterfaceType::VectorType;
|
using VectorType = ColliderInterfaceType::VectorType;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static VectorType find_support_vertex(const ColliderInterfaceType& collider_a,
|
static VectorType find_support_vertex(const ColliderInterfaceType& collider_a,
|
||||||
@@ -36,7 +40,8 @@ namespace omath::collision
|
|||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static GjkHitInfo<VectorType> is_collide_with_simplex_info(const ColliderInterfaceType& collider_a,
|
static GjkHitInfo<VectorType> is_collide_with_simplex_info(const ColliderInterfaceType& collider_a,
|
||||||
const ColliderInterfaceType& collider_b)
|
const ColliderInterfaceType& collider_b,
|
||||||
|
const GjkSettings& settings = {})
|
||||||
{
|
{
|
||||||
auto support = find_support_vertex(collider_a, collider_b, VectorType{1, 0, 0});
|
auto support = find_support_vertex(collider_a, collider_b, VectorType{1, 0, 0});
|
||||||
|
|
||||||
@@ -45,11 +50,11 @@ namespace omath::collision
|
|||||||
|
|
||||||
auto direction = -support;
|
auto direction = -support;
|
||||||
|
|
||||||
while (true)
|
for (std::size_t iteration = 0; iteration < settings.max_iterations; ++iteration)
|
||||||
{
|
{
|
||||||
support = find_support_vertex(collider_a, collider_b, direction);
|
support = find_support_vertex(collider_a, collider_b, direction);
|
||||||
|
|
||||||
if (support.dot(direction) <= 0.f)
|
if (support.dot(direction) <= settings.epsilon)
|
||||||
return {false, simplex};
|
return {false, simplex};
|
||||||
|
|
||||||
simplex.push_front(support);
|
simplex.push_front(support);
|
||||||
@@ -57,6 +62,7 @@ namespace omath::collision
|
|||||||
if (simplex.handle(direction))
|
if (simplex.handle(direction))
|
||||||
return {true, simplex};
|
return {true, simplex};
|
||||||
}
|
}
|
||||||
|
return {false, simplex};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace omath::collision
|
} // namespace omath::collision
|
||||||
@@ -46,9 +46,26 @@ namespace omath::collision
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
const VertexType& find_furthest_vertex(const VectorType& direction) const
|
const VertexType& find_furthest_vertex(const VectorType& direction) const
|
||||||
{
|
{
|
||||||
return *std::ranges::max_element(
|
// The support query arrives in world space, but vertex positions are stored
|
||||||
m_mesh.m_vertex_buffer, [&direction](const auto& first, const auto& second)
|
// in local space. We need argmax_v { world(v) · d }.
|
||||||
{ return first.position.dot(direction) < second.position.dot(direction); });
|
//
|
||||||
|
// world(v) = M·v (ignoring translation, which is constant across vertices)
|
||||||
|
// world(v) · d = v · Mᵀ·d
|
||||||
|
//
|
||||||
|
// So we transform the direction to local space once — O(1) — then compare
|
||||||
|
// raw local positions, which is far cheaper than calling
|
||||||
|
// vertex_position_to_world_space (full 4×4 multiply) for every vertex.
|
||||||
|
//
|
||||||
|
// d_local = upper-left 3×3 of M, transposed, times d_world:
|
||||||
|
// d_local[j] = sum_i M.at(i,j) * d[i] (i.e. column j of M dotted with d)
|
||||||
|
const auto& m = m_mesh.get_to_world_matrix();
|
||||||
|
const VectorType d_local = {
|
||||||
|
m[0, 0] * direction.x + m[1, 0] * direction.y + m[2, 0] * direction.z,
|
||||||
|
m[0, 1] * direction.x + m[1, 1] * direction.y + m[2, 1] * direction.z,
|
||||||
|
m[0, 2] * direction.x + m[1, 2] * direction.y + m[2, 2] * direction.z,
|
||||||
|
};
|
||||||
|
return *std::ranges::max_element(m_mesh.m_vertex_buffer, [&d_local](const auto& first, const auto& second)
|
||||||
|
{ return first.position.dot(d_local) < second.position.dot(d_local); });
|
||||||
}
|
}
|
||||||
MeshType m_mesh;
|
MeshType m_mesh;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,14 +2,10 @@
|
|||||||
// Created by Vladislav on 04.01.2026.
|
// Created by Vladislav on 04.01.2026.
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <VMProtectSDK.h>
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <span>
|
#include <span>
|
||||||
#include <source_location>
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef OMATH_ENABLE_FORCE_INLINE
|
#ifdef OMATH_ENABLE_FORCE_INLINE
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define OMATH_FORCE_INLINE __forceinline
|
#define OMATH_FORCE_INLINE __forceinline
|
||||||
@@ -114,18 +110,16 @@ namespace omath
|
|||||||
bool m_is_encrypted{};
|
bool m_is_encrypted{};
|
||||||
value_type m_data{};
|
value_type m_data{};
|
||||||
|
|
||||||
OMATH_FORCE_INLINE void xor_contained_var_by_key()
|
OMATH_FORCE_INLINE constexpr void xor_contained_var_by_key()
|
||||||
{
|
{
|
||||||
VMProtectBeginVirtualization(nullptr);
|
|
||||||
// Safe, keeps const-correctness, and avoids reinterpret_cast issues
|
// Safe, keeps const-correctness, and avoids reinterpret_cast issues
|
||||||
auto bytes = std::as_writable_bytes(std::span<value_type, 1>{&m_data, 1});
|
auto bytes = std::as_writable_bytes(std::span<value_type, 1>{&m_data, 1});
|
||||||
|
|
||||||
for (std::size_t i = 0; i < bytes.size(); ++i)
|
for (std::size_t i = 0; i < bytes.size(); ++i)
|
||||||
{
|
{
|
||||||
const auto k = static_cast<std::uint8_t>(key[i % key_size] + (i * key_size));
|
const std::uint8_t k = static_cast<std::uint8_t>(key[i % key_size] + (i * key_size));
|
||||||
bytes[i] ^= static_cast<std::byte>(k);
|
bytes[i] ^= static_cast<std::byte>(k);
|
||||||
}
|
}
|
||||||
VMProtectEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -140,7 +134,7 @@ namespace omath
|
|||||||
return m_is_encrypted;
|
return m_is_encrypted;
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_FORCE_INLINE void decrypt()
|
OMATH_FORCE_INLINE constexpr void decrypt()
|
||||||
{
|
{
|
||||||
if (!m_is_encrypted)
|
if (!m_is_encrypted)
|
||||||
return;
|
return;
|
||||||
@@ -148,7 +142,7 @@ namespace omath
|
|||||||
m_is_encrypted = false;
|
m_is_encrypted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_FORCE_INLINE void encrypt()
|
OMATH_FORCE_INLINE constexpr void encrypt()
|
||||||
{
|
{
|
||||||
if (m_is_encrypted)
|
if (m_is_encrypted)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <VMProtectSDK.h>
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"default-registry": {
|
"default-registry": {
|
||||||
"kind": "git",
|
"kind": "git",
|
||||||
"baseline": "05442024c3fda64320bd25d2251cc9807b84fb6f",
|
"baseline": "b1b19307e2d2ec1eefbdb7ea069de7d4bcd31f01",
|
||||||
"repository": "https://github.com/microsoft/vcpkg"
|
"repository": "https://github.com/microsoft/vcpkg"
|
||||||
},
|
},
|
||||||
"registries": [
|
"registries": [
|
||||||
|
|||||||
11
vcpkg.json
11
vcpkg.json
@@ -17,16 +17,9 @@
|
|||||||
],
|
],
|
||||||
"features": {
|
"features": {
|
||||||
"avx2": {
|
"avx2": {
|
||||||
"description": "omath will use AVX2 to boost performance",
|
"description": "Omath will use AVX2 to boost performance",
|
||||||
"supports": "!arm"
|
"supports": "!arm"
|
||||||
},
|
},
|
||||||
"vmprotect": {
|
|
||||||
"description": "omath will use vmprotect sdk to protect sensitive parts of code from reverse engineering",
|
|
||||||
"supports": "windows | linux | osx | android",
|
|
||||||
"dependencies": [
|
|
||||||
"orange-vmprotect-sdk"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"benchmark": {
|
"benchmark": {
|
||||||
"description": "Build benchmarks",
|
"description": "Build benchmarks",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
@@ -42,7 +35,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"imgui": {
|
"imgui": {
|
||||||
"description": "omath will define method to convert omath types to imgui types",
|
"description": "Omath will define method to convert omath types to imgui types",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"imgui"
|
"imgui"
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user