Skip to content

Commit

Permalink
Make structs return by value
Browse files Browse the repository at this point in the history
  • Loading branch information
qubka committed Oct 6, 2024
1 parent ba3a3fd commit eebc1ff
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 71 deletions.
15 changes: 0 additions & 15 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
4 changes: 2 additions & 2 deletions docs/doxy.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 11 additions & 8 deletions src/export/clients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#include <core/sdk/entity/cbaseplayercontroller.h>
#include <core/sdk/entity/ccsplayercontroller.h>
#include <core/sdk/utils.h>
#include <plugify/cpp_plugin.h>
#include <plugin_export.h>

//!
//!
extern "C" PLUGIN_API int GetClientIndexFromEntityPointer(CBaseEntity* entity)
{
return utils::GetEntityPlayerSlot(entity).Get() + 1;
Expand Down Expand Up @@ -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<const plg::vec3*>(&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<const plg::vec3*>(&ang);
}

/**
Expand Down
21 changes: 13 additions & 8 deletions src/export/cvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <core/game_config.h>
#include <core/sdk/utils.h>
#include <core/sdk/virtual.h>
#include <plugify/cpp_plugin.h>
#include <plugin_export.h>

// CreateConVar()
Expand Down Expand Up @@ -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<Vector2D>()->GetValue();
const Vector2D& vec = conVar->Cast<Vector2D>()->GetValue();
return *reinterpret_cast<const plg::vec2*>(&vec);
}

/**
Expand All @@ -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<Vector>()->GetValue();
const Vector& vec = conVar->Cast<Vector>()->GetValue();
return *reinterpret_cast<const plg::vec3*>(&vec);
}

/**
Expand All @@ -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<Vector4D>()->GetValue();
const Vector4D& vec = conVar->Cast<Vector4D>()->GetValue();
return *reinterpret_cast<const plg::vec4*>(&vec);
}

/**
Expand All @@ -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<QAngle>()->GetValue();
const QAngle& ang = conVar->Cast<QAngle>()->GetValue();
return *reinterpret_cast<const plg::vec3*>(&ang);
}

/**
Expand Down
27 changes: 15 additions & 12 deletions src/export/entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CBaseEntity*>(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<const plg::vec3*>(&vec);
}

/**
Expand Down Expand Up @@ -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<CBaseEntity*>(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<const plg::vec3*>(&ang);
}

/**
Expand Down Expand Up @@ -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<CBaseEntity*>(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle)));
if (!ent)
{
return;
return {};
}

output = ent->m_vecAbsVelocity();
const Vector& vec = ent->m_vecAbsVelocity();
return *reinterpret_cast<const plg::vec3*>(&vec);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/export/schema.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <core/core_config.h>
#include <core/sdk/entity/cschemasystem.h>
#include <core/sdk/schema.h>
#include <tier0/utlstring.h>
#include <plugify/cpp_plugin.h>
#include <plugin_export.h>
#include <tier0/utlstring.h>

/**
* @brief Get the offset of a member in a given schema class.
Expand Down Expand Up @@ -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<std::add_pointer_t<Vector>>((uintptr_t)(instancePointer) + m_key.offset);
const Vector& vec = *reinterpret_cast<std::add_pointer_t<Vector>>((uintptr_t)(instancePointer) + m_key.offset);
return *reinterpret_cast<const plg::vec3*>(&vec);
}

/**
Expand Down
48 changes: 25 additions & 23 deletions src/plugify/cpp_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
}

0 comments on commit eebc1ff

Please sign in to comment.