2
0
mirror of https://github.com/rehlds/reapi.git synced 2024-12-28 07:35:31 +03:00

Implement RH_*_Precache_*, RH_SV_AddResource, RH_SV_ClientPrintf & RH_SV_CheckUserInfo hooks (#249)

Co-authored-by: Sergey Shorokhov <wopox1337@ya.ru>
This commit is contained in:
Adrian Cirstea 2022-09-19 19:08:46 +03:00 committed by GitHub
parent 2bda2c303c
commit 4e23c6573b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 214 additions and 4 deletions

View File

@ -13,6 +13,23 @@ enum MapNameType
MNT_SET // return the name of the current map
};
/*
* For RH_SV_AddResource hook
*/
enum ResourceType_t
{
t_sound = 0,
t_skin,
t_model,
t_decal,
t_generic,
t_eventscript,
t_world, // Fake type for world, is really t_model
rt_unk,
rt_max
};
/**
* rh_emit_sound2 flags
*/
@ -91,10 +108,60 @@ enum EngineFunc
RH_ED_Free,
/*
* Description: -
* Description: Called when a message is being sent to the server's console.
* Params: (const string[])
*/
RH_Con_Printf,
/*
* Description: Called when a player's userinfo is being checked.
* Params: (adr, userinfo[], bool:reconnect, reconnectSlot, name[])
*
* @note Param adr is unused, guaranteed to return nothing also, don't send anything through it.
* @note In order for param name work, hook needs to be registered as Post.
*/
RH_SV_CheckUserInfo,
/*
* Description: Called when a generic resource is being added to generic precache list.
* Return type: int
* Params: (const string[])
*/
RH_PF_precache_generic_I,
/*
* Description: Called when a model is being added to model precache list.
* Return type: int
* Params: (const string[])
*/
RH_PF_precache_model_I,
/*
* Description: Called when a sound is being added to sound precache list.
* Return type: int
* Params: (const string[])
*/
RH_PF_precache_sound_I,
/*
* Description: Called when an event is being added to event precache list.
* Return type: int
* Params: (const string[])
*/
RH_EV_Precache,
/*
* Description: Called when a resource is being added to resource list.
* Params: (ResourceType_t:type, const filename[], size, flags, index)
*/
RH_SV_AddResource,
/*
* Description: Called when message is being printed to client console.
* Params: (const string[])
*/
RH_SV_ClientPrintf,
};
/**

View File

@ -36,7 +36,7 @@
#include "pr_dlls.h"
#define REHLDS_API_VERSION_MAJOR 3
#define REHLDS_API_VERSION_MINOR 11
#define REHLDS_API_VERSION_MINOR 12
//Steam_NotifyClientConnect hook
typedef IHookChain<qboolean, IGameClient*, const void*, unsigned int> IRehldsHook_Steam_NotifyClientConnect;
@ -226,6 +226,34 @@ typedef IVoidHookChainRegistry<edict_t *> IRehldsHookRegistry_ED_Free;
typedef IHookChain<void, const char *> IRehldsHook_Con_Printf;
typedef IHookChainRegistry<void, const char *> IRehldsHookRegistry_Con_Printf;
//SV_CheckUserInfo hook
typedef IHookChain<int, netadr_t*, char*, qboolean, int, char*> IRehldsHook_SV_CheckUserInfo;
typedef IHookChainRegistry<int, netadr_t*, char*, qboolean, int, char*> IRehldsHookRegistry_SV_CheckUserInfo;
//PF_precache_generic_I hook
typedef IHookChain<int, const char*> IRehldsHook_PF_precache_generic_I;
typedef IHookChainRegistry<int, const char*> IRehldsHookRegistry_PF_precache_generic_I;
//PF_precache_model_I hook
typedef IHookChain<int, char*> IRehldsHook_PF_precache_model_I;
typedef IHookChainRegistry<int, char*> IRehldsHookRegistry_PF_precache_model_I;
//PF_precache_sound_I hook
typedef IHookChain<int, const char*> IRehldsHook_PF_precache_sound_I;
typedef IHookChainRegistry<int, const char*> IRehldsHookRegistry_PF_precache_sound_I;
//EV_Precache hook
typedef IHookChain<unsigned short, int, const char *> IRehldsHook_EV_Precache;
typedef IHookChainRegistry<unsigned short, int, const char *> IRehldsHookRegistry_EV_Precache;
//SV_AddResource hook
typedef IVoidHookChain<resourcetype_t, const char *, int, unsigned char, int> IRehldsHook_SV_AddResource;
typedef IVoidHookChainRegistry<resourcetype_t, const char *, int, unsigned char, int> IRehldsHookRegistry_SV_AddResource;
//SV_ClientPrintf hook
typedef IVoidHookChain<const char *> IRehldsHook_SV_ClientPrintf;
typedef IVoidHookChainRegistry<const char *> IRehldsHookRegistry_SV_ClientPrintf;
class IRehldsHookchains {
public:
virtual ~IRehldsHookchains() { }
@ -277,6 +305,13 @@ public:
virtual IRehldsHookRegistry_ED_Alloc* ED_Alloc() = 0;
virtual IRehldsHookRegistry_ED_Free* ED_Free() = 0;
virtual IRehldsHookRegistry_Con_Printf* Con_Printf() = 0;
virtual IRehldsHookRegistry_SV_CheckUserInfo* SV_CheckUserInfo() = 0;
virtual IRehldsHookRegistry_PF_precache_generic_I* PF_precache_generic_I() = 0;
virtual IRehldsHookRegistry_PF_precache_model_I* PF_precache_model_I() = 0;
virtual IRehldsHookRegistry_PF_precache_sound_I* PF_precache_sound_I() = 0;
virtual IRehldsHookRegistry_EV_Precache* EV_Precache() = 0;
virtual IRehldsHookRegistry_SV_AddResource* SV_AddResource() = 0;
virtual IRehldsHookRegistry_SV_ClientPrintf* SV_ClientPrintf() = 0;
};
struct RehldsFuncs_t {

View File

@ -115,7 +115,6 @@ void SV_EmitPings_AMXX(SV_EmitPings_t* data, IGameClient* cl)
void SV_EmitPings(IRehldsHook_SV_EmitPings *chain, IGameClient *cl, sizebuf_t *msg)
{
SV_EmitPings_args_t args(cl, msg);
SV_EmitPings_t data(chain, args);
SV_EmitPings_AMXX(&data, cl);
@ -141,6 +140,83 @@ void ED_Free(IRehldsHook_ED_Free* chain, edict_t *entity)
callVoidForward(RH_ED_Free, original, indexOfEdict(entity));
}
int SV_CheckUserInfo(IRehldsHook_SV_CheckUserInfo *chain, netadr_t *adr, char *userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name)
{
auto original = [chain](netadr_t *_adr, char *_userinfo, qboolean _bIsReconnecting, int _iReconnectSlot, char *_name)
{
return chain->callNext(_adr, _userinfo, _bIsReconnecting, _iReconnectSlot, _name);
};
return callForward<int>(RH_SV_CheckUserInfo, original, adr, userinfo, bIsReconnecting, iReconnectSlot, name);
}
int PF_precache_generic_I(IRehldsHook_PF_precache_generic_I *chain, const char *s)
{
auto original = [chain](const char *_s)
{
return chain->callNext(_s);
};
return callForward<int>(RH_PF_precache_generic_I, original, s);
}
int PF_precache_model_I(IRehldsHook_PF_precache_model_I *chain, char *s)
{
auto original = [chain](char *_s)
{
return chain->callNext(_s);
};
return callForward<int>(RH_PF_precache_model_I, original, s);
}
int PF_precache_sound_I(IRehldsHook_PF_precache_sound_I *chain, const char *s)
{
auto original = [chain](const char *_s)
{
return chain->callNext(_s);
};
return callForward<int>(RH_PF_precache_sound_I, original, s);
}
unsigned short EV_Precache_AMXX(EventPrecache_t *data, const char *psz)
{
auto original = [data](const char *_psz)
{
return data->m_chain->callNext(data->m_args.type, _psz);
};
return callForward<unsigned short>(RH_EV_Precache, original, psz);
}
unsigned short EV_Precache(IRehldsHook_EV_Precache *chain, int type, const char *psz)
{
EventPrecache_args_t args(type);
EventPrecache_t data(chain, args);
return EV_Precache_AMXX(&data, psz);
}
void SV_AddResource(IRehldsHook_SV_AddResource *chain, resourcetype_t type, const char *name, int size, unsigned char flags, int index)
{
auto original = [chain](resourcetype_t _type, const char *_name, int _size, unsigned char _flags, int _index)
{
chain->callNext(_type, _name, _size, _flags, _index);
};
callVoidForward(RH_SV_AddResource, original, type, name, size, flags, index);
}
void SV_ClientPrintf(IRehldsHook_SV_ClientPrintf *chain, const char *string)
{
auto original = [chain](const char *_string)
{
chain->callNext(_string);
};
callVoidForward(RH_SV_ClientPrintf, original, string);
}
/*
* ReGameDLL functions
*/

