Skip to content

Commit 4e23c65

Browse files
Implement RH_*_Precache_*, RH_SV_AddResource, RH_SV_ClientPrintf & RH_SV_CheckUserInfo hooks (#249)
Co-authored-by: Sergey Shorokhov <[email protected]>
1 parent 2bda2c3 commit 4e23c65

File tree

7 files changed

+214
-4
lines changed

7 files changed

+214
-4
lines changed

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

+68-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ enum MapNameType
1313
MNT_SET // return the name of the current map
1414
};
1515

16+
/*
17+
* For RH_SV_AddResource hook
18+
*/
19+
enum ResourceType_t
20+
{
21+
t_sound = 0,
22+
t_skin,
23+
t_model,
24+
t_decal,
25+
t_generic,
26+
t_eventscript,
27+
t_world, // Fake type for world, is really t_model
28+
rt_unk,
29+
30+
rt_max
31+
};
32+
1633
/**
1734
* rh_emit_sound2 flags
1835
*/
@@ -91,10 +108,60 @@ enum EngineFunc
91108
RH_ED_Free,
92109

93110
/*
94-
* Description: -
111+
* Description: Called when a message is being sent to the server's console.
95112
* Params: (const string[])
96113
*/
97114
RH_Con_Printf,
115+
116+
/*
117+
* Description: Called when a player's userinfo is being checked.
118+
* Params: (adr, userinfo[], bool:reconnect, reconnectSlot, name[])
119+
*
120+
* @note Param adr is unused, guaranteed to return nothing also, don't send anything through it.
121+
* @note In order for param name work, hook needs to be registered as Post.
122+
*/
123+
RH_SV_CheckUserInfo,
124+
125+
/*
126+
* Description: Called when a generic resource is being added to generic precache list.
127+
* Return type: int
128+
* Params: (const string[])
129+
*/
130+
RH_PF_precache_generic_I,
131+
132+
/*
133+
* Description: Called when a model is being added to model precache list.
134+
* Return type: int
135+
* Params: (const string[])
136+
*/
137+
RH_PF_precache_model_I,
138+
139+
/*
140+
* Description: Called when a sound is being added to sound precache list.
141+
* Return type: int
142+
* Params: (const string[])
143+
*/
144+
RH_PF_precache_sound_I,
145+
146+
/*
147+
* Description: Called when an event is being added to event precache list.
148+
* Return type: int
149+
* Params: (const string[])
150+
*/
151+
RH_EV_Precache,
152+
153+
/*
154+
* Description: Called when a resource is being added to resource list.
155+
* Params: (ResourceType_t:type, const filename[], size, flags, index)
156+
*/
157+
RH_SV_AddResource,
158+
159+
/*
160+
* Description: Called when message is being printed to client console.
161+
* Params: (const string[])
162+
*/
163+
RH_SV_ClientPrintf,
164+
98165
};
99166

