Skip to content

Commit dd1fdae

Browse files
francoromaniellowopox1337justgo97
authored
Implement Con_Printf() hook (#222)
* 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>
1 parent 866295f commit dd1fdae

6 files changed

Lines changed: 29 additions & 6 deletions

File tree

reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ enum EngineFunc
7777
* Params: (const this)
7878
*/
7979
RH_SV_EmitPings,
80-
8180
/*
8281
* Description: Called when an entity is created.
8382
* Return type: Edict * (Entity index)
@@ -90,6 +89,12 @@ enum EngineFunc
9089
* Params: (const entity)
9190
*/
9291
RH_ED_Free,
92+
93+
/*
94+
* Description: -
95+
* Params: (const string[])
96+
*/
97+
RH_Con_Printf,
9398
};
9499

95100
/**

reapi/include/cssdk/engine/rehlds_api.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ typedef IHookChain<int, enum sv_delta_s, IGameClient *, struct packet_entities_s
187187
typedef IHookChainRegistry<int, enum sv_delta_s, IGameClient *, struct packet_entities_s *, struct sizebuf_s *> IRehldsHookRegistry_SV_CreatePacketEntities;
188188

189189
//SV_EmitSound2 hook
190-
typedef IHookChain<bool, edict_t *, IGameClient *, int, const char*, float, float, int, int, int, const float*> IRehldsHook_SV_EmitSound2;
191-
typedef IHookChainRegistry<bool, edict_t *, IGameClient *, int, const char*, float, float, int, int, int, const float*> IRehldsHookRegistry_SV_EmitSound2;
190+
typedef IHookChain<bool, edict_t *, IGameClient *, int, const char *, float, float, int, int, int, const float *> IRehldsHook_SV_EmitSound2;
191+
typedef IHookChainRegistry<bool, edict_t *, IGameClient *, int, const char *, float, float, int, int, int, const float *> IRehldsHookRegistry_SV_EmitSound2;
192192

193193
//CreateFakeClient hook
194194
typedef IHookChain<edict_t *, const char *> IRehldsHook_CreateFakeClient;
@@ -203,8 +203,8 @@ typedef IVoidHookChain<> IRehldsHook_SV_Frame;
203203
typedef IVoidHookChainRegistry<> IRehldsHookRegistry_SV_Frame;
204204

205205
//SV_ShouldSendConsistencyList hook
206-
typedef IHookChain<bool, IGameClient*, bool> IRehldsHook_SV_ShouldSendConsistencyList;
207-
typedef IHookChainRegistry<bool, IGameClient*, bool> IRehldsHookRegistry_SV_ShouldSendConsistencyList;
206+
typedef IHookChain<bool, IGameClient *, bool> IRehldsHook_SV_ShouldSendConsistencyList;
207+
typedef IHookChainRegistry<bool, IGameClient *, bool> IRehldsHookRegistry_SV_ShouldSendConsistencyList;
208208

209209
//GetEntityInit hook
210210
typedef IHookChain<ENTITYINIT, char *> IRehldsHook_GetEntityInit;
@@ -222,6 +222,10 @@ typedef IHookChainRegistry<edict_t *> IRehldsHookRegistry_ED_Alloc;
222222
typedef IVoidHookChain<edict_t *> IRehldsHook_ED_Free;
223223
typedef IVoidHookChainRegistry<edict_t *> IRehldsHookRegistry_ED_Free;
224224

225+
//Con_Printf hook
226+
typedef IHookChain<void, const char *> IRehldsHook_Con_Printf;
227+
typedef IHookChainRegistry<void, const char *> IRehldsHookRegistry_Con_Printf;
228+
225229
class IRehldsHookchains {
226230
public:
227231
virtual ~IRehldsHookchains() { }
@@ -272,6 +276,7 @@ class IRehldsHookchains {
272276
virtual IRehldsHookRegistry_SV_EmitPings* SV_EmitPings() = 0;
273277
virtual IRehldsHookRegistry_ED_Alloc* ED_Alloc() = 0;
274278
virtual IRehldsHookRegistry_ED_Free* ED_Free() = 0;
279+
virtual IRehldsHookRegistry_Con_Printf* Con_Printf() = 0;
275280
};
276281

277282
struct RehldsFuncs_t {

reapi/src/hook_callback.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ void SV_WriteFullClientUpdate(IRehldsHook_SV_WriteFullClientUpdate *chain, IGame
6363
SV_WriteFullClientUpdate_AMXX(&data, client, (size_t)buffer, receiver);
6464
}
6565

66+
void Con_Printf(IRehldsHook_Con_Printf *chain, const char *string)
67+
{
68+
auto original = [chain](const char *_string)
69+
{
70+
chain->callNext(_string);
71+
};
72+
73+
callVoidForward(RH_Con_Printf, original, string);
74+
}
75+
6676
ENTITYINIT GetEntityInit(IRehldsHook_GetEntityInit *chain, char *classname)
6777
{
6878
auto original = [chain](char *_classname)

reapi/src/hook_callback.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ struct SV_EmitPings_args_t
359359
using SV_EmitPings_t = hookdata_t<IRehldsHook_SV_EmitPings *, SV_EmitPings_args_t &>;
360360
void SV_EmitPings_AMXX(SV_EmitPings_t *data, IGameClient *client);
361361
void SV_EmitPings(IRehldsHook_SV_EmitPings *chain, IGameClient *client, sizebuf_t *msg);
362+
void Con_Printf(IRehldsHook_Con_Printf *chain, const char *string);
362363

363364
edict_t *ED_Alloc(IRehldsHook_ED_Alloc* chain);
364365
void ED_Free(IRehldsHook_ED_Free* chain, edict_t *entity);

reapi/src/hook_list.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ hook_t hooklist_engine[] = {
9393
ENG(SV_EmitPings, _AMXX),
9494
ENG(ED_Alloc),
9595
ENG(ED_Free),
96+
ENG(Con_Printf),
9697
};
9798

9899
#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}

reapi/src/hook_list.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ enum EngineFunc
104104
RH_SV_EmitPings,
105105
RH_ED_Alloc,
106106
RH_ED_Free,
107-
107+
RH_Con_Printf,
108+
108109
// [...]
109110
};
110111

0 commit comments

Comments
 (0)