From 6063144a31c5d0f416b9ec8e6a0638e5813d580a Mon Sep 17 00:00:00 2001 From: fl0werD Date: Thu, 2 Sep 2021 18:09:10 +0400 Subject: [PATCH] Implement player `Pain`, `DeathSound` and `JoiningThink` hooks (#209) * Implement player Pain, DeathSound and JoiningThink hooks * fix descriptions Co-authored-by: Sergey Shorokhov --- .../scripting/include/reapi_gamedll_const.inc | 22 +++++++++++++ reapi/include/cssdk/dlls/regamedll_api.h | 33 ++++++++++++++----- reapi/src/hook_callback.cpp | 30 +++++++++++++++++ reapi/src/hook_callback.h | 3 ++ reapi/src/hook_list.cpp | 3 ++ reapi/src/hook_list.h | 3 ++ reapi/version/version.h | 2 +- 7 files changed, 86 insertions(+), 10 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index d31c51c..6151043 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -784,6 +784,28 @@ enum GamedllFunc_CBasePlayer * Params: (const this, const reason[]) */ RG_CBasePlayer_DropIdlePlayer, + + /* + * Description: Called when a client emits a "pain sound" after received damage. + * Return type: void + * Params: (const this) + */ + RG_CBasePlayer_Pain, + + /* + * Description: Called when a client emits a "death sound" after death. + * Return type: void + * Params: (const this, lastHitGroup, bool:hasArmour) + */ + RG_CBasePlayer_DeathSound, + + /* + * Description: Called when a client "thinks for the join status". + * (permanently called on each call of "CBasePlayer::PreThink", and only when he is not assigned as specatator or not playing) + * Return type: void + * Params: (const this) + */ + RG_CBasePlayer_JoiningThink, }; /** diff --git a/reapi/include/cssdk/dlls/regamedll_api.h b/reapi/include/cssdk/dlls/regamedll_api.h index a3597c8..f24e009 100644 --- a/reapi/include/cssdk/dlls/regamedll_api.h +++ b/reapi/include/cssdk/dlls/regamedll_api.h @@ -39,7 +39,7 @@ #include #define REGAMEDLL_API_VERSION_MAJOR 5 -#define REGAMEDLL_API_VERSION_MINOR 20 +#define REGAMEDLL_API_VERSION_MINOR 21 // CBasePlayer::Spawn hook typedef IHookChainClass IReGameHook_CBasePlayer_Spawn; @@ -462,8 +462,8 @@ typedef IHookChainClass IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload; // CBasePlayer::DropIdlePlayer hook -typedef IHookChainClass IReGameHook_CBasePlayer_DropIdlePlayer; -typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_DropIdlePlayer; +typedef IHookChainClass IReGameHook_CBasePlayer_DropIdlePlayer; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_DropIdlePlayer; // CreateWeaponBox hook typedef IHookChain IReGameHook_CreateWeaponBox; @@ -490,17 +490,28 @@ typedef IHookChainClass IReGameHook_CGib_WaitTillLand; typedef IHookChainRegistryClass IReGameHookRegistry_CGib_WaitTillLand; // CBaseEntity::FireBullets hook -typedef IHookChainClass IReGameHook_CBaseEntity_FireBullets; -typedef IHookChainRegistryClass IReGameHookRegistry_CBaseEntity_FireBullets; +typedef IHookChainClass IReGameHook_CBaseEntity_FireBullets; +typedef IHookChainRegistryClass IReGameHookRegistry_CBaseEntity_FireBullets; // CBaseEntity::FireBuckshots hook -typedef IHookChainClass IReGameHook_CBaseEntity_FireBuckshots; -typedef IHookChainRegistryClass IReGameHookRegistry_CBaseEntity_FireBuckshots; +typedef IHookChainClass IReGameHook_CBaseEntity_FireBuckshots; +typedef IHookChainRegistryClass IReGameHookRegistry_CBaseEntity_FireBuckshots; // CBaseEntity::FireBullets3 hook -typedef IHookChainClass IReGameHook_CBaseEntity_FireBullets3; -typedef IHookChainRegistryClass IReGameHookRegistry_CBaseEntity_FireBullets3; +typedef IHookChainClass IReGameHook_CBaseEntity_FireBullets3; +typedef IHookChainRegistryClass IReGameHookRegistry_CBaseEntity_FireBullets3; +// CBasePlayer::Pain hook +typedef IHookChainClass IReGameHook_CBasePlayer_Pain; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_Pain; + +// CBasePlayer::DeathSound hook +typedef IHookChainClass IReGameHook_CBasePlayer_DeathSound; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_DeathSound; + +// CBasePlayer::JoiningThink hook +typedef IHookChainClass IReGameHook_CBasePlayer_JoiningThink; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_JoiningThink; class IReGameHookchains { public: @@ -628,6 +639,10 @@ public: virtual IReGameHookRegistry_CBaseEntity_FireBullets *CBaseEntity_FireBullets() = 0; virtual IReGameHookRegistry_CBaseEntity_FireBuckshots *CBaseEntity_FireBuckshots() = 0; virtual IReGameHookRegistry_CBaseEntity_FireBullets3 *CBaseEntity_FireBullets3() = 0; + + virtual IReGameHookRegistry_CBasePlayer_Pain *CBasePlayer_Pain() = 0; + virtual IReGameHookRegistry_CBasePlayer_DeathSound *CBasePlayer_DeathSound() = 0; + virtual IReGameHookRegistry_CBasePlayer_JoiningThink *CBasePlayer_JoiningThink() = 0; }; struct ReGameFuncs_t { diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index 1307ffb..1e0080a 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -562,6 +562,36 @@ void CBasePlayer_DropIdlePlayer(IReGameHook_CBasePlayer_DropIdlePlayer *chain, C callVoidForward(RG_CBasePlayer_DropIdlePlayer, original, indexOfEdict(pthis->pev), reason); } +void CBasePlayer_Pain(IReGameHook_CBasePlayer_Pain *chain, CBasePlayer *pthis, int iLastHitGroup, bool bHasArmour) +{ + auto original = [chain](int _pthis, int _iLastHitGroup, bool _bHasArmour) + { + return chain->callNext(getPrivate(_pthis), _iLastHitGroup, _bHasArmour); + }; + + callVoidForward(RG_CBasePlayer_Pain, original, indexOfEdict(pthis->pev), iLastHitGroup, bHasArmour); +} + +void CBasePlayer_DeathSound(IReGameHook_CBasePlayer_DeathSound *chain, CBasePlayer *pthis) +{ + auto original = [chain](int _pthis) + { + return chain->callNext(getPrivate(_pthis)); + }; + + callVoidForward(RG_CBasePlayer_DeathSound, original, indexOfEdict(pthis->pev)); +} + +void CBasePlayer_JoiningThink(IReGameHook_CBasePlayer_JoiningThink *chain, CBasePlayer *pthis) +{ + auto original = [chain](int _pthis) + { + return chain->callNext(getPrivate(_pthis)); + }; + + callVoidForward(RG_CBasePlayer_JoiningThink, original, indexOfEdict(pthis->pev)); +} + void CBaseAnimating_ResetSequenceInfo(IReGameHook_CBaseAnimating_ResetSequenceInfo *chain, CBaseAnimating *pthis) { auto original = [chain](int _pthis) diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index 32e1182..06eef29 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -428,6 +428,9 @@ void CBasePlayer_RemoveSpawnProtection(IReGameHook_CBasePlayer_RemoveSpawnProtec bool CBasePlayer_HintMessageEx(IReGameHook_CBasePlayer_HintMessageEx *chain, CBasePlayer *pthis, const char *pMessage, float duration, bool bDisplayIfPlayerDead, bool bOverride); void CBasePlayer_UseEmpty(IReGameHook_CBasePlayer_UseEmpty *chain, CBasePlayer *pthis); void CBasePlayer_DropIdlePlayer(IReGameHook_CBasePlayer_DropIdlePlayer *chain, CBasePlayer *pthis, const char *reason); +void CBasePlayer_Pain(IReGameHook_CBasePlayer_Pain *chain, CBasePlayer *pthis, int iLastHitGroup, bool bHasArmour); +void CBasePlayer_DeathSound(IReGameHook_CBasePlayer_DeathSound *chain, CBasePlayer *pthis); +void CBasePlayer_JoiningThink(IReGameHook_CBasePlayer_JoiningThink *chain, CBasePlayer *pthis); void CBaseAnimating_ResetSequenceInfo(IReGameHook_CBaseAnimating_ResetSequenceInfo *chain, CBaseAnimating *pthis); diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index ffbbe88..9ab7d51 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -167,6 +167,9 @@ hook_t hooklist_player[] = { DLL(CBasePlayer_HintMessageEx), DLL(CBasePlayer_UseEmpty), DLL(CBasePlayer_DropIdlePlayer), + DLL(CBasePlayer_Pain), + DLL(CBasePlayer_DeathSound), + DLL(CBasePlayer_JoiningThink), }; hook_t hooklist_gamerules[] = { diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 0e4841f..d9f18db 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -192,6 +192,9 @@ enum GamedllFunc_CBasePlayer RG_CBasePlayer_HintMessageEx, RG_CBasePlayer_UseEmpty, RG_CBasePlayer_DropIdlePlayer, + RG_CBasePlayer_Pain, + RG_CBasePlayer_DeathSound, + RG_CBasePlayer_JoiningThink, // [...] }; diff --git a/reapi/version/version.h b/reapi/version/version.h index b68b0f3..8d97dcb 100644 --- a/reapi/version/version.h +++ b/reapi/version/version.h @@ -6,5 +6,5 @@ #pragma once #define VERSION_MAJOR 5 -#define VERSION_MINOR 19 +#define VERSION_MINOR 20 #define VERSION_MAINTENANCE 0