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 1/5] `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) { From 15ba121fb6dede0fd24d154c7cad6b0901a67f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Mat=C3=ADas?= <41979395+FEDERICOMB96@users.noreply.github.com> Date: Tue, 6 Feb 2024 01:13:10 -0300 Subject: [PATCH 2/5] fix use indexOfPDataAmx --- reapi/src/hook_callback.cpp | 2 +- reapi/src/type_conversion.h | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index 015dee87..8f74a026 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -1737,7 +1737,7 @@ void CSGameRules_SendDeathMessage(IReGameHook_CSGameRules_SendDeathMessage *chai 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); + callVoidForward(RG_CSGameRules_SendDeathMessage, original, indexOfPDataAmx(pKiller), indexOfEdict(pVictim->pev), indexOfPDataAmx(pAssister), indexOfEdictAmx(pevInflictor), killerWeaponName, iDeathMessageFlags, iRarityOfKill); } /* diff --git a/reapi/src/type_conversion.h b/reapi/src/type_conversion.h index 456fab11..41b9e0c8 100644 --- a/reapi/src/type_conversion.h +++ b/reapi/src/type_conversion.h @@ -88,15 +88,6 @@ 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) { From 4063428151e42adec57544744dc1a63a351f1e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Mat=C3=ADas?= <41979395+FEDERICOMB96@users.noreply.github.com> Date: Thu, 8 Feb 2024 00:06:58 -0300 Subject: [PATCH 3/5] implement `rg_send_death_message` native --- .../scripting/include/reapi_gamedll.inc | 18 ++++++- reapi/include/cssdk/dlls/gamerules.h | 2 + reapi/src/natives/natives_misc.cpp | 54 +++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 454ff8ce..7e66a4ed 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -1204,4 +1204,20 @@ native rg_death_notice(const pVictim, const pKiller, const pevInflictor); * * @return Match player relationship, see GR_* constants in cssdk_const.inc */ -native rg_player_relationship(const player, const target); \ No newline at end of file +native rg_player_relationship(const player, const target); + +/* +* Sends death messages to all players, including info about the killer, victim, weapon used, +* extra death flags, death position, assistant, and kill rarity +* +* @param pKiller Killer index (if any). +* @param pVictim Victim index. +* @param pAssister Assisting player index (if any). +* @param pevInflictor Inflictor entity. 0 = world +* @param killerWeaponName The name of the weapon used by the killer. +* @param iDeathMessageFlags Flags indicating extra death message info, see DeathMessageFlags enum in cssdk_const.inc +* @param iRarityOfKill An bitsums representing the rarity classification of the kill, see KillRarity enum in cssdk_const.inc +* +* @noreturn +*/ +native rg_send_death_message(const pKiller, const pVictim, const pAssister, const pevInflictor, const killerWeaponName[], const DeathMessageFlags:iDeathMessageFlags, const KillRarity:iRarityOfKill); \ No newline at end of file diff --git a/reapi/include/cssdk/dlls/gamerules.h b/reapi/include/cssdk/dlls/gamerules.h index d0781beb..5bb125d0 100644 --- a/reapi/include/cssdk/dlls/gamerules.h +++ b/reapi/include/cssdk/dlls/gamerules.h @@ -553,6 +553,8 @@ class CHalfLifeMultiplay: public CGameRules virtual bool HasRoundTimeExpired() = 0; virtual bool IsBombPlanted() = 0; + virtual void SendDeathMessage(CBaseEntity *pKiller, CBasePlayer *pVictim, CBasePlayer *pAssister, entvars_t *pevInflictor, const char *killerWeaponName, int iDeathMessageFlags, int iRarityOfKill) = 0; + public: bool ShouldSkipShowMenu() const { return m_bSkipShowMenu; } void MarkShowMenuSkipped() { m_bSkipShowMenu = false; } diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 609695c3..0e10c02c 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -3293,6 +3293,58 @@ cell AMX_NATIVE_CALL rg_player_relationship(AMX *amx, cell *params) return CSGameRules()->PlayerRelationship(pPlayer, pTarget); } +/* +* Sends death messages to all players, including info about the killer, victim, weapon used, +* extra death flags, death position, assistant, and kill rarity +* +* @param pKiller The entity who performed the kill (Note: The killer may be a non-player) +* @param pVictim The player who was killed +* @param pAssister The assisting player (if any) +* @param pevInflictor Inflictor entity. 0 = world +* @param killerWeaponName The name of the weapon used by the killer +* @param iDeathMessageFlags Flags indicating extra death message info +* @param iRarityOfKill An bitsums representing the rarity classification of the kill +* +* @noreturn +*/ +cell AMX_NATIVE_CALL rg_send_death_message(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_killer, arg_victim, arg_assister, arg_inflictor, arg_weaponname, arg_deathmsgflags, arg_rarityofkill }; + + CHECK_GAMERULES(); + + CHECK_ISPLAYER(arg_victim); + CBasePlayer *pVictim = UTIL_PlayerByIndex(params[arg_victim]); + CHECK_CONNECTED(pVictim, arg_victim); + + CBasePlayer *pKiller = nullptr; + CBasePlayer *pAssister = nullptr; + + // Check if the killer is a player + if (params[arg_killer]) + { + CHECK_ISPLAYER(arg_killer); + pKiller = UTIL_PlayerByIndex(params[arg_killer]); + CHECK_CONNECTED(pKiller, arg_killer); + } + + // Check if the assister is a player + if (params[arg_assister]) + { + CHECK_ISPLAYER(arg_assister); + pAssister = UTIL_PlayerByIndex(params[arg_assister]); + CHECK_CONNECTED(pAssister, arg_assister); + } + + CAmxArgs args(amx, params); + + char weaponStr[32]; + const char *weaponName = getAmxString(amx, params[arg_weaponname], weaponStr); + + CSGameRules()->SendDeathMessage(pKiller, pVictim, pAssister, args[arg_inflictor], weaponName, args[arg_deathmsgflags], args[arg_rarityofkill]); + return TRUE; +} + AMX_NATIVE_INFO Misc_Natives_RG[] = { { "rg_set_animation", rg_set_animation }, @@ -3406,6 +3458,8 @@ AMX_NATIVE_INFO Misc_Natives_RG[] = { "rg_death_notice", rg_death_notice }, { "rg_player_relationship", rg_player_relationship }, + { "rg_send_death_message", rg_send_death_message }, + { nullptr, nullptr } }; From 1982ca6f7047acb0ed77a5b9721a8b4aed4ee809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Mat=C3=ADas?= <41979395+FEDERICOMB96@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:16:41 -0300 Subject: [PATCH 4/5] improve native description --- reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc | 2 +- reapi/src/natives/natives_misc.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 7e66a4ed..000efac2 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -1208,7 +1208,7 @@ native rg_player_relationship(const player, const target); /* * Sends death messages to all players, including info about the killer, victim, weapon used, -* extra death flags, death position, assistant, and kill rarity +* extra death flags, death position, assistant, and kill rarity using the CHalfLifeMultiplay::SendDeathMessage function. * * @param pKiller Killer index (if any). * @param pVictim Victim index. diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 0e10c02c..1f2e13a9 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -3295,7 +3295,7 @@ cell AMX_NATIVE_CALL rg_player_relationship(AMX *amx, cell *params) /* * Sends death messages to all players, including info about the killer, victim, weapon used, -* extra death flags, death position, assistant, and kill rarity +* extra death flags, death position, assistant, and kill rarity using the CHalfLifeMultiplay::SendDeathMessage function. * * @param pKiller The entity who performed the kill (Note: The killer may be a non-player) * @param pVictim The player who was killed From ab4a06582ab5b6a7109bfe71325809b1a33b664a Mon Sep 17 00:00:00 2001 From: s1lentq Date: Thu, 9 May 2024 15:50:30 +0700 Subject: [PATCH 5/5] Add new flag rarity of kill in-air Minor cleanup --- reapi/extra/amxmodx/scripting/include/cssdk_const.inc | 5 +++-- reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc | 4 ++-- reapi/src/natives/natives_misc.cpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/cssdk_const.inc b/reapi/extra/amxmodx/scripting/include/cssdk_const.inc index b3522bc6..821bbe9f 100644 --- a/reapi/extra/amxmodx/scripting/include/cssdk_const.inc +++ b/reapi/extra/amxmodx/scripting/include/cssdk_const.inc @@ -1580,5 +1580,6 @@ enum KillRarity 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 + KILLRARITY_REVENGE = 0x100, // Revenge by the killer + KILLRARITY_INAIR = 0x200 // Killer was in the air (skill to deal with high inaccuracy) +}; diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 000efac2..013eb5ea 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -1217,7 +1217,7 @@ native rg_player_relationship(const player, const target); * @param killerWeaponName The name of the weapon used by the killer. * @param iDeathMessageFlags Flags indicating extra death message info, see DeathMessageFlags enum in cssdk_const.inc * @param iRarityOfKill An bitsums representing the rarity classification of the kill, see KillRarity enum in cssdk_const.inc -* +* * @noreturn */ -native rg_send_death_message(const pKiller, const pVictim, const pAssister, const pevInflictor, const killerWeaponName[], const DeathMessageFlags:iDeathMessageFlags, const KillRarity:iRarityOfKill); \ No newline at end of file +native rg_send_death_message(const pKiller, const pVictim, const pAssister, const pevInflictor, const killerWeaponName[], const DeathMessageFlags:iDeathMessageFlags, const KillRarity:iRarityOfKill); diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 1f2e13a9..8c1ef8af 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -3304,7 +3304,7 @@ cell AMX_NATIVE_CALL rg_player_relationship(AMX *amx, cell *params) * @param killerWeaponName The name of the weapon used by the killer * @param iDeathMessageFlags Flags indicating extra death message info * @param iRarityOfKill An bitsums representing the rarity classification of the kill -* +* * @noreturn */ cell AMX_NATIVE_CALL rg_send_death_message(AMX *amx, cell *params)