From cfa4cacc6da5c5a7457123e7f238856e9ff51169 Mon Sep 17 00:00:00 2001 From: ShadowsAdi <54354938+ShadowsAdi@users.noreply.github.com> Date: Wed, 23 Mar 2022 17:59:58 +0200 Subject: [PATCH 1/4] `API`: Implement `PM_(Un)Duck` hooks --- regamedll/dlls/API/CAPI_Impl.cpp | 2 ++ regamedll/dlls/API/CAPI_Impl.h | 13 +++++++++++++ regamedll/pm_shared/pm_shared.cpp | 9 +++++++-- regamedll/pm_shared/pm_shared.h | 2 ++ regamedll/public/regamedll/regamedll_api.h | 10 ++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/regamedll/dlls/API/CAPI_Impl.cpp b/regamedll/dlls/API/CAPI_Impl.cpp index 0fe10a490..9fb1967ea 100644 --- a/regamedll/dlls/API/CAPI_Impl.cpp +++ b/regamedll/dlls/API/CAPI_Impl.cpp @@ -158,6 +158,8 @@ GAMEHOOK_REGISTRY(CSGameRules_GoToIntermission); GAMEHOOK_REGISTRY(CSGameRules_BalanceTeams); GAMEHOOK_REGISTRY(CSGameRules_OnRoundFreezeEnd); GAMEHOOK_REGISTRY(PM_UpdateStepSound); +GAMEHOOK_REGISTRY(PM_Duck); +GAMEHOOK_REGISTRY(PM_UnDuck); GAMEHOOK_REGISTRY(CBasePlayer_StartDeathCam); GAMEHOOK_REGISTRY(CBasePlayer_SwitchTeam); GAMEHOOK_REGISTRY(CBasePlayer_CanSwitchTeam); diff --git a/regamedll/dlls/API/CAPI_Impl.h b/regamedll/dlls/API/CAPI_Impl.h index 1be3dd232..41e93aa65 100644 --- a/regamedll/dlls/API/CAPI_Impl.h +++ b/regamedll/dlls/API/CAPI_Impl.h @@ -485,6 +485,14 @@ typedef IHookChainRegistryClassEmptyImpl CReGameHook_PM_UpdateStepSound; typedef IHookChainRegistryImpl CReGameHookRegistry_PM_UpdateStepSound; +// PM_Duck hook +typedef IHookChainImpl CReGameHook_PM_Duck; +typedef IHookChainRegistryImpl CReGameHookRegistry_PM_Duck; + +// PM_UnDuck hook +typedef IHookChainImpl CReGameHook_PM_UnDuck; +typedef IHookChainRegistryImpl CReGameHookRegistry_PM_UnDuck; + // CBasePlayer::StartDeathCam hook typedef IHookChainClassImpl CReGameHook_CBasePlayer_StartDeathCam; typedef IHookChainRegistryClassImpl CReGameHookRegistry_CBasePlayer_StartDeathCam; @@ -728,6 +736,8 @@ class CReGameHookchains: public IReGameHookchains { CReGameHookRegistry_CSGameRules_BalanceTeams m_CSGameRules_BalanceTeams; CReGameHookRegistry_CSGameRules_OnRoundFreezeEnd m_CSGameRules_OnRoundFreezeEnd; CReGameHookRegistry_PM_UpdateStepSound m_PM_UpdateStepSound; + CReGameHookRegistry_PM_Duck m_PM_Duck; + CReGameHookRegistry_PM_UnDuck m_PM_UnDuck; CReGameHookRegistry_CBasePlayer_StartDeathCam m_CBasePlayer_StartDeathCam; CReGameHookRegistry_CBasePlayer_SwitchTeam m_CBasePlayer_SwitchTeam; CReGameHookRegistry_CBasePlayer_CanSwitchTeam m_CBasePlayer_CanSwitchTeam; @@ -904,6 +914,9 @@ class CReGameHookchains: public IReGameHookchains { virtual IReGameHookRegistry_CBasePlayer_Pain *CBasePlayer_Pain(); virtual IReGameHookRegistry_CBasePlayer_DeathSound *CBasePlayer_DeathSound(); virtual IReGameHookRegistry_CBasePlayer_JoiningThink *CBasePlayer_JoiningThink(); + + virtual IReGameHookRegistry_PM_Duck *PM_Duck(); + virtual IReGameHookRegistry_PM_UnDuck *PM_UnDuck(); }; extern CReGameHookchains g_ReGameHookchains; diff --git a/regamedll/pm_shared/pm_shared.cpp b/regamedll/pm_shared/pm_shared.cpp index 75d4a4909..27a35d860 100644 --- a/regamedll/pm_shared/pm_shared.cpp +++ b/regamedll/pm_shared/pm_shared.cpp @@ -1793,7 +1793,9 @@ void PM_FixPlayerCrouchStuck(int direction) VectorCopy(test, pmove->origin); } -void PM_UnDuck() +LINK_HOOK_VOID_CHAIN2(PM_UnDuck); + +void EXT_FUNC __API_HOOK(PM_UnDuck)() { #ifdef REGAMEDLL_ADD if (unduck_method.value) @@ -1863,7 +1865,10 @@ void PM_UnDuck() } } -void PM_Duck() + +LINK_HOOK_VOID_CHAIN2(PM_Duck); + +void EXT_FUNC __API_HOOK(PM_Duck)() { int buttonsChanged = (pmove->oldbuttons ^ pmove->cmd.buttons); // These buttons have changed this frame int nButtonPressed = buttonsChanged & pmove->cmd.buttons; // The changed ones still down are "pressed" diff --git a/regamedll/pm_shared/pm_shared.h b/regamedll/pm_shared/pm_shared.h index 94113ae0a..e33d47737 100644 --- a/regamedll/pm_shared/pm_shared.h +++ b/regamedll/pm_shared/pm_shared.h @@ -83,6 +83,8 @@ void PM_Init_OrigFunc(struct playermove_s *ppmove); void PM_Move_OrigFunc(struct playermove_s *ppmove, int server); void PM_AirMove_OrigFunc(int playerIndex = 0); void PM_UpdateStepSound_OrigFunc(); +void PM_Duck_OrigFunc(); +void PM_UnDuck_OrigFunc(); #else void PM_AirMove(int playerIndex = 0); #endif diff --git a/regamedll/public/regamedll/regamedll_api.h b/regamedll/public/regamedll/regamedll_api.h index ba7a8517c..6d4947ac1 100644 --- a/regamedll/public/regamedll/regamedll_api.h +++ b/regamedll/public/regamedll/regamedll_api.h @@ -364,6 +364,14 @@ typedef IHookChainRegistry IReGa typedef IHookChain IReGameHook_PM_UpdateStepSound; typedef IHookChainRegistry IReGameHookRegistry_PM_UpdateStepSound; +// PM_Duck hook +typedef IHookChain IReGameHook_PM_Duck; +typedef IHookChainRegistry IReGameHookRegistry_PM_Duck; + +// PM_UnDuck hook +typedef IHookChain IReGameHook_PM_UnDuck; +typedef IHookChainRegistry IReGameHookRegistry_PM_UnDuck; + // CBasePlayer::StartDeathCam hook typedef IHookChainClass IReGameHook_CBasePlayer_StartDeathCam; typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_StartDeathCam; @@ -653,6 +661,8 @@ class IReGameHookchains { virtual IReGameHookRegistry_CBasePlayer_Pain *CBasePlayer_Pain() = 0; virtual IReGameHookRegistry_CBasePlayer_DeathSound *CBasePlayer_DeathSound() = 0; virtual IReGameHookRegistry_CBasePlayer_JoiningThink *CBasePlayer_JoiningThink() = 0; + virtual IReGameHookRegistry_PM_Duck *PM_Duck() = 0; + virtual IReGameHookRegistry_PM_UnDuck *PM_UnDuck() = 0; }; struct ReGameFuncs_t { From 3db4b9c61d20d07203ccdfebd6f06fcfb7f0224c Mon Sep 17 00:00:00 2001 From: ShadowsAdi <54354938+ShadowsAdi@users.noreply.github.com> Date: Wed, 23 Mar 2022 18:01:50 +0200 Subject: [PATCH 2/4] Update pm_shared.cpp --- regamedll/pm_shared/pm_shared.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regamedll/pm_shared/pm_shared.cpp b/regamedll/pm_shared/pm_shared.cpp index 27a35d860..9a56a436f 100644 --- a/regamedll/pm_shared/pm_shared.cpp +++ b/regamedll/pm_shared/pm_shared.cpp @@ -1872,7 +1872,7 @@ void EXT_FUNC __API_HOOK(PM_Duck)() { int buttonsChanged = (pmove->oldbuttons ^ pmove->cmd.buttons); // These buttons have changed this frame int nButtonPressed = buttonsChanged & pmove->cmd.buttons; // The changed ones still down are "pressed" - + int duckchange = buttonsChanged & IN_DUCK ? 1 : 0; int duckpressed = nButtonPressed & IN_DUCK ? 1 : 0; From 0e1bdbc20d8fe213e45ccbec387fe3cc940d27b1 Mon Sep 17 00:00:00 2001 From: ShadowsAdi <54354938+ShadowsAdi@users.noreply.github.com> Date: Wed, 23 Mar 2022 20:10:31 +0200 Subject: [PATCH 3/4] Update pm_shared.cpp --- regamedll/pm_shared/pm_shared.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regamedll/pm_shared/pm_shared.cpp b/regamedll/pm_shared/pm_shared.cpp index 9a56a436f..27a35d860 100644 --- a/regamedll/pm_shared/pm_shared.cpp +++ b/regamedll/pm_shared/pm_shared.cpp @@ -1872,7 +1872,7 @@ void EXT_FUNC __API_HOOK(PM_Duck)() { int buttonsChanged = (pmove->oldbuttons ^ pmove->cmd.buttons); // These buttons have changed this frame int nButtonPressed = buttonsChanged & pmove->cmd.buttons; // The changed ones still down are "pressed" - + int duckchange = buttonsChanged & IN_DUCK ? 1 : 0; int duckpressed = nButtonPressed & IN_DUCK ? 1 : 0; From a1ccbf87907271fbfe4860f5c912ca88cc013150 Mon Sep 17 00:00:00 2001 From: ShadowsAdi <54354938+ShadowsAdi@users.noreply.github.com> Date: Mon, 28 Mar 2022 21:03:36 +0300 Subject: [PATCH 4/4] Removed `PM_Duck` hook due it's called per `PM_Move` frame --- regamedll/dlls/API/CAPI_Impl.cpp | 1 - regamedll/dlls/API/CAPI_Impl.h | 8 +------- regamedll/pm_shared/pm_shared.cpp | 5 +---- regamedll/pm_shared/pm_shared.h | 1 - regamedll/public/regamedll/regamedll_api.h | 5 ----- 5 files changed, 2 insertions(+), 18 deletions(-) diff --git a/regamedll/dlls/API/CAPI_Impl.cpp b/regamedll/dlls/API/CAPI_Impl.cpp index 9fb1967ea..9c7e9bf68 100644 --- a/regamedll/dlls/API/CAPI_Impl.cpp +++ b/regamedll/dlls/API/CAPI_Impl.cpp @@ -158,7 +158,6 @@ GAMEHOOK_REGISTRY(CSGameRules_GoToIntermission); GAMEHOOK_REGISTRY(CSGameRules_BalanceTeams); GAMEHOOK_REGISTRY(CSGameRules_OnRoundFreezeEnd); GAMEHOOK_REGISTRY(PM_UpdateStepSound); -GAMEHOOK_REGISTRY(PM_Duck); GAMEHOOK_REGISTRY(PM_UnDuck); GAMEHOOK_REGISTRY(CBasePlayer_StartDeathCam); GAMEHOOK_REGISTRY(CBasePlayer_SwitchTeam); diff --git a/regamedll/dlls/API/CAPI_Impl.h b/regamedll/dlls/API/CAPI_Impl.h index 41e93aa65..54d948e1b 100644 --- a/regamedll/dlls/API/CAPI_Impl.h +++ b/regamedll/dlls/API/CAPI_Impl.h @@ -485,10 +485,6 @@ typedef IHookChainRegistryClassEmptyImpl CReGameHook_PM_UpdateStepSound; typedef IHookChainRegistryImpl CReGameHookRegistry_PM_UpdateStepSound; -// PM_Duck hook -typedef IHookChainImpl CReGameHook_PM_Duck; -typedef IHookChainRegistryImpl CReGameHookRegistry_PM_Duck; - // PM_UnDuck hook typedef IHookChainImpl CReGameHook_PM_UnDuck; typedef IHookChainRegistryImpl CReGameHookRegistry_PM_UnDuck; @@ -736,7 +732,6 @@ class CReGameHookchains: public IReGameHookchains { CReGameHookRegistry_CSGameRules_BalanceTeams m_CSGameRules_BalanceTeams; CReGameHookRegistry_CSGameRules_OnRoundFreezeEnd m_CSGameRules_OnRoundFreezeEnd; CReGameHookRegistry_PM_UpdateStepSound m_PM_UpdateStepSound; - CReGameHookRegistry_PM_Duck m_PM_Duck; CReGameHookRegistry_PM_UnDuck m_PM_UnDuck; CReGameHookRegistry_CBasePlayer_StartDeathCam m_CBasePlayer_StartDeathCam; CReGameHookRegistry_CBasePlayer_SwitchTeam m_CBasePlayer_SwitchTeam; @@ -914,8 +909,7 @@ class CReGameHookchains: public IReGameHookchains { virtual IReGameHookRegistry_CBasePlayer_Pain *CBasePlayer_Pain(); virtual IReGameHookRegistry_CBasePlayer_DeathSound *CBasePlayer_DeathSound(); virtual IReGameHookRegistry_CBasePlayer_JoiningThink *CBasePlayer_JoiningThink(); - - virtual IReGameHookRegistry_PM_Duck *PM_Duck(); + virtual IReGameHookRegistry_PM_UnDuck *PM_UnDuck(); }; diff --git a/regamedll/pm_shared/pm_shared.cpp b/regamedll/pm_shared/pm_shared.cpp index 27a35d860..dfafb1e4a 100644 --- a/regamedll/pm_shared/pm_shared.cpp +++ b/regamedll/pm_shared/pm_shared.cpp @@ -1865,10 +1865,7 @@ void EXT_FUNC __API_HOOK(PM_UnDuck)() } } - -LINK_HOOK_VOID_CHAIN2(PM_Duck); - -void EXT_FUNC __API_HOOK(PM_Duck)() +void PM_Duck() { int buttonsChanged = (pmove->oldbuttons ^ pmove->cmd.buttons); // These buttons have changed this frame int nButtonPressed = buttonsChanged & pmove->cmd.buttons; // The changed ones still down are "pressed" diff --git a/regamedll/pm_shared/pm_shared.h b/regamedll/pm_shared/pm_shared.h index e33d47737..00e21d2b5 100644 --- a/regamedll/pm_shared/pm_shared.h +++ b/regamedll/pm_shared/pm_shared.h @@ -83,7 +83,6 @@ void PM_Init_OrigFunc(struct playermove_s *ppmove); void PM_Move_OrigFunc(struct playermove_s *ppmove, int server); void PM_AirMove_OrigFunc(int playerIndex = 0); void PM_UpdateStepSound_OrigFunc(); -void PM_Duck_OrigFunc(); void PM_UnDuck_OrigFunc(); #else void PM_AirMove(int playerIndex = 0); diff --git a/regamedll/public/regamedll/regamedll_api.h b/regamedll/public/regamedll/regamedll_api.h index 6d4947ac1..4eacc84a2 100644 --- a/regamedll/public/regamedll/regamedll_api.h +++ b/regamedll/public/regamedll/regamedll_api.h @@ -364,10 +364,6 @@ typedef IHookChainRegistry IReGa typedef IHookChain IReGameHook_PM_UpdateStepSound; typedef IHookChainRegistry IReGameHookRegistry_PM_UpdateStepSound; -// PM_Duck hook -typedef IHookChain IReGameHook_PM_Duck; -typedef IHookChainRegistry IReGameHookRegistry_PM_Duck; - // PM_UnDuck hook typedef IHookChain IReGameHook_PM_UnDuck; typedef IHookChainRegistry IReGameHookRegistry_PM_UnDuck; @@ -661,7 +657,6 @@ class IReGameHookchains { virtual IReGameHookRegistry_CBasePlayer_Pain *CBasePlayer_Pain() = 0; virtual IReGameHookRegistry_CBasePlayer_DeathSound *CBasePlayer_DeathSound() = 0; virtual IReGameHookRegistry_CBasePlayer_JoiningThink *CBasePlayer_JoiningThink() = 0; - virtual IReGameHookRegistry_PM_Duck *PM_Duck() = 0; virtual IReGameHookRegistry_PM_UnDuck *PM_UnDuck() = 0; };