From b2ed5f949c869ac8b4d42c3e721f3f81ddb808fb Mon Sep 17 00:00:00 2001 From: Sergey Shorokhov Date: Sun, 17 Dec 2023 19:26:10 +0300 Subject: [PATCH] Remove `ReAPI` dependency (#318) * Core: replace `reapi` by `fakemeta` * DeathMute: use `hamsandwich` instead `reapi` * RankRestrictions: add is_user_steam if ReAPI not found * RankRestrictions: allow to work without ReAPI module installed * README: reapi is `optional` now --- .github/README.md | 2 +- .../amxmodx/scripting/CA_Addon_DeathMute.sma | 10 ++-- .../scripting/CA_Addon_RankRestrictions.sma | 25 +++++++++- .../amxmodx/scripting/ChatAdditions_Core.sma | 49 +++++++++++-------- 4 files changed, 60 insertions(+), 26 deletions(-) diff --git a/.github/README.md b/.github/README.md index a21e7d3..ba8d69c 100644 --- a/.github/README.md +++ b/.github/README.md @@ -49,7 +49,7 @@ Rich API capabilities allow the system to connect any functionality (work with p - HLDS installed; - [ReGameDLL](https://github.com/s1lentq/ReGameDLL_CS) installed; - Installed AMXModX ([`v1.9`](https://www.amxmodx.org/downloads-new.php) or [`v1.10`](https://www.amxmodx.org/downloads-new.php?branch=master)); - - Installed [ReAPI](https://github.com/s1lentq/reapi) module; + - Installed [ReAPI](https://github.com/s1lentq/reapi) module (optional, but not required); ## Installation - [Download the latest](https://github.com/ChatAdditions/ChatAdditions_AMXX/releases/latest) stable version from the release section. diff --git a/cstrike/addons/amxmodx/scripting/CA_Addon_DeathMute.sma b/cstrike/addons/amxmodx/scripting/CA_Addon_DeathMute.sma index c46e43c..06fff73 100644 --- a/cstrike/addons/amxmodx/scripting/CA_Addon_DeathMute.sma +++ b/cstrike/addons/amxmodx/scripting/CA_Addon_DeathMute.sma @@ -1,6 +1,6 @@ #include #include -#include +#include #include @@ -43,8 +43,9 @@ public plugin_init() { AutoExecConfig(true, "CA_Addon_DeathMute", "ChatAdditions") - RegisterHookChain(RG_CBasePlayer_Killed, "CBasePlayer_Killed", .post = true) - RegisterHookChain(RG_CSGameRules_PlayerSpawn, "CBasePlayer_Spawn", .post = true) + // RegisterHam(Ham_TFC_Killed, "player", "CBasePlayer_Killed", .Post = true) // Does it need ?! + RegisterHam(Ham_Killed, "player", "CBasePlayer_Killed", .Post = true) + RegisterHam(Ham_Spawn, "player", "CBasePlayer_Spawn", .Post = true) g_syncHudOj = CreateHudSyncObj() } @@ -132,6 +133,9 @@ public client_disconnected(id) { } public CBasePlayer_Spawn(const id) { + if(!is_user_alive(id)) + return + g_canSpeakWithAlive[id] = true remove_task(id) diff --git a/cstrike/addons/amxmodx/scripting/CA_Addon_RankRestrictions.sma b/cstrike/addons/amxmodx/scripting/CA_Addon_RankRestrictions.sma index 20f95ce..a3bf274 100644 --- a/cstrike/addons/amxmodx/scripting/CA_Addon_RankRestrictions.sma +++ b/cstrike/addons/amxmodx/scripting/CA_Addon_RankRestrictions.sma @@ -1,5 +1,5 @@ #include -#include +#tryinclude #include @@ -189,7 +189,7 @@ bool: CanCommunicate(const player, const bool: print, chatType) { return true } - if(ca_rankrestrictions_steam_immunity && is_user_steam(player)) { + if(ca_rankrestrictions_steam_immunity && _is_user_steam(player)) { return true } @@ -286,3 +286,24 @@ GetUserFragsFromStats(const player) { return 0 } + +static stock bool: _is_user_steam(const player) { + #if (defined _reapi_reunion_included) + if(has_reunion()) + return (REU_GetAuthtype(player) == CA_TYPE_STEAM) + #endif + + static dp_r_id_provider + if (dp_r_id_provider || (dp_r_id_provider = get_cvar_pointer("dp_r_id_provider"))) { + server_cmd("dp_clientinfo %i", player) + server_exec() + + #define DP_AUTH_STEAM 2 + if(get_pcvar_num(dp_r_id_provider) == DP_AUTH_STEAM) + return true + + return false + } + + return false +} diff --git a/cstrike/addons/amxmodx/scripting/ChatAdditions_Core.sma b/cstrike/addons/amxmodx/scripting/ChatAdditions_Core.sma index a765b7e..2ad2b97 100644 --- a/cstrike/addons/amxmodx/scripting/ChatAdditions_Core.sma +++ b/cstrike/addons/amxmodx/scripting/ChatAdditions_Core.sma @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include @@ -65,8 +65,8 @@ public plugin_init() { register_clcmd("say", "ClCmd_Say", ADMIN_ALL) register_clcmd("say_team", "ClCmd_Say", ADMIN_ALL) - RegisterHookChain(RG_CSGameRules_CanPlayerHearPlayer, "CSGameRules_CanPlayerHearPlayer", .post = false) - RegisterHookChain(RG_CBasePlayer_SetClientUserInfoName, "CBasePlayer_SetClientUserInfoName", .post = false) + register_forward(FM_Voice_SetClientListening, "Voice_SetClientListening_Pre", ._post = false) + register_forward(FM_ClientUserInfoChanged, "ClientUserInfoChanged_Pre", ._post = false) register_clcmd("VModEnable", "ClCmd_VModEnable", ADMIN_ALL, .FlagManager = false) register_clcmd("vban", "ClCmd_vban", ADMIN_ALL, .FlagManager = false) @@ -218,32 +218,41 @@ public ClCmd_Say(const id) { return (g_retVal == CA_SUPERCEDE) ? PLUGIN_HANDLED : PLUGIN_CONTINUE } -public CSGameRules_CanPlayerHearPlayer(const listener, const sender) { - if(listener == sender /* || !g_PlayerModEnable[listener] */) { - return HC_CONTINUE - } +public Voice_SetClientListening_Pre(const receiver, const sender, bool: canListen) { + if(receiver == sender) + return FMRES_IGNORED - ExecuteForward(g_fwdClientVoice, g_retVal, listener, sender) + if(!g_PlayerModEnable[receiver]) + return FMRES_IGNORED - if(g_retVal == CA_SUPERCEDE) { - SetHookChainReturn(ATYPE_BOOL, false) + if (!is_user_connected(receiver) || !is_user_connected(sender)) + return FMRES_IGNORED - return HC_BREAK - } + ExecuteForward(g_fwdClientVoice, g_retVal, receiver, sender) + if(g_retVal != CA_SUPERCEDE) + return FMRES_IGNORED - return HC_CONTINUE + // Block voice + engfunc(EngFunc_SetClientListening, receiver, sender, (canListen = false)) + return FMRES_SUPERCEDE } -public CBasePlayer_SetClientUserInfoName(const id, const infobuffer[], newName[]) { - ExecuteForward(g_fwdClientChangeName, g_retVal, id, newName) +public ClientUserInfoChanged_Pre(const player, const infobuffer) { + new currentName[32] + get_user_name(player, currentName, charsmax(currentName)) - if(g_retVal == CA_SUPERCEDE) { - SetHookChainReturn(ATYPE_BOOL, false) + new newName[32] + engfunc(EngFunc_InfoKeyValue, infobuffer, "name", newName, charsmax(newName)) - return HC_SUPERCEDE - } + if(strcmp(currentName, newName) == 0) + return + + ExecuteForward(g_fwdClientChangeName, g_retVal, player, newName) + if(g_retVal != CA_SUPERCEDE) + return - return HC_CONTINUE + // Change back name + engfunc(EngFunc_SetClientKeyValue, player, infobuffer, "name", currentName) } public ClCmd_VModEnable(const id) {