From c66ee2f57add564eaa7df80a5112159e8fdf5909 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Fri, 4 Mar 2016 21:14:15 +0600 Subject: [PATCH] ReHLDS API: Add hook on SV_EstablishTimeBase --- rehlds/engine/sv_user.cpp | 12 +++++++++++- rehlds/engine/sv_user.h | 1 + rehlds/public/rehlds/rehlds_api.h | 7 ++++++- rehlds/public/rehlds/rehlds_interfaces.h | 1 + rehlds/rehlds/rehlds_api_impl.cpp | 4 ++++ rehlds/rehlds/rehlds_api_impl.h | 6 ++++++ rehlds/rehlds/rehlds_interfaces_impl.cpp | 5 +++++ rehlds/rehlds/rehlds_interfaces_impl.h | 1 + 8 files changed, 35 insertions(+), 2 deletions(-) diff --git a/rehlds/engine/sv_user.cpp b/rehlds/engine/sv_user.cpp index d28ea96..c15781e 100644 --- a/rehlds/engine/sv_user.cpp +++ b/rehlds/engine/sv_user.cpp @@ -1464,8 +1464,18 @@ void SV_ParseDelta(client_t *pSenderClient) host_client->delta_sequence = MSG_ReadByte(); } -/* ../engine/sv_user.c:1790 */ +void EXT_FUNC SV_EstablishTimeBase_mod(IGameClient *cl, usercmd_t *cmds, int dropped, int numbackup, int numcmds) +{ + SV_EstablishTimeBase_internal(cl->GetClient(), cmds, dropped, numbackup, numcmds); +} + void SV_EstablishTimeBase(client_t *cl, usercmd_t *cmds, int dropped, int numbackup, int numcmds) +{ + return g_RehldsHookchains.m_SV_EstablishTimeBase.callChain(SV_EstablishTimeBase_mod, GetRehldsApiClient(cl), cmds, dropped, numbackup, numcmds); +} + +/* ../engine/sv_user.c:1790 */ +void SV_EstablishTimeBase_internal(client_t *cl, usercmd_t *cmds, int dropped, int numbackup, int numcmds) { int cmdnum; double runcmd_time; diff --git a/rehlds/engine/sv_user.h b/rehlds/engine/sv_user.h index c69e2f3..45fd43b 100644 --- a/rehlds/engine/sv_user.h +++ b/rehlds/engine/sv_user.h @@ -144,6 +144,7 @@ void SV_RestoreMove(client_t *_host_client); void SV_ParseStringCommand(client_t *pSenderClient); void SV_ParseDelta(client_t *pSenderClient); void SV_EstablishTimeBase(client_t *cl, usercmd_t *cmds, int dropped, int numbackup, int numcmds); +void SV_EstablishTimeBase_internal(client_t *cl, usercmd_t *cmds, int dropped, int numbackup, int numcmds); void SV_ParseMove(client_t *pSenderClient); void SV_ParseVoiceData(client_t *cl); void SV_IgnoreHLTV(client_t *cl); diff --git a/rehlds/public/rehlds/rehlds_api.h b/rehlds/public/rehlds/rehlds_api.h index 4dc28eb..4bb2d25 100644 --- a/rehlds/public/rehlds/rehlds_api.h +++ b/rehlds/public/rehlds/rehlds_api.h @@ -35,7 +35,7 @@ #include "model.h" #define REHLDS_API_VERSION_MAJOR 2 -#define REHLDS_API_VERSION_MINOR 9 +#define REHLDS_API_VERSION_MINOR 10 //Steam_NotifyClientConnect hook typedef IHookChain IRehldsHook_Steam_NotifyClientConnect; @@ -173,6 +173,10 @@ typedef IHookChainRegistry IRehldsHookRegist typedef IVoidHookChain IRehldsHook_Cvar_DirectSet; typedef IVoidHookChainRegistry IRehldsHookRegistry_Cvar_DirectSet; +//SV_EstablishTimeBase hook +typedef IVoidHookChain IRehldsHook_SV_EstablishTimeBase; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_EstablishTimeBase; + class IRehldsHookchains { public: virtual ~IRehldsHookchains() { } @@ -211,6 +215,7 @@ public: virtual IRehldsHookRegistry_SV_TransferConsistencyInfo* SV_TransferConsistencyInfo() = 0; virtual IRehldsHookRegistry_Steam_GSBUpdateUserData* Steam_GSBUpdateUserData() = 0; virtual IRehldsHookRegistry_Cvar_DirectSet* Cvar_DirectSet() = 0; + virtual IRehldsHookRegistry_SV_EstablishTimeBase* SV_EstablishTimeBase() = 0; }; struct RehldsFuncs_t { diff --git a/rehlds/public/rehlds/rehlds_interfaces.h b/rehlds/public/rehlds/rehlds_interfaces.h index d740b03..261460e 100644 --- a/rehlds/public/rehlds/rehlds_interfaces.h +++ b/rehlds/public/rehlds/rehlds_interfaces.h @@ -71,6 +71,7 @@ public: virtual void SetLastVoiceTime(double time) = 0; virtual double GetLastVoiceTime() = 0; virtual bool GetLoopback() = 0; + virtual struct usercmd_s *GetLastCmd() = 0; // this must be the last virtual function in class #ifdef REHLDS_SELF diff --git a/rehlds/rehlds/rehlds_api_impl.cpp b/rehlds/rehlds/rehlds_api_impl.cpp index 423be48..145959e 100644 --- a/rehlds/rehlds/rehlds_api_impl.cpp +++ b/rehlds/rehlds/rehlds_api_impl.cpp @@ -364,6 +364,10 @@ IRehldsHookRegistry_Cvar_DirectSet* CRehldsHookchains::Cvar_DirectSet() { return &m_Cvar_DirectSet; } +IRehldsHookRegistry_SV_EstablishTimeBase* CRehldsHookchains::SV_EstablishTimeBase() { + return &m_SV_EstablishTimeBase; +} + int EXT_FUNC CRehldsApi::GetMajorVersion() { return REHLDS_API_VERSION_MAJOR; diff --git a/rehlds/rehlds/rehlds_api_impl.h b/rehlds/rehlds/rehlds_api_impl.h index 04e60e9..fd1e489 100644 --- a/rehlds/rehlds/rehlds_api_impl.h +++ b/rehlds/rehlds/rehlds_api_impl.h @@ -167,6 +167,10 @@ typedef IHookChainRegistryImpl CRehldsHookRe typedef IVoidHookChainImpl CRehldsHook_Cvar_DirectSet; typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_Cvar_DirectSet; +//SV_EstablishTimeBase hook +typedef IVoidHookChainImpl CRehldsHook_SV_EstablishTimeBase; +typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_SV_EstablishTimeBase; + class CRehldsHookchains : public IRehldsHookchains { public: CRehldsHookRegistry_Steam_NotifyClientConnect m_Steam_NotifyClientConnect; @@ -203,6 +207,7 @@ public: CRehldsHookRegistry_SV_TransferConsistencyInfo m_SV_TransferConsistencyInfo; CRehldsHookRegistry_Steam_GSBUpdateUserData m_Steam_GSBUpdateUserData; CRehldsHookRegistry_Cvar_DirectSet m_Cvar_DirectSet; + CRehldsHookRegistry_SV_EstablishTimeBase m_SV_EstablishTimeBase; public: virtual IRehldsHookRegistry_Steam_NotifyClientConnect* Steam_NotifyClientConnect(); @@ -239,6 +244,7 @@ public: virtual IRehldsHookRegistry_SV_TransferConsistencyInfo* SV_TransferConsistencyInfo(); virtual IRehldsHookRegistry_Steam_GSBUpdateUserData* Steam_GSBUpdateUserData(); virtual IRehldsHookRegistry_Cvar_DirectSet* Cvar_DirectSet(); + virtual IRehldsHookRegistry_SV_EstablishTimeBase* SV_EstablishTimeBase(); }; extern CRehldsHookchains g_RehldsHookchains; diff --git a/rehlds/rehlds/rehlds_interfaces_impl.cpp b/rehlds/rehlds/rehlds_interfaces_impl.cpp index 557a21b..6be8cf4 100644 --- a/rehlds/rehlds/rehlds_interfaces_impl.cpp +++ b/rehlds/rehlds/rehlds_interfaces_impl.cpp @@ -43,6 +43,11 @@ int EXT_FUNC CGameClient::GetId() return m_Id; } +struct usercmd_s* EXT_FUNC CGameClient::GetLastCmd() +{ + return &m_pClient->lastcmd; +} + bool EXT_FUNC CGameClient::IsActive() { return m_pClient->active != 0; diff --git a/rehlds/rehlds/rehlds_interfaces_impl.h b/rehlds/rehlds/rehlds_interfaces_impl.h index 63f2ccd..76325e7 100644 --- a/rehlds/rehlds/rehlds_interfaces_impl.h +++ b/rehlds/rehlds/rehlds_interfaces_impl.h @@ -92,6 +92,7 @@ public: virtual void SetLastVoiceTime(double time); virtual double GetLastVoiceTime(); virtual bool GetLoopback(); + virtual struct usercmd_s *GetLastCmd(); virtual client_t* GetClient();