From 4812e92fbbce3463f192b9c7a84146bc3ed642da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Mat=C3=ADas?= <41979395+FEDERICOMB96@users.noreply.github.com> Date: Sun, 4 Feb 2024 00:54:58 -0300 Subject: [PATCH] `API`: Implement `RG_CSGameRules_SendDeathMessage` hook --- .../amxmodx/scripting/include/cssdk_const.inc | 31 +++++++++++++++++++ .../scripting/include/reapi_gamedll_const.inc | 8 +++++ reapi/src/hook_callback.cpp | 10 ++++++ reapi/src/hook_callback.h | 1 + reapi/src/hook_list.cpp | 1 + reapi/src/hook_list.h | 1 + reapi/src/type_conversion.h | 9 ++++++ 7 files changed, 61 insertions(+) diff --git a/reapi/extra/amxmodx/scripting/include/cssdk_const.inc b/reapi/extra/amxmodx/scripting/include/cssdk_const.inc index 0f91158b..b3522bc6 100644 --- a/reapi/extra/amxmodx/scripting/include/cssdk_const.inc +++ b/reapi/extra/amxmodx/scripting/include/cssdk_const.inc @@ -1550,4 +1550,35 @@ enum GR_ENEMY, GR_ALLY, GR_NEUTRAL, +}; + +// Flags for specifying extra info about player death +enum DeathMessageFlags +{ + // float[3] + // Position where the victim was killed by the enemy + PLAYERDEATH_POSITION = 0x001, + + // byte + // Index of the assistant who helped the attacker kill the victim + PLAYERDEATH_ASSISTANT = 0x002, + + // short + // Bitsum classification for the rarity of the kill + // See enum KillRarity for details + PLAYERDEATH_KILLRARITY = 0x004 +}; + +// Classifying various player kill methods in the game +enum KillRarity +{ + KILLRARITY_HEADSHOT = 0x001, // Headshot + KILLRARITY_KILLER_BLIND = 0x002, // Killer was blind + KILLRARITY_NOSCOPE = 0x004, // No-scope sniper rifle kill + KILLRARITY_PENETRATED = 0x008, // Penetrated kill (through walls) + KILLRARITY_THRUSMOKE = 0x010, // Smoke grenade penetration kill (bullets went through smoke) + KILLRARITY_ASSISTEDFLASH = 0x020, // Assister helped with a flash + KILLRARITY_DOMINATION_BEGAN = 0x040, // Killer player began dominating the victim (NOTE: this flag is set once) + KILLRARITY_DOMINATION = 0x080, // Continues domination by the killer + KILLRARITY_REVENGE = 0x100 // Revenge by the killer }; \ No newline at end of file diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 2970c5d5..4892904d 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -1246,6 +1246,14 @@ enum GamedllFunc_CSGameRules * Params: (const pPlayer, const pWeapon) */ RG_CSGameRules_PlayerGotWeapon, + + /* + * Description: Called when a player is killed, sends death messages to all players, including info about the killer, victim, weapon used, + * extra death flags, death position, assistant, and kill rarity + * Return type: void + * Params: (const pKiller, const pVictim, const pAssister, const pevInflictor, const killerWeaponName[], const DeathMessageFlags:iDeathMessageFlags, const KillRarity:iRarityOfKill) + */ + RG_CSGameRules_SendDeathMessage, }; /** diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index 3c286045..015dee87 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -1730,6 +1730,16 @@ void CBasePlayer_Observer_Think(IReGameHook_CBasePlayer_Observer_Think *chain, C callVoidForward(RG_CBasePlayer_Observer_Think, original, indexOfEdict(pthis->pev)); } +void CSGameRules_SendDeathMessage(IReGameHook_CSGameRules_SendDeathMessage *chain, CBaseEntity *pKiller, CBasePlayer *pVictim, CBasePlayer *pAssister, entvars_t *pevInflictor, const char *killerWeaponName, int iDeathMessageFlags, int iRarityOfKill) +{ + auto original = [chain](int _pKiller, int _pVictim, int _pAssister, int _pevInflictor, const char *_killerWeaponName, int _iDeathMessageFlags, int _iRarityOfKill) + { + chain->callNext(getPrivate(_pKiller), getPrivate(_pVictim), getPrivate(_pAssister), PEV(_pevInflictor), _killerWeaponName, _iDeathMessageFlags, _iRarityOfKill); + }; + + callVoidForward(RG_CSGameRules_SendDeathMessage, original, indexOfPData(pKiller), indexOfEdict(pVictim->pev), indexOfPData(pAssister), indexOfEdictAmx(pevInflictor), killerWeaponName, iDeathMessageFlags, iRarityOfKill); +} + /* * VTC functions */ diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index ede4ad76..e0c2374f 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -560,6 +560,7 @@ void CBasePlayerWeapon_KickBack(IReGameHook_CBasePlayerWeapon_KickBack *chain, C void CBasePlayerWeapon_SendWeaponAnim(IReGameHook_CBasePlayerWeapon_SendWeaponAnim *chain, CBasePlayerWeapon *pthis, int iAnim, int skiplocal); void CBasePlayer_PlayerDeathThink(IReGameHook_CBasePlayer_PlayerDeathThink *chain, CBasePlayer *pthis); void CBasePlayer_Observer_Think(IReGameHook_CBasePlayer_Observer_Think *chain, CBasePlayer *pthis); +void CSGameRules_SendDeathMessage(IReGameHook_CSGameRules_SendDeathMessage *chain, CBaseEntity *pKiller, CBasePlayer *pVictim, CBasePlayer *pAssister, entvars_t *pevInflictor, const char *killerWeaponName, int iDeathMessageFlags, int iRarityOfKill); /* * VTC functions diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index 8f5bf54a..d19f6709 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -246,6 +246,7 @@ hook_t hooklist_gamerules[] = { DLL(CSGameRules_TeamFull), DLL(CSGameRules_TeamStacked), DLL(CSGameRules_PlayerGotWeapon), + DLL(CSGameRules_SendDeathMessage), }; hook_t hooklist_grenade[] = { diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 6e6d9da7..deaeadbf 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -305,6 +305,7 @@ enum GamedllFunc_CSGameRules RG_CSGameRules_TeamFull, RG_CSGameRules_TeamStacked, RG_CSGameRules_PlayerGotWeapon, + RG_CSGameRules_SendDeathMessage, // [...] }; diff --git a/reapi/src/type_conversion.h b/reapi/src/type_conversion.h index 41b9e0c8..456fab11 100644 --- a/reapi/src/type_conversion.h +++ b/reapi/src/type_conversion.h @@ -88,6 +88,15 @@ inline entvars_t* PEV(const int index) return pvars; } +template +inline size_t indexOfPData(const T* pdata) +{ + size_t index = 0; + if (likely(pdata != nullptr)) + index = indexOfEdict(pdata->pev); + return index; +} + template inline size_t indexOfPDataAmx(const T* pdata) {