Skip to content

Commit

Permalink
Add PF_Message(Begin|End)_I, PF_Write*_I hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowsAdi committed Feb 22, 2024
1 parent a7043d1 commit d90a1ba
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 1 deletion.
61 changes: 61 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,67 @@ enum EngineFunc
* Params: (const cmd[], source, id)
*/
RH_ExecuteServerStringCmd,

/*
* Description: Called when a message is being sent.
* Params: (msg_dest, msg_type, const float fOrigin[3], const entity)
*/
RH_PF_MessageBegin_I,

/*
* Description: Called when a message is done sending.
* Params: ()
*/
RH_PF_MessageEnd_I,

/*
* Description: Called when a byte is being write to message buffer.
* Params: (iValue)
*/
RH_PF_WriteByte_I,

/*
* Description: Called when a char is being write to message buffer.
* Params: (iValue)
*/
RH_PF_WriteChar_I,

/*
* Description: Called when a short int is being write to message buffer.
* Params: (iValue)
*/
RH_PF_WriteShort_I,

/*
* Description: Called when a long int is being write to message buffer.
* Params: (iValue)
*/
RH_PF_WriteLong_I,

/*
* Description: Called when an angle is being write to message buffer.
* Params: (Float:flValue)
*/
RH_PF_WriteAngle_I,

/*
* Description: Called when a coord is being write to message buffer.
* Params: (Float:flValue)
*/
RH_PF_WriteCoord_I,

/*
* Description: Called when a string is being write to message buffer.
* Params: (const sz[])
*/
RH_PF_WriteString_I,

/*
* Description: Called when an entity is being write to message buffer.
* Params: (iValue)
*/
RH_PF_WriteEntity_I


};

Expand Down
50 changes: 50 additions & 0 deletions reapi/include/cssdk/engine/rehlds_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,46 @@ typedef IVoidHookChainRegistry<const char *> IRehldsHookRegistry_SV_ClientPrintf
typedef IHookChain<bool, edict_t*, edict_t*> IRehldsHook_SV_AllowPhysent;
typedef IHookChainRegistry<bool, edict_t*, edict_t*> IRehldsHookRegistry_SV_AllowPhysent;

//PF_MessageBegin_I hook
typedef IVoidHookChain<int, int, const float *, edict_t *> IRehldsHook_PF_MessageBegin_I;
typedef IVoidHookChainRegistry<int, int, const float *, edict_t *> IRehldsHookRegistry_PF_MessageBegin_I;

//PF_MessageEnd_I hook
typedef IVoidHookChain<> IRehldsHook_PF_MessageEnd_I;
typedef IVoidHookChainRegistry<> IRehldsHookRegistry_PF_MessageEnd_I;

//PF_WriteByte_I hook
typedef IVoidHookChain<int> IRehldsHook_PF_WriteByte_I;
typedef IVoidHookChainRegistry<int> IRehldsHookRegistry_PF_WriteByte_I;

//PF_WriteChar_I hook
typedef IVoidHookChain<int> IRehldsHook_PF_WriteChar_I;
typedef IVoidHookChainRegistry<int> IRehldsHookRegistry_PF_WriteChar_I;

//PF_WriteShort_I hook
typedef IVoidHookChain<int> IRehldsHook_PF_WriteShort_I;
typedef IVoidHookChainRegistry<int> IRehldsHookRegistry_PF_WriteShort_I;

//PF_WriteLong_I hook
typedef IVoidHookChain<int> IRehldsHook_PF_WriteLong_I;
typedef IVoidHookChainRegistry<int> IRehldsHookRegistry_PF_WriteLong_I;

//PF_WriteAngle_I hook
typedef IVoidHookChain<float> IRehldsHook_PF_WriteAngle_I;
typedef IVoidHookChainRegistry<float> IRehldsHookRegistry_PF_WriteAngle_I;

//PF_WriteCoord_I hook
typedef IVoidHookChain<float> IRehldsHook_PF_WriteCoord_I;
typedef IVoidHookChainRegistry<float> IRehldsHookRegistry_PF_WriteCoord_I;

