From 38dda25a8422d6e8e625e7d5e6e94feb523b0a36 Mon Sep 17 00:00:00 2001 From: fl0werD Date: Sun, 29 Aug 2021 08:12:25 +0400 Subject: [PATCH] Implement player Pain, DeathSound and JoiningThink hooks (#607) --- regamedll/dlls/API/CAPI_Impl.cpp | 4 ++++ regamedll/dlls/API/CAPI_Impl.h | 20 ++++++++++++++++++++ regamedll/dlls/player.cpp | 12 +++++++++--- regamedll/dlls/player.h | 3 +++ regamedll/public/regamedll/regamedll_api.h | 17 ++++++++++++++++- regamedll/version/version.h | 2 +- 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/regamedll/dlls/API/CAPI_Impl.cpp b/regamedll/dlls/API/CAPI_Impl.cpp index e6dbeaed..9251fe3e 100644 --- a/regamedll/dlls/API/CAPI_Impl.cpp +++ b/regamedll/dlls/API/CAPI_Impl.cpp @@ -186,6 +186,10 @@ GAMEHOOK_REGISTRY(CBaseEntity_FireBullets); GAMEHOOK_REGISTRY(CBaseEntity_FireBuckshots); GAMEHOOK_REGISTRY(CBaseEntity_FireBullets3); +GAMEHOOK_REGISTRY(CBasePlayer_Pain); +GAMEHOOK_REGISTRY(CBasePlayer_DeathSound); +GAMEHOOK_REGISTRY(CBasePlayer_JoiningThink); + int CReGameApi::GetMajorVersion() { return REGAMEDLL_API_VERSION_MAJOR; } diff --git a/regamedll/dlls/API/CAPI_Impl.h b/regamedll/dlls/API/CAPI_Impl.h index d967b516..8ff309bb 100644 --- a/regamedll/dlls/API/CAPI_Impl.h +++ b/regamedll/dlls/API/CAPI_Impl.h @@ -621,6 +621,18 @@ typedef IHookChainRegistryClassImpl CReGameHook_CBaseEntity_FireBullets3; typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBaseEntity_FireBullets3; +// CBasePlayer::Pain hook +typedef IHookChainClassImpl CReGameHook_CBasePlayer_Pain; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBasePlayer_Pain; + +// CBasePlayer::DeathSound hook +typedef IHookChainClassImpl CReGameHook_CBasePlayer_DeathSound; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBasePlayer_DeathSound; + +// CBasePlayer::JoiningThink hook +typedef IHookChainClassImpl CReGameHook_CBasePlayer_JoiningThink; +typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBasePlayer_JoiningThink; + class CReGameHookchains: public IReGameHookchains { public: // CBasePlayer virtual @@ -746,6 +758,10 @@ public: CReGameHookRegistry_CBaseEntity_FireBullets m_CBaseEntity_FireBullets; CReGameHookRegistry_CBaseEntity_FireBuckshots m_CBaseEntity_FireBuckshots; CReGameHookRegistry_CBaseEntity_FireBullets3 m_CBaseEntity_FireBullets3; + + CReGameHookRegistry_CBasePlayer_Pain m_CBasePlayer_Pain; + CReGameHookRegistry_CBasePlayer_DeathSound m_CBasePlayer_DeathSound; + CReGameHookRegistry_CBasePlayer_JoiningThink m_CBasePlayer_JoiningThink; public: virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn(); @@ -870,6 +886,10 @@ public: virtual IReGameHookRegistry_CBaseEntity_FireBullets *CBaseEntity_FireBullets(); virtual IReGameHookRegistry_CBaseEntity_FireBuckshots *CBaseEntity_FireBuckshots(); virtual IReGameHookRegistry_CBaseEntity_FireBullets3 *CBaseEntity_FireBullets3(); + + virtual IReGameHookRegistry_CBasePlayer_Pain *CBasePlayer_Pain(); + virtual IReGameHookRegistry_CBasePlayer_DeathSound *CBasePlayer_DeathSound(); + virtual IReGameHookRegistry_CBasePlayer_JoiningThink *CBasePlayer_JoiningThink(); }; extern CReGameHookchains g_ReGameHookchains; diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 41618966..8c595776 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -461,7 +461,9 @@ void CBasePlayer::SmartRadio() ; } -void CBasePlayer::Pain(int iLastHitGroup, bool bHasArmour) +LINK_HOOK_CLASS_VOID_CHAIN(CBasePlayer, Pain, (int iLastHitGroup, bool bHasArmour), iLastHitGroup, bHasArmour) + +void EXT_FUNC CBasePlayer::__API_HOOK(Pain)(int iLastHitGroup, bool bHasArmour) { int temp = RANDOM_LONG(0, 2); @@ -537,7 +539,9 @@ int TrainSpeed(int iSpeed, int iMax) return iRet; } -void CBasePlayer::DeathSound() +LINK_HOOK_CLASS_VOID_CHAIN2(CBasePlayer, DeathSound) + +void EXT_FUNC CBasePlayer::__API_HOOK(DeathSound)() { // temporarily using pain sounds for death sounds switch (RANDOM_LONG(1, 4)) @@ -3538,7 +3542,9 @@ void EXT_FUNC CBasePlayer::__API_HOOK(MakeVIP)() CSGameRules()->m_iConsecutiveVIP = 1; } -void CBasePlayer::JoiningThink() +LINK_HOOK_CLASS_VOID_CHAIN2(CBasePlayer, JoiningThink) + +void EXT_FUNC CBasePlayer::__API_HOOK(JoiningThink)() { switch (m_iJoiningState) { diff --git a/regamedll/dlls/player.h b/regamedll/dlls/player.h index 4fd978c5..76a9c207 100644 --- a/regamedll/dlls/player.h +++ b/regamedll/dlls/player.h @@ -439,6 +439,9 @@ public: bool HintMessageEx_OrigFunc(const char *pMessage, float duration = 6.0f, bool bDisplayIfPlayerDead = false, bool bOverride = false); void UseEmpty_OrigFunc(); void DropIdlePlayer_OrigFunc(const char *reason); + void Pain_OrigFunc(int iLastHitGroup, bool bHasArmour); + void DeathSound_OrigFunc(); + void JoiningThink_OrigFunc(); CCSPlayer *CSPlayer() const; #endif // REGAMEDLL_API diff --git a/regamedll/public/regamedll/regamedll_api.h b/regamedll/public/regamedll/regamedll_api.h index 3e496117..541c32fa 100644 --- a/regamedll/public/regamedll/regamedll_api.h +++ b/regamedll/public/regamedll/regamedll_api.h @@ -38,7 +38,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; @@ -500,6 +500,17 @@ typedef IHookChainRegistryClass 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: @@ -627,6 +638,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/regamedll/version/version.h b/regamedll/version/version.h index 8d97dcbf..ba22bb75 100644 --- a/regamedll/version/version.h +++ b/regamedll/version/version.h @@ -6,5 +6,5 @@ #pragma once #define VERSION_MAJOR 5 -#define VERSION_MINOR 20 +#define VERSION_MINOR 21 #define VERSION_MAINTENANCE 0