Skip to content

Commit

Permalink
Implement Con_Printf() hook (#222)
Browse files Browse the repository at this point in the history
* Implement Con_Printf hook

* Update REHLDS_API_VERSION_MINOR

* FIX rehlds_api.h

* Update rehlds_api.h

* Update reapi_engine_const.inc

* Update reapi_engine_const.inc

* FIX pointer style

* FIX pointer style

* Update hook_list.cpp

* Update reapi/src/hook_list.h

Co-authored-by: justgo97 <hamdi2050@live.com>

* Apply suggestions from code review

Co-authored-by: Sergey Shorokhov <wopox1337@ya.ru>
Co-authored-by: justgo97 <hamdi2050@live.com>
  • Loading branch information
3 people committed Oct 25, 2021
1 parent 866295f commit dd1fdae
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
7 changes: 6 additions & 1 deletion reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ enum EngineFunc
* Params: (const this)
*/
RH_SV_EmitPings,

/*
* Description: Called when an entity is created.
* Return type: Edict * (Entity index)
Expand All @@ -90,6 +89,12 @@ enum EngineFunc
* Params: (const entity)
*/
RH_ED_Free,

/*
* Description: -
* Params: (const string[])
*/
RH_Con_Printf,
};

/**
Expand Down
13 changes: 9 additions & 4 deletions reapi/include/cssdk/engine/rehlds_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ typedef IHookChain<int, enum sv_delta_s, IGameClient *, struct packet_entities_s
typedef IHookChainRegistry<int, enum sv_delta_s, IGameClient *, struct packet_entities_s *, struct sizebuf_s *> IRehldsHookRegistry_SV_CreatePacketEntities;

//SV_EmitSound2 hook
typedef IHookChain<bool, edict_t *, IGameClient *, int, const char*, float, float, int, int, int, const float*> IRehldsHook_SV_EmitSound2;
typedef IHookChainRegistry<bool, edict_t *, IGameClient *, int, const char*, float, float, int, int, int, const float*> IRehldsHookRegistry_SV_EmitSound2;
typedef IHookChain<bool, edict_t *, IGameClient *, int, const char *, float, float, int, int, int, const float *> IRehldsHook_SV_EmitSound2;
typedef IHookChainRegistry<bool, edict_t *, IGameClient *, int, const char *, float, float, int, int, int, const float *> IRehldsHookRegistry_SV_EmitSound2;

//CreateFakeClient hook
typedef IHookChain<edict_t *, const char *> IRehldsHook_CreateFakeClient;
Expand All @@ -203,8 +203,8 @@ typedef IVoidHookChain<> IRehldsHook_SV_Frame;
typedef IVoidHookChainRegistry<> IRehldsHookRegistry_SV_Frame;

//SV_ShouldSendConsistencyList hook
typedef IHookChain<bool, IGameClient*, bool> IRehldsHook_SV_ShouldSendConsistencyList;
typedef IHookChainRegistry<bool, IGameClient*, bool> IRehldsHookRegistry_SV_ShouldSendConsistencyList;
typedef IHookChain<bool, IGameClient *, bool> IRehldsHook_SV_ShouldSendConsistencyList;
typedef IHookChainRegistry<bool, IGameClient *, bool> IRehldsHookRegistry_SV_ShouldSendConsistencyList;

//GetEntityInit hook
typedef IHookChain<ENTITYINIT, char *> IRehldsHook_GetEntityInit;
Expand All @@ -222,6 +222,10 @@ typedef IHookChainRegistry<edict_t *> IRehldsHookRegistry_ED_Alloc;
typedef IVoidHookChain<edict_t *> IRehldsHook_ED_Free;
typedef IVoidHookChainRegistry<edict_t *> IRehldsHookRegistry_ED_Free;

//Con_Printf hook
typedef IHookChain<void, const char *> IRehldsHook_Con_Printf;
typedef IHookChainRegistry<void, const char *> IRehldsHookRegistry_Con_Printf;

class IRehldsHookchains {
public:
virtual ~IRehldsHookchains() { }
Expand Down Expand Up @@ -272,6 +276,7 @@ class IRehldsHookchains {
virtual IRehldsHookRegistry_SV_EmitPings* SV_EmitPings() = 0;
virtual IRehldsHookRegistry_ED_Alloc* ED_Alloc() = 0;
virtual IRehldsHookRegistry_ED_Free* ED_Free() = 0;
virtual IRehldsHookRegistry_Con_Printf* Con_Printf() = 0;
};

struct RehldsFuncs_t {
Expand Down
10 changes: 10 additions & 0 deletions reapi/src/hook_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ void SV_WriteFullClientUpdate(IRehldsHook_SV_WriteFullClientUpdate *chain, IGame
SV_WriteFullClientUpdate_AMXX(&data, client, (size_t)buffer, receiver);
}

void Con_Printf(IRehldsHook_Con_Printf *chain, const char *string)
{
auto original = [chain](const char *_string)
{
chain->callNext(_string);
};

callVoidForward(RH_Con_Printf, original, string);
}

ENTITYINIT GetEntityInit(IRehldsHook_GetEntityInit *chain, char *classname)
{
auto original = [chain](char *_classname)
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ struct SV_EmitPings_args_t
using SV_EmitPings_t = hookdata_t<IRehldsHook_SV_EmitPings *, SV_EmitPings_args_t &>;
void SV_EmitPings_AMXX(SV_EmitPings_t *data, IGameClient *client);
void SV_EmitPings(IRehldsHook_SV_EmitPings *chain, IGameClient *client, sizebuf_t *msg);
void Con_Printf(IRehldsHook_Con_Printf *chain, const char *string);

edict_t *ED_Alloc(IRehldsHook_ED_Alloc* chain);
void ED_Free(IRehldsHook_ED_Free* chain, edict_t *entity);
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ hook_t hooklist_engine[] = {
ENG(SV_EmitPings, _AMXX),
ENG(ED_Alloc),
ENG(ED_Free),
ENG(Con_Printf),
};

#define DLL(h,...) { {}, {}, #h, "ReGameDLL", [](){ return api_cfg.hasReGameDLL(); }, ((!(RG_##h & (MAX_REGION_RANGE - 1)) ? regfunc::current_cell = 1, true : false) || (RG_##h & (MAX_REGION_RANGE - 1)) == regfunc::current_cell++) ? regfunc(h##__VA_ARGS__) : regfunc(#h#__VA_ARGS__), [](){ g_ReGameHookchains->h()->registerHook(&h); }, [](){ g_ReGameHookchains->h()->unregisterHook(&h); }, false}
Expand Down
3 changes: 2 additions & 1 deletion reapi/src/hook_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ enum EngineFunc
RH_SV_EmitPings,
RH_ED_Alloc,
RH_ED_Free,

RH_Con_Printf,

// [...]
};

Expand Down

0 comments on commit dd1fdae

Please sign in to comment.