100167
/**

reapi/include/cssdk/engine/rehlds_api.h

+36-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "pr_dlls.h"
3737

3838
#define REHLDS_API_VERSION_MAJOR 3
39-
#define REHLDS_API_VERSION_MINOR 11
39+
#define REHLDS_API_VERSION_MINOR 12
4040

4141
//Steam_NotifyClientConnect hook
4242
typedef IHookChain<qboolean, IGameClient*, const void*, unsigned int> IRehldsHook_Steam_NotifyClientConnect;
@@ -226,6 +226,34 @@ typedef IVoidHookChainRegistry<edict_t *> IRehldsHookRegistry_ED_Free;
226226
typedef IHookChain<void, const char *> IRehldsHook_Con_Printf;
227227
typedef IHookChainRegistry<void, const char *> IRehldsHookRegistry_Con_Printf;
228228

229+
//SV_CheckUserInfo hook
230+
typedef IHookChain<int, netadr_t*, char*, qboolean, int, char*> IRehldsHook_SV_CheckUserInfo;
231+
typedef IHookChainRegistry<int, netadr_t*, char*, qboolean, int, char*> IRehldsHookRegistry_SV_CheckUserInfo;
232+
233+
//PF_precache_generic_I hook
234+
typedef IHookChain<int, const char*> IRehldsHook_PF_precache_generic_I;
235+
typedef IHookChainRegistry<int, const char*> IRehldsHookRegistry_PF_precache_generic_I;
236+
237+
//PF_precache_model_I hook
238+
typedef IHookChain<int, char*> IRehldsHook_PF_precache_model_I;
239+
typedef IHookChainRegistry<int, char*> IRehldsHookRegistry_PF_precache_model_I;
240+
241+
//PF_precache_sound_I hook
242+
typedef IHookChain<int, const char*> IRehldsHook_PF_precache_sound_I;
243+
typedef IHookChainRegistry<int, const char*> IRehldsHookRegistry_PF_precache_sound_I;
244+
245+
//EV_Precache hook
246+
typedef IHookChain<unsigned short, int, const char *> IRehldsHook_EV_Precache;
247+
typedef IHookChainRegistry<unsigned short, int, const char *> IRehldsHookRegistry_EV_Precache;
248+
249+
//SV_AddResource hook
250+
typedef IVoidHookChain<resourcetype_t, const char *, int, unsigned char, int> IRehldsHook_SV_AddResource;
251+
typedef IVoidHookChainRegistry<resourcetype_t, const char *, int, unsigned char, int> IRehldsHookRegistry_SV_AddResource;
252+
253+
//SV_ClientPrintf hook
254+
typedef IVoidHookChain<const char *> IRehldsHook_SV_ClientPrintf;
255+
typedef IVoidHookChainRegistry<const char *> IRehldsHookRegistry_SV_ClientPrintf;
256+
229257
class IRehldsHookchains {
230258
public:
231259
virtual ~IRehldsHookchains() { }
@@ -277,6 +305,13 @@ class IRehldsHookchains {
277305
virtual IRehldsHookRegistry_ED_Alloc* ED_Alloc() = 0;
278306
virtual IRehldsHookRegistry_ED_Free* ED_Free() = 0;
279307
virtual IRehldsHookRegistry_Con_Printf* Con_Printf() = 0;
308+
virtual IRehldsHookRegistry_SV_CheckUserInfo* SV_CheckUserInfo() = 0;
309+
virtual IRehldsHookRegistry_PF_precache_generic_I* PF_precache_generic_I() = 0;
310+
virtual IRehldsHookRegistry_PF_precache_model_I* PF_precache_model_I() = 0;
311+
virtual IRehldsHookRegistry_PF_precache_sound_I* PF_precache_sound_I() = 0;
312+
virtual IRehldsHookRegistry_EV_Precache* EV_Precache() = 0;
313+
virtual IRehldsHookRegistry_SV_AddResource* SV_AddResource() = 0;
314+
virtual IRehldsHookRegistry_SV_ClientPrintf* SV_ClientPrintf() = 0;
280315
};
281316

282317
struct RehldsFuncs_t {

reapi/src/hook_callback.cpp

+77-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ void SV_EmitPings_AMXX(SV_EmitPings_t* data, IGameClient* cl)
115115

116116
void SV_EmitPings(IRehldsHook_SV_EmitPings *chain, IGameClient *cl, sizebuf_t *msg)
117117
{
118-
119118
SV_EmitPings_args_t args(cl, msg);
120119
SV_EmitPings_t data(chain, args);
121120
SV_EmitPings_AMXX(&data, cl);
@@ -141,6 +140,83 @@ void ED_Free(IRehldsHook_ED_Free* chain, edict_t *entity)
141140
callVoidForward(RH_ED_Free, original, indexOfEdict(entity));
142141
}
143142

143+
int SV_CheckUserInfo(IRehldsHook_SV_CheckUserInfo *chain, netadr_t *adr, char *userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name)
144+
{
145+
auto original = [chain](netadr_t *_adr, char *_userinfo, qboolean _bIsReconnecting, int _iReconnectSlot, char *_name)
146+
{
147+
return chain->callNext(_adr, _userinfo, _bIsReconnecting, _iReconnectSlot, _name);
148+
};
149+
150+
return callForward<int>(RH_SV_CheckUserInfo, original, adr, userinfo, bIsReconnecting, iReconnectSlot, name);
151+
}
152+
153+
int PF_precache_generic_I(IRehldsHook_PF_precache_generic_I *chain, const char *s)
154+
{
155+
auto original = [chain](const char *_s)
156+
{
157+
return chain->callNext(_s);
158+
};
159+
160+
return callForward<int>(RH_PF_precache_generic_I, original, s);
161+
}
162+
163+
int PF_precache_model_I(IRehldsHook_PF_precache_model_I *chain, char *s)
164+
{
165+
auto original = [chain](char *_s)
166+
{
167+
return chain->callNext(_s);
168+
};
169+
170+
return callForward<int>(RH_PF_precache_model_I, original, s);
171+
}
172+
173+
int PF_precache_sound_I(IRehldsHook_PF_precache_sound_I *chain, const char *s)
174+
{
175+
auto original = [chain](const char *_s)
176+
{
177+
return chain->callNext(_s);
178+
};
179+
180+
return callForward<int>(RH_PF_precache_sound_I, original, s);
181+
}
182+
183+
unsigned short EV_Precache_AMXX(EventPrecache_t *data, const char *psz)
184+
{
185+
auto original = [data](const char *_psz)
186+
{
187+
return data->m_chain->callNext(data->m_args.type, _psz);
188+
};
189+
190+
return callForward<unsigned short>(RH_EV_Precache, original, psz);
191+
}
192+
193+
unsigned short EV_Precache(IRehldsHook_EV_Precache *chain, int type, const char *psz)
194+
{
195+
EventPrecache_args_t args(type);
196+
EventPrecache_t data(chain, args);
197+
return EV_Precache_AMXX(&data, psz);
198+
}
199+
200+
void SV_AddResource(IRehldsHook_SV_AddResource *chain, resourcetype_t type, const char *name, int size, unsigned char flags, int index)
201+
{
202+
auto original = [chain](resourcetype_t _type, const char *_name, int _size, unsigned char _flags, int _index)
203+
{
204+
chain->callNext(_type, _name, _size, _flags, _index);
205+
};
206+
207+
callVoidForward(RH_SV_AddResource, original, type, name, size, flags, index);
208+
}
209+
210+
void SV_ClientPrintf(IRehldsHook_SV_ClientPrintf *chain, const char *string)
211+
{
212+
auto original = [chain](const char *_string)
213+
{
214+
chain->callNext(_string);
215+
};
216+
217+
callVoidForward(RH_SV_ClientPrintf, original, string);
218+
}
219+
144220
/*
145221
* ReGameDLL functions
146222
*/

