diff --git a/rehlds/engine/pr_cmds.cpp b/rehlds/engine/pr_cmds.cpp index 82ff324..909f053 100644 --- a/rehlds/engine/pr_cmds.cpp +++ b/rehlds/engine/pr_cmds.cpp @@ -961,8 +961,13 @@ edict_t* EXT_FUNC CreateNamedEntity(int className) } } +void PF_Remove_I(edict_t *ed) +{ + g_RehldsHookchains.m_PF_Remove_I.callChain(PF_Remove_I_internal, ed); +} + /* <7941a> ../engine/pr_cmds.c:1253 */ -void EXT_FUNC PF_Remove_I(edict_t *ed) +void EXT_FUNC PF_Remove_I_internal(edict_t *ed) { ED_Free(ed); } @@ -1172,8 +1177,18 @@ short unsigned int EXT_FUNC EV_Precache(int type, const char *psz) } } +void EXT_FUNC EV_PlayReliableEvent_api(IGameClient *cl, int entindex, short unsigned int eventindex, float delay, event_args_t *pargs) +{ + EV_PlayReliableEvent_internal(cl->GetClient(), entindex, eventindex, delay, pargs); +} + +void EV_PlayReliableEvent(client_t *cl, int entindex, short unsigned int eventindex, float delay, event_args_t *pargs) +{ + g_RehldsHookchains.m_EV_PlayReliableEvent.callChain(EV_PlayReliableEvent_api, GetRehldsApiClient(cl), entindex, eventindex, delay, pargs); +} + /* <796ae> ../engine/pr_cmds.c:1531 */ -void EXT_FUNC EV_PlayReliableEvent(client_t *cl, int entindex, short unsigned int eventindex, float delay, event_args_t *pargs) +void EV_PlayReliableEvent_internal(client_t *cl, int entindex, short unsigned int eventindex, float delay, event_args_t *pargs) { // unsigned char data; // 1533 // sizebuf_t msg; // 1534 @@ -2546,8 +2561,13 @@ const char* EXT_FUNC PF_GetPlayerAuthId(edict_t *e) return szAuthID[count]; } +void PF_BuildSoundMsg_I(edict_t *entity, int channel, const char *sample, float volume, float attenuation, int fFlags, int pitch, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed) +{ + g_RehldsHookchains.m_PF_BuildSoundMsg_I.callChain(PF_BuildSoundMsg_I_internal, entity, channel, sample, volume, attenuation, fFlags, pitch, msg_dest, msg_type, pOrigin, ed); +} + /* <7a902> ../engine/pr_cmds.c:3229 */ -void EXT_FUNC PF_BuildSoundMsg_I(edict_t *entity, int channel, const char *sample, float volume, float attenuation, int fFlags, int pitch, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed) +void EXT_FUNC PF_BuildSoundMsg_I_internal(edict_t *entity, int channel, const char *sample, float volume, float attenuation, int fFlags, int pitch, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed) { PF_MessageBegin_I(msg_dest, msg_type, pOrigin, ed); SV_BuildSoundMsg(entity, channel, sample, (int)volume, attenuation, fFlags, pitch, pOrigin, &gMsgBuffer); diff --git a/rehlds/engine/pr_cmds.h b/rehlds/engine/pr_cmds.h index 9b7d8d5..6363661 100644 --- a/rehlds/engine/pr_cmds.h +++ b/rehlds/engine/pr_cmds.h @@ -136,6 +136,7 @@ edict_t *FindEntityInSphere(edict_t *pEdictStartSearchAfter, const float *org, f edict_t *PF_Spawn_I(void); edict_t *CreateNamedEntity(int className); void PF_Remove_I(edict_t *ed); +void PF_Remove_I_internal(edict_t *ed); edict_t *PF_find_Shared(int eStartSearchAfter, int iFieldToMatch, const char *szValueToFind); int iGetIndex(const char *pszField); edict_t *FindEntityByString(edict_t *pEdictStartSearchAfter, const char *pszField, const char *pszValue); @@ -143,7 +144,9 @@ int GetEntityIllum(edict_t *pEnt); qboolean PR_IsEmptyString(const char *s); int PF_precache_sound_I(const char *s); short unsigned int EV_Precache(int type, const char *psz); +void EV_PlayReliableEvent_api(IGameClient *cl, int entindex, short unsigned int eventindex, float delay, event_args_t *pargs); void EV_PlayReliableEvent(client_t *cl, int entindex, short unsigned int eventindex, float delay, event_args_t *pargs); +void EV_PlayReliableEvent_internal(client_t *cl, int entindex, short unsigned int eventindex, float delay, event_args_t *pargs); void EV_Playback(int flags, const edict_t *pInvoker, short unsigned int eventindex, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2); void EV_SV_Playback(int flags, int clientindex, short unsigned int eventindex, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2); int PF_precache_model_I(const char *s); @@ -194,6 +197,7 @@ int PF_GetPlayerUserId(edict_t *e); unsigned int PF_GetPlayerWONId(edict_t *e); const char *PF_GetPlayerAuthId(edict_t *e); void PF_BuildSoundMsg_I(edict_t *entity, int channel, const char *sample, float volume, float attenuation, int fFlags, int pitch, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed); +void PF_BuildSoundMsg_I_internal(edict_t *entity, int channel, const char *sample, float volume, float attenuation, int fFlags, int pitch, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed); int PF_IsDedicatedServer(void); const char *PF_GetPhysicsInfoString(const edict_t *pClient); const char *PF_GetPhysicsKeyValue(const edict_t *pClient, const char *key); diff --git a/rehlds/engine/server.h b/rehlds/engine/server.h index 983694e..3a205c3 100644 --- a/rehlds/engine/server.h +++ b/rehlds/engine/server.h @@ -610,6 +610,7 @@ void SV_CountProxies(int *proxies); void SV_FindModelNumbers(void); void SV_StartParticle(const vec_t *org, const vec_t *dir, int color, int count); void SV_StartSound(int recipients, edict_t *entity, int channel, const char *sample, int volume, float attenuation, int fFlags, int pitch); +void SV_StartSound_internal(int recipients, edict_t *entity, int channel, const char *sample, int volume, float attenuation, int fFlags, int pitch); qboolean SV_BuildSoundMsg(edict_t *entity, int channel, const char *sample, int volume, float attenuation, int fFlags, int pitch, const float *origin, sizebuf_t *buffer); int SV_HashString(const char *string, int iBounds); int SV_LookupSoundIndex(const char *sample); @@ -689,6 +690,7 @@ void SV_CheckTimeouts(void); int SV_CalcPing(client_t *cl); void SV_FullClientUpdate(client_t *cl, sizebuf_t *sb); void SV_EmitEvents(client_t *cl, packet_entities_t *pack, sizebuf_t *msg); +void SV_EmitEvents_internal(client_t *cl, packet_entities_t *pack, sizebuf_t *msg); void SV_AddToFatPVS(vec_t *org, mnode_t *node); unsigned char *SV_FatPVS(float *org); void SV_AddToFatPAS(vec_t *org, mnode_t *node); diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index 4490663..4554184 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -730,8 +730,13 @@ void SV_StartParticle(const vec_t *org, const vec_t *dir, int color, int count) } } -/* ../engine/sv_main.c:887 */ void SV_StartSound(int recipients, edict_t *entity, int channel, const char *sample, int volume, float attenuation, int fFlags, int pitch) +{ + g_RehldsHookchains.m_SV_StartSound.callChain(SV_StartSound_internal, recipients, entity, channel, sample, volume, attenuation, fFlags, pitch); +} + +/* ../engine/sv_main.c:887 */ +void EXT_FUNC SV_StartSound_internal(int recipients, edict_t *entity, int channel, const char *sample, int volume, float attenuation, int fFlags, int pitch) { vec3_t origin; @@ -3719,8 +3724,18 @@ void SV_FullClientUpdate(client_t *cl, sizebuf_t *sb) MSG_WriteBuf(sb, sizeof(digest), digest); } +void EXT_FUNC SV_EmitEvents_api(IGameClient *cl, packet_entities_t *pack, sizebuf_t *ms) +{ + SV_EmitEvents_internal(cl->GetClient(), pack, ms); +} + +void SV_EmitEvents(client_t *cl, packet_entities_t *pack, sizebuf_t *ms) +{ + g_RehldsHookchains.m_SV_EmitEvents.callChain(SV_EmitEvents_api, GetRehldsApiClient(cl), pack, ms); +} + /* ../engine/sv_main.c:5027 */ -void SV_EmitEvents(client_t *cl, packet_entities_t *pack, sizebuf_t *msg) +void SV_EmitEvents_internal(client_t *cl, packet_entities_t *pack, sizebuf_t *msg) { int i; int ev; diff --git a/rehlds/public/rehlds/hookchains.h b/rehlds/public/rehlds/hookchains.h index 52f15c7..3906fcc 100644 --- a/rehlds/public/rehlds/hookchains.h +++ b/rehlds/public/rehlds/hookchains.h @@ -45,6 +45,7 @@ public: typedef t_ret(*hookfunc_t)(IHookChain*, t_args...); virtual void registerHook(hookfunc_t hook) = 0; + virtual void unregisterHook(hookfunc_t hook) = 0; }; @@ -64,4 +65,5 @@ public: typedef void(*hookfunc_t)(IVoidHookChain*, t_args...); virtual void registerHook(hookfunc_t hook) = 0; + virtual void unregisterHook(hookfunc_t hook) = 0; }; diff --git a/rehlds/public/rehlds/rehlds_api.h b/rehlds/public/rehlds/rehlds_api.h index f795c77..b25364b 100644 --- a/rehlds/public/rehlds/rehlds_api.h +++ b/rehlds/public/rehlds/rehlds_api.h @@ -117,6 +117,26 @@ typedef IVoidHookChainRegistry IRehldsHookRegistry_Mod_LoadBrus typedef IVoidHookChain IRehldsHook_Mod_LoadStudioModel; typedef IVoidHookChainRegistry IRehldsHookRegistry_Mod_LoadStudioModel; +//SV_EmitEvents hook +typedef IVoidHookChain IRehldsHook_SV_EmitEvents; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_EmitEvents; + +//EV_PlayReliableEvent hook +typedef IVoidHookChain IRehldsHook_EV_PlayReliableEvent; +typedef IVoidHookChainRegistry IRehldsHookRegistry_EV_PlayReliableEvent; + +//SV_StartSound hook +typedef IVoidHookChain IRehldsHook_SV_StartSound; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_StartSound; + +//PF_Remove_I hook +typedef IVoidHookChain IRehldsHook_PF_Remove_I; +typedef IVoidHookChainRegistry IRehldsHookRegistry_PF_Remove_I; + +//PF_BuildSoundMsg_I hook +typedef IVoidHookChain IRehldsHook_PF_BuildSoundMsg_I; +typedef IVoidHookChainRegistry IRehldsHookRegistry_PF_BuildSoundMsg_I; + class IRehldsHookchains { public: virtual ~IRehldsHookchains() { } @@ -141,6 +161,11 @@ public: virtual IRehldsHookRegistry_Mod_LoadBrushModel* Mod_LoadBrushModel() = 0; virtual IRehldsHookRegistry_Mod_LoadStudioModel* Mod_LoadStudioModel() = 0; virtual IRehldsHookRegistry_ExecuteServerStringCmd* ExecuteServerStringCmd() = 0; + virtual IRehldsHookRegistry_SV_EmitEvents* SV_EmitEvents() = 0; + virtual IRehldsHookRegistry_EV_PlayReliableEvent* EV_PlayReliableEvent() = 0; + virtual IRehldsHookRegistry_SV_StartSound* SV_StartSound() = 0; + virtual IRehldsHookRegistry_PF_Remove_I* PF_Remove_I() = 0; + virtual IRehldsHookRegistry_PF_BuildSoundMsg_I* PF_BuildSoundMsg_I() = 0; }; struct RehldsFuncs_t { @@ -166,6 +191,14 @@ struct RehldsFuncs_t { int*(*GetMsgBadRead)(); cmd_source_t*(*GetCmdSource)(); void(*Log)(const char* prefix, const char* msg); + DLL_FUNCTIONS *(*GetEntityInterface)(); + void(*EV_PlayReliableEvent)(IGameClient *cl, int entindex, short unsigned int eventindex, float delay, event_args_t *pargs); + int(*SV_LookupSoundIndex)(const char *sample); + void(*MSG_StartBitWriting)(sizebuf_t *buf); + void(*MSG_WriteBits)(uint32 data, int numbits); + void(*MSG_WriteBitVec3Coord)(const float *fa); + void(*MSG_EndBitWriting)(sizebuf_t *buf); + void*(*SZ_GetSpace)(sizebuf_t *buf, int length); }; class IRehldsApi { diff --git a/rehlds/rehlds/hookchains_impl.cpp b/rehlds/rehlds/hookchains_impl.cpp index 7ef5c90..1553380 100644 --- a/rehlds/rehlds/hookchains_impl.cpp +++ b/rehlds/rehlds/hookchains_impl.cpp @@ -50,4 +50,17 @@ void AbstractHookChainRegistry::addHook(void* hookFunc) { } m_Hooks[m_NumHooks++] = hookFunc; -} \ No newline at end of file +} + +void AbstractHookChainRegistry::removeHook(void* hookFunc) { + + // erase hook + for (int i = 0; i < m_NumHooks; i++) { + if (hookFunc == m_Hooks[i]) { + if(--m_NumHooks != i) + memmove(&m_Hooks[i], &m_Hooks[i + 1], (m_NumHooks - i) * sizeof(m_Hooks[0])); + + return; + } + } +} diff --git a/rehlds/rehlds/hookchains_impl.h b/rehlds/rehlds/hookchains_impl.h index 34bf8d2..efee471 100644 --- a/rehlds/rehlds/hookchains_impl.h +++ b/rehlds/rehlds/hookchains_impl.h @@ -122,6 +122,7 @@ protected: protected: void addHook(void* hookFunc); + void removeHook(void* hookFunc); public: AbstractHookChainRegistry(); @@ -144,6 +145,9 @@ public: virtual void registerHook(hookfunc_t hook) { addHook((void*)hook); } + virtual void unregisterHook(hookfunc_t hook) { + removeHook((void*)hook); + } }; template @@ -163,4 +167,7 @@ public: virtual void registerHook(hookfunc_t hook) { addHook((void*)hook); } + virtual void unregisterHook(hookfunc_t hook) { + removeHook((void*)hook); + } }; diff --git a/rehlds/rehlds/rehlds_api_impl.cpp b/rehlds/rehlds/rehlds_api_impl.cpp index 3b65208..5a6b070 100644 --- a/rehlds/rehlds/rehlds_api_impl.cpp +++ b/rehlds/rehlds/rehlds_api_impl.cpp @@ -61,6 +61,10 @@ void EXT_FUNC Log_api(const char* prefix, const char* msg) { #endif } +DLL_FUNCTIONS* EXT_FUNC GetEntityInterface_api() { + return &gEntityInterface; +} + CRehldsServerStatic g_RehldsServerStatic; CRehldsServerData g_RehldsServerData; CRehldsHookchains g_RehldsHookchains; @@ -87,7 +91,15 @@ RehldsFuncs_t g_RehldsApiFuncs = &GetRealTime_api, &GetMsgBadRead_api, &GetCmdSource_api, - &Log_api + &Log_api, + &GetEntityInterface_api, + &EV_PlayReliableEvent_api, + &SV_LookupSoundIndex, + &MSG_StartBitWriting, + &MSG_WriteBits, + &MSG_WriteBitVec3Coord, + &MSG_EndBitWriting, + &SZ_GetSpace }; sizebuf_t* EXT_FUNC GetNetMessage_api() @@ -201,6 +213,26 @@ IRehldsHookRegistry_ExecuteServerStringCmd* CRehldsHookchains::ExecuteServerStri return &m_ExecuteServerStringCmd; } +IRehldsHookRegistry_SV_EmitEvents* CRehldsHookchains::SV_EmitEvents() { + return &m_SV_EmitEvents; +} + +IRehldsHookRegistry_EV_PlayReliableEvent* CRehldsHookchains::EV_PlayReliableEvent() { + return &m_EV_PlayReliableEvent; +} + +IRehldsHookRegistry_SV_StartSound* CRehldsHookchains::SV_StartSound() { + return &m_SV_StartSound; +} + +IRehldsHookRegistry_PF_Remove_I* CRehldsHookchains::PF_Remove_I() { + return &m_PF_Remove_I; +} + +IRehldsHookRegistry_PF_BuildSoundMsg_I* CRehldsHookchains::PF_BuildSoundMsg_I() { + return &m_PF_BuildSoundMsg_I; +} + 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 95304b3..fdfdc9b 100644 --- a/rehlds/rehlds/rehlds_api_impl.h +++ b/rehlds/rehlds/rehlds_api_impl.h @@ -111,6 +111,26 @@ typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_Mod_Load typedef IVoidHookChainImpl CRehldsHook_Mod_LoadStudioModel; typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_Mod_LoadStudioModel; +//SV_EmitEvents hook +typedef IVoidHookChainImpl CRehldsHook_SV_EmitEvents; +typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_SV_EmitEvents; + +//EV_PlayReliableEvent hook +typedef IVoidHookChainImpl CRehldsHook_EV_PlayReliableEvent; +typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_EV_PlayReliableEvent; + +//SV_StartSound hook +typedef IVoidHookChainImpl CRehldsHook_SV_StartSound; +typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_SV_StartSound; + +//PF_Remove_I hook +typedef IVoidHookChainImpl CRehldsHook_PF_Remove_I; +typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_PF_Remove_I; + +//PF_BuildSoundMsg_I hook +typedef IVoidHookChainImpl CRehldsHook_PF_BuildSoundMsg_I; +typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_PF_BuildSoundMsg_I; + class CRehldsHookchains : public IRehldsHookchains { public: CRehldsHookRegistry_Steam_NotifyClientConnect m_Steam_NotifyClientConnect; @@ -133,6 +153,11 @@ public: CRehldsHookRegistry_Mod_LoadBrushModel m_Mod_LoadBrushModel; CRehldsHookRegistry_Mod_LoadStudioModel m_Mod_LoadStudioModel; CRehldsHookRegistry_ExecuteServerStringCmd m_ExecuteServerStringCmd; + CRehldsHookRegistry_SV_EmitEvents m_SV_EmitEvents; + CRehldsHookRegistry_EV_PlayReliableEvent m_EV_PlayReliableEvent; + CRehldsHookRegistry_SV_StartSound m_SV_StartSound; + CRehldsHookRegistry_PF_Remove_I m_PF_Remove_I; + CRehldsHookRegistry_PF_BuildSoundMsg_I m_PF_BuildSoundMsg_I; public: virtual IRehldsHookRegistry_Steam_NotifyClientConnect* Steam_NotifyClientConnect(); @@ -155,6 +180,11 @@ public: virtual IRehldsHookRegistry_Mod_LoadBrushModel* Mod_LoadBrushModel(); virtual IRehldsHookRegistry_Mod_LoadStudioModel* Mod_LoadStudioModel(); virtual IRehldsHookRegistry_ExecuteServerStringCmd* ExecuteServerStringCmd(); + virtual IRehldsHookRegistry_SV_EmitEvents* SV_EmitEvents(); + virtual IRehldsHookRegistry_EV_PlayReliableEvent* EV_PlayReliableEvent(); + virtual IRehldsHookRegistry_SV_StartSound* SV_StartSound(); + virtual IRehldsHookRegistry_PF_Remove_I* PF_Remove_I(); + virtual IRehldsHookRegistry_PF_BuildSoundMsg_I* PF_BuildSoundMsg_I(); }; extern CRehldsHookchains g_RehldsHookchains;