Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RH_SV_SendResources hook #308

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ enum EngineFunc

/*
* Description: Called when client it's in the scoreboard
* Params: (const this)
* Params: (const client)
*/
RH_SV_EmitPings,

/*
* Description: Called when an entity is created.
* Return type: Edict * (Entity index)
Expand Down Expand Up @@ -184,6 +185,12 @@ enum EngineFunc
*/
RH_ExecuteServerStringCmd,

/*
* Description: Called when server sends resources list and location.
* Params: (const client)
*/
RH_SV_SendResources,

};

/**
Expand Down
5 changes: 5 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,10 @@ 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;

//SV_SendResources hook
typedef IVoidHookChain<sizebuf_t *> IRehldsHook_SV_SendResources;
typedef IVoidHookChainRegistry<sizebuf_t *> IRehldsHookRegistry_SV_SendResources;

class IRehldsHookchains {
public:
virtual ~IRehldsHookchains() { }
Expand Down Expand Up @@ -317,6 +321,7 @@ 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_SV_SendResources* SV_SendResources() = 0;
};

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

void SV_SendResources_AMXX(SV_SendResources_t *data, IGameClient *cl)
{
auto original = [data](int _cl)
{
data->m_chain->callNext(data->m_args);
};

callVoidForward(RH_SV_SendResources, original, cl ? cl->GetId() + 1 : AMX_NULLENT);
}

void SV_SendResources(IRehldsHook_SV_SendResources *chain, sizebuf_t *msg)
{
SV_SendResources_t data(chain, msg);
SV_SendResources_AMXX(&data, g_RehldsFuncs->GetHostClient());
}

/*
* ReGameDLL functions
*/
Expand Down
4 changes: 4 additions & 0 deletions reapi/src/hook_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ int PF_precache_generic_I(IRehldsHook_PF_precache_generic_I *chain, const char *
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);

using SV_SendResources_t = hookdata_t<IRehldsHook_SV_SendResources *, sizebuf_t *>;
void SV_SendResources_AMXX(SV_SendResources_t *data, IGameClient *cl);
void SV_SendResources(IRehldsHook_SV_SendResources *chain, sizebuf_t *msg);

struct EventPrecache_args_t
{
EventPrecache_args_t(int _type) : type(_type) {}
Expand Down
2 changes: 1 addition & 1 deletion reapi/src/hook_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ hook_t hooklist_engine[] = {
ENG(SV_ClientPrintf),
ENG(SV_AllowPhysent),
ENG(ExecuteServerStringCmd),

ENG(SV_SendResources, _AMXX),
};

#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
1 change: 1 addition & 0 deletions reapi/src/hook_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ enum EngineFunc
RH_SV_ClientPrintf,
RH_SV_AllowPhysent,
RH_ExecuteServerStringCmd,
RH_SV_SendResources,

// [...]
};
Expand Down
Loading