reapi/src/hook_callback.h

+15
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ void SV_ActivateServer(IRehldsHook_SV_ActivateServer *chain, int runPhysics);
334334
void Cvar_DirectSet(IRehldsHook_Cvar_DirectSet *chain, cvar_t *var, const char *value);
335335
void ClientConnected(IRehldsHook_ClientConnected* chain, IGameClient* cl);
336336
void SV_ConnectClient(IRehldsHook_SV_ConnectClient* chain);
337+
int SV_CheckUserInfo(IRehldsHook_SV_CheckUserInfo* chain, netadr_t *adr, char *userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name);
337338

338339
struct SV_WriteFullClientUpdate_args_t
339340
{
@@ -360,9 +361,23 @@ using SV_EmitPings_t = hookdata_t<IRehldsHook_SV_EmitPings *, SV_EmitPings_args_
360361
void SV_EmitPings_AMXX(SV_EmitPings_t *data, IGameClient *client);
361362
void SV_EmitPings(IRehldsHook_SV_EmitPings *chain, IGameClient *client, sizebuf_t *msg);
362363
void Con_Printf(IRehldsHook_Con_Printf *chain, const char *string);
364+
int PF_precache_generic_I(IRehldsHook_PF_precache_generic_I *chain, const char *s);
365+
int PF_precache_model_I(IRehldsHook_PF_precache_model_I *chain, char *s);
366+
int PF_precache_sound_I(IRehldsHook_PF_precache_sound_I *chain, const char *s);
363367

368+
struct EventPrecache_args_t
369+
{
370+
EventPrecache_args_t(int _type) : type(_type) {}
371+
int type;
372+
};
373+
374+
using EventPrecache_t = hookdata_t<IRehldsHook_EV_Precache *, EventPrecache_args_t &>;
375+
unsigned short EV_Precache_AMXX(EventPrecache_t *data, const char *psz);
376+
unsigned short EV_Precache(IRehldsHook_EV_Precache *chain, int type, const char *psz);
377+
void SV_AddResource(IRehldsHook_SV_AddResource *chain, resourcetype_t type, const char *name, int size, unsigned char flags, int index);
364378
edict_t *ED_Alloc(IRehldsHook_ED_Alloc* chain);
365379
void ED_Free(IRehldsHook_ED_Free* chain, edict_t *entity);
380+
void SV_ClientPrintf(IRehldsHook_SV_ClientPrintf* chain, const char *string);
366381

367382
// regamedll functions
368383
int GetForceCamera(IReGameHook_GetForceCamera *chain, CBasePlayer *pObserver);

reapi/src/hook_list.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ inline size_t getFwdParamType(void(*)(float&)) { return FP_FLOA
2020
inline size_t getFwdParamType(void(*)(const char *)) { return FP_STRING; }
2121
inline size_t getFwdParamType(void(*)(char *)) { return FP_STRING; }
2222
inline size_t getFwdParamType(void(*)(IResourceBuffer*)) { return FP_CELL; }
23+
inline size_t getFwdParamType(void(*)(unsigned char)) { return FP_CELL; }
24+
inline size_t getFwdParamType(void(*)(resourcetype_t)) { return FP_CELL; }
2325

2426
template <typename T>
2527
inline size_t getFwdParamType(void(*)(T *)) { return FP_CELL; }
@@ -94,6 +96,14 @@ hook_t hooklist_engine[] = {
9496
ENG(ED_Alloc),
9597
ENG(ED_Free),
9698
ENG(Con_Printf),
99+
ENG(SV_CheckUserInfo),
100+
ENG(PF_precache_generic_I),
101+
ENG(PF_precache_model_I),
102+
ENG(PF_precache_sound_I),
103+
ENG(EV_Precache, _AMXX),
104+
ENG(SV_AddResource),
105+
ENG(SV_ClientPrintf),
106+
97107
};
98108

99109
#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

+7
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ enum EngineFunc
105105
RH_ED_Alloc,
106106
RH_ED_Free,
107107
RH_Con_Printf,
108+
RH_SV_CheckUserInfo,
109+
RH_PF_precache_generic_I,
110+
RH_PF_precache_model_I,
111+
RH_PF_precache_sound_I,
112+
RH_EV_Precache,
113+
RH_SV_AddResource,
114+
RH_SV_ClientPrintf,
108115

109116
// [...]
110117
};

reapi/version/version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
#pragma once
77

88
#define VERSION_MAJOR 5
9-
#define VERSION_MINOR 21
9+
#define VERSION_MINOR 22
1010
#define VERSION_MAINTENANCE 0

0 commit comments

Comments
 (0)