2
0
mirror of https://github.com/rehlds/rehlds.git synced 2025-01-01 01:25:38 +03:00

Merge pull request #49 from s1lentq/master

Added some functions to ReHLDS API
This commit is contained in:
dreamstalker 2015-07-08 00:24:46 +04:00
commit 9cbc891694
10 changed files with 165 additions and 7 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -730,8 +730,13 @@ void SV_StartParticle(const vec_t *org, const vec_t *dir, int color, int count)
}
}
/* <a6df2> ../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);
}
/* <a6df2> ../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);
}
/* <a8995> ../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;

View File

@ -45,6 +45,7 @@ public:
typedef t_ret(*hookfunc_t)(IHookChain<t_ret, t_args...>*, 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...>*, t_args...);
virtual void registerHook(hookfunc_t hook) = 0;
virtual void unregisterHook(hookfunc_t hook) = 0;
};

View File

@ -117,6 +117,26 @@ typedef IVoidHookChainRegistry<model_t*, void*> IRehldsHookRegistry_Mod_LoadBrus
typedef IVoidHookChain<model_t*, void*> IRehldsHook_Mod_LoadStudioModel;
typedef IVoidHookChainRegistry<model_t*, void*> IRehldsHookRegistry_Mod_LoadStudioModel;
//SV_EmitEvents hook
typedef IVoidHookChain<IGameClient *, packet_entities_t *, sizebuf_t *> IRehldsHook_SV_EmitEvents;
typedef IVoidHookChainRegistry<IGameClient *, packet_entities_t *, sizebuf_t *> IRehldsHookRegistry_SV_EmitEvents;
//EV_PlayReliableEvent hook
typedef IVoidHookChain<IGameClient *, int, short unsigned int, float, event_args_t *> IRehldsHook_EV_PlayReliableEvent;
typedef IVoidHookChainRegistry<IGameClient *, int, short unsigned int, float, event_args_t *> IRehldsHookRegistry_EV_PlayReliableEvent;
//SV_StartSound hook
typedef IVoidHookChain<int , edict_t *, int, const char *, int, float, int, int> IRehldsHook_SV_StartSound;
typedef IVoidHookChainRegistry<int , edict_t *, int, const char *, int, float, int, int> IRehldsHookRegistry_SV_StartSound;
//PF_Remove_I hook
typedef IVoidHookChain<edict_t *> IRehldsHook_PF_Remove_I;
typedef IVoidHookChainRegistry<edict_t *> IRehldsHookRegistry_PF_Remove_I;
//PF_BuildSoundMsg_I hook
typedef IVoidHookChain<edict_t *, int, const char *, float, float, int, int, int, int, const float *, edict_t *> IRehldsHook_PF_BuildSoundMsg_I;
typedef IVoidHookChainRegistry<edict_t *, int, const char *, float, float, int, int, int, int, const float *, edict_t *> 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 {

View File

@ -50,4 +50,17 @@ void AbstractHookChainRegistry::addHook(void* hookFunc) {
}
m_Hooks[m_NumHooks++] = hookFunc;
}
}
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;
}
}
}

View File

@ -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<typename ...t_args>
@ -163,4 +167,7 @@ public:
virtual void registerHook(hookfunc_t hook) {
addHook((void*)hook);
}
virtual void unregisterHook(hookfunc_t hook) {
removeHook((void*)hook);
}
};

View File

@ -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;

View File

@ -111,6 +111,26 @@ typedef IVoidHookChainRegistryImpl<model_t*, void*> CRehldsHookRegistry_Mod_Load
typedef IVoidHookChainImpl<model_t*, void*> CRehldsHook_Mod_LoadStudioModel;
typedef IVoidHookChainRegistryImpl<model_t*, void*> CRehldsHookRegistry_Mod_LoadStudioModel;
//SV_EmitEvents hook
typedef IVoidHookChainImpl<IGameClient *, packet_entities_t *, sizebuf_t *> CRehldsHook_SV_EmitEvents;
typedef IVoidHookChainRegistryImpl<IGameClient *, packet_entities_t *, sizebuf_t *> CRehldsHookRegistry_SV_EmitEvents;
//EV_PlayReliableEvent hook
typedef IVoidHookChainImpl<IGameClient *, int, short unsigned int, float, event_args_t *> CRehldsHook_EV_PlayReliableEvent;
typedef IVoidHookChainRegistryImpl<IGameClient *, int, short unsigned int, float, event_args_t *> CRehldsHookRegistry_EV_PlayReliableEvent;
//SV_StartSound hook
typedef IVoidHookChainImpl<int , edict_t *, int, const char *, int, float, int, int> CRehldsHook_SV_StartSound;
typedef IVoidHookChainRegistryImpl<int , edict_t *, int, const char *, int, float, int, int> CRehldsHookRegistry_SV_StartSound;
//PF_Remove_I hook
typedef IVoidHookChainImpl<edict_t *> CRehldsHook_PF_Remove_I;
typedef IVoidHookChainRegistryImpl<edict_t *> CRehldsHookRegistry_PF_Remove_I;
//PF_BuildSoundMsg_I hook
typedef IVoidHookChainImpl<edict_t *, int, const char *, float, float, int, int, int, int, const float *, edict_t *> CRehldsHook_PF_BuildSoundMsg_I;
typedef IVoidHookChainRegistryImpl<edict_t *, int, const char *, float, float, int, int, int, int, const float *, edict_t *> 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;