Skip to content

Commit

Permalink
Remove ReAPI dependency (#318)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SergeyShorokhov authored Dec 17, 2023
1 parent 86a4cb8 commit b2ed5f9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions cstrike/addons/amxmodx/scripting/CA_Addon_DeathMute.sma
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <amxmodx>
#include <amxmisc>
#include <reapi>
#include <hamsandwich>

#include <ChatAdditions>

Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 23 additions & 2 deletions cstrike/addons/amxmodx/scripting/CA_Addon_RankRestrictions.sma
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <amxmodx>
#include <reapi_reunion>
#tryinclude <reapi>

#include <ChatAdditions>

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
49 changes: 29 additions & 20 deletions cstrike/addons/amxmodx/scripting/ChatAdditions_Core.sma
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <amxmodx>
#include <amxmisc>
#include <reapi>
#include <fakemeta>

#include <grip>
#include <ChatAdditions>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b2ed5f9

Please sign in to comment.