diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index 6b9973ca..654e1f27 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -329,6 +329,8 @@ extern int FF_PluginEnd; extern int FF_InconsistentFile; extern int FF_ClientAuthorized; extern int FF_ChangeLevel; +extern int FF_CvarChanged; + extern bool g_coloredmenus; typedef void (*AUTHORIZEFUNC)(int player, const char *authstring); diff --git a/amxmodx/cvars.cpp b/amxmodx/cvars.cpp index a6eee812..6f7a8c43 100644 --- a/amxmodx/cvars.cpp +++ b/amxmodx/cvars.cpp @@ -15,7 +15,16 @@ CDetour *Cvar_DirectSetDetour; DETOUR_DECL_STATIC2(Cvar_DirectSet, void, struct cvar_s*, var, const char*, value) { - printf("Cvar_DirectSet - %s -> %s\n", var->name, value); + if (var && value) + { + if (strcmp(var->string, value) != 0) + { + if (executeForwards(FF_CvarChanged, reinterpret_cast(var), var->string, value, var->name) > 0) + { + return; + } + } + } DETOUR_STATIC_CALL(Cvar_DirectSet)(var, value); } diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 6cfecb41..7e4ad667 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -143,6 +143,7 @@ int FF_PluginEnd = -1; int FF_InconsistentFile = -1; int FF_ClientAuthorized = -1; int FF_ChangeLevel = -1; +int FF_CvarChanged = -1; bool ColoredMenus(String & ModName) { @@ -503,6 +504,7 @@ int C_Spawn(edict_t *pent) FF_InconsistentFile = registerForward("inconsistent_file", ET_STOP, FP_CELL, FP_STRING, FP_STRINGEX, FP_DONE); FF_ClientAuthorized = registerForward("client_authorized", ET_IGNORE, FP_CELL, FP_DONE); FF_ChangeLevel = registerForward("server_changelevel", ET_STOP, FP_STRING, FP_DONE); + FF_CvarChanged = registerForward("OnCvarChanged", ET_STOP, FP_CELL, FP_STRING, FP_STRING, FP_STRING, FP_DONE); #if defined BINLOG_ENABLED if (!g_BinLog.Open()) diff --git a/plugins/include/amxmodx.inc b/plugins/include/amxmodx.inc index e778a381..78107435 100755 --- a/plugins/include/amxmodx.inc +++ b/plugins/include/amxmodx.inc @@ -29,6 +29,7 @@ #include #include #include +#include /** * Called just after server activation. diff --git a/plugins/include/cvars.inc b/plugins/include/cvars.inc new file mode 100644 index 00000000..21be38f3 --- /dev/null +++ b/plugins/include/cvars.inc @@ -0,0 +1,23 @@ +// vim: set ts=4 sw=4 tw=99 noet: +// +// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO"). +// Copyright (C) The AMX Mod X Development Team. +// +// This software is licensed under the GNU General Public License, version 3 or higher. +// Additional exceptions apply. For full license details, see LICENSE.txt or visit: +// https://alliedmods.net/amxmodx-license + +#if defined _cvars_included + #endinput +#endif +#define _cvars_included + +/** + * Called when a console variable's value is changed. + * + * @param cvarHandle Handle to the cvar that was changed + * @param oldValue String containing the value of the cvar before it was changed + * @param newValue String containing the new value of the cvar + * @param cvarName String containing the name of the cvar + */ +forward OnCvarChanged(cvarHandle, const oldValue[], const newValue[], const cvarName[]); diff --git a/support/PackageScript b/support/PackageScript index 8fa1e99f..868013e6 100644 --- a/support/PackageScript +++ b/support/PackageScript @@ -245,6 +245,7 @@ scripting_files = [ 'include/csstats.inc', 'include/cstrike.inc', 'include/csx.inc', + 'include/cvars.inc', 'include/datapack.inc', 'include/dbi.inc', 'include/dodconst.inc',