View File

@ -334,6 +334,7 @@ void SV_ActivateServer(IRehldsHook_SV_ActivateServer *chain, int runPhysics);
void Cvar_DirectSet(IRehldsHook_Cvar_DirectSet *chain, cvar_t *var, const char *value);
void ClientConnected(IRehldsHook_ClientConnected* chain, IGameClient* cl);
void SV_ConnectClient(IRehldsHook_SV_ConnectClient* chain);
int SV_CheckUserInfo(IRehldsHook_SV_CheckUserInfo* chain, netadr_t *adr, char *userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name);
struct SV_WriteFullClientUpdate_args_t
{
@ -360,9 +361,23 @@ using SV_EmitPings_t = hookdata_t<IRehldsHook_SV_EmitPings *, SV_EmitPings_args_
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);
int PF_precache_generic_I(IRehldsHook_PF_precache_generic_I *chain, const char *s);
int PF_precache_model_I(IRehldsHook_PF_precache_model_I *chain, char *s);
int PF_precache_sound_I(IRehldsHook_PF_precache_sound_I *chain, const char *s);
struct EventPrecache_args_t
{
EventPrecache_args_t(int _type) : type(_type) {}
int type;
};
using EventPrecache_t = hookdata_t<IRehldsHook_EV_Precache *, EventPrecache_args_t &>;
unsigned short EV_Precache_AMXX(EventPrecache_t *data, const char *psz);
unsigned short EV_Precache(IRehldsHook_EV_Precache *chain, int type, const char *psz);
void SV_AddResource(IRehldsHook_SV_AddResource *chain, resourcetype_t type, const char *name, int size, unsigned char flags, int index);
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);
// regamedll functions
int GetForceCamera(IReGameHook_GetForceCamera *chain, CBasePlayer *pObserver);

