2
0
mirror of https://github.com/rehlds/reapi.git synced 2024-12-29 08:05:36 +03:00

API: Add hooks ED_Alloc() and ED_Free() (#227)

Co-authored-by: Sergey Shorokhov <wopox1337@ya.ru>
This commit is contained in:
DarthMan 2021-10-24 15:27:57 +03:00 committed by GitHub
parent 81ced333ae
commit 866295f111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 4 deletions

View File

@ -76,7 +76,20 @@ enum EngineFunc
* Description: Called when client it's in the scoreboard
* Params: (const this)
*/
RH_SV_EmitPings
RH_SV_EmitPings,
/*
* Description: Called when an entity is created.
* Return type: Edict * (Entity index)
* Params: ()
*/
RH_ED_Alloc,
/*
* Description: Called when an entity is removed (freed from server).
* Params: (const entity)
*/
RH_ED_Free,
};
/**

View File

@ -111,6 +111,26 @@ void SV_EmitPings(IRehldsHook_SV_EmitPings *chain, IGameClient *cl, sizebuf_t *m
SV_EmitPings_AMXX(&data, cl);
}
edict_t *ED_Alloc(IRehldsHook_ED_Alloc* chain)
{
auto original = [chain]()
{
return indexOfEdict(chain->callNext());
};
return edictByIndexAmx(callForward<size_t>(RH_ED_Alloc, original));
}
void ED_Free(IRehldsHook_ED_Free* chain, edict_t *entity)
{
auto original = [chain](int _entity)
{
chain->callNext(edictByIndexAmx(_entity));
};
callVoidForward(RH_ED_Free, original, indexOfEdict(entity));
}
/*
* ReGameDLL functions
*/

View File

@ -360,6 +360,9 @@ 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);
edict_t *ED_Alloc(IRehldsHook_ED_Alloc* chain);
void ED_Free(IRehldsHook_ED_Free* chain, edict_t *entity);
// regamedll functions
int GetForceCamera(IReGameHook_GetForceCamera *chain, CBasePlayer *pObserver);
void PlayerBlind(IReGameHook_PlayerBlind *chain, CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAttacker, float fadeTime, float fadeHold, int alpha, Vector& color);

View File

@ -90,7 +90,9 @@ hook_t hooklist_engine[] = {
ENG(GetEntityInit),
ENG(ClientConnected),
ENG(SV_ConnectClient),
ENG(SV_EmitPings, _AMXX)
ENG(SV_EmitPings, _AMXX),
ENG(ED_Alloc),
ENG(ED_Free),
};
#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

@ -101,7 +101,9 @@ enum EngineFunc
RH_GetEntityInit,
RH_ClientConnected,
RH_SV_ConnectClient,
RH_SV_EmitPings
RH_SV_EmitPings,
RH_ED_Alloc,
RH_ED_Free,
// [...]
};