From eebc1ff2058a3160b591a84e3c0563e5cfc10a48 Mon Sep 17 00:00:00 2001 From: qubka Date: Mon, 7 Oct 2024 00:05:39 +0100 Subject: [PATCH] Make structs return by value --- docs/CMakeLists.txt | 15 ------------- docs/doxy.in | 4 ++-- src/export/clients.cpp | 19 +++++++++------- src/export/cvars.cpp | 21 +++++++++++------- src/export/entities.cpp | 27 ++++++++++++---------- src/export/schema.cpp | 8 ++++--- src/plugify/cpp_plugin.h | 48 +++++++++++++++++++++------------------- 7 files changed, 71 insertions(+), 71 deletions(-) diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 5bfe47f..4988b0b 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -2,22 +2,7 @@ include(FetchContent) -FetchContent_Declare( - doxygen-awesome-css - GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css - GIT_TAG main - GIT_SHALLOW 1 -) - -FetchContent_GetProperties(doxygen-awesome-css) - -if(NOT doxygen-awesome-css_POPULATED) - FetchContent_Populate(doxygen-awesome-css) - set(doxygen-awesome-css_INCLUDE_DIR ${doxygen-awesome-css_SOURCE_DIR}) -endif() - set(DOXY_SOURCE_DIRECTORY ${PROJECT_SOURCE_DIR}/src/export) -set(DOXY_CSS_DIRECTORY ${doxygen-awesome-css_INCLUDE_DIR}) set(DOXY_DOCS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) set(DOXY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/docs/doxy.in b/docs/doxy.in index ea31fc3..b9243ba 100644 --- a/docs/doxy.in +++ b/docs/doxy.in @@ -1326,7 +1326,7 @@ HTML_FOOTER = # obsolete. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_STYLESHEET = @DOXY_CSS_DIRECTORY@/doxygen-awesome.css +HTML_STYLESHEET = # The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined # cascading style sheets that are included after the standard style sheets @@ -1344,7 +1344,7 @@ HTML_STYLESHEET = @DOXY_CSS_DIRECTORY@/doxygen-awesome.css # documentation. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_EXTRA_STYLESHEET = doxygen-awesome-css/doxygen-awesome.css +HTML_EXTRA_STYLESHEET = # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the HTML output directory. Note diff --git a/src/export/clients.cpp b/src/export/clients.cpp index a5728da..4b58cc7 100644 --- a/src/export/clients.cpp +++ b/src/export/clients.cpp @@ -3,9 +3,10 @@ #include #include #include +#include #include -//! +//! extern "C" PLUGIN_API int GetClientIndexFromEntityPointer(CBaseEntity* entity) { return utils::GetEntityPlayerSlot(entity).Get() + 1; @@ -387,32 +388,34 @@ extern "C" PLUGIN_API int GetClientArmor(int clientIndex) * @param output Reference to a Vector where the client's origin will be stored. * @param clientIndex Index of the client. */ -extern "C" PLUGIN_API void GetClientAbsOrigin(Vector& output, int clientIndex) +extern "C" PLUGIN_API plg::vec3 GetClientAbsOrigin(int clientIndex) { auto client = utils::GetController(CPlayerSlot(clientIndex - 1)); if (!client) { - return; + return {}; } - output = client->m_CBodyComponent->m_pSceneNode->m_vecAbsOrigin(); + const Vector& vec = client->m_CBodyComponent->m_pSceneNode->m_vecAbsOrigin(); + return *reinterpret_cast(&vec); } /** * @brief Retrieves the client's position angle. * - * @param output Reference to a QAngle where the client's position angle will be stored. * @param clientIndex Index of the client. + * @return A QAngle where the client's position angle will be stored. */ -extern "C" PLUGIN_API void GetClientAbsAngles(QAngle& output, int clientIndex) +extern "C" PLUGIN_API plg::vec3 GetClientAbsAngles(int clientIndex) { auto client = utils::GetController(CPlayerSlot(clientIndex - 1)); if (!client) { - return; + return {}; } - std::construct_at(&output, client->m_CBodyComponent->m_pSceneNode->m_angRotation()); + const QAngle& ang = client->m_CBodyComponent->m_pSceneNode->m_angRotation(); + return *reinterpret_cast(&ang); } /** diff --git a/src/export/cvars.cpp b/src/export/cvars.cpp index 9cfe0ec..dde5fed 100644 --- a/src/export/cvars.cpp +++ b/src/export/cvars.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include // CreateConVar() @@ -833,9 +834,10 @@ extern "C" PLUGIN_API Color GetConVarColor(CConVarBaseData* conVar) * @param conVar Pointer to the console variable data. * @return The current Vector2D value of the console variable. */ -extern "C" PLUGIN_API Vector2D GetConVarVector2(CConVarBaseData* conVar) +extern "C" PLUGIN_API plg::vec2 GetConVarVector2(CConVarBaseData* conVar) { - return conVar->Cast()->GetValue(); + const Vector2D& vec = conVar->Cast()->GetValue(); + return *reinterpret_cast(&vec); } /** @@ -844,9 +846,10 @@ extern "C" PLUGIN_API Vector2D GetConVarVector2(CConVarBaseData* conVar) * @param conVar Pointer to the console variable data. * @return The current Vector value of the console variable. */ -extern "C" PLUGIN_API Vector GetConVarVector(CConVarBaseData* conVar) +extern "C" PLUGIN_API plg::vec3 GetConVarVector(CConVarBaseData* conVar) { - return conVar->Cast()->GetValue(); + const Vector& vec = conVar->Cast()->GetValue(); + return *reinterpret_cast(&vec); } /** @@ -855,9 +858,10 @@ extern "C" PLUGIN_API Vector GetConVarVector(CConVarBaseData* conVar) * @param conVar Pointer to the console variable data. * @return The current Vector4D value of the console variable. */ -extern "C" PLUGIN_API Vector4D GetConVarVector4(CConVarBaseData* conVar) +extern "C" PLUGIN_API plg::vec4 GetConVarVector4(CConVarBaseData* conVar) { - return conVar->Cast()->GetValue(); + const Vector4D& vec = conVar->Cast()->GetValue(); + return *reinterpret_cast(&vec); } /** @@ -866,9 +870,10 @@ extern "C" PLUGIN_API Vector4D GetConVarVector4(CConVarBaseData* conVar) * @param conVar Pointer to the console variable data. * @return The current QAngle value of the console variable. */ -extern "C" PLUGIN_API QAngle GetConVarQangle(CConVarBaseData* conVar) +extern "C" PLUGIN_API plg::vec3 GetConVarQangle(CConVarBaseData* conVar) { - return conVar->Cast()->GetValue(); + const QAngle& ang = conVar->Cast()->GetValue(); + return *reinterpret_cast(&ang); } /** diff --git a/src/export/entities.cpp b/src/export/entities.cpp index a1f29ef..e08f136 100644 --- a/src/export/entities.cpp +++ b/src/export/entities.cpp @@ -750,18 +750,19 @@ extern "C" PLUGIN_API void SetEntityParent(int entityHandle, int parentHandle) * This function gets the absolute position of the specified entity. * If the entity is invalid, the function does nothing. * - * @param output A reference to a Vector where the absolute origin will be stored. * @param entityHandle The handle of the entity whose absolute origin is to be retrieved. + * @return A vector where the absolute origin will be stored. */ -extern "C" PLUGIN_API void GetEntityAbsOrigin(Vector& output, int entityHandle) +extern "C" PLUGIN_API plg::vec3 GetEntityAbsOrigin(int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); if (!ent) { - return; + return {}; } - output = ent->m_CBodyComponent->m_pSceneNode->m_vecAbsOrigin(); + const Vector& vec = ent->m_CBodyComponent->m_pSceneNode->m_vecAbsOrigin(); + return *reinterpret_cast(&vec); } /** @@ -790,18 +791,19 @@ extern "C" PLUGIN_API void SetEntityAbsOrigin(int entityHandle, const Vector& or * This function gets the angular rotation of the specified entity. * If the entity is invalid, the function does nothing. * - * @param output A reference to a QAngle where the angular rotation will be stored. * @param entityHandle The handle of the entity whose angular rotation is to be retrieved. + * @return A QAngle where the angular rotation will be stored. */ -extern "C" PLUGIN_API void GetEntityAngRotation(QAngle& output, int entityHandle) +extern "C" PLUGIN_API plg::vec3 GetEntityAngRotation(int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); if (!ent) { - return; + return {}; } - std::construct_at(&output, ent->m_CBodyComponent->m_pSceneNode->m_angRotation()); + const QAngle& ang = ent->m_CBodyComponent->m_pSceneNode->m_angRotation(); + return *reinterpret_cast(&ang); } /** @@ -830,18 +832,19 @@ extern "C" PLUGIN_API void SetEntityAngRotation(int entityHandle, const QAngle& * This function gets the absolute velocity of the specified entity. * If the entity is invalid, the function does nothing. * - * @param output A reference to a Vector where the absolute velocity will be stored. * @param entityHandle The handle of the entity whose absolute velocity is to be retrieved. + * @return A vector where the absolute velocity will be stored. */ -extern "C" PLUGIN_API void GetEntityAbsVelocity(Vector& output, int entityHandle) +extern "C" PLUGIN_API plg::vec3 GetEntityAbsVelocity(int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); if (!ent) { - return; + return {}; } - output = ent->m_vecAbsVelocity(); + const Vector& vec = ent->m_vecAbsVelocity(); + return *reinterpret_cast(&vec); } /** diff --git a/src/export/schema.cpp b/src/export/schema.cpp index ffeffc6..c451c96 100644 --- a/src/export/schema.cpp +++ b/src/export/schema.cpp @@ -1,8 +1,9 @@ #include #include #include -#include +#include #include +#include /** * @brief Get the offset of a member in a given schema class. @@ -331,14 +332,15 @@ extern "C" PLUGIN_API void GetSchemaStringByName(plg::string& output, void* inst * @param memberName The name of the member whose value is to be retrieved. * @return The value of the member. */ -extern "C" PLUGIN_API void GetSchemaVectorByName(Vector& output, void* instancePointer, const plg::string& className, const plg::string& memberName) +extern "C" PLUGIN_API plg::vec3 GetSchemaVectorByName(void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); auto memberKey = hash_32_fnv1a_const(memberName.c_str()); const auto m_key = schema::GetOffset(className.c_str(), classKey, memberName.c_str(), memberKey); - output = *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); + const Vector& vec = *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); + return *reinterpret_cast(&vec); } /** diff --git a/src/plugify/cpp_plugin.h b/src/plugify/cpp_plugin.h index 921957f..3679707 100644 --- a/src/plugify/cpp_plugin.h +++ b/src/plugify/cpp_plugin.h @@ -143,33 +143,35 @@ namespace plg { } namespace plg { - struct Vector2 { - float x{}; - float y{}; + extern "C" { + struct vec2 { + float x{}; + float y{}; - bool operator==(const Vector2&) const = default; - }; + bool operator==(const vec2&) const = default; + }; - struct Vector3 { - float x{}; - float y{}; - float z{}; + struct vec3 { + float x{}; + float y{}; + float z{}; - bool operator==(const Vector3&) const = default; - }; + bool operator==(const vec3&) const = default; + }; - struct Vector4 { - float x{}; - float y{}; - float z{}; - float w{}; + struct vec4 { + float x{}; + float y{}; + float z{}; + float w{}; - bool operator==(const Vector4&) const = default; - }; + bool operator==(const vec4&) const = default; + }; - struct Matrix4x4 { - float m[4][4]{}; + struct mat4x4 { + float m[4][4]{}; - bool operator==(const Matrix4x4&) const = default; - }; -} + bool operator==(const mat4x4&) const = default; + }; + } +} \ No newline at end of file