From ba3a3fd5ecb965523fa58f5872d47f80ac3f23cd Mon Sep 17 00:00:00 2001 From: qubka Date: Sun, 6 Oct 2024 23:32:54 +0100 Subject: [PATCH] Add more comments --- cs2sdk.pplugin.in | 109 ++++-- src/export/clients.cpp | 70 ++-- src/export/commands.cpp | 61 ++- src/export/console.cpp | 84 +++- src/export/cvars.cpp | 788 +++++++++++++++++++++++++++++++++++++- src/export/engine.cpp | 167 +++++++- src/export/entities.cpp | 668 ++++++++++++++++++++++++++------ src/export/events.cpp | 252 ++++++++++-- src/export/gameconfig.cpp | 91 +++++ src/export/logger.cpp | 175 ++++++++- src/export/schema.cpp | 322 ++++++++++++++++ src/export/timers.cpp | 40 ++ src/export/voice.cpp | 133 ++++--- 13 files changed, 2652 insertions(+), 308 deletions(-) diff --git a/cs2sdk.pplugin.in b/cs2sdk.pplugin.in index fb09af8..daec708 100644 --- a/cs2sdk.pplugin.in +++ b/cs2sdk.pplugin.in @@ -684,8 +684,8 @@ } }, { - "name": "ClientCommandFromServer", - "funcName": "ClientCommandFromServer", + "name": "FakeClientCommand", + "funcName": "FakeClientCommand", "paramTypes": [ { "name": "clientIndex", @@ -703,8 +703,8 @@ } }, { - "name": "PrintServer", - "funcName": "PrintServer", + "name": "PrintToServer", + "funcName": "PrintToServer", "paramTypes": [ { "name": "msg", @@ -717,8 +717,8 @@ } }, { - "name": "PrintConsole", - "funcName": "PrintConsole", + "name": "PrintToConsole", + "funcName": "PrintToConsole", "paramTypes": [ { "name": "clientIndex", @@ -736,8 +736,8 @@ } }, { - "name": "PrintChat", - "funcName": "PrintChat", + "name": "PrintToChat", + "funcName": "PrintToChat", "paramTypes": [ { "name": "clientIndex", @@ -755,8 +755,8 @@ } }, { - "name": "PrintCentre", - "funcName": "PrintCentre", + "name": "PrintCenterText", + "funcName": "PrintCenterText", "paramTypes": [ { "name": "clientIndex", @@ -774,8 +774,8 @@ } }, { - "name": "PrintAlert", - "funcName": "PrintAlert", + "name": "PrintAlertText", + "funcName": "PrintAlertText", "paramTypes": [ { "name": "clientIndex", @@ -793,8 +793,8 @@ } }, { - "name": "PrintHtmlCentre", - "funcName": "PrintHtmlCentre", + "name": "PrintCentreHtml", + "funcName": "PrintCentreHtml", "paramTypes": [ { "name": "clientIndex", @@ -812,8 +812,8 @@ } }, { - "name": "PrintConsoleAll", - "funcName": "PrintConsoleAll", + "name": "PrintToConsoleAll", + "funcName": "PrintToConsoleAll", "paramTypes": [ { "name": "message", @@ -826,8 +826,8 @@ } }, { - "name": "PrintChatAll", - "funcName": "PrintChatAll", + "name": "PrintToChatAll", + "funcName": "PrintToChatAll", "paramTypes": [ { "name": "message", @@ -840,8 +840,8 @@ } }, { - "name": "PrintCentreAll", - "funcName": "PrintCentreAll", + "name": "PrintCenterTextAll", + "funcName": "PrintCenterTextAll", "paramTypes": [ { "name": "message", @@ -854,8 +854,8 @@ } }, { - "name": "PrintAlertAll", - "funcName": "PrintAlertAll", + "name": "PrintAlertTextToAll", + "funcName": "PrintAlertTextToAll", "paramTypes": [ { "name": "message", @@ -868,8 +868,8 @@ } }, { - "name": "PrintHtmlCentreAll", - "funcName": "PrintHtmlCentreAll", + "name": "PrintCentreHtmlAll", + "funcName": "PrintCentreHtmlAll", "paramTypes": [ { "name": "message", @@ -882,8 +882,8 @@ } }, { - "name": "PrintChatColored", - "funcName": "PrintChatColored", + "name": "PrintToChatColored", + "funcName": "PrintToChatColored", "paramTypes": [ { "name": "clientIndex", @@ -901,8 +901,8 @@ } }, { - "name": "PrintChatColoredAll", - "funcName": "PrintChatColoredAll", + "name": "PrintToChatColoredAll", + "funcName": "PrintToChatColoredAll", "paramTypes": [ { "name": "message", @@ -1792,6 +1792,25 @@ "type": "int64" } }, + { + "name": "GetConVarBounds", + "funcName": "GetConVarBounds", + "paramTypes": [ + { + "name": "conVar", + "type": "ptr64", + "ref": false + }, + { + "name": "max", + "type": "bool", + "ref": false + } + ], + "retType": { + "type": "string" + } + }, { "name": "SetConVarBounds", "funcName": "SetConVarBounds", @@ -1925,8 +1944,8 @@ } }, { - "name": "GetMapName", - "funcName": "GetMapName", + "name": "GetCurrentMap", + "funcName": "GetCurrentMap", "paramTypes": [], "retType": { "type": "string" @@ -1986,6 +2005,34 @@ "type": "int32" } }, + { + "name": "GenericModel", + "funcName": "GenericModel", + "paramTypes": [ + { + "name": "file", + "type": "string", + "ref": false + } + ], + "retType": { + "type": "int32" + } + }, + { + "name": "IsGenericPrecache", + "funcName": "IsGenericPrecache", + "paramTypes": [ + { + "name": "file", + "type": "string", + "ref": false + } + ], + "retType": { + "type": "bool" + } + }, { "name": "PrecacheModel", "funcName": "PrecacheModel", @@ -2011,7 +2058,7 @@ } ], "retType": { - "type": "void" + "type": "bool" } }, { diff --git a/src/export/clients.cpp b/src/export/clients.cpp index c519072..a5728da 100644 --- a/src/export/clients.cpp +++ b/src/export/clients.cpp @@ -5,16 +5,14 @@ #include #include -extern "C" { - //! -PLUGIN_API int GetClientIndexFromEntityPointer(CBaseEntity* entity) +extern "C" PLUGIN_API int GetClientIndexFromEntityPointer(CBaseEntity* entity) { return utils::GetEntityPlayerSlot(entity).Get() + 1; } /*//! -PLUGIN_API void* GetClientFromIndex(int clientIndex) +extern "C" PLUGIN_API void* GetClientFromIndex(int clientIndex) { CUtlVector* pClients = utils::GetClientList(); if (!pClients) @@ -26,7 +24,7 @@ PLUGIN_API void* GetClientFromIndex(int clientIndex) } //! -PLUGIN_API int GetIndexFromClient(CServerSideClient* client) +extern "C" PLUGIN_API int GetIndexFromClient(CServerSideClient* client) { CUtlVector* pClients = utils::GetClientList(); if (!pClients) @@ -48,7 +46,7 @@ PLUGIN_API int GetIndexFromClient(CServerSideClient* client) * @param clientIndex Index of the client whose authentication string is being retrieved. * @return The authentication string. */ -PLUGIN_API void GetClientAuthId(plg::string& output, int clientIndex) +extern "C" PLUGIN_API void GetClientAuthId(plg::string& output, int clientIndex) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr || !pPlayer->m_bAuthorized) @@ -71,7 +69,7 @@ PLUGIN_API void GetClientAuthId(plg::string& output, int clientIndex) * @param clientIndex Index of the client. * @return uint64_t Steam account ID. */ -PLUGIN_API uint64_t GetClientAccountId(int clientIndex) +extern "C" PLUGIN_API uint64_t GetClientAccountId(int clientIndex) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr || !pPlayer->m_bAuthorized) @@ -94,7 +92,7 @@ PLUGIN_API uint64_t GetClientAccountId(int clientIndex) * @param clientIndex Index of the client. * @return The IP address. */ -PLUGIN_API void GetClientIp(plg::string& output, int clientIndex) +extern "C" PLUGIN_API void GetClientIp(plg::string& output, int clientIndex) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr) @@ -111,7 +109,7 @@ PLUGIN_API void GetClientIp(plg::string& output, int clientIndex) * @param clientIndex Index of the client. * @return The client's name. */ -PLUGIN_API void GetClientName(plg::string& output, int clientIndex) +extern "C" PLUGIN_API void GetClientName(plg::string& output, int clientIndex) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr) @@ -128,7 +126,7 @@ PLUGIN_API void GetClientName(plg::string& output, int clientIndex) * @param clientIndex Index of the client. * @return float Connection time in seconds. */ -PLUGIN_API float GetClientTime(int clientIndex) +extern "C" PLUGIN_API float GetClientTime(int clientIndex) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr) @@ -145,7 +143,7 @@ PLUGIN_API float GetClientTime(int clientIndex) * @param clientIndex Index of the client. * @return float Latency value. */ -PLUGIN_API float GetClientLatency(int clientIndex) +extern "C" PLUGIN_API float GetClientLatency(int clientIndex) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr) @@ -162,7 +160,7 @@ PLUGIN_API float GetClientLatency(int clientIndex) * @param clientIndex Index of the client. * @return uint64 Access flags as a bitmask. */ -PLUGIN_API uint64 GetUserFlagBits(int clientIndex) +extern "C" PLUGIN_API uint64 GetUserFlagBits(int clientIndex) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr) @@ -179,7 +177,7 @@ PLUGIN_API uint64 GetUserFlagBits(int clientIndex) * @param clientIndex Index of the client. * @param flags Bitmask representing the flags to be set. */ -PLUGIN_API void SetUserFlagBits(int clientIndex, uint64 flags) +extern "C" PLUGIN_API void SetUserFlagBits(int clientIndex, uint64 flags) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr) @@ -198,7 +196,7 @@ PLUGIN_API void SetUserFlagBits(int clientIndex, uint64 flags) * @param clientIndex Index of the client. * @param flags Bitmask representing the flags to be added. */ -PLUGIN_API void AddUserFlags(int clientIndex, uint64 flags) +extern "C" PLUGIN_API void AddUserFlags(int clientIndex, uint64 flags) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr) @@ -217,7 +215,7 @@ PLUGIN_API void AddUserFlags(int clientIndex, uint64 flags) * @param clientIndex Index of the client. * @param flags Bitmask representing the flags to be removed. */ -PLUGIN_API void RemoveUserFlags(int clientIndex, uint64 flags) +extern "C" PLUGIN_API void RemoveUserFlags(int clientIndex, uint64 flags) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr) @@ -234,7 +232,7 @@ PLUGIN_API void RemoveUserFlags(int clientIndex, uint64 flags) * @param clientIndex Index of the client. * @return true if the player is authenticated, false otherwise. */ -PLUGIN_API bool IsClientAuthorized(int clientIndex) +extern "C" PLUGIN_API bool IsClientAuthorized(int clientIndex) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr) @@ -251,7 +249,7 @@ PLUGIN_API bool IsClientAuthorized(int clientIndex) * @param clientIndex Index of the client. * @return true if the player is connected, false otherwise. */ -PLUGIN_API bool IsClientConnected(int clientIndex) +extern "C" PLUGIN_API bool IsClientConnected(int clientIndex) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr) @@ -268,7 +266,7 @@ PLUGIN_API bool IsClientConnected(int clientIndex) * @param clientIndex Index of the client. * @return true if the player is in the game, false otherwise. */ -PLUGIN_API bool IsClientInGame(int clientIndex) +extern "C" PLUGIN_API bool IsClientInGame(int clientIndex) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr) @@ -285,7 +283,7 @@ PLUGIN_API bool IsClientInGame(int clientIndex) * @param clientIndex Index of the client. * @return true if the client is the SourceTV bot, false otherwise. */ -PLUGIN_API bool IsClientSourceTV(int clientIndex) +extern "C" PLUGIN_API bool IsClientSourceTV(int clientIndex) { auto client = utils::GetController(CPlayerSlot(clientIndex - 1)); if (!client) @@ -302,7 +300,7 @@ PLUGIN_API bool IsClientSourceTV(int clientIndex) * @param clientIndex Index of the client. * @return true if the client is alive, false if dead. */ -PLUGIN_API bool IsClientAlive(int clientIndex) +extern "C" PLUGIN_API bool IsClientAlive(int clientIndex) { auto client = utils::GetController(CPlayerSlot(clientIndex - 1)); if (!client) @@ -319,7 +317,7 @@ PLUGIN_API bool IsClientAlive(int clientIndex) * @param clientIndex Index of the client. * @return true if the client is a fake client, false otherwise. */ -PLUGIN_API bool IsFakeClient(int clientIndex) +extern "C" PLUGIN_API bool IsFakeClient(int clientIndex) { auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); if (pPlayer == nullptr) @@ -338,7 +336,7 @@ PLUGIN_API bool IsFakeClient(int clientIndex) * @param clientIndex Index of the client. * @return int The team index of the client. */ -PLUGIN_API int GetClientTeam(int clientIndex) +extern "C" PLUGIN_API int GetClientTeam(int clientIndex) { auto client = utils::GetController(CPlayerSlot(clientIndex - 1)); if (!client) @@ -355,7 +353,7 @@ PLUGIN_API int GetClientTeam(int clientIndex) * @param clientIndex Index of the client. * @return int The health value of the client. */ -PLUGIN_API int GetClientHealth(int clientIndex) +extern "C" PLUGIN_API int GetClientHealth(int clientIndex) { auto client = utils::GetController(CPlayerSlot(clientIndex - 1)); if (!client) @@ -372,7 +370,7 @@ PLUGIN_API int GetClientHealth(int clientIndex) * @param clientIndex Index of the client. * @return int The armor value of the client. */ -PLUGIN_API int GetClientArmor(int clientIndex) +extern "C" PLUGIN_API int GetClientArmor(int clientIndex) { auto client = utils::GetController(CPlayerSlot(clientIndex - 1)); if (!client) @@ -380,7 +378,7 @@ PLUGIN_API int GetClientArmor(int clientIndex) return 0; } - return 0;//client->m_Armor(); + return 0;//client->m_Armor(); // TODO: } /** @@ -389,7 +387,7 @@ 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. */ -PLUGIN_API void GetClientAbsOrigin(Vector& output, int clientIndex) +extern "C" PLUGIN_API void GetClientAbsOrigin(Vector& output, int clientIndex) { auto client = utils::GetController(CPlayerSlot(clientIndex - 1)); if (!client) @@ -406,7 +404,7 @@ PLUGIN_API void GetClientAbsOrigin(Vector& output, int clientIndex) * @param output Reference to a QAngle where the client's position angle will be stored. * @param clientIndex Index of the client. */ -PLUGIN_API void GetClientAbsAngles(QAngle& output, int clientIndex) +extern "C" PLUGIN_API void GetClientAbsAngles(QAngle& output, int clientIndex) { auto client = utils::GetController(CPlayerSlot(clientIndex - 1)); if (!client) @@ -424,7 +422,7 @@ PLUGIN_API void GetClientAbsAngles(QAngle& output, int clientIndex) * @param caller Index of the client making the target request. * @param target The target string specifying the player or players to be targeted. */ -PLUGIN_API void ProcessTargetString(std::vector& output, int caller, const plg::string& target) +extern "C" PLUGIN_API void ProcessTargetString(std::vector& output, int caller, const plg::string& target) { g_PlayerManager.TargetPlayerString(caller, target.c_str(), output); } @@ -435,7 +433,7 @@ PLUGIN_API void ProcessTargetString(std::vector& output, int caller, const * @param clientIndex Index of the client. * @param team The team index to assign the client to. */ -PLUGIN_API void ChangeClientTeam(int clientIndex, int team) +extern "C" PLUGIN_API void ChangeClientTeam(int clientIndex, int team) { auto client = static_cast(utils::GetController(CPlayerSlot(clientIndex - 1))); if (!client) @@ -452,7 +450,7 @@ PLUGIN_API void ChangeClientTeam(int clientIndex, int team) * @param clientIndex Index of the client. * @param team The team index to switch the client to. */ -PLUGIN_API void SwitchClientTeam(int clientIndex, int team) +extern "C" PLUGIN_API void SwitchClientTeam(int clientIndex, int team) { auto client = static_cast(utils::GetController(CPlayerSlot(clientIndex - 1))); if (!client) @@ -468,7 +466,7 @@ PLUGIN_API void SwitchClientTeam(int clientIndex, int team) * * @param clientIndex Index of the client to respawn. */ -PLUGIN_API void RespawnClient(int clientIndex) +extern "C" PLUGIN_API void RespawnClient(int clientIndex) { auto client = utils::GetController(CPlayerSlot(clientIndex - 1)); if (!client) @@ -494,7 +492,7 @@ PLUGIN_API void RespawnClient(int clientIndex) * @param explode If true, the client will explode upon death. * @param force If true, the suicide will be forced. */ -PLUGIN_API void ForcePlayerSuicide(int clientIndex, bool explode, bool force) +extern "C" PLUGIN_API void ForcePlayerSuicide(int clientIndex, bool explode, bool force) { auto client = utils::GetController(CPlayerSlot(clientIndex - 1)); if (!client) @@ -510,7 +508,7 @@ PLUGIN_API void ForcePlayerSuicide(int clientIndex, bool explode, bool force) * * @param clientIndex Index of the client to be kicked. */ -PLUGIN_API void KickClient(int clientIndex) +extern "C" PLUGIN_API void KickClient(int clientIndex) { g_pEngineServer2->DisconnectClient(CPlayerSlot(clientIndex - 1), NETWORK_DISCONNECT_KICKED); } @@ -522,7 +520,7 @@ PLUGIN_API void KickClient(int clientIndex) * @param duration Duration of the ban in seconds. * @param kick If true, the client will be kicked immediately after being banned. */ -PLUGIN_API void BanClient(int clientIndex, float duration, bool kick) +extern "C" PLUGIN_API void BanClient(int clientIndex, float duration, bool kick) { g_pEngineServer2->BanClient(CPlayerSlot(clientIndex - 1), duration, kick); } @@ -534,9 +532,7 @@ PLUGIN_API void BanClient(int clientIndex, float duration, bool kick) * @param duration Duration of the ban in seconds. * @param kick If true, the client will be kicked immediately after being banned. */ -PLUGIN_API void BanIdentity(uint64_t steamId, float duration, bool kick) +extern "C" PLUGIN_API void BanIdentity(uint64_t steamId, float duration, bool kick) { g_pEngineServer2->BanClient(CSteamID(static_cast(steamId)), duration, kick); } - -} \ No newline at end of file diff --git a/src/export/commands.cpp b/src/export/commands.cpp index 7c7eba8..0e0abde 100644 --- a/src/export/commands.cpp +++ b/src/export/commands.cpp @@ -1,6 +1,17 @@ #include #include +/** + * @brief Creates a console command as an administrative command. + * If the command does not exist, it is created. When this command is invoked, + * the access rights of the player are automatically checked before allowing it to continue. + * + * @param name The name of the console command. + * @param adminFlags The admin flags that indicate which admin level can use this command. + * @param description A brief description of what the command does. + * @param flags Command flags that define the behavior of the command. + * @param callback A callback function that is invoked when the command is executed. + */ extern "C" PLUGIN_API void AddAdminCommand(const plg::string& name, int64_t adminFlags, const plg::string& description, int64_t flags, CommandListenerCallback callback) { g_Logger.LogFormat(LS_DEBUG, "Adding admin command %s, %d, %s, %d, %p\n", name.c_str(), (int)adminFlags, description.c_str(), (int)flags, (void*)callback); @@ -9,6 +20,14 @@ extern "C" PLUGIN_API void AddAdminCommand(const plg::string& name, int64_t admi g_CommandManager.AddCommandListener(name, callback, HookMode::Pre); } +/** + * @brief Creates a console command or hooks an already existing one. + * + * @param name The name of the console command. + * @param description A brief description of what the command does. + * @param flags Command flags that define the behavior of the command. + * @param callback A callback function that is invoked when the command is executed. + */ extern "C" PLUGIN_API void AddConsoleCommand(const plg::string& name, const plg::string& description, int64_t flags, CommandListenerCallback callback) { g_Logger.LogFormat(LS_DEBUG, "Adding command %s, %s, %d, %p\n", name.c_str(), description.c_str(), (int)flags, (void*)callback); @@ -17,22 +36,47 @@ extern "C" PLUGIN_API void AddConsoleCommand(const plg::string& name, const plg: g_CommandManager.AddCommandListener(name, callback, HookMode::Pre); } +/** + * @brief Removes a console command from the system. + * + * @param name The name of the command to be removed. + * @param callback The callback function associated with the command to be removed. + */ extern "C" PLUGIN_API void RemoveCommand(const plg::string& name, CommandListenerCallback callback) { g_CommandManager.RemoveCommandListener(name, callback, HookMode::Pre); g_CommandManager.RemoveValveCommand(name); } +/** + * @brief Adds a callback that will fire when a command is sent to the server. + * + * @param name The name of the command. + * @param callback The callback function that will be invoked when the command is executed. + * @param post A boolean indicating whether the callback should fire after the command is executed. + */ extern "C" PLUGIN_API void AddCommandListener(const plg::string& name, CommandListenerCallback callback, bool post) { g_CommandManager.AddCommandListener(name, callback, static_cast(post)); } +/** + * @brief Removes a callback that fires when a command is sent to the server. + * + * @param name The name of the command. + * @param callback The callback function to be removed. + * @param post A boolean indicating whether the callback should be removed for post-execution. + */ extern "C" PLUGIN_API void RemoveCommandListener(const plg::string& name, CommandListenerCallback callback, bool post) { g_CommandManager.RemoveCommandListener(name, callback, static_cast(post)); } +/** + * @brief Executes a server command as if it were run on the server console or through RCON. + * + * @param command The command to execute on the server. + */ extern "C" PLUGIN_API void ServerCommand(const plg::string& command) { auto cleanCommand = command; @@ -40,6 +84,13 @@ extern "C" PLUGIN_API void ServerCommand(const plg::string& command) g_pEngineServer2->ServerCommand(cleanCommand.c_str()); } +/** + * @brief Executes a client command. + * This will only work if clients have `cl_restrict_server_commands` set to 0. + * + * @param clientIndex The index of the client executing the command. + * @param command The command to execute on the client. + */ extern "C" PLUGIN_API void ClientCommand(int clientIndex, const plg::string& command) { auto cleanCommand = command; @@ -47,7 +98,13 @@ extern "C" PLUGIN_API void ClientCommand(int clientIndex, const plg::string& com g_pEngineServer2->ClientCommand(CPlayerSlot(clientIndex - 1), "%s", cleanCommand.c_str()); } -extern "C" PLUGIN_API void ClientCommandFromServer(int clientIndex, const plg::string& command) +/** + * @brief Executes a client command on the server without network communication. + * + * @param clientIndex The index of the client. + * @param command The command to be executed by the client. + */ +extern "C" PLUGIN_API void FakeClientCommand(int clientIndex, const plg::string& command) { CCommand args; args.Tokenize(command.c_str(), CCommand::DefaultBreakSet()); @@ -59,4 +116,4 @@ extern "C" PLUGIN_API void ClientCommandFromServer(int clientIndex, const plg::s CCommandContext context(CommandTarget_t::CT_NO_TARGET, CPlayerSlot(clientIndex - 1)); g_pCVar->DispatchConCommand(handle, context, args); -} \ No newline at end of file +} diff --git a/src/export/console.cpp b/src/export/console.cpp index 117f3a5..b24c463 100644 --- a/src/export/console.cpp +++ b/src/export/console.cpp @@ -1,67 +1,125 @@ #include #include -extern "C" PLUGIN_API void PrintServer(const plg::string& msg) +/** + * @brief Sends a message to the server console. + * @param msg The message to be sent to the server console. + */ +extern "C" PLUGIN_API void PrintToServer(const plg::string& msg) { ConMsg("%s", msg.c_str()); } -extern "C" PLUGIN_API void PrintConsole(int clientIndex, const plg::string& message) +/** + * @brief Sends a message to a client's console. + * @param clientIndex Index of the client to whom the message will be sent. + * @param message The message to be sent to the client's console. + */ +extern "C" PLUGIN_API void PrintToConsole(int clientIndex, const plg::string& message) { utils::PrintConsole(CPlayerSlot(clientIndex - 1), message.c_str()); } -extern "C" PLUGIN_API void PrintChat(int clientIndex, const plg::string& message) +/** + * @brief Prints a message to a specific client in the chat area. + * @param clientIndex Index of the client to whom the message will be sent. + * @param message The message to be printed in the chat area. + */ +extern "C" PLUGIN_API void PrintToChat(int clientIndex, const plg::string& message) { utils::PrintChat(CPlayerSlot(clientIndex - 1), message.c_str()); } -extern "C" PLUGIN_API void PrintCentre(int clientIndex, const plg::string& message) +/** + * @brief Prints a message to a specific client in the center of the screen. + * @param clientIndex Index of the client to whom the message will be sent. + * @param message The message to be printed in the center of the screen. + */ +extern "C" PLUGIN_API void PrintCenterText(int clientIndex, const plg::string& message) { utils::PrintCentre(CPlayerSlot(clientIndex - 1), message.c_str()); } -extern "C" PLUGIN_API void PrintAlert(int clientIndex, const plg::string& message) +/** + * @brief Prints a message to a specific client with an alert box. + * @param clientIndex Index of the client to whom the message will be sent. + * @param message The message to be printed in the alert box. + */ +extern "C" PLUGIN_API void PrintAlertText(int clientIndex, const plg::string& message) { utils::PrintAlert(CPlayerSlot(clientIndex - 1), message.c_str()); } -extern "C" PLUGIN_API void PrintHtmlCentre(int clientIndex, const plg::string& message) +/** + * @brief Prints a html message to a specific client in the center of the screen. + * @param clientIndex Index of the client to whom the message will be sent. + * @param message The HTML-formatted message to be printed. + */ +extern "C" PLUGIN_API void PrintCentreHtml(int clientIndex, const plg::string& message) { utils::PrintHtmlCentre(CPlayerSlot(clientIndex - 1), message.c_str()); } -extern "C" PLUGIN_API void PrintConsoleAll(const plg::string& message) +/** + * @brief Sends a message to every client's console. + * @param message The message to be sent to all clients' consoles. + */ +extern "C" PLUGIN_API void PrintToConsoleAll(const plg::string& message) { utils::PrintConsoleAll(message.c_str()); } -extern "C" PLUGIN_API void PrintChatAll(const plg::string& message) +/** + * @brief Prints a message to all clients in the chat area. + * @param message The message to be printed in the chat area for all clients. + */ +extern "C" PLUGIN_API void PrintToChatAll(const plg::string& message) { utils::PrintChatAll(message.c_str()); } -extern "C" PLUGIN_API void PrintCentreAll(const plg::string& message) +/** + * @brief Prints a message to all clients in the center of the screen. + * @param message The message to be printed in the center of the screen for all clients. + */ +extern "C" PLUGIN_API void PrintCenterTextAll(const plg::string& message) { utils::PrintCentreAll(message.c_str()); } -extern "C" PLUGIN_API void PrintAlertAll(const plg::string& message) +/** + * @brief Prints a message to all clients with an alert box. + * @param message The message to be printed in an alert box for all clients. + */ +extern "C" PLUGIN_API void PrintAlertTextToAll(const plg::string& message) { utils::PrintAlertAll(message.c_str()); } -extern "C" PLUGIN_API void PrintHtmlCentreAll(const plg::string& message) +/** + * @brief Prints a html message to all clients in the center of the screen. + * @param message The HTML-formatted message to be printed in the center of the screen for all clients. + */ +extern "C" PLUGIN_API void PrintCentreHtmlAll(const plg::string& message) { utils::PrintHtmlCentreAll(message.c_str()); } -extern "C" PLUGIN_API void PrintChatColored(int clientIndex, const plg::string& message) +/** + * @brief Prints a colored message to a specific client in the chat area. + * @param clientIndex Index of the client to whom the message will be sent. + * @param message The message to be printed in the chat area with color. + */ +extern "C" PLUGIN_API void PrintToChatColored(int clientIndex, const plg::string& message) { utils::CPrintChat(CPlayerSlot(clientIndex - 1), message.c_str()); } -extern "C" PLUGIN_API void PrintChatColoredAll(const plg::string& message) +/** + * @brief Prints a colored message to all clients in the chat area. + * @param message The colored message to be printed in the chat area for all clients. + */ +extern "C" PLUGIN_API void PrintToChatColoredAll(const plg::string& message) { utils::CPrintChatAll(message.c_str()); } diff --git a/src/export/cvars.cpp b/src/export/cvars.cpp index 9735094..9cfe0ec 100644 --- a/src/export/cvars.cpp +++ b/src/export/cvars.cpp @@ -7,56 +7,217 @@ // CreateConVar() +/** + * @brief Creates a new console variable. + * @param name The name of the console variable. + * @param defaultValue The default value of the console variable. + * @param description A description of the console variable's purpose. + * @param flags Additional flags for the console variable. + * @return A pointer to the created console variable. + */ +extern "C" PLUGIN_API CConVarBaseData* CreateConVar(const plg::string& name, const plg::string& defaultValue, const plg::string& description, int flags) +{ + return g_ConVarManager.CreateConVar(name, description, defaultValue.data(), flags); +} + +/** + * @brief Creates a new boolean console variable. + * + * This function registers a new console variable of type boolean with the specified name, default value, + * description, and flags. Additionally, it allows for setting minimum and maximum constraints. + * + * @param name The name of the console variable. + * @param defaultValue The default value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarBool(const plg::string& name, bool defaultValue, const plg::string& description, int flags, bool hasMin, bool min, bool hasMax, bool max) { return g_ConVarManager.CreateConVar(name, description, defaultValue, flags, hasMin, min, hasMax, max); } +/** + * @brief Creates a new 16-bit signed integer console variable. + * + * This function registers a new console variable of type int16_t with the specified parameters. + * + * @param name The name of the console variable. + * @param defaultValue The default value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarInt16(const plg::string& name, int16_t defaultValue, const plg::string& description, int flags, bool hasMin, int16_t min, bool hasMax, int16_t max) { return g_ConVarManager.CreateConVar(name, description, defaultValue, flags, hasMin, min, hasMax, max); } +/** + * @brief Creates a new 16-bit unsigned integer console variable. + * + * This function registers a new console variable of type uint16_t with the specified parameters. + * + * @param name The name of the console variable. + * @param defaultValue The default value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarUInt16(const plg::string& name, uint16_t defaultValue, const plg::string& description, int flags, bool hasMin, uint16_t min, bool hasMax, uint16_t max) { return g_ConVarManager.CreateConVar(name, description, defaultValue, flags, hasMin, min, hasMax, max); } +/** + * @brief Creates a new 32-bit signed integer console variable. + * + * This function registers a new console variable of type int32_t with the specified parameters. + * + * @param name The name of the console variable. + * @param defaultValue The default value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarInt32(const plg::string& name, int32_t defaultValue, const plg::string& description, int flags, bool hasMin, int32_t min, bool hasMax, int32_t max) { return g_ConVarManager.CreateConVar(name, description, defaultValue, flags, hasMin, min, hasMax, max); } +/** + * @brief Creates a new 32-bit unsigned integer console variable. + * + * This function registers a new console variable of type uint32_t with the specified parameters. + * + * @param name The name of the console variable. + * @param defaultValue The default value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarUInt32(const plg::string& name, uint32_t defaultValue, const plg::string& description, int flags, bool hasMin, uint32_t min, bool hasMax, uint32_t max) { return g_ConVarManager.CreateConVar(name, description, defaultValue, flags, hasMin, min, hasMax, max); } + +/** + * @brief Creates a new 64-bit signed integer console variable. + * + * This function registers a new console variable of type int64_t with the specified parameters. + * + * @param name The name of the console variable. + * @param defaultValue The default value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarInt64(const plg::string& name, int64_t defaultValue, const plg::string& description, int flags, bool hasMin, int64_t min, bool hasMax, int64_t max) { return g_ConVarManager.CreateConVar(name, description, defaultValue, flags, hasMin, min, hasMax, max); } +/** + * @brief Creates a new 64-bit unsigned integer console variable. + * + * This function registers a new console variable of type uint64_t with the specified parameters. + * + * @param name The name of the console variable. + * @param defaultValue The default value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarUInt64(const plg::string& name, uint64_t defaultValue, const plg::string& description, int flags, bool hasMin, uint64_t min, bool hasMax, uint64_t max) { return g_ConVarManager.CreateConVar(name, description, defaultValue, flags, hasMin, min, hasMax, max); } +/** + * @brief Creates a new floating-point console variable. + * + * This function registers a new console variable of type float with the specified parameters. + * + * @param name The name of the console variable. + * @param defaultValue The default value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarFloat(const plg::string& name, float defaultValue, const plg::string& description, int flags, bool hasMin, float min, bool hasMax, float max) { return g_ConVarManager.CreateConVar(name, description, defaultValue, flags, hasMin, min, hasMax, max); } +/** + * @brief Creates a new double-precision console variable. + * + * This function registers a new console variable of type double with the specified parameters. + * + * @param name The name of the console variable. + * @param defaultValue The default value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarDouble(const plg::string& name, double defaultValue, const plg::string& description, int flags, bool hasMin, double min, bool hasMax, double max) { return g_ConVarManager.CreateConVar(name, description, defaultValue, flags, hasMin, min, hasMax, max); } -extern "C" PLUGIN_API CConVarBaseData* CreateConVar(const plg::string& name, const plg::string& defaultValue, const plg::string& description, int flags) -{ - return g_ConVarManager.CreateConVar(name, description, defaultValue.data(), flags); -} - +/** + * @brief Creates a new color console variable. + * + * This function registers a new console variable of type Color with the specified parameters. + * The color is specified as an integer value. + * + * @param name The name of the console variable. + * @param defaultValue The default color value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum color value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum color value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarColor(const plg::string& name, int defaultValue, const plg::string& description, int flags, bool hasMin, int min, bool hasMax, int max) { Color defaultCol; @@ -68,61 +229,295 @@ extern "C" PLUGIN_API CConVarBaseData* CreateConVarColor(const plg::string& name return g_ConVarManager.CreateConVar(name, description, defaultCol, flags, hasMin, minCol, hasMax, maxCol); } +/** + * @brief Creates a new 2D vector console variable. + * + * This function registers a new console variable of type Vector2D with the specified parameters. + * + * @param name The name of the console variable. + * @param defaultValue The default value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarVector2(const plg::string& name, const Vector2D& defaultValue, const plg::string& description, int flags, bool hasMin, const Vector2D& min, bool hasMax, const Vector2D& max) { return g_ConVarManager.CreateConVar(name, description, defaultValue, flags, hasMin, min, hasMax, max); } +/** + * @brief Creates a new 3D vector console variable. + * + * This function registers a new console variable of type Vector with the specified parameters. + * + * @param name The name of the console variable. + * @param defaultValue The default value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarVector3(const plg::string& name, const Vector& defaultValue, const plg::string& description, int flags, bool hasMin, const Vector& min, bool hasMax, const Vector& max) { return g_ConVarManager.CreateConVar(name, description, defaultValue, flags, hasMin, min, hasMax, max); } +/** + * @brief Creates a new 4D vector console variable. + * + * This function registers a new console variable of type Vector4D with the specified parameters. + * + * @param name The name of the console variable. + * @param defaultValue The default value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarVector4(const plg::string& name, const Vector4D& defaultValue, const plg::string& description, int flags, bool hasMin, const Vector4D& min, bool hasMax, const Vector4D& max) { return g_ConVarManager.CreateConVar(name, description, defaultValue, flags, hasMin, min, hasMax, max); } +/** + * @brief Creates a new quaternion angle console variable. + * + * This function registers a new console variable of type QAngle with the specified parameters. + * + * @param name The name of the console variable. + * @param defaultValue The default value for the console variable. + * @param description A brief description of the console variable. + * @param flags Flags that define the behavior of the console variable. + * @param hasMin Indicates if a minimum value is provided. + * @param min The minimum value if hasMin is true. + * @param hasMax Indicates if a maximum value is provided. + * @param max The maximum value if hasMax is true. + * @return A pointer to the created console variable data. + */ extern "C" PLUGIN_API CConVarBaseData* CreateConVarQangle(const plg::string& name, const QAngle& defaultValue, const plg::string& description, int flags, bool hasMin, const QAngle& min, bool hasMax, const QAngle& max) { return g_ConVarManager.CreateConVar(name, description, defaultValue, flags, hasMin, min, hasMax, max); } +/** + * @brief Searches for a console variable. * + * @param name The name of the console variable to search for. + * @return Pointer to the console variable data if found; otherwise, nullptr. + */ extern "C" PLUGIN_API CConVarBaseData* FindConVar(const plg::string& name) { return g_ConVarManager.FindConVar(name); } +/** + * @brief Creates a hook for when a console variable's value is changed. +* + * This function allows a callback to be executed whenever the specified console variable is modified. + * + * @param name The name of the console variable to hook. + * @param callback The callback function to be executed when the variable's value changes. + */ extern "C" PLUGIN_API void HookConVarChange(const plg::string& name, ConVarChangeListenerCallback callback) { g_ConVarManager.HookConVarChange(name, callback); } +/** + * @brief Removes a hook for when a console variable's value is changed. +* + * This function unhooks a previously set callback for a console variable. + * + * @param name The name of the console variable to unhook. + * @param callback The callback function to be removed. + */ extern "C" PLUGIN_API void UnhookConVarChange(const plg::string& name, ConVarChangeListenerCallback callback) { g_ConVarManager.UnhookConVarChange(name, callback); } +/** + * @brief Checks if a specific flag is set for a console variable. + * + * @param conVar Pointer to the console variable data. + * @param flag The flag to check against the console variable. + * @return True if the flag is set; otherwise, false. + */ extern "C" PLUGIN_API bool IsConVarFlagSet(CConVarBaseData* conVar, int64_t flag) { return conVar->IsFlagSet(flag); } +/** + * @brief Adds flags to a console variable. + * + * @param conVar Pointer to the console variable data. + * @param flags The flags to be added. + */ extern "C" PLUGIN_API void AddConVarFlags(CConVarBaseData* conVar, int64_t flags) { conVar->AddFlags(flags); } +/** + * @brief Removes flags from a console variable. + * + * @param conVar Pointer to the console variable data. + * @param flags The flags to be removed. + */ extern "C" PLUGIN_API void RemoveConVarFlags(CConVarBaseData* conVar, int64_t flags) { conVar->RemoveFlags(flags); } +/** + * @brief Retrieves the current flags of a console variable. + * + * @param conVar Pointer to the console variable data. + * @return The current flags set on the console variable. + */ extern "C" PLUGIN_API int64_t GetConVarFlags(CConVarBaseData* conVar) { return conVar->GetFlags(); } +/** + * @brief Gets the specified bound (max or min) of a console variable and stores it in the output string. + * + * @param output Reference to the output string to store the bound value. + * @param conVar Pointer to the console variable data. + * @param max Indicates whether to get the maximum (true) or minimum (false) bound. + */ +extern "C" PLUGIN_API void GetConVarBounds(const plg::string& output, CConVarBaseData* conVar, bool max) +{ + plg::string value(256, '\0'); + if (max) + { + switch (conVar->GetType()) + { + case EConVarType_Bool: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_Int16: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_UInt16: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_Int32: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_UInt32: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_Int64: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_UInt64: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_Float32: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_Float64: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_String: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_Color: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_Vector2: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_Vector3: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_Vector4: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + case EConVarType_Qangle: + conVar->Cast()->GetStringMaxValue(value.data(), value.size()); + break; + default: + g_Logger.Log(LS_WARNING, "Invalid convar type.\n"); + break; + } + } + else + { + switch (conVar->GetType()) + { + case EConVarType_Bool: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_Int16: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_UInt16: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_Int32: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_UInt32: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_Int64: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_UInt64: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_Float32: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_Float64: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_String: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_Color: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_Vector2: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_Vector3: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_Vector4: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + case EConVarType_Qangle: + conVar->Cast()->GetStringMinValue(value.data(), value.size()); + break; + default: + g_Logger.Log(LS_WARNING, "Invalid convar type.\n"); + break; + } + } + std::construct_at(&output, std::move(value)); +} + +/** + * @brief Sets the specified bound (max or min) for a console variable. + * + * @param conVar Pointer to the console variable data. + * @param max Indicates whether to set the maximum (true) or minimum (false) bound. + * @param value The value to set as the bound. + */ extern "C" PLUGIN_API void SetConVarBounds(CConVarBaseData* conVar, bool max, const plg::string& value) { if (max) @@ -235,6 +630,12 @@ extern "C" PLUGIN_API void SetConVarBounds(CConVarBaseData* conVar, bool max, co } } +/** + * @brief Retrieves the current value of a console variable and stores it in the output string. + * + * @param conVar Pointer to the console variable data. + * @return The output value in string format. + */ extern "C" PLUGIN_API void GetConVarValue(plg::string& output, CConVarBaseData* conVar) { switch (conVar->GetType()) @@ -272,41 +673,31 @@ extern "C" PLUGIN_API void GetConVarValue(plg::string& output, CConVarBaseData* case EConVarType_Color: { const auto& value = conVar->Cast()->GetValue(); - std::stringstream ss; - ss << value.r() << " " << value.g() << " " << value.b() << " " << value.a(); - std::construct_at(&output, ss.str()); + std::construct_at(&output, std::format("{} {} {} {}", value.r(), value.g(), value.b(), value.a())); break; } case EConVarType_Vector2: { const auto& value = conVar->Cast()->GetValue(); - std::stringstream ss; - ss << value.x << " " << value.y; - std::construct_at(&output, ss.str()); + std::construct_at(&output, std::format("{} {}", value.x, value.y)); break; } case EConVarType_Vector3: { const auto& value = conVar->Cast()->GetValue(); - std::stringstream ss; - ss << value.x << " " << value.y << " " << value.z; - std::construct_at(&output, ss.str()); + std::construct_at(&output, std::format("{} {} {}", value.x, value.y, value.z)); break; } case EConVarType_Vector4: { const auto& value = conVar->Cast()->GetValue(); - std::stringstream ss; - ss << value.x << " " << value.y << " " << value.z << " " << value.w; - std::construct_at(&output, ss.str()); + std::construct_at(&output, std::format("{} {} {} {}", value.x, value.y, value.z, value.w)); break; } case EConVarType_Qangle: { const auto& value = conVar->Cast()->GetValue(); - std::stringstream ss; - ss << value.x << " " << value.y << " " << value.z; - std::construct_at(&output, ss.str()); + std::construct_at(&output, std::format("{} {} {}", value.x, value.y, value.z)); break; } default: @@ -315,6 +706,177 @@ extern "C" PLUGIN_API void GetConVarValue(plg::string& output, CConVarBaseData* } } +/** + * @brief Retrieves the current value of a boolean console variable. + * + * @param conVar Pointer to the console variable data. + * @return The current boolean value of the console variable. + */ +extern "C" PLUGIN_API bool GetConVarBool(CConVarBaseData* conVar) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Retrieves the current value of a signed 16-bit integer console variable. + * + * @param conVar Pointer to the console variable data. + * @return The current int16_t value of the console variable. + */ +extern "C" PLUGIN_API int16_t GetConVarInt16(CConVarBaseData* conVar) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Retrieves the current value of an unsigned 16-bit integer console variable. + * + * @param conVar Pointer to the console variable data. + * @return The current uint16_t value of the console variable. + */ +extern "C" PLUGIN_API uint16_t GetConVarUInt16(CConVarBaseData* conVar) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Retrieves the current value of a signed 32-bit integer console variable. + * + * @param conVar Pointer to the console variable data. + * @return The current int32_t value of the console variable. + */ +extern "C" PLUGIN_API int32_t GetConVarInt32(CConVarBaseData* conVar) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Retrieves the current value of an unsigned 32-bit integer console variable. + * + * @param conVar Pointer to the console variable data. + * @return The current uint32_t value of the console variable. + */ +extern "C" PLUGIN_API uint32_t GetConVarUInt32(CConVarBaseData* conVar) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Retrieves the current value of a signed 64-bit integer console variable. + * + * @param conVar Pointer to the console variable data. + * @return The current int64_t value of the console variable. + */ +extern "C" PLUGIN_API int64_t GetConVarInt64(CConVarBaseData* conVar) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Retrieves the current value of an unsigned 64-bit integer console variable. + * + * @param conVar Pointer to the console variable data. + * @return The current uint64_t value of the console variable. + */ +extern "C" PLUGIN_API uint64_t GetConVarUInt64(CConVarBaseData* conVar) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Retrieves the current value of a float console variable. + * + * @param conVar Pointer to the console variable data. + * @return The current float value of the console variable. + */ +extern "C" PLUGIN_API float GetConVarFloat(CConVarBaseData* conVar) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Retrieves the current value of a double console variable. + * + * @param conVar Pointer to the console variable data. + * @return The current double value of the console variable. + */ +extern "C" PLUGIN_API double GetConVarDouble(CConVarBaseData* conVar) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Retrieves the current value of a string console variable. + * + * @param conVar Pointer to the console variable data. + * @return The current string value of the console variable. + */ +extern "C" PLUGIN_API void GetConVarString(plg::string& output, CConVarBaseData* conVar) +{ + std::construct_at(&output, conVar->Cast()->GetValue()); +} + +/** + * @brief Retrieves the current value of a Color console variable. + * + * @param conVar Pointer to the console variable data. + * @return The current Color value of the console variable. + */ +extern "C" PLUGIN_API Color GetConVarColor(CConVarBaseData* conVar) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Retrieves the current value of a Vector2D console variable. + * + * @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) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Retrieves the current value of a Vector console variable. + * + * @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) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Retrieves the current value of a Vector4D console variable. + * + * @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) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Retrieves the current value of a QAngle console variable. + * + * @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) +{ + return conVar->Cast()->GetValue(); +} + +/** + * @brief Sets the value of a console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ extern "C" PLUGIN_API void SetConVarValue(CConVarBaseData* conVar, const plg::string& value) { switch (conVar->GetType()) @@ -370,16 +932,202 @@ extern "C" PLUGIN_API void SetConVarValue(CConVarBaseData* conVar, const plg::st } } +/** + * @brief Sets the value of a boolean console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarBool(CConVarBaseData* conVar, bool value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Sets the value of a signed 16-bit integer console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarInt16(CConVarBaseData* conVar, int16_t value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Sets the value of an unsigned 16-bit integer console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarUInt16(CConVarBaseData* conVar, uint16_t value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Sets the value of a signed 32-bit integer console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarInt32(CConVarBaseData* conVar, int32_t value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Sets the value of an unsigned 32-bit integer console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarUInt32(CConVarBaseData* conVar, uint32_t value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Sets the value of a signed 64-bit integer console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarInt64(CConVarBaseData* conVar, int64_t value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Sets the value of an unsigned 64-bit integer console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarUInt64(CConVarBaseData* conVar, uint64_t value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Sets the value of a floating-point console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarFloat(CConVarBaseData* conVar, float value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Sets the value of a double-precision floating-point console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarDouble(CConVarBaseData* conVar, double value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Sets the value of a string console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarString(CConVarBaseData* conVar, const plg::string& value) +{ + conVar->Cast()->SetValue(value.c_str()); +} + +/** + * @brief Sets the value of a color console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarColor(CConVarBaseData* conVar, const Color& value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Sets the value of a 2D vector console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarVector2(CConVarBaseData* conVar, const Vector2D& value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Sets the value of a 3D vector console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarVector3(CConVarBaseData* conVar, const Vector& value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Sets the value of a 4D vector console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarVector4(CConVarBaseData* conVar, const Vector4D& value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Sets the value of a quaternion angle console variable. + * + * @param conVar Pointer to the console variable data. + * @param value The value to set for the console variable. + */ +extern "C" PLUGIN_API void SetConVarQangle(CConVarBaseData* conVar, const QAngle& value) +{ + conVar->Cast()->SetValue(value); +} + +/** + * @brief Replicates a console variable value to a specific client. This does not change the actual console variable value. + * + * @param conVar Pointer to the console variable data. + * @param clientIndex The index of the client to replicate the value to. + * @param value The value to send to the client. + */ extern "C" PLUGIN_API void SendConVarValue(CConVarBaseData* conVar, int clientIndex, const plg::string& value) { utils::SendConVarValue(CPlayerSlot(clientIndex - 1), conVar, value.c_str()); } +/** + * @brief Retrieves the value of a client's console variable and stores it in the output string. + * + * @param clientIndex The index of the client whose console variable value is being retrieved. + * @param convarName The name of the console variable to retrieve. + * @return The output string to store the client's console variable value. + */ extern "C" PLUGIN_API void GetClientConVarValue(plg::string& output, int clientIndex, const plg::string& convarName) { std::construct_at(&output, g_pEngineServer2->GetClientConVarValue(CPlayerSlot(clientIndex - 1), convarName.c_str())); } +/** + * @brief Replicates a console variable value to a specific fake client. This does not change the actual console variable value. + * + * @param clientIndex The index of the fake client to replicate the value to. + * @param convarName The name of the console variable. + * @param convarValue The value to set for the console variable. + */ extern "C" PLUGIN_API void SetFakeClientConVarValue(int clientIndex, const plg::string& convarName, const plg::string& convarValue) { g_pEngineServer2->SetFakeClientConVarValue(CPlayerSlot(clientIndex - 1), convarName.c_str(), convarValue.c_str()); diff --git a/src/export/engine.cpp b/src/export/engine.cpp index fdbf715..e9fcdfc 100644 --- a/src/export/engine.cpp +++ b/src/export/engine.cpp @@ -5,13 +5,22 @@ #include #include #include - +/** + * @brief Returns the path of the game's directory. + * + * @param result A reference to a string where the game directory path will be stored. + */ extern "C" PLUGIN_API void GetGameDirectory(plg::string& result) { std::construct_at(&result, Plat_GetGameDirectory()); } -extern "C" PLUGIN_API void GetMapName(plg::string& result) +/** + * @brief Returns the current map name. + * + * @param result A reference to a string where the current map name will be stored. + */ +extern "C" PLUGIN_API void GetCurrentMap(plg::string& result) { if (gpGlobals == nullptr) return; @@ -19,11 +28,22 @@ extern "C" PLUGIN_API void GetMapName(plg::string& result) std::construct_at(&result, gpGlobals->mapname.ToCStr()); } +/** + * @brief Returns whether a specified map is valid or not. + * + * @param mapname The name of the map to check for validity. + * @return True if the map is valid, false otherwise. + */ extern "C" PLUGIN_API bool IsMapValid(const plg::string& mapname) { return g_pEngineServer2->IsMapValid(mapname.c_str()) != 0; } +/** + * @brief Returns the game time based on the game tick. + * + * @return The current game time. + */ extern "C" PLUGIN_API float GetGameTime() { if (gpGlobals == nullptr) @@ -35,6 +55,11 @@ extern "C" PLUGIN_API float GetGameTime() return gpGlobals->curtime; } +/** + * @brief Returns the game's internal tick count. + * + * @return The current tick count of the game. + */ extern "C" PLUGIN_API int GetGameTickCount() { if (gpGlobals == nullptr) @@ -46,6 +71,11 @@ extern "C" PLUGIN_API int GetGameTickCount() return gpGlobals->tickcount; } +/** + * @brief Returns the time the game took processing the last frame. + * + * @return The frame time of the last processed frame. + */ extern "C" PLUGIN_API float GetGameFrameTime() { if (gpGlobals == nullptr) @@ -57,11 +87,21 @@ extern "C" PLUGIN_API float GetGameFrameTime() return gpGlobals->frametime; } +/** + * @brief Returns a high-precision time value for profiling the engine. + * + * @return A high-precision time value. + */ extern "C" PLUGIN_API double GetEngineTime() { return Plat_FloatTime(); } +/** + * @brief Returns the maximum number of clients that can connect to the server. + * + * @return The maximum client count, or -1 if global variables are not initialized. + */ extern "C" PLUGIN_API int GetMaxClients() { if (gpGlobals == nullptr) @@ -73,71 +113,154 @@ extern "C" PLUGIN_API int GetMaxClients() return gpGlobals->maxClients; } +/** + * @brief Precaches a given generic file. + * + * @param model The name of the model to be precached. + * @return An integer identifier for the generic file. + */ +extern "C" PLUGIN_API int PrecacheGeneric(const plg::string& model) +{ + return g_pEngineServer2->PrecacheGeneric(model.c_str()); +} + +/** + * @brief Checks if a specified generic file is precached. + * + * @param model The name of the generic file to check. + */ +extern "C" PLUGIN_API bool IsGenericPrecache(const plg::string& model) +{ + return g_pEngineServer2->IsGenericPrecached(model.c_str()); +} + +/** + * @brief Precaches a specified model. + * + * @param model The name of the model to be precached. + * @return An integer identifier for the model. + */ extern "C" PLUGIN_API int PrecacheModel(const plg::string& model) { return g_pEngineServer2->PrecacheGeneric(model.c_str()); } -extern "C" PLUGIN_API void IsModelPrecache(const plg::string& model) +/** + * @brief Checks if a specified model is precached. + * + * @param model The name of the model to check. + */ +extern "C" PLUGIN_API bool IsModelPrecache(const plg::string& model) { - g_pEngineServer2->IsGenericPrecached(model.c_str()); + return g_pEngineServer2->IsGenericPrecached(model.c_str()); } +/** + * @brief Precaches a specified sound. + * + * @param sound The name of the sound to be precached. + * @param preload A boolean indicating if the sound should be preloaded. + * @return True if the sound is successfully precached, false otherwise. + */ extern "C" PLUGIN_API bool PrecacheSound(const plg::string& sound, bool preload) { return g_pEngineSound->PrecacheSound(sound.c_str(), preload); } +/** + * @brief Checks if a specified sound is precached. + * + * @param sound The name of the sound to check. + * @return True if the sound is precached, false otherwise. + */ extern "C" PLUGIN_API bool IsSoundPrecached(const plg::string& sound) { return g_pEngineSound->IsSoundPrecached(sound.c_str()); } +/** + * @brief Precaches a specified decal. + * + * @param decal The name of the decal to be precached. + * @param preload A boolean indicating if the decal should be preloaded. + * @return An integer identifier for the decal. + */ extern "C" PLUGIN_API int PrecacheDecal(const plg::string& decal, bool preload) { return g_pEngineServer2->PrecacheDecal(decal.c_str(), preload); } +/** + * @brief Checks if a specified decal is precached. + * + * @param decal The name of the decal to check. + * @return True if the decal is precached, false otherwise. + */ extern "C" PLUGIN_API bool IsDecalPrecached(const plg::string& decal) { return g_pEngineServer2->IsDecalPrecached(decal.c_str()); } -extern "C" PLUGIN_API float GetTickInterval() -{ - return CTimerSystem::GetTickedInterval(); -} - -extern "C" PLUGIN_API double GetTickedTime() -{ - return CTimerSystem::GetTickedTime(); -} - +/** + * @brief Returns a pointer to the Economy Item System. + * + * @return A pointer to the Econ Item System. + */ extern "C" PLUGIN_API void* GetEconItemSystem() { return g_pSource2Server->GetEconItemSystem(); } +/** + * @brief Checks if the server is currently paused. + * + * @return True if the server is paused, false otherwise. + */ extern "C" PLUGIN_API bool IsServerPaused() { return g_pSource2Server->IsPaused(); } +/** + * @brief Queues a task to be executed on the next frame. + * + * @param callback A callback function to be executed on the next frame. + */ extern "C" PLUGIN_API void QueueTaskForNextFrame(TaskCallback callback) { g_ServerManager.AddTaskForNextFrame(callback); } +/** + * @brief Queues a task to be executed on the next world update. + * + * @param callback A callback function to be executed on the next world update. + */ extern "C" PLUGIN_API void QueueTaskForNextWorldUpdate(TaskCallback callback) { g_ServerManager.AddTaskForNextWorldUpdate(callback); } +/** + * @brief Returns the duration of a specified sound. + * + * @param name The name of the sound to check. + * @return The duration of the sound in seconds. + */ extern "C" PLUGIN_API float GetSoundDuration(const plg::string& name) { return g_pEngineSound->GetSoundDuration(name.c_str()); } +/** + * @brief Emits a sound from a specified entity. + * + * @param entityHandle The handle of the entity that will emit the sound. + * @param sound The name of the sound to emit. + * @param pitch The pitch of the sound. + * @param volume The volume of the sound. + * @param delay The delay before the sound is played. + */ extern "C" PLUGIN_API void EmitSound(int entityHandle, const plg::string& sound, int pitch, float volume, float delay) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -149,10 +272,20 @@ extern "C" PLUGIN_API void EmitSound(int entityHandle, const plg::string& sound, addresses::CBaseEntity_EmitSoundParams(ent, sound.c_str(), pitch, volume, delay); } +/** + * @brief Emits a sound to a specific client. + * + * @param clientIndex The index of the client to whom the sound will be emitted. + * @param channel The channel through which the sound will be played. + * @param sound The name of the sound to emit. + * @param volume The volume of the sound. + * @param soundLevel The level of the sound. + * @param flags Additional flags for sound playback. + * @param pitch The pitch of the sound. + * @param origin The origin of the sound in 3D space. + * @param soundTime The time at which the sound should be played. + */ extern "C" PLUGIN_API void EmitSoundToClient(int clientIndex, int channel, const plg::string& sound, float volume, int soundLevel, int flags, int pitch, const Vector& origin, float soundTime) { utils::PlaySoundToClient(CPlayerSlot(clientIndex - 1), channel, sound.c_str(), volume, static_cast(soundLevel), flags, pitch, origin, soundTime); } - - - diff --git a/src/export/entities.cpp b/src/export/entities.cpp index e02d396..a1f29ef 100644 --- a/src/export/entities.cpp +++ b/src/export/entities.cpp @@ -2,169 +2,323 @@ #include #include #include - +/** + * @brief Converts an entity index into an entity pointer. + * + * This function retrieves a pointer to the entity corresponding to the given + * entity index. It is essential for accessing entity properties and methods + * using the entity index. + * + * @param entityIndex The index of the entity to convert. + * @return A pointer to the entity instance, or nullptr if the entity does not exist. + */ extern "C" PLUGIN_API void* EntIndexToEntPointer(int entityIndex) { - return static_cast(g_pEntitySystem->GetEntityInstance(CEntityIndex(entityIndex))); + return static_cast(g_pEntitySystem->GetEntityInstance(CEntityIndex(entityIndex))); } +/** + * @brief Retrieves the entity index from an entity pointer. + * + * This function returns the index associated with a given entity pointer, + * allowing for the identification of the entity's position in the entity list. + * + * @param entity A pointer to the entity whose index is to be retrieved. + * @return The index of the entity, or -1 if the entity is nullptr. + */ extern "C" PLUGIN_API int EntPointerToEntIndex(CBaseEntity* entity) { - return entity->entindex(); + return entity->entindex(); } +/** + * @brief Converts an entity pointer into an entity handle. + * + * This function creates and returns an entity handle from a given entity pointer. + * If the entity pointer is null, it returns an invalid entity handle index. + * + * @param entity A pointer to the entity to convert. + * @return The entity handle as an integer, or INVALID_EHANDLE_INDEX if the entity is nullptr. + */ extern "C" PLUGIN_API int EntPointerToEntHandle(CBaseEntity* entity) { - if (entity == nullptr) - { - return INVALID_EHANDLE_INDEX; - } + if (entity == nullptr) + { + return INVALID_EHANDLE_INDEX; + } - return entity->GetRefEHandle().ToInt(); + return entity->GetRefEHandle().ToInt(); } +/** + * @brief Retrieves the entity pointer from an entity handle. + * + * This function retrieves the entity pointer corresponding to the given entity handle. + * If the handle is invalid, it returns nullptr. + * + * @param entityHandle The entity handle to convert. + * @return A pointer to the entity instance, or nullptr if the handle is invalid. + */ extern "C" PLUGIN_API void* EntHandleToEntPointer(int entityHandle) { - CEntityHandle handle((uint32)entityHandle); - if (!handle.IsValid()) - { - return nullptr; - } + CEntityHandle handle((uint32)entityHandle); + if (!handle.IsValid()) + { + return nullptr; + } - return g_pEntitySystem->GetEntityInstance(handle); + return g_pEntitySystem->GetEntityInstance(handle); } +/** + * @brief Converts an entity index into an entity handle. + * + * This function converts a given entity index into its corresponding entity handle. + * If the entity index is invalid, it returns INVALID_EHANDLE_INDEX. + * + * @param entityIndex The index of the entity to convert. + * @return The entity handle as an integer, or INVALID_EHANDLE_INDEX if the entity index is invalid. + */ extern "C" PLUGIN_API int EntIndexToEntHandle(int entityIndex) { - CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityIndex(entityIndex))); - if (!ent) - { - return INVALID_EHANDLE_INDEX; - } + CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityIndex(entityIndex))); + if (!ent) + { + return INVALID_EHANDLE_INDEX; + } - return ent->GetRefEHandle().ToInt(); + return ent->GetRefEHandle().ToInt(); } +/** + * @brief Retrieves the entity index from an entity handle. + * + * This function retrieves the entity index corresponding to the provided entity handle. + * If the handle is invalid or does not correspond to an entity, it returns -1. + * + * @param entityHandle The entity handle from which to retrieve the index. + * @return The index of the entity, or -1 if the handle is invalid. + */ extern "C" PLUGIN_API int EntHandleToEntIndex(int entityHandle) { - CEntityHandle handle((uint32)entityHandle); - if (!handle.IsValid()) - { - return -1; - } - - CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(handle)); - if (!ent) - { - return -1; - } - - return ent->entindex(); -} - + CEntityHandle handle((uint32)entityHandle); + if (!handle.IsValid()) + { + return -1; + } + + CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(handle)); + if (!ent) + { + return -1; + } + + return ent->entindex(); +} + +/** + * @brief Checks if the provided entity handle is valid. + * + * This function checks whether the entity handle points to a valid entity in the + * entity system. It returns true if valid, and false otherwise. + * + * @param entityHandle The entity handle to check. + * @return True if the entity handle is valid, false otherwise. + */ extern "C" PLUGIN_API bool IsValidEntHandle(int entityHandle) { - CEntityHandle handle((uint32)entityHandle); - if (!handle.IsValid()) - { - return false; - } + CEntityHandle handle((uint32)entityHandle); + if (!handle.IsValid()) + { + return false; + } - return g_pEntitySystem->GetEntityInstance(handle) != nullptr; + return g_pEntitySystem->GetEntityInstance(handle) != nullptr; } +/** + * @brief Retrieves the pointer to the first active entity. + * + * This function returns a pointer to the first active entity in the entity system, + * which can be useful for iterating through active entities. + * + * @return A pointer to the first active entity. + */ extern "C" PLUGIN_API void* GetFirstActiveEntity() { - return g_pEntitySystem->m_EntityList.m_pFirstActiveEntity; + return g_pEntitySystem->m_EntityList.m_pFirstActiveEntity; } +/** + * @brief Retrieves a pointer to the concrete entity list. + * + * This function returns a pointer to the concrete entity list, allowing for direct + * access to the list of entities managed by the entity system. + * + * @return A pointer to the entity list structure. + */ extern "C" PLUGIN_API void* GetConcreteEntityListPointer() { - return &g_pEntitySystem->m_EntityList; + return &g_pEntitySystem->m_EntityList; } +/** + * @brief Adds an entity output hook on a specified entity class name. + * + * This function hooks a specified output for a given entity class name. The provided + * callback will be triggered when the output is fired. + * + * @param szClassname The class name of the entity to hook the output for. + * @param szOutput The output event name to hook. + * @param callback The callback function to invoke when the output is fired. + * @param post Indicates whether the hook should be a post-hook (true) or pre-hook (false). + */ extern "C" PLUGIN_API void HookEntityOutput(const plg::string& szClassname, const plg::string& szOutput, EntityListenerCallback callback, bool post) { - g_OutputManager.HookEntityOutput(szClassname, szOutput, callback, static_cast(post)); + g_OutputManager.HookEntityOutput(szClassname, szOutput, callback, static_cast(post)); } +/** + * @brief Removes an entity output hook. + * + * This function unhooks a previously set output for a given entity class name. + * + * @param szClassname The class name of the entity from which to unhook the output. + * @param szOutput The output event name to unhook. + * @param callback The callback function that was previously hooked. + * @param post Indicates whether the hook was a post-hook (true) or pre-hook (false). + */ extern "C" PLUGIN_API void UnhookEntityOutput(const plg::string& szClassname, const plg::string& szOutput, EntityListenerCallback callback, bool post) { - g_OutputManager.UnhookEntityOutput(szClassname, szOutput, callback, static_cast(post)); + g_OutputManager.UnhookEntityOutput(szClassname, szOutput, callback, static_cast(post)); } //////////////////////// - - -extern "C" PLUGIN_API int FindEntityByClassname(int startEntity, const plg::string& szName) -{ - CBaseEntity* start = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle(startEntity))); - /*if (!start) - { - return INVALID_EHANDLE_INDEX; - }*/ - - CBaseEntity* ent = static_cast(addresses::CGameEntitySystem_FindEntityByClassName(g_pEntitySystem, start, szName.c_str())); - if (!ent) - { - return INVALID_EHANDLE_INDEX; - } - - return ent->GetRefEHandle().ToInt(); -} - -extern "C" PLUGIN_API int FindEntityByName(int startEntity, const plg::string& szName) -{ - CBaseEntity* start = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle(startEntity))); - /*if (!start) - { - return INVALID_EHANDLE_INDEX; - }*/ - - CBaseEntity* ent = static_cast(addresses::CGameEntitySystem_FindEntityByName(g_pEntitySystem, start, szName.c_str(), nullptr, nullptr, nullptr, nullptr)); - if (!ent) - { - return INVALID_EHANDLE_INDEX; - } - - return ent->GetRefEHandle().ToInt(); -} - +/** + * @brief Searches for an entity by classname. + * + * This function searches for the first entity that matches the specified class name, + * starting from a given entity. If no entity is found, it returns an invalid handle index. + * + * @param startEntity The entity handle from which to start the search. + * @param classname The class name of the entity to search for. + * @return The entity handle of the found entity, or INVALID_EHANDLE_INDEX if no entity is found. + */ +extern "C" PLUGIN_API int FindEntityByClassname(int startEntity, const plg::string& classname) +{ + CBaseEntity* start = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle(startEntity))); + /*if (!start) + { + return INVALID_EHANDLE_INDEX; + }*/ + + CBaseEntity* ent = static_cast(addresses::CGameEntitySystem_FindEntityByClassName(g_pEntitySystem, start, classname.c_str())); + if (!ent) + { + return INVALID_EHANDLE_INDEX; + } + + return ent->GetRefEHandle().ToInt(); +} + +/** + * @brief Searches for an entity by name. + * + * This function searches for the first entity that matches the specified name, + * starting from a given entity. If no entity is found, it returns an invalid handle index. + * + * @param startEntity The entity handle from which to start the search. + * @param name The name of the entity to search for. + * @return The entity handle of the found entity, or INVALID_EHANDLE_INDEX if no entity is found. + */ +extern "C" PLUGIN_API int FindEntityByName(int startEntity, const plg::string& name) +{ + CBaseEntity* start = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle(startEntity))); + /*if (!start) + { + return INVALID_EHANDLE_INDEX; + }*/ + + CBaseEntity* ent = static_cast(addresses::CGameEntitySystem_FindEntityByName(g_pEntitySystem, start, name.c_str(), nullptr, nullptr, nullptr, nullptr)); + if (!ent) + { + return INVALID_EHANDLE_INDEX; + } + + return ent->GetRefEHandle().ToInt(); +} + +/** + * @brief Creates an entity by string name but does not spawn it. + * + * This function creates an entity using the specified class name. The entity + * is not spawned until DispatchSpawn is called. If ForceEdictIndex is not -1, + * it will use the edict by that index. If the index is invalid or there is + * already an edict using that index, it will error out. + * + * @param className The class name of the entity to create. + * @return The entity handle of the created entity, or INVALID_EHANDLE_INDEX if the entity could not be created. + */ extern "C" PLUGIN_API int CreateEntityByName(const plg::string& className) { - CBaseEntity* ent = static_cast(addresses::CreateEntityByName(className.c_str(), -1)); - if (!ent) - { - return INVALID_EHANDLE_INDEX; - } + CBaseEntity* ent = static_cast(addresses::CreateEntityByName(className.c_str(), -1)); + if (!ent) + { + return INVALID_EHANDLE_INDEX; + } - return ent->GetRefEHandle().ToInt(); + return ent->GetRefEHandle().ToInt(); } +/** + * @brief Spawns an entity into the game. + * + * This function spawns the specified entity into the game world. + * It requires a valid entity handle to function correctly. + * + * @param entityHandle The handle of the entity to spawn. + */ extern "C" PLUGIN_API void DispatchSpawn(int entityHandle) { - CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); - if (!ent) - { - return; - } + CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); + if (!ent) + { + return; + } - ent->DispatchSpawn(); + ent->DispatchSpawn(); } +/** + * @brief Marks an entity for deletion. + * + * This function marks the specified entity for deletion from the game world. + * It requires a valid entity handle to function correctly. + * + * @param entityHandle The handle of the entity to be deleted. + */ extern "C" PLUGIN_API void RemoveEntity(int entityHandle) { - CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); - if (!ent) - { - return; - } + CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); + if (!ent) + { + return; + } - ent->Remove(); + ent->Remove(); } /// +/** + * @brief Retrieves the class name of an entity. + * + * This function gets the class name of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param output A reference to a string where the class name will be stored. + * @param entityHandle The handle of the entity whose class name is to be retrieved. + */ extern "C" PLUGIN_API void GetEntityClassname(plg::string& output, int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -176,6 +330,15 @@ extern "C" PLUGIN_API void GetEntityClassname(plg::string& output, int entityHan std::construct_at(&output, ent->GetClassname()); } +/** + * @brief Retrieves the name of an entity. + * + * This function gets the name of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param output A reference to a string where the entity name will be stored. + * @param entityHandle The handle of the entity whose name is to be retrieved. + */ extern "C" PLUGIN_API void GetEntityName(plg::string& output, int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -187,6 +350,15 @@ extern "C" PLUGIN_API void GetEntityName(plg::string& output, int entityHandle) std::construct_at(&output, ent->GetName()); } +/** + * @brief Sets the name of an entity. + * + * This function updates the name of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose name is to be set. + * @param name The new name to set for the entity. + */ extern "C" PLUGIN_API void SetEntityName(int entityHandle, const plg::string& name) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -198,6 +370,15 @@ extern "C" PLUGIN_API void SetEntityName(int entityHandle, const plg::string& na ent->SetName(name.c_str()); } +/** + * @brief Retrieves the movement type of an entity. + * + * This function returns the movement type of the specified entity. + * If the entity is invalid, it returns 0. + * + * @param entityHandle The handle of the entity whose movement type is to be retrieved. + * @return The movement type of the entity, or 0 if the entity is invalid. + */ extern "C" PLUGIN_API int GetEntityMoveType(int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -208,6 +389,16 @@ extern "C" PLUGIN_API int GetEntityMoveType(int entityHandle) return ent->m_MoveType(); } + +/** + * @brief Sets the movement type of an entity. + * + * This function updates the movement type of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose movement type is to be set. + * @param moveType The new movement type to set for the entity. + */ extern "C" PLUGIN_API void SetEntityMoveType(int entityHandle, int moveType) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -219,6 +410,15 @@ extern "C" PLUGIN_API void SetEntityMoveType(int entityHandle, int moveType) ent->SetMoveType(static_cast(moveType)); } +/** + * @brief Retrieves the gravity scale of an entity. + * + * This function returns the gravity scale of the specified entity. + * If the entity is invalid, it returns 0.0f. + * + * @param entityHandle The handle of the entity whose gravity scale is to be retrieved. + * @return The gravity scale of the entity, or 0.0f if the entity is invalid. + */ extern "C" PLUGIN_API float GetEntityGravity(int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -229,6 +429,16 @@ extern "C" PLUGIN_API float GetEntityGravity(int entityHandle) return ent->m_flGravityScale(); } + +/** + * @brief Sets the gravity scale of an entity. + * + * This function updates the gravity scale of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose gravity scale is to be set. + * @param gravity The new gravity scale to set for the entity. + */ extern "C" PLUGIN_API void SetEntityGravity(int entityHandle, float gravity) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -240,6 +450,15 @@ extern "C" PLUGIN_API void SetEntityGravity(int entityHandle, float gravity) ent->m_flGravityScale = gravity; } +/** + * @brief Retrieves the flags of an entity. + * + * This function returns the flags of the specified entity. + * If the entity is invalid, it returns 0. + * + * @param entityHandle The handle of the entity whose flags are to be retrieved. + * @return The flags of the entity, or 0 if the entity is invalid. + */ extern "C" PLUGIN_API int GetEntityFlags(int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -250,6 +469,16 @@ extern "C" PLUGIN_API int GetEntityFlags(int entityHandle) return ent->m_fFlags(); } + +/** + * @brief Sets the flags of an entity. + * + * This function updates the flags of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose flags are to be set. + * @param flags The new flags to set for the entity. + */ extern "C" PLUGIN_API void SetEntityFlags(int entityHandle, int flags) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -261,6 +490,15 @@ extern "C" PLUGIN_API void SetEntityFlags(int entityHandle, int flags) ent->m_fFlags = flags; } +/** + * @brief Retrieves the render color of an entity. + * + * This function gets the render color of the specified entity. + * If the entity is invalid, it returns 0. + * + * @param entityHandle The handle of the entity whose render color is to be retrieved. + * @return The raw color value of the entity's render color, or 0 if the entity is invalid. + */ extern "C" PLUGIN_API int GetEntityRenderColor(int entityHandle) { CBaseModelEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -271,6 +509,16 @@ extern "C" PLUGIN_API int GetEntityRenderColor(int entityHandle) return ent->m_clrRender().GetRawColor(); } + +/** + * @brief Sets the render color of an entity. + * + * This function updates the render color of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose render color is to be set. + * @param color The new raw color value to set for the entity's render color. + */ extern "C" PLUGIN_API void SetEntityRenderColor(int entityHandle, int color) { CBaseModelEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -284,6 +532,15 @@ extern "C" PLUGIN_API void SetEntityRenderColor(int entityHandle, int color) ent->m_clrRender = clr; } +/** + * @brief Retrieves the render mode of an entity. + * + * This function gets the render mode of the specified entity. + * If the entity is invalid, it returns 0. + * + * @param entityHandle The handle of the entity whose render mode is to be retrieved. + * @return The render mode of the entity, or 0 if the entity is invalid. + */ extern "C" PLUGIN_API int8_t GetEntityRenderMode(int entityHandle) { CBaseModelEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -294,6 +551,16 @@ extern "C" PLUGIN_API int8_t GetEntityRenderMode(int entityHandle) return ent->m_nRenderMode(); } + +/** + * @brief Sets the render mode of an entity. + * + * This function updates the render mode of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose render mode is to be set. + * @param renderMode The new render mode to set for the entity. + */ extern "C" PLUGIN_API void SetEntityRenderMode(int entityHandle, int8_t renderMode) { CBaseModelEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -305,6 +572,15 @@ extern "C" PLUGIN_API void SetEntityRenderMode(int entityHandle, int8_t renderMo ent->m_nRenderMode = renderMode; } +/** + * @brief Retrieves the health of an entity. + * + * This function returns the current health of the specified entity. + * If the entity is invalid, it returns 0. + * + * @param entityHandle The handle of the entity whose health is to be retrieved. + * @return The health of the entity, or 0 if the entity is invalid. + */ extern "C" PLUGIN_API int GetEntityHealth(int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -315,6 +591,16 @@ extern "C" PLUGIN_API int GetEntityHealth(int entityHandle) return ent->m_iHealth(); } + +/** + * @brief Sets the health of an entity. + * + * This function updates the health of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose health is to be set. + * @param health The new health value to set for the entity. + */ extern "C" PLUGIN_API void SetEntityHealth(int entityHandle, int health) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -326,6 +612,15 @@ extern "C" PLUGIN_API void SetEntityHealth(int entityHandle, int health) ent->m_iHealth = health; } +/** + * @brief Retrieves the team number of an entity. + * + * This function returns the team number of the specified entity. + * If the entity is invalid, it returns 0. + * + * @param entityHandle The handle of the entity whose team number is to be retrieved. + * @return The team number of the entity, or 0 if the entity is invalid. + */ extern "C" PLUGIN_API int GetTeamEntity(int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -336,6 +631,16 @@ extern "C" PLUGIN_API int GetTeamEntity(int entityHandle) return ent->m_iTeamNum(); } + +/** + * @brief Sets the team number of an entity. + * + * This function updates the team number of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose team number is to be set. + * @param team The new team number to set for the entity. + */ extern "C" PLUGIN_API void SetTeamEntity(int entityHandle, int team) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -347,6 +652,15 @@ extern "C" PLUGIN_API void SetTeamEntity(int entityHandle, int team) ent->m_iTeamNum = team; } +/** + * @brief Retrieves the owner of an entity. + * + * This function returns the entity handle of the owner for the specified entity. + * If the entity is invalid, it returns INVALID_EHANDLE_INDEX. + * + * @param entityHandle The handle of the entity whose owner is to be retrieved. + * @return The handle of the owner entity, or INVALID_EHANDLE_INDEX if the entity is invalid. + */ extern "C" PLUGIN_API int GetEntityOwner(int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -356,8 +670,17 @@ extern "C" PLUGIN_API int GetEntityOwner(int entityHandle) } return ent->m_CBodyComponent->m_pSceneNode->m_pOwner()->GetRefEHandle().ToInt(); - } + +/** + * @brief Sets the owner of an entity. + * + * This function updates the owner of the specified entity. + * If either the entity or the new owner is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose owner is to be set. + * @param ownerHandle The handle of the new owner entity. + */ extern "C" PLUGIN_API void SetEntityOwner(int entityHandle, int ownerHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -375,6 +698,15 @@ extern "C" PLUGIN_API void SetEntityOwner(int entityHandle, int ownerHandle) ent->m_CBodyComponent->m_pSceneNode->m_pOwner = owner; } +/** + * @brief Retrieves the parent of an entity. + * + * This function returns the entity handle of the parent for the specified entity. + * If the entity is invalid, it returns INVALID_EHANDLE_INDEX. + * + * @param entityHandle The handle of the entity whose parent is to be retrieved. + * @return The handle of the parent entity, or INVALID_EHANDLE_INDEX if the entity is invalid. + */ extern "C" PLUGIN_API int GetEntityParent(int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -384,8 +716,17 @@ extern "C" PLUGIN_API int GetEntityParent(int entityHandle) } return ent->m_CBodyComponent->m_pSceneNode->m_pParent()->m_pOwner->GetRefEHandle().ToInt(); - } + +/** + * @brief Sets the parent of an entity. + * + * This function updates the parent of the specified entity. + * If either the entity or the new parent is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose parent is to be set. + * @param parentHandle The handle of the new parent entity. + */ extern "C" PLUGIN_API void SetEntityParent(int entityHandle, int parentHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -403,6 +744,15 @@ extern "C" PLUGIN_API void SetEntityParent(int entityHandle, int parentHandle) ent->SetParent(owner); } +/** + * @brief Retrieves the absolute origin of an entity. + * + * 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. + */ extern "C" PLUGIN_API void GetEntityAbsOrigin(Vector& output, int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -413,6 +763,16 @@ extern "C" PLUGIN_API void GetEntityAbsOrigin(Vector& output, int entityHandle) output = ent->m_CBodyComponent->m_pSceneNode->m_vecAbsOrigin(); } + +/** + * @brief Sets the absolute origin of an entity. + * + * This function updates the absolute position of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose absolute origin is to be set. + * @param origin The new absolute origin to set for the entity. + */ extern "C" PLUGIN_API void SetEntityAbsOrigin(int entityHandle, const Vector& origin) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -424,6 +784,15 @@ extern "C" PLUGIN_API void SetEntityAbsOrigin(int entityHandle, const Vector& or ent->m_CBodyComponent->m_pSceneNode->m_vecAbsOrigin = origin; } +/** + * @brief Retrieves the angular rotation of an entity. + * + * 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. + */ extern "C" PLUGIN_API void GetEntityAngRotation(QAngle& output, int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -433,8 +802,17 @@ extern "C" PLUGIN_API void GetEntityAngRotation(QAngle& output, int entityHandle } std::construct_at(&output, ent->m_CBodyComponent->m_pSceneNode->m_angRotation()); - } + +/** + * @brief Sets the angular rotation of an entity. + * + * This function updates the angular rotation of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose angular rotation is to be set. + * @param angle The new angular rotation to set for the entity. + */ extern "C" PLUGIN_API void SetEntityAngRotation(int entityHandle, const QAngle& angle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -446,6 +824,15 @@ extern "C" PLUGIN_API void SetEntityAngRotation(int entityHandle, const QAngle& ent->m_CBodyComponent->m_pSceneNode->m_angRotation = angle; } +/** + * @brief Retrieves the absolute velocity of an entity. + * + * 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. + */ extern "C" PLUGIN_API void GetEntityAbsVelocity(Vector& output, int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -455,8 +842,17 @@ extern "C" PLUGIN_API void GetEntityAbsVelocity(Vector& output, int entityHandle } output = ent->m_vecAbsVelocity(); - } + +/** + * @brief Sets the absolute velocity of an entity. + * + * This function updates the absolute velocity of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose absolute velocity is to be set. + * @param velocity The new absolute velocity to set for the entity. + */ extern "C" PLUGIN_API void SetEntityAbsVelocity(int entityHandle, const Vector& velocity) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -468,6 +864,15 @@ extern "C" PLUGIN_API void SetEntityAbsVelocity(int entityHandle, const Vector& ent->m_vecAbsVelocity = velocity; } +/** + * @brief Retrieves the model name of an entity. + * + * This function gets the model name of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param output A reference to a string where the model name will be stored. + * @param entityHandle The handle of the entity whose model name is to be retrieved. + */ extern "C" PLUGIN_API void GetEntityModel(plg::string& output, int entityHandle) { CBaseModelEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -477,8 +882,17 @@ extern "C" PLUGIN_API void GetEntityModel(plg::string& output, int entityHandle) } std::construct_at(&output, ent->GetModelName()); - } + +/** + * @brief Sets the model name of an entity. + * + * This function updates the model name of the specified entity. + * If the entity is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity whose model name is to be set. + * @param model The new model name to set for the entity. + */ extern "C" PLUGIN_API void SetEntityModel(int entityHandle, const plg::string& model) { CBaseModelEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -490,8 +904,15 @@ extern "C" PLUGIN_API void SetEntityModel(int entityHandle, const plg::string& m ent->SetModel(model.c_str()); } -/// - +/** + * @brief Retrieves the water level of an entity. + * + * This function returns the water level of the specified entity. + * If the entity is invalid, it returns 0.0f. + * + * @param entityHandle The handle of the entity whose water level is to be retrieved. + * @return The water level of the entity, or 0.0f if the entity is invalid. + */ extern "C" PLUGIN_API float GetEntityWaterLevel(int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -501,8 +922,17 @@ extern "C" PLUGIN_API float GetEntityWaterLevel(int entityHandle) } return ent->m_flWaterLevel(); - } + +/** + * @brief Retrieves the ground entity of an entity. + * + * This function returns the handle of the ground entity for the specified entity. + * If the entity is invalid, it returns INVALID_EHANDLE_INDEX. + * + * @param entityHandle The handle of the entity whose ground entity is to be retrieved. + * @return The handle of the ground entity, or INVALID_EHANDLE_INDEX if the entity is invalid. + */ extern "C" PLUGIN_API int GetEntityGroundEntity(int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -512,8 +942,17 @@ extern "C" PLUGIN_API int GetEntityGroundEntity(int entityHandle) } return ent->m_hGroundEntity()->GetRefEHandle().ToInt(); - } + +/** + * @brief Retrieves the effects of an entity. + * + * This function returns the effect flags of the specified entity. + * If the entity is invalid, it returns 0. + * + * @param entityHandle The handle of the entity whose effects are to be retrieved. + * @return The effect flags of the entity, or 0 if the entity is invalid. + */ extern "C" PLUGIN_API int GetEntityEffects(int entityHandle) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -525,6 +964,17 @@ extern "C" PLUGIN_API int GetEntityEffects(int entityHandle) return ent->m_fEffects(); } +/** + * @brief Teleports an entity to a specified location and orientation. + * + * This function teleports the specified entity to the given absolute position, + * with an optional new orientation and velocity. If the entity is invalid, the function does nothing. + * + * @param entityHandle The handle of the entity to teleport. + * @param origin A pointer to a Vector representing the new absolute position. Can be nullptr. + * @param angles A pointer to a QAngle representing the new orientation. Can be nullptr. + * @param velocity A pointer to a Vector representing the new velocity. Can be nullptr. + */ extern "C" PLUGIN_API void TeleportEntity(int entityHandle, const Vector* origin, const QAngle* angles, const Vector* velocity) { CBaseEntity* ent = static_cast(g_pEntitySystem->GetEntityInstance(CEntityHandle((uint32)entityHandle))); @@ -534,4 +984,4 @@ extern "C" PLUGIN_API void TeleportEntity(int entityHandle, const Vector* origin } ent->Teleport(origin, angles, velocity); -} \ No newline at end of file +} diff --git a/src/export/events.cpp b/src/export/events.cpp index 6923a89..2d4ca03 100644 --- a/src/export/events.cpp +++ b/src/export/events.cpp @@ -1,162 +1,350 @@ #include #include +/** + * @brief Creates a hook for when a game event is fired. + * @param name The name of the event to hook. + * @param pCallback The callback function to call when the event is fired. + * @param post A boolean indicating whether the hook should be for a post event. + * @return An integer indicating the result of the hook operation. + */ extern "C" PLUGIN_API int HookEvent(const plg::string& name, EventListenerCallback pCallback, bool post) { - return static_cast(g_EventManager.HookEvent(name, pCallback, static_cast(post))); + return static_cast(g_EventManager.HookEvent(name, pCallback, static_cast(post))); } +/** + * @brief Removes a hook for when a game event is fired. + * @param name The name of the event to unhook. + * @param pCallback The callback function to remove. + * @param post A boolean indicating whether the hook is for a post event. + * @return An integer indicating the result of the unhook operation. + */ extern "C" PLUGIN_API int UnhookEvent(const plg::string& name, EventListenerCallback pCallback, bool post) { - return static_cast(g_EventManager.UnhookEvent(name, pCallback, static_cast(post))); + return static_cast(g_EventManager.UnhookEvent(name, pCallback, static_cast(post))); } +/** + * @brief Creates a game event to be fired later. + * @param name The name of the event to create. + * @param force A boolean indicating whether to force the creation of the event. + * @return A pointer to the created EventInfo structure. + */ extern "C" PLUGIN_API EventInfo* CreateEvent(const plg::string& name, bool force) { - return g_EventManager.CreateEvent(name, force); + return g_EventManager.CreateEvent(name, force); } +/** + * @brief Fires a game event. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param bDontBroadcast A boolean indicating whether to broadcast the event. + */ extern "C" PLUGIN_API void FireEvent(EventInfo* pInfo, bool bDontBroadcast) { - g_EventManager.FireEvent(pInfo, bDontBroadcast); + g_EventManager.FireEvent(pInfo, bDontBroadcast); } +/** + * @brief Fires a game event to a specific client. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param clientIndex The index of the client to fire the event to. + */ extern "C" PLUGIN_API void FireEventToClient(EventInfo* pInfo, int clientIndex) { - g_EventManager.FireEventToClient(pInfo, CPlayerSlot(clientIndex - 1)); + g_EventManager.FireEventToClient(pInfo, CPlayerSlot(clientIndex - 1)); } +/** + * @brief Cancels a previously created game event that has not been fired. + * @param pInfo A pointer to the EventInfo structure of the event to cancel. + */ extern "C" PLUGIN_API void CancelCreatedEvent(EventInfo* pInfo) { - g_EventManager.CancelCreatedEvent(pInfo); + g_EventManager.CancelCreatedEvent(pInfo); } +/** + * @brief Retrieves the boolean value of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to retrieve the boolean value. + * @return The boolean value associated with the key. + */ extern "C" PLUGIN_API bool GetEventBool(EventInfo* pInfo, const plg::string& key) { - return pInfo->pEvent->GetBool(key.c_str()); + return pInfo->pEvent->GetBool(key.c_str()); } +/** + * @brief Retrieves the float value of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to retrieve the float value. + * @return The float value associated with the key. + */ extern "C" PLUGIN_API float GetEventFloat(EventInfo* pInfo, const plg::string& key) { - return pInfo->pEvent->GetFloat(key.c_str()); + return pInfo->pEvent->GetFloat(key.c_str()); } +/** + * @brief Retrieves the integer value of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to retrieve the integer value. + * @return The integer value associated with the key. + */ extern "C" PLUGIN_API int GetEventInt(EventInfo* pInfo, const plg::string& key) { - return pInfo->pEvent->GetInt(key.c_str()); + return pInfo->pEvent->GetInt(key.c_str()); } +/** + * @brief Retrieves the long integer value of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to retrieve the long integer value. + * @return The long integer value associated with the key. + */ extern "C" PLUGIN_API uint64_t GetEventUInt64(EventInfo* pInfo, const plg::string& key) { - return pInfo->pEvent->GetUint64(key.c_str()); + return pInfo->pEvent->GetUint64(key.c_str()); } +/** + * @brief Retrieves the string value of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to retrieve the string value. + * @return A string where the result will be stored. + */ extern "C" PLUGIN_API void GetEventString(plg::string& output, EventInfo* pInfo, const plg::string& key) { - std::construct_at(&output, pInfo->pEvent->GetString(key.c_str())); + std::construct_at(&output, pInfo->pEvent->GetString(key.c_str())); } +/** + * @brief Retrieves the pointer value of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to retrieve the pointer value. + * @return The pointer value associated with the key. + */ extern "C" PLUGIN_API void* GetEventPtr(EventInfo* pInfo, const plg::string& key) { - return pInfo->pEvent->GetPtr(key.c_str()); + return pInfo->pEvent->GetPtr(key.c_str()); } +/** + * @brief Retrieves the player controller address of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to retrieve the player controller address. + * @return A pointer to the player controller associated with the key. + */ extern "C" PLUGIN_API CEntityInstance* GetEventPlayerController(EventInfo* pInfo, const plg::string& key) { - return pInfo->pEvent->GetPlayerController(key.c_str()); + return pInfo->pEvent->GetPlayerController(key.c_str()); } +/** + * @brief Retrieves the player index of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to retrieve the player index. + * @return The player index associated with the key. + */ extern "C" PLUGIN_API int GetEventPlayerIndex(EventInfo* pInfo, const plg::string& key) { - return pInfo->pEvent->GetPlayerSlot(key.c_str()).Get(); + return pInfo->pEvent->GetPlayerSlot(key.c_str()).Get(); } +/** + * @brief Retrieves the player pawn address of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to retrieve the player pawn address. + * @return A pointer to the player pawn associated with the key. + */ extern "C" PLUGIN_API CEntityInstance* GetEventPlayerPawn(EventInfo* pInfo, const plg::string& key) { - return pInfo->pEvent->GetPlayerPawn(key.c_str()); + return pInfo->pEvent->GetPlayerPawn(key.c_str()); } +/** + * @brief Retrieves the entity address of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to retrieve the entity address. + * @return A pointer to the entity associated with the key. + */ extern "C" PLUGIN_API CEntityInstance* GetEventEntity(EventInfo* pInfo, const plg::string& key) { - return pInfo->pEvent->GetEntity(key.c_str()); + return pInfo->pEvent->GetEntity(key.c_str()); } +/** + * @brief Retrieves the entity index of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to retrieve the entity index. + * @return The entity index associated with the key. + */ extern "C" PLUGIN_API int GetEventEntityIndex(EventInfo* pInfo, const plg::string& key) { - return pInfo->pEvent->GetEntityIndex(key.c_str()).Get(); + return pInfo->pEvent->GetEntityIndex(key.c_str()).Get(); } +/** + * @brief Retrieves the entity handle of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to retrieve the entity handle. + * @return The entity handle associated with the key. + */ extern "C" PLUGIN_API int GetEventEntityHandle(EventInfo* pInfo, const plg::string& key) { - return pInfo->pEvent->GetEHandle(key.c_str()).ToInt(); + return pInfo->pEvent->GetEHandle(key.c_str()).ToInt(); } +/** + * @brief Retrieves the name of a game event. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @return A string where the result will be stored. + */ extern "C" PLUGIN_API void GetEventName(plg::string& output, EventInfo* pInfo) { - std::construct_at(&output, pInfo->pEvent->GetName()); + std::construct_at(&output, pInfo->pEvent->GetName()); } +/** + * @brief Sets the boolean value of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to set the boolean value. + * @param value The boolean value to set. + */ extern "C" PLUGIN_API void SetEventBool(EventInfo* pInfo, const plg::string& key, bool value) { - pInfo->pEvent->SetBool(key.c_str(), value); + pInfo->pEvent->SetBool(key.c_str(), value); } +/** + * @brief Sets the floating point value of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to set the float value. + * @param value The float value to set. + */ extern "C" PLUGIN_API void SetEventFloat(EventInfo* pInfo, const plg::string& key, float value) { - pInfo->pEvent->SetFloat(key.c_str(), value); + pInfo->pEvent->SetFloat(key.c_str(), value); } +/** + * @brief Sets the integer value of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to set the integer value. + * @param value The integer value to set. + */ extern "C" PLUGIN_API void SetEventInt(EventInfo* pInfo, const plg::string& key, int value) { - pInfo->pEvent->SetInt(key.c_str(), value); + pInfo->pEvent->SetInt(key.c_str(), value); } +/** + * @brief Sets the long integer value of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to set the long integer value. + * @param value The long integer value to set. + */ extern "C" PLUGIN_API void SetEventUInt64(EventInfo* pInfo, const plg::string& key, uint64_t value) { - pInfo->pEvent->SetUint64(key.c_str(), value); + pInfo->pEvent->SetUint64(key.c_str(), value); } +/** + * @brief Sets the string value of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to set the string value. + * @param value The string value to set. + */ extern "C" PLUGIN_API void SetEventString(EventInfo* pInfo, const plg::string& key, const plg::string& value) { - pInfo->pEvent->SetString(key.c_str(), value.c_str()); + pInfo->pEvent->SetString(key.c_str(), value.c_str()); } +/** + * @brief Sets the pointer value of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to set the pointer value. + * @param value The pointer value to set. + */ extern "C" PLUGIN_API void SetEventPtr(EventInfo* pInfo, const plg::string& key, void* value) { - pInfo->pEvent->SetPtr(key.c_str(), value); + pInfo->pEvent->SetPtr(key.c_str(), value); } +/** + * @brief Sets the player controller address of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to set the player controller address. + * @param value A pointer to the player controller to set. + */ extern "C" PLUGIN_API void SetEventPlayerController(EventInfo* pInfo, const plg::string& key, CEntityInstance* value) { - pInfo->pEvent->SetPlayer(key.c_str(), value); + pInfo->pEvent->SetPlayer(key.c_str(), value); } +/** + * @brief Sets the player index value of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to set the player index value. + * @param value The player index value to set. + */ extern "C" PLUGIN_API void SetEventPlayerIndex(EventInfo* pInfo, const plg::string& key, int value) { - pInfo->pEvent->SetPlayer(key.c_str(), CPlayerSlot(value)); + pInfo->pEvent->SetPlayer(key.c_str(), CPlayerSlot(value)); } +/** + * @brief Sets the entity address of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to set the entity address. + * @param value A pointer to the entity to set. + */ extern "C" PLUGIN_API void SetEventEntity(EventInfo* pInfo, const plg::string& key, CEntityInstance* value) { - pInfo->pEvent->SetEntity(key.c_str(), value); + pInfo->pEvent->SetEntity(key.c_str(), value); } +/** + * @brief Sets the entity index of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to set the entity index. + * @param value The entity index value to set. + */ extern "C" PLUGIN_API void SetEventEntityIndex(EventInfo* pInfo, const plg::string& key, int value) { - pInfo->pEvent->SetEntity(key.c_str(), CEntityIndex(value)); + pInfo->pEvent->SetEntity(key.c_str(), CEntityIndex(value)); } +/** + * @brief Sets the entity handle of a game event's key. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param key The key for which to set the entity handle. + * @param value The entity handle value to set. + */ extern "C" PLUGIN_API void SetEventEntityHandle(EventInfo* pInfo, const plg::string& key, int value) { - pInfo->pEvent->SetEntity(key.c_str(), CEntityHandle((uint32)value).Get()); + pInfo->pEvent->SetEntity(key.c_str(), CEntityHandle((uint32)value).Get()); } +/** + * @brief Sets whether an event's broadcasting will be disabled or not. + * @param pInfo A pointer to the EventInfo structure containing event data. + * @param dontBroadcast A boolean indicating whether to disable broadcasting. + */ extern "C" PLUGIN_API void SetEventBroadcast(EventInfo* pInfo, bool dontBroadcast) { - pInfo->bDontBroadcast = dontBroadcast; + pInfo->bDontBroadcast = dontBroadcast; } +/** + * @brief Load game event descriptions from a file (e.g., "resource/gameevents.res"). + * @param path The path to the file containing event descriptions. + * @param searchAll A boolean indicating whether to search all paths for the file. + * @return An integer indicating the result of the loading operation. + */ extern "C" PLUGIN_API int LoadEventsFromFile(const plg::string& path, bool searchAll) { - return g_gameEventManager->LoadEventsFromFile(path.c_str(), searchAll); + return g_gameEventManager->LoadEventsFromFile(path.c_str(), searchAll); } diff --git a/src/export/gameconfig.cpp b/src/export/gameconfig.cpp index e36ff75..0d5d1ba 100644 --- a/src/export/gameconfig.cpp +++ b/src/export/gameconfig.cpp @@ -1,51 +1,142 @@ #include #include +/** + * @brief Closes a game configuration file. + * + * This function closes the specified game configuration file. + * + * @param pGameConfig A pointer to the game configuration to be closed. + */ extern "C" PLUGIN_API void CloseGameConfigFile(CGameConfig* pGameConfig) { g_pGameConfigManager.CloseGameConfigFile(pGameConfig); } +/** + * @brief Loads a game configuration file. + * + * This function loads a game configuration file from the specified file path. + * + * @param file The path to the game configuration file to be loaded. + * @return A pointer to the loaded CGameConfig object, or nullptr if loading fails. + */ extern "C" PLUGIN_API CGameConfig* LoadGameConfigFile(const plg::string& file) { return g_pGameConfigManager.LoadGameConfigFile(file); } +/** + * @brief Retrieves the path of a game configuration. + * + * This function retrieves the path of the specified game configuration and + * stores it in the provided output string. + * + * @param output A reference to a string where the path will be stored. + * @param pGameConfig A pointer to the game configuration whose path is to be retrieved. + */ extern "C" PLUGIN_API void GetGameConfigPath(plg::string& output, CGameConfig* pGameConfig) { std::construct_at(&output, pGameConfig->GetPath()); } +/** + * @brief Retrieves a library associated with the game configuration. + * + * This function retrieves a library by name from the specified game configuration + * and stores it in the provided output string. + * + * @param output A reference to a string where the library will be stored. + * @param pGameConfig A pointer to the game configuration from which to retrieve the library. + * @param name The name of the library to be retrieved. + */ extern "C" PLUGIN_API void GetGameConfigLibrary(plg::string& output, CGameConfig* pGameConfig, const plg::string& name) { std::construct_at(&output, pGameConfig->GetLibrary(name)); } +/** + * @brief Retrieves the signature associated with the game configuration. + * + * This function retrieves a signature by name from the specified game configuration + * and stores it in the provided output string. + * + * @param output A reference to a string where the signature will be stored. + * @param pGameConfig A pointer to the game configuration from which to retrieve the signature. + * @param name The name of the signature to be retrieved. + */ extern "C" PLUGIN_API void GetGameConfigSignature(plg::string& output, CGameConfig* pGameConfig, const plg::string& name) { std::construct_at(&output, pGameConfig->GetSignature(name)); } +/** + * @brief Retrieves a symbol associated with the game configuration. + * + * This function retrieves a symbol by name from the specified game configuration + * and stores it in the provided output string. + * + * @param output A reference to a string where the symbol will be stored. + * @param pGameConfig A pointer to the game configuration from which to retrieve the symbol. + * @param name The name of the symbol to be retrieved. + */ extern "C" PLUGIN_API void GetGameConfigSymbol(plg::string& output, CGameConfig* pGameConfig, const plg::string& name) { std::construct_at(&output, pGameConfig->GetSymbol(name)); } +/** + * @brief Retrieves a patch associated with the game configuration. + * + * This function retrieves a patch by name from the specified game configuration + * and stores it in the provided output string. + * + * @param output A reference to a string where the patch will be stored. + * @param pGameConfig A pointer to the game configuration from which to retrieve the patch. + * @param name The name of the patch to be retrieved. + */ extern "C" PLUGIN_API void GetGameConfigPatch(plg::string& output, CGameConfig* pGameConfig, const plg::string& name) { std::construct_at(&output, pGameConfig->GetPatch(name)); } +/** + * @brief Retrieves the offset associated with a name from the game configuration. + * + * This function retrieves the offset of the specified name from the game configuration. + * + * @param pGameConfig A pointer to the game configuration from which to retrieve the offset. + * @param name The name whose offset is to be retrieved. + * @return The offset associated with the specified name. + */ extern "C" PLUGIN_API int GetGameConfigOffset(CGameConfig* pGameConfig, const plg::string& name) { return pGameConfig->GetOffset(name); } +/** + * @brief Retrieves the address associated with a name from the game configuration. + * + * This function retrieves the address of the specified name from the game configuration. + * + * @param pGameConfig A pointer to the game configuration from which to retrieve the address. + * @param name The name whose address is to be retrieved. + * @return A pointer to the address associated with the specified name. + */ extern "C" PLUGIN_API void* GetGameConfigAddress(CGameConfig* pGameConfig, const plg::string& name) { return pGameConfig->GetAddress(name); } +/** + * @brief Retrieves the memory signature associated with a name from the game configuration. + * + * This function resolves and retrieves the memory signature of the specified name from the game configuration. + * + * @param pGameConfig A pointer to the game configuration from which to retrieve the memory signature. + * @param name The name whose memory signature is to be resolved and retrieved. + * @return A pointer to the memory signature associated with the specified name. + */ extern "C" PLUGIN_API void* GetGameConfigMemSig(CGameConfig* pGameConfig, const plg::string& name) { return pGameConfig->ResolveSignature(name); diff --git a/src/export/logger.cpp b/src/export/logger.cpp index 1e0f75d..4a4821b 100644 --- a/src/export/logger.cpp +++ b/src/export/logger.cpp @@ -1,5 +1,17 @@ #include - +/** + * @brief Registers a new logging channel with specified properties. + * + * This function creates a new logging channel, assigning it a name, flags, + * verbosity level, and color. The channel can be used to log messages + * according to the defined properties. + * + * @param name The name of the logging channel. + * @param iFlags Flags associated with the logging channel. + * @param verbosity The verbosity level for the logging channel. + * @param color The color for messages logged to this channel. + * @return The ID of the newly created logging channel. + */ extern "C" PLUGIN_API int RegisterLoggingChannel(const plg::string& name, int iFlags, int verbosity, int color) { Color spewColor; @@ -7,71 +19,200 @@ extern "C" PLUGIN_API int RegisterLoggingChannel(const plg::string& name, int iF return LoggingSystem_RegisterLoggingChannel(name.c_str(), &CLogger::RegisterTags, iFlags, static_cast(verbosity), spewColor); } +/** + * @brief Adds a tag to a specified logging channel. + * + * This function allows you to associate a tag with a logging channel, enabling + * better categorization and filtering of logged messages. + * + * @param channelID The ID of the logging channel to which the tag will be added. + * @param tagName The name of the tag to add to the channel. + */ extern "C" PLUGIN_API void AddLoggerTagToChannel(int channelID, const plg::string& tagName) { LoggingSystem_AddTagToChannel(channelID, tagName.c_str()); } +/** + * @brief Checks if a specified tag exists in a logging channel. + * + * This function verifies whether a specific tag is associated with a + * logging channel. + * + * @param channelID The ID of the logging channel. + * @param tag The name of the tag to check for. + * @return True if the tag exists in the channel, otherwise false. + */ extern "C" PLUGIN_API bool HasLoggerTag(int channelID, const plg::string& tag) { return LoggingSystem_HasTag(channelID, tag.c_str()); } +/** + * @brief Checks if a logging channel is enabled based on severity. + * + * This function determines if the logging channel is active for a + * given severity level. + * + * @param channelID The ID of the logging channel. + * @param severity The severity level to check. + * @return True if the channel is enabled for the specified severity, otherwise false. + */ extern "C" PLUGIN_API bool IsLoggerChannelEnabledBySeverity(int channelID, int severity) { return LoggingSystem_IsChannelEnabled(channelID, static_cast(severity)); } +/** + * @brief Checks if a logging channel is enabled based on verbosity. + * + * This function determines if the logging channel is active for a + * specified verbosity level. + * + * @param channelID The ID of the logging channel. + * @param verbosity The verbosity level to check. + * @return True if the channel is enabled for the specified verbosity, otherwise false. + */ extern "C" PLUGIN_API bool IsLoggerChannelEnabledByVerbosity(int channelID, int verbosity) { return LoggingSystem_IsChannelEnabled(channelID, static_cast(verbosity)); } +/** + * @brief Retrieves the verbosity level of a logging channel. + * + * This function returns the current verbosity level set for a + * specific logging channel. + * + * @param channelID The ID of the logging channel. + * @return The verbosity level of the specified logging channel. + */ extern "C" PLUGIN_API int GetLoggerChannelVerbosity(int channelID) { return LoggingSystem_GetChannelVerbosity(channelID); } +/** + * @brief Sets the verbosity level of a logging channel. + * + * This function updates the verbosity level for a specific logging channel. + * + * @param channelID The ID of the logging channel. + * @param verbosity The new verbosity level to set. + */ extern "C" PLUGIN_API void SetLoggerChannelVerbosity(int channelID, int verbosity) { return LoggingSystem_SetChannelVerbosity(channelID, static_cast(verbosity)); } +/** + * @brief Sets the verbosity level of a logging channel by name. + * + * This function updates the verbosity level for a logging channel identified by its name. + * + * @param channelID The ID of the logging channel. + * @param name The name of the logging channel. + * @param verbosity The new verbosity level to set. + */ extern "C" PLUGIN_API void SetLoggerChannelVerbosityByName(int channelID, const plg::string& name, int verbosity) { return LoggingSystem_SetChannelVerbosityByName(name.c_str(), static_cast(verbosity)); } +/** + * @brief Sets the verbosity level of a logging channel by tag. + * + * This function updates the verbosity level for a logging channel identified by its tag. + * + * @param channelID The ID of the logging channel. + * @param tag The name of the tag. + * @param verbosity The new verbosity level to set. + */ extern "C" PLUGIN_API void SetLoggerChannelVerbosityByTag(int channelID, const plg::string& tag, int verbosity) { LoggingSystem_SetChannelVerbosityByTag(tag.c_str(), static_cast(verbosity)); } +/** + * @brief Retrieves the color setting of a logging channel. + * + * This function returns the color associated with a specific logging channel. + * + * @param channelID The ID of the logging channel. + * @return The color value of the specified logging channel. + */ extern "C" PLUGIN_API int GetLoggerChannelColor(int channelID) { return LoggingSystem_GetChannelColor(channelID); } +/** + * @brief Sets the color setting of a logging channel. + * + * This function updates the color for messages logged to a specific logging channel. + * + * @param channelID The ID of the logging channel. + * @param color The new color value to set for the channel. + */ extern "C" PLUGIN_API void SetLoggerChannelColor(int channelID, int color) { LoggingSystem_SetChannelColor(channelID, color); } +/** + * @brief Retrieves the flags of a logging channel. + * + * This function returns the flags associated with a specific logging channel. + * + * @param channelID The ID of the logging channel. + * @return The flags of the specified logging channel. + */ extern "C" PLUGIN_API int GetLoggerChannelFlags(int channelID) { return LoggingSystem_GetChannelFlags(channelID); } +/** + * @brief Sets the flags of a logging channel. + * + * This function updates the flags for a specific logging channel, allowing + * customization of the logging behavior. + * + * @param channelID The ID of the logging channel. + * @param eFlags The new flags to set for the channel. + */ extern "C" PLUGIN_API void SetLoggerChannelFlags(int channelID, int eFlags) { LoggingSystem_SetChannelFlags(channelID, static_cast(eFlags)); } +/** + * @brief Logs a message to a specified channel with a severity level. + * + * This function logs a message to a specified logging channel and severity level. + * + * @param channelID The ID of the logging channel. + * @param severity The severity level for the log message. + * @param message The message to log. + * @return An integer indicating the result of the logging operation. + */ extern "C" PLUGIN_API int Log(int channelID, int severity, const plg::string& message) { return LoggingSystem_LogDirect(channelID, static_cast(severity), message.c_str()); } +/** + * @brief Logs a colored message to a specified channel with a severity level. + * + * This function logs a message to a specified logging channel with a + * specific color and severity level. + * + * @param channelID The ID of the logging channel. + * @param severity The severity level for the log message. + * @param color The color for the log message. + * @param message The message to log. + * @return An integer indicating the result of the logging operation. + */ extern "C" PLUGIN_API int LogColored(int channelID, int severity, int color, const plg::string& message) { Color spewColor; @@ -79,16 +220,46 @@ extern "C" PLUGIN_API int LogColored(int channelID, int severity, int color, con return LoggingSystem_LogDirect(channelID, static_cast(severity), spewColor, message.c_str()); } +/** + * @brief Logs a detailed message to a specified channel, including source code info. + * + * This function logs a message to a specified logging channel, along with + * the file name, line number, and function name where the log call occurred. + * + * @param channelID The ID of the logging channel. + * @param severity The severity level for the log message. + * @param file The file name where the log call occurred. + * @param line The line number where the log call occurred. + * @param function The name of the function where the log call occurred. + * @param message The message to log. + * @return An integer indicating the result of the logging operation. + */ extern "C" PLUGIN_API int LogFull(int channelID, int severity, const plg::string& file, int line, const plg::string& function, const plg::string& message) { LeafCodeInfo_t codeInfo{file.c_str(), line, function.c_str()}; return LoggingSystem_LogDirect(channelID, static_cast(severity), codeInfo, message.c_str()); } +/** + * @brief Logs a detailed colored message to a specified channel, including source code info. + * + * This function logs a message with color to a specified logging channel, + * including details about the file, line number, and function name where + * the log call occurred. + * + * @param channelID The ID of the logging channel. + * @param severity The severity level for the log message. + * @param file The file name where the log call occurred. + * @param line The line number where the log call occurred. + * @param function The name of the function where the log call occurred. + * @param color The color for the log message. + * @param message The message to log. + * @return An integer indicating the result of the logging operation. + */ extern "C" PLUGIN_API int LogFullColored(int channelID, int severity, const plg::string& file, int line, const plg::string& function, int color, const plg::string& message) { LeafCodeInfo_t codeInfo{file.c_str(), line, function.c_str()}; Color spewColor; spewColor.SetRawColor(color); return LoggingSystem_LogDirect(channelID, static_cast(severity), codeInfo, spewColor, message.c_str()); -} \ No newline at end of file +} diff --git a/src/export/schema.cpp b/src/export/schema.cpp index d1f9164..ffeffc6 100644 --- a/src/export/schema.cpp +++ b/src/export/schema.cpp @@ -4,6 +4,15 @@ #include #include +/** + * @brief Get the offset of a member in a given schema class. + * + * This function retrieves the offset of a member in the specified class. + * + * @param className The name of the class. + * @param memberName The name of the member whose offset is to be retrieved. + * @return The offset of the member in the class. + */ extern "C" PLUGIN_API int32 GetSchemaOffset(const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -14,6 +23,15 @@ extern "C" PLUGIN_API int32 GetSchemaOffset(const plg::string& className, const return m_key.offset; } +/** + * @brief Check if a schema field is networked. + * + * This function checks whether the specified member of the given class is networked. + * + * @param className The name of the class. + * @param memberName The name of the member to check. + * @return True if the member is networked, false otherwise. + */ extern "C" PLUGIN_API bool IsSchemaFieldNetworked(const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -24,6 +42,14 @@ extern "C" PLUGIN_API bool IsSchemaFieldNetworked(const plg::string& className, return m_key.networked; } +/** + * @brief Get the size of a schema class. + * + * This function retrieves the size of the specified class in bytes. + * + * @param className The name of the class. + * @return The size of the class in bytes, or -1 if the class is not found. + */ extern "C" PLUGIN_API int GetSchemaClassSize(const plg::string& className) { CSchemaSystemTypeScope2* pType = g_pSchemaSystem2->FindTypeScopeForModule(CS2SDK_LIBRARY_PREFIX "server" CS2SDK_LIBRARY_SUFFIX); @@ -34,6 +60,16 @@ extern "C" PLUGIN_API int GetSchemaClassSize(const plg::string& className) return pClassInfo->m_nSize; } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @param memberName The name of the member whose value is to be retrieved. + * @return The value of the member. + */ extern "C" PLUGIN_API bool GetSchemaBoolByName(void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -44,6 +80,16 @@ extern "C" PLUGIN_API bool GetSchemaBoolByName(void* instancePointer, const plg: return *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @param memberName The name of the member whose value is to be retrieved. + * @return The value of the member. + */ extern "C" PLUGIN_API int8_t GetSchemaInt8ByName(void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -54,6 +100,16 @@ extern "C" PLUGIN_API int8_t GetSchemaInt8ByName(void* instancePointer, const pl return *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @param memberName The name of the member whose value is to be retrieved. + * @return The value of the member. + */ extern "C" PLUGIN_API int16_t GetSchemaInt16ByName(void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -64,6 +120,16 @@ extern "C" PLUGIN_API int16_t GetSchemaInt16ByName(void* instancePointer, const return *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @param memberName The name of the member whose value is to be retrieved. + * @return The value of the member. + */ extern "C" PLUGIN_API int32_t GetSchemaInt32ByName(void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -74,6 +140,16 @@ extern "C" PLUGIN_API int32_t GetSchemaInt32ByName(void* instancePointer, const return *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @param memberName The name of the member whose value is to be retrieved. + * @return The value of the member. + */ extern "C" PLUGIN_API int64_t GetSchemaInt64ByName(void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -84,6 +160,16 @@ extern "C" PLUGIN_API int64_t GetSchemaInt64ByName(void* instancePointer, const return *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @param memberName The name of the member whose value is to be retrieved. + * @return The value of the member. + */ extern "C" PLUGIN_API uint8_t GetSchemaUInt8ByName(void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -94,6 +180,16 @@ extern "C" PLUGIN_API uint8_t GetSchemaUInt8ByName(void* instancePointer, const return *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @param memberName The name of the member whose value is to be retrieved. + * @return The value of the member. + */ extern "C" PLUGIN_API uint16_t GetSchemaUInt16ByName(void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -104,6 +200,16 @@ extern "C" PLUGIN_API uint16_t GetSchemaUInt16ByName(void* instancePointer, cons return *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @param memberName The name of the member whose value is to be retrieved. + * @return The value of the member. + */ extern "C" PLUGIN_API uint32_t GetSchemaUInt32ByName(void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -114,6 +220,16 @@ extern "C" PLUGIN_API uint32_t GetSchemaUInt32ByName(void* instancePointer, cons return *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @param memberName The name of the member whose value is to be retrieved. + * @return The value of the member. + */ extern "C" PLUGIN_API uint64_t GetSchemaUInt64ByName(void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -124,6 +240,16 @@ extern "C" PLUGIN_API uint64_t GetSchemaUInt64ByName(void* instancePointer, cons return *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @param memberName The name of the member whose value is to be retrieved. + * @return The value of the member. + */ extern "C" PLUGIN_API float GetSchemaFloatByName(void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -134,6 +260,16 @@ extern "C" PLUGIN_API float GetSchemaFloatByName(void* instancePointer, const pl return *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @param memberName The name of the member whose value is to be retrieved. + * @return The value of the member. + */ extern "C" PLUGIN_API double GetSchemaDoubleByName(void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -144,6 +280,16 @@ extern "C" PLUGIN_API double GetSchemaDoubleByName(void* instancePointer, const return *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @param memberName The name of the member whose value is to be retrieved. + * @return The value of the member. + */ extern "C" PLUGIN_API void* GetSchemaPointerByName(void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -154,6 +300,16 @@ extern "C" PLUGIN_API void* GetSchemaPointerByName(void* instancePointer, const return *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @param memberName The name of the member whose value is to be retrieved. + * @return The value of the member. + */ extern "C" PLUGIN_API void GetSchemaStringByName(plg::string& output, void* instancePointer, const plg::string& className, const plg::string& memberName) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -165,6 +321,16 @@ extern "C" PLUGIN_API void GetSchemaStringByName(plg::string& output, void* inst std::construct_at(&output, str != nullptr ? str->Get() : ""); } +/** + * @brief Get a value from a schema member by its name. + * + * This function retrieves the value of the specified member from the given instance. + * + * @param instancePointer Pointer to the instance from which the value is to be retrieved. + * @param className The name of the class. + * @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) { auto classKey = hash_32_fnv1a_const(className.c_str()); @@ -175,6 +341,18 @@ extern "C" PLUGIN_API void GetSchemaVectorByName(Vector& output, void* instanceP output = *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset); } +/** + * @brief Set a value for a schema member by its name. + * + * This function sets the specified member's value for a given instance of a class. + * If the "FollowCS2ServerGuidelines" option is enabled and the member is in the bad list, + * a warning is logged and the value is not set. + * + * @param instancePointer Pointer to the instance of the class where the value is to be set. + * @param className The name of the class that contains the member. + * @param memberName The name of the member to be set. + * @param value The value to assign to the member. + */ extern "C" PLUGIN_API void SetSchemaValueBoolByName(void* instancePointer, const plg::string& className, const plg::string& memberName, bool value) { if (g_pCoreConfig->FollowCS2ServerGuidelines && std::find(schema::CS2BadList.begin(), schema::CS2BadList.end(), memberName) != schema::CS2BadList.end()) @@ -191,6 +369,18 @@ extern "C" PLUGIN_API void SetSchemaValueBoolByName(void* instancePointer, const *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset) = value; } +/** + * @brief Set a value for a schema member by its name. + * + * This function sets the specified member's value for a given instance of a class. + * If the "FollowCS2ServerGuidelines" option is enabled and the member is in the bad list, + * a warning is logged and the value is not set. + * + * @param instancePointer Pointer to the instance of the class where the value is to be set. + * @param className The name of the class that contains the member. + * @param memberName The name of the member to be set. + * @param value The value to assign to the member. + */ extern "C" PLUGIN_API void SetSchemaValueInt8ByName(void* instancePointer, const plg::string& className, const plg::string& memberName, int8_t value) { if (g_pCoreConfig->FollowCS2ServerGuidelines && std::find(schema::CS2BadList.begin(), schema::CS2BadList.end(), memberName) != schema::CS2BadList.end()) @@ -207,6 +397,18 @@ extern "C" PLUGIN_API void SetSchemaValueInt8ByName(void* instancePointer, const *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset) = value; } +/** + * @brief Set a value for a schema member by its name. + * + * This function sets the specified member's value for a given instance of a class. + * If the "FollowCS2ServerGuidelines" option is enabled and the member is in the bad list, + * a warning is logged and the value is not set. + * + * @param instancePointer Pointer to the instance of the class where the value is to be set. + * @param className The name of the class that contains the member. + * @param memberName The name of the member to be set. + * @param value The value to assign to the member. + */ extern "C" PLUGIN_API void SetSchemaValueInt16ByName(void* instancePointer, const plg::string& className, const plg::string& memberName, int16_t value) { if (g_pCoreConfig->FollowCS2ServerGuidelines && std::find(schema::CS2BadList.begin(), schema::CS2BadList.end(), memberName) != schema::CS2BadList.end()) @@ -223,6 +425,18 @@ extern "C" PLUGIN_API void SetSchemaValueInt16ByName(void* instancePointer, cons *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset) = value; } +/** + * @brief Set a value for a schema member by its name. + * + * This function sets the specified member's value for a given instance of a class. + * If the "FollowCS2ServerGuidelines" option is enabled and the member is in the bad list, + * a warning is logged and the value is not set. + * + * @param instancePointer Pointer to the instance of the class where the value is to be set. + * @param className The name of the class that contains the member. + * @param memberName The name of the member to be set. + * @param value The value to assign to the member. + */ extern "C" PLUGIN_API void SetSchemaValueInt32ByName(void* instancePointer, const plg::string& className, const plg::string& memberName, int32_t value) { if (g_pCoreConfig->FollowCS2ServerGuidelines && std::find(schema::CS2BadList.begin(), schema::CS2BadList.end(), memberName) != schema::CS2BadList.end()) @@ -239,6 +453,18 @@ extern "C" PLUGIN_API void SetSchemaValueInt32ByName(void* instancePointer, cons *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset) = value; } +/** + * @brief Set a value for a schema member by its name. + * + * This function sets the specified member's value for a given instance of a class. + * If the "FollowCS2ServerGuidelines" option is enabled and the member is in the bad list, + * a warning is logged and the value is not set. + * + * @param instancePointer Pointer to the instance of the class where the value is to be set. + * @param className The name of the class that contains the member. + * @param memberName The name of the member to be set. + * @param value The value to assign to the member. + */ extern "C" PLUGIN_API void SetSchemaValueInt64ByName(void* instancePointer, const plg::string& className, const plg::string& memberName, int64_t value) { if (g_pCoreConfig->FollowCS2ServerGuidelines && std::find(schema::CS2BadList.begin(), schema::CS2BadList.end(), memberName) != schema::CS2BadList.end()) @@ -255,6 +481,18 @@ extern "C" PLUGIN_API void SetSchemaValueInt64ByName(void* instancePointer, cons *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset) = value; } +/** + * @brief Set a value for a schema member by its name. + * + * This function sets the specified member's value for a given instance of a class. + * If the "FollowCS2ServerGuidelines" option is enabled and the member is in the bad list, + * a warning is logged and the value is not set. + * + * @param instancePointer Pointer to the instance of the class where the value is to be set. + * @param className The name of the class that contains the member. + * @param memberName The name of the member to be set. + * @param value The value to assign to the member. + */ extern "C" PLUGIN_API void SetSchemaValueUInt8ByName(void* instancePointer, const plg::string& className, const plg::string& memberName, uint8_t value) { if (g_pCoreConfig->FollowCS2ServerGuidelines && std::find(schema::CS2BadList.begin(), schema::CS2BadList.end(), memberName) != schema::CS2BadList.end()) @@ -271,6 +509,18 @@ extern "C" PLUGIN_API void SetSchemaValueUInt8ByName(void* instancePointer, cons *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset) = value; } +/** + * @brief Set a value for a schema member by its name. + * + * This function sets the specified member's value for a given instance of a class. + * If the "FollowCS2ServerGuidelines" option is enabled and the member is in the bad list, + * a warning is logged and the value is not set. + * + * @param instancePointer Pointer to the instance of the class where the value is to be set. + * @param className The name of the class that contains the member. + * @param memberName The name of the member to be set. + * @param value The value to assign to the member. + */ extern "C" PLUGIN_API void SetSchemaValueUInt16ByName(void* instancePointer, const plg::string& className, const plg::string& memberName, uint16_t value) { if (g_pCoreConfig->FollowCS2ServerGuidelines && std::find(schema::CS2BadList.begin(), schema::CS2BadList.end(), memberName) != schema::CS2BadList.end()) @@ -287,6 +537,18 @@ extern "C" PLUGIN_API void SetSchemaValueUInt16ByName(void* instancePointer, con *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset) = value; } +/** + * @brief Set a value for a schema member by its name. + * + * This function sets the specified member's value for a given instance of a class. + * If the "FollowCS2ServerGuidelines" option is enabled and the member is in the bad list, + * a warning is logged and the value is not set. + * + * @param instancePointer Pointer to the instance of the class where the value is to be set. + * @param className The name of the class that contains the member. + * @param memberName The name of the member to be set. + * @param value The value to assign to the member. + */ extern "C" PLUGIN_API void SetSchemaValueUInt32ByName(void* instancePointer, const plg::string& className, const plg::string& memberName, uint32_t value) { if (g_pCoreConfig->FollowCS2ServerGuidelines && std::find(schema::CS2BadList.begin(), schema::CS2BadList.end(), memberName) != schema::CS2BadList.end()) @@ -303,6 +565,18 @@ extern "C" PLUGIN_API void SetSchemaValueUInt32ByName(void* instancePointer, con *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset) = value; } +/** + * @brief Set a value for a schema member by its name. + * + * This function sets the specified member's value for a given instance of a class. + * If the "FollowCS2ServerGuidelines" option is enabled and the member is in the bad list, + * a warning is logged and the value is not set. + * + * @param instancePointer Pointer to the instance of the class where the value is to be set. + * @param className The name of the class that contains the member. + * @param memberName The name of the member to be set. + * @param value The value to assign to the member. + */ extern "C" PLUGIN_API void SetSchemaValueUInt64ByName(void* instancePointer, const plg::string& className, const plg::string& memberName, uint64_t value) { if (g_pCoreConfig->FollowCS2ServerGuidelines && std::find(schema::CS2BadList.begin(), schema::CS2BadList.end(), memberName) != schema::CS2BadList.end()) @@ -319,6 +593,18 @@ extern "C" PLUGIN_API void SetSchemaValueUInt64ByName(void* instancePointer, con *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset) = value; } +/** + * @brief Set a value for a schema member by its name. + * + * This function sets the specified member's value for a given instance of a class. + * If the "FollowCS2ServerGuidelines" option is enabled and the member is in the bad list, + * a warning is logged and the value is not set. + * + * @param instancePointer Pointer to the instance of the class where the value is to be set. + * @param className The name of the class that contains the member. + * @param memberName The name of the member to be set. + * @param value The value to assign to the member. + */ extern "C" PLUGIN_API void SetSchemaValueFloatByName(void* instancePointer, const plg::string& className, const plg::string& memberName, float value) { if (g_pCoreConfig->FollowCS2ServerGuidelines && std::find(schema::CS2BadList.begin(), schema::CS2BadList.end(), memberName) != schema::CS2BadList.end()) @@ -335,6 +621,18 @@ extern "C" PLUGIN_API void SetSchemaValueFloatByName(void* instancePointer, cons *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset) = value; } +/** + * @brief Set a value for a schema member by its name. + * + * This function sets the specified member's value for a given instance of a class. + * If the "FollowCS2ServerGuidelines" option is enabled and the member is in the bad list, + * a warning is logged and the value is not set. + * + * @param instancePointer Pointer to the instance of the class where the value is to be set. + * @param className The name of the class that contains the member. + * @param memberName The name of the member to be set. + * @param value The value to assign to the member. + */ extern "C" PLUGIN_API void SetSchemaValueDoubleByName(void* instancePointer, const plg::string& className, const plg::string& memberName, double value) { if (g_pCoreConfig->FollowCS2ServerGuidelines && std::find(schema::CS2BadList.begin(), schema::CS2BadList.end(), memberName) != schema::CS2BadList.end()) @@ -351,6 +649,18 @@ extern "C" PLUGIN_API void SetSchemaValueDoubleByName(void* instancePointer, con *reinterpret_cast>((uintptr_t)(instancePointer) + m_key.offset) = value; } +/** + * @brief Set a value for a schema member by its name. + * + * This function sets the specified member's value for a given instance of a class. + * If the "FollowCS2ServerGuidelines" option is enabled and the member is in the bad list, + * a warning is logged and the value is not set. + * + * @param instancePointer Pointer to the instance of the class where the value is to be set. + * @param className The name of the class that contains the member. + * @param memberName The name of the member to be set. + * @param value The value to assign to the member. + */ extern "C" PLUGIN_API void SetSchemaValueStringByName(void* instancePointer, const plg::string& className, const plg::string& memberName, const plg::string& value) { if (g_pCoreConfig->FollowCS2ServerGuidelines && std::find(schema::CS2BadList.begin(), schema::CS2BadList.end(), memberName) != schema::CS2BadList.end()) @@ -367,6 +677,18 @@ extern "C" PLUGIN_API void SetSchemaValueStringByName(void* instancePointer, con *reinterpret_cast((uintptr_t)(instancePointer) + m_key.offset) = value.c_str(); } +/** + * @brief Set a value for a schema member by its name. + * + * This function sets the specified member's value for a given instance of a class. + * If the "FollowCS2ServerGuidelines" option is enabled and the member is in the bad list, + * a warning is logged and the value is not set. + * + * @param instancePointer Pointer to the instance of the class where the value is to be set. + * @param className The name of the class that contains the member. + * @param memberName The name of the member to be set. + * @param value The value to assign to the member. + */ extern "C" PLUGIN_API void SetSchemaValueVectorByName(void* instancePointer, const plg::string& className, const plg::string& memberName, const Vector& value) { if (g_pCoreConfig->FollowCS2ServerGuidelines && std::find(schema::CS2BadList.begin(), schema::CS2BadList.end(), memberName) != schema::CS2BadList.end()) diff --git a/src/export/timers.cpp b/src/export/timers.cpp index 49a23aa..8cce124 100644 --- a/src/export/timers.cpp +++ b/src/export/timers.cpp @@ -1,12 +1,52 @@ #include #include +/** + * @brief Creates a new timer that executes a callback function at specified intervals. + * + * This function initializes a timer that will call the provided callback function + * after the specified interval in seconds. The timer can be configured with various flags + * to control its behavior. + * + * @param interval The time interval in seconds between each callback execution. + * @param callback The function to be called when the timer expires. + * @param flags Flags that modify the behavior of the timer (e.g., no-map change, repeating). + * @return A pointer to the newly created CTimer object, or nullptr if the timer could not be created. + */ extern "C" PLUGIN_API CTimer* CreateTimer(float interval, TimerCallback callback, int flags) { return g_TimerSystem.CreateTimer(interval, callback, flags); } +/** + * @brief Stops and removes an existing timer. + * + * This function terminates the specified timer, preventing it from calling + * its callback function. Once killed, the timer cannot be reused. + * + * @param timer A pointer to the CTimer object to be stopped and removed. + */ extern "C" PLUGIN_API void KillsTimer(CTimer* timer) { g_TimerSystem.KillTimer(timer); +} + +/** + * @brief Returns the number of seconds in between game server ticks. + * + * @return The tick interval value. + */ +extern "C" PLUGIN_API float GetTickInterval() +{ + return CTimerSystem::GetTickedInterval(); +} + +/** + * @brief Returns the simulated game time. + * + * @return The ticked time value. + */ +extern "C" PLUGIN_API double GetTickedTime() +{ + return CTimerSystem::GetTickedTime(); } \ No newline at end of file diff --git a/src/export/voice.cpp b/src/export/voice.cpp index dc35c82..5aefa0e 100644 --- a/src/export/voice.cpp +++ b/src/export/voice.cpp @@ -1,62 +1,105 @@ #include #include +/** + * @brief Sets the listening state of a client with respect to another client. + * + * This function allows you to specify whether a receiver client should + * listen to a sender client. The listening state can be controlled + * through the `listen` parameter which can enable or disable the + * listening of the sender by the receiver. + * + * @param receiverIndex The index of the client who will receive the audio. + * @param senderIndex The index of the client who will be sending audio. + * @param listen The listening state override for the receiver with respect to the sender. + * This can be a value representing enabled or disabled listening. + */ extern "C" PLUGIN_API void SetClientListening(int receiverIndex, int senderIndex, int8_t listen) { - if (senderIndex < 0 || senderIndex >= gpGlobals->maxClients) - { - g_Logger.Log(LS_WARNING, "Invalid sender\n"); - return; - } - - auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(receiverIndex - 1)); - if (pPlayer == nullptr) - { - g_Logger.Log(LS_WARNING, "Invalid receiver\n"); - return; - } - - pPlayer->SetListen(CPlayerSlot(senderIndex - 1), static_cast(listen)); + if (senderIndex < 0 || senderIndex >= gpGlobals->maxClients) + { + g_Logger.Log(LS_WARNING, "Invalid sender\n"); + return; + } + + auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(receiverIndex - 1)); + if (pPlayer == nullptr) + { + g_Logger.Log(LS_WARNING, "Invalid receiver\n"); + return; + } + + pPlayer->SetListen(CPlayerSlot(senderIndex - 1), static_cast(listen)); } +/** + * @brief Retrieves the listening state of a client with respect to another client. + * + * This function returns the current listening state of a receiver client + * for a specific sender client. It checks if the sender is valid and returns + * the listening state if valid, or a default value if invalid. + * + * @param receiverIndex The index of the client who receives the audio. + * @param senderIndex The index of the client who sends the audio. + * @return The listening state override for the receiver with respect to the sender. + */ extern "C" PLUGIN_API int8_t GetClientListening(int receiverIndex, int senderIndex) { - if (senderIndex < 0 || senderIndex >= gpGlobals->maxClients) - { - g_Logger.Log(LS_WARNING, "Invalid sender\n"); - return Listen_Default; - } - - auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(receiverIndex - 1)); - if (pPlayer == nullptr) - { - g_Logger.Log(LS_WARNING, "Invalid receiver\n"); - return Listen_Default; - } - - return pPlayer->GetListen(CPlayerSlot(senderIndex - 1)); + if (senderIndex < 0 || senderIndex >= gpGlobals->maxClients) + { + g_Logger.Log(LS_WARNING, "Invalid sender\n"); + return Listen_Default; + } + + auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(receiverIndex - 1)); + if (pPlayer == nullptr) + { + g_Logger.Log(LS_WARNING, "Invalid receiver\n"); + return Listen_Default; + } + + return pPlayer->GetListen(CPlayerSlot(senderIndex - 1)); } +/** + * @brief Sets the voice flags for a specified client. + * + * This function allows you to set the voice-related flags for a client, + * which can determine aspects of voice communication such as muting or enabling + * the client’s voice transmission. + * + * @param clientIndex The index of the client for whom the voice flags are being set. + * @param flags The voice flags to be set for the client. + */ extern "C" PLUGIN_API void SetClientVoiceFlags(int clientIndex, uint8_t flags) { - auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); - if (pPlayer == nullptr) - { - g_Logger.Log(LS_WARNING, "Invalid receiver\n"); - return; - } - - pPlayer->SetVoiceFlags(flags); + auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); + if (pPlayer == nullptr) + { + g_Logger.Log(LS_WARNING, "Invalid receiver\n"); + return; + } + + pPlayer->SetVoiceFlags(flags); } +/** + * @brief Retrieves the voice flags for a specified client. + * + * This function returns the current voice flags for a specified client. + * If the client is invalid, it returns zero as the default. + * + * @param clientIndex The index of the client for whom the voice flags are being retrieved. + * @return The current voice flags for the specified client. + */ extern "C" PLUGIN_API uint8_t GetClientVoiceFlags(int clientIndex) { - auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); - if (pPlayer == nullptr) - { - g_Logger.Log(LS_WARNING, "Invalid receiver\n"); - return 0; - } - - return pPlayer->GetVoiceFlags(); -} \ No newline at end of file + auto pPlayer = g_PlayerManager.GetPlayerBySlot(CPlayerSlot(clientIndex - 1)); + if (pPlayer == nullptr) + { + g_Logger.Log(LS_WARNING, "Invalid receiver\n"); + return 0; + } + + return pPlayer->GetVoiceFlags(); +}