View File

@ -20,6 +20,8 @@ inline size_t getFwdParamType(void(*)(float&)) { return FP_FLOA
inline size_t getFwdParamType(void(*)(const char *)) { return FP_STRING; }
inline size_t getFwdParamType(void(*)(char *)) { return FP_STRING; }
inline size_t getFwdParamType(void(*)(IResourceBuffer*)) { return FP_CELL; }
inline size_t getFwdParamType(void(*)(unsigned char)) { return FP_CELL; }
inline size_t getFwdParamType(void(*)(resourcetype_t)) { return FP_CELL; }
template <typename T>
inline size_t getFwdParamType(void(*)(T *)) { return FP_CELL; }
@ -94,6 +96,14 @@ hook_t hooklist_engine[] = {
ENG(ED_Alloc),
ENG(ED_Free),
ENG(Con_Printf),
ENG(SV_CheckUserInfo),
ENG(PF_precache_generic_I),
ENG(PF_precache_model_I),
ENG(PF_precache_sound_I),
ENG(EV_Precache, _AMXX),
ENG(SV_AddResource),
ENG(SV_ClientPrintf),
};
#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}

View File

@ -105,6 +105,13 @@ enum EngineFunc
RH_ED_Alloc,
RH_ED_Free,
RH_Con_Printf,
RH_SV_CheckUserInfo,
RH_PF_precache_generic_I,
RH_PF_precache_model_I,
RH_PF_precache_sound_I,
RH_EV_Precache,
RH_SV_AddResource,
RH_SV_ClientPrintf,
// [...]
};

View File

@ -6,5 +6,5 @@
#pragma once
#define VERSION_MAJOR 5
#define VERSION_MINOR 21
#define VERSION_MINOR 22
#define VERSION_MAINTENANCE 0