From 5a72644486b418199c8606851218948bace0cfec Mon Sep 17 00:00:00 2001 From: Vladimir <47463683+Wend4r@users.noreply.github.com> Date: Sun, 21 Mar 2021 17:10:17 +0300 Subject: [PATCH] Add ConVar.GetDescription() method (#1449) * Add ConVar.GetDescription() method Issue #1432 * Update basecommands.sp Add prints description of ConVar * Revert "Update basecommands.sp" This reverts commit ad485069a837f602bdeeeb50f9e02452b3860ecd. * Remove GetConVarDescription() function --- core/smn_console.cpp | 18 ++++++++++++++++++ plugins/include/convars.inc | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/core/smn_console.cpp b/core/smn_console.cpp index fbb6f206..5ed90a7e 100644 --- a/core/smn_console.cpp +++ b/core/smn_console.cpp @@ -650,6 +650,23 @@ static cell_t sm_GetConVarName(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t sm_GetConVarDescription(IPluginContext *pContext, const cell_t *params) +{ + Handle_t hndl = static_cast(params[1]); + HandleError err; + ConVar *pConVar; + + if ((err=g_ConVarManager.ReadConVarHandle(hndl, &pConVar)) + != HandleError_None) + { + return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err); + } + + pContext->StringToLocalUTF8(params[2], params[3], pConVar->GetHelpText(), NULL); + + return 1; +} + static bool s_QueryAlreadyWarned = false; static cell_t sm_QueryClientConVar(IPluginContext *pContext, const cell_t *params) @@ -1510,6 +1527,7 @@ REGISTER_NATIVES(consoleNatives) {"ConVar.GetBounds", sm_GetConVarBounds}, {"ConVar.SetBounds", sm_SetConVarBounds}, {"ConVar.GetName", sm_GetConVarName}, + {"ConVar.GetDescription", sm_GetConVarDescription}, {"ConVar.ReplicateToClient", ConVar_ReplicateToClient}, {"ConVar.AddChangeHook", sm_HookConVarChange}, {"ConVar.RemoveChangeHook", sm_UnhookConVarChange}, diff --git a/plugins/include/convars.inc b/plugins/include/convars.inc index 7533a7f5..cde31d1e 100644 --- a/plugins/include/convars.inc +++ b/plugins/include/convars.inc @@ -225,6 +225,12 @@ methodmap ConVar < Handle // @param maxlength Maximum length of string buffer. public native void GetName(char[] name, int maxlength); + // Retrieves the description of a console variable. + // + // @param buffer Buffer to store the description of the convar. + // @param maxlength Maximum length of string buffer. + public native void GetDescription(char[] buffer, int maxlength); + // Replicates a convar value to a specific client. This does not change the actual convar value. // // @param client Client index