//PF_WriteString_I hook
typedef IVoidHookChain<const char *> IRehldsHook_PF_WriteString_I;
typedef IVoidHookChainRegistry<const char *> IRehldsHookRegistry_PF_WriteString_I;

//PF_WriteEntity_I hook
typedef IVoidHookChain<int> IRehldsHook_PF_WriteEntity_I;
typedef IVoidHookChainRegistry<int> IRehldsHookRegistry_PF_WriteEntity_I;

class IRehldsHookchains {
public:
virtual ~IRehldsHookchains() { }
Expand Down Expand Up @@ -317,6 +357,16 @@ class IRehldsHookchains {
virtual IRehldsHookRegistry_SV_AddResource* SV_AddResource() = 0;
virtual IRehldsHookRegistry_SV_ClientPrintf* SV_ClientPrintf() = 0;
virtual IRehldsHookRegistry_SV_AllowPhysent* SV_AllowPhysent() = 0;
virtual IRehldsHookRegistry_PF_MessageBegin_I* PF_MessageBegin_I() = 0;
virtual IRehldsHookRegistry_PF_MessageEnd_I* PF_MessageEnd_I() = 0;
virtual IRehldsHookRegistry_PF_WriteByte_I* PF_WriteByte_I() = 0;
virtual IRehldsHookRegistry_PF_WriteChar_I* PF_WriteChar_I() = 0;
virtual IRehldsHookRegistry_PF_WriteShort_I* PF_WriteShort_I() = 0;
virtual IRehldsHookRegistry_PF_WriteLong_I* PF_WriteLong_I() = 0;
virtual IRehldsHookRegistry_PF_WriteAngle_I* PF_WriteAngle_I() = 0;
virtual IRehldsHookRegistry_PF_WriteCoord_I* PF_WriteCoord_I() = 0;
virtual IRehldsHookRegistry_PF_WriteString_I* PF_WriteString_I() = 0;
virtual IRehldsHookRegistry_PF_WriteEntity_I* PF_WriteEntity_I() = 0;
};

struct RehldsFuncs_t {
Expand Down
100 changes: 100 additions & 0 deletions reapi/src/hook_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,106 @@ void ExecuteServerStringCmd(IRehldsHook_ExecuteServerStringCmd* chain, const cha
callVoidForward(RH_ExecuteServerStringCmd, original, cmdName, cmdSrc, cmdSrc == src_client ? cl->GetId() + 1 : AMX_NULLENT);
}

void PF_MessageBegin_I(IRehldsHook_PF_MessageBegin_I* chain, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)
{
auto original = [chain](int _msg_dest, int _msg_type, const float *_pOrigin, int _entity)
{
chain->callNext(_msg_dest, _msg_type, _pOrigin, edictByIndexAmx(_entity));
};

callVoidForward(RH_PF_MessageBegin_I, original, msg_dest, msg_type, pOrigin, indexOfEdictAmx(ed));
}

void PF_MessageEnd_I(IRehldsHook_PF_MessageEnd_I *chain)
{
auto original = [chain]()
{
chain->callNext();
};

callVoidForward(RH_PF_MessageEnd_I, original);
}

void PF_WriteByte_I(IRehldsHook_PF_WriteByte_I *chain, int iValue)
{
auto original = [chain](int _value)
{
chain->callNext(_value);
};

callVoidForward(RH_PF_WriteByte_I, original, iValue);
}

void PF_WriteChar_I(IRehldsHook_PF_WriteChar_I *chain, int iValue)
{
auto original = [chain](int _value)
{
chain->callNext(_value);
};

callVoidForward(RH_PF_WriteChar_I, original, iValue);
}

void PF_WriteShort_I(IRehldsHook_PF_WriteShort_I *chain, int iValue)
{
auto original = [chain](int _value)
{
chain->callNext(_value);
};

callVoidForward(RH_PF_WriteShort_I, original, iValue);
}

void PF_WriteLong_I(IRehldsHook_PF_WriteLong_I *chain, int iValue)
{
auto original = [chain](int _value)
{
chain->callNext(_value);
};

callVoidForward(RH_PF_WriteLong_I, original, iValue);
}

void PF_WriteAngle_I(IRehldsHook_PF_WriteAngle_I *chain, float flValue)
{
auto original = [chain](float _fvalue)
{
chain->callNext(_fvalue);
};

callVoidForward(RH_PF_WriteAngle_I, original, flValue);
}

void PF_WriteCoord_I(IRehldsHook_PF_WriteCoord_I *chain, float flValue)
{
auto original = [chain](float _fvalue)
{
chain->callNext(_fvalue);
};

callVoidForward(RH_PF_WriteCoord_I, original, flValue);
}

void PF_WriteString_I(IRehldsHook_PF_WriteString_I *chain, const char * sz)
{
auto original = [chain](const char *_sz)
{
chain->callNext(_sz);
};

callVoidForward(RH_PF_WriteString_I, original, sz);
}

void PF_WriteEntity_I(IRehldsHook_PF_WriteEntity_I *chain, int iValue)
{
auto original = [chain](int _value)
{
chain->callNext(_value);
};

callVoidForward(RH_PF_WriteEntity_I, original, iValue);
}

/*
* ReGameDLL functions
*/
Expand Down
11 changes: 10 additions & 1 deletion reapi/src/hook_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,16 @@ edict_t *ED_Alloc(IRehldsHook_ED_Alloc* chain);
void ED_Free(IRehldsHook_ED_Free* chain, edict_t *entity);
void SV_ClientPrintf(IRehldsHook_SV_ClientPrintf* chain, const char *string);
bool SV_AllowPhysent(IRehldsHook_SV_AllowPhysent* chain, edict_t* check, edict_t* sv_player);

void PF_MessageBegin_I(IRehldsHook_PF_MessageBegin_I* chain, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);
void PF_MessageEnd_I(IRehldsHook_PF_MessageEnd_I* chain);
void PF_WriteByte_I(IRehldsHook_PF_WriteByte_I* chain, int iValue);
void PF_WriteChar_I(IRehldsHook_PF_WriteChar_I* chain, int iValue);
void PF_WriteShort_I(IRehldsHook_PF_WriteShort_I* chain, int iValue);
void PF_WriteLong_I(IRehldsHook_PF_WriteLong_I* chain, int iValue);
void PF_WriteAngle_I(IRehldsHook_PF_WriteAngle_I* chain, float flValue);
void PF_WriteCoord_I(IRehldsHook_PF_WriteCoord_I* chain, float flValue);
void PF_WriteString_I(IRehldsHook_PF_WriteString_I* chain, const char *sz);
void PF_WriteEntity_I(IRehldsHook_PF_WriteEntity_I* chain, int iValue);
/*
* ReGameDLL functions
*/
Expand Down
10 changes: 10 additions & 0 deletions reapi/src/hook_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ hook_t hooklist_engine[] = {
ENG(SV_ClientPrintf),
ENG(SV_AllowPhysent),
ENG(ExecuteServerStringCmd),
ENG(PF_MessageBegin_I),
ENG(PF_MessageEnd_I),
ENG(PF_WriteByte_I),
ENG(PF_WriteChar_I),
ENG(PF_WriteShort_I),
ENG(PF_WriteLong_I),
ENG(PF_WriteAngle_I),
ENG(PF_WriteCoord_I),
ENG(PF_WriteString_I),
ENG(PF_WriteEntity_I),

};

Expand Down
10 changes: 10 additions & 0 deletions reapi/src/hook_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ enum EngineFunc
RH_SV_ClientPrintf,
RH_SV_AllowPhysent,
RH_ExecuteServerStringCmd,
RH_PF_MessageBegin_I,
RH_PF_MessageEnd_I,
RH_PF_WriteByte_I,
RH_PF_WriteChar_I,
RH_PF_WriteShort_I,
RH_PF_WriteLong_I,
RH_PF_WriteAngle_I,
RH_PF_WriteCoord_I,
RH_PF_WriteString_I,
RH_PF_WriteEntity_I,

// [...]
};
Expand Down

0 comments on commit d90a1ba

Please sign in to comment.