Skip to content

Commit

Permalink
Do not pass sizebuf_t to AMXX callback
Browse files Browse the repository at this point in the history
Pass client index to AMXX callback
Minor cleanup
  • Loading branch information
s1lentq committed May 13, 2024
1 parent 69b223c commit 065ad6a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
7 changes: 4 additions & 3 deletions 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 @@ -183,10 +184,10 @@ enum EngineFunc
* Params: (const cmd[], source, id)
*/
RH_ExecuteServerStringCmd,

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

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

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

callVoidForward(RH_SV_SendResources, original, msg);
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());
}

/*
Expand Down
3 changes: 3 additions & 0 deletions reapi/src/hook_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ 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);

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
Expand Down
3 changes: 1 addition & 2 deletions reapi/src/hook_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ hook_t hooklist_engine[] = {
ENG(SV_ClientPrintf),
ENG(SV_AllowPhysent),
ENG(ExecuteServerStringCmd),
ENG(SV_SendResources),

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

0 comments on commit 065ad6a

Please sign in to comment.