Skip to content

Commit

Permalink
Implement RH_SV_AllowPhysent hook (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
justgo97 committed Feb 11, 2023
1 parent 7d9bd65 commit aeabd1f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc
Expand Up @@ -162,6 +162,13 @@ enum EngineFunc
*/
RH_SV_ClientPrintf,

/*
* Description: Called before adding an entity to the physents of a player.
* Return type: bool
* Params: (const entity, const client)
*/
RH_SV_AllowPhysent,

};

/**
Expand Down
7 changes: 6 additions & 1 deletion reapi/include/cssdk/engine/rehlds_api.h
Expand Up @@ -36,7 +36,7 @@
#include "pr_dlls.h"

#define REHLDS_API_VERSION_MAJOR 3
#define REHLDS_API_VERSION_MINOR 12
#define REHLDS_API_VERSION_MINOR 13

//Steam_NotifyClientConnect hook
typedef IHookChain<qboolean, IGameClient*, const void*, unsigned int> IRehldsHook_Steam_NotifyClientConnect;
Expand Down Expand Up @@ -254,6 +254,10 @@ typedef IVoidHookChainRegistry<resourcetype_t, const char *, int, unsigned char,
typedef IVoidHookChain<const char *> IRehldsHook_SV_ClientPrintf;
typedef IVoidHookChainRegistry<const char *> IRehldsHookRegistry_SV_ClientPrintf;

//SV_AllowPhysent hook
typedef IHookChain<bool, edict_t*, edict_t*> IRehldsHook_SV_AllowPhysent;
typedef IHookChainRegistry<bool, edict_t*, edict_t*> IRehldsHookRegistry_SV_AllowPhysent;

class IRehldsHookchains {
public:
virtual ~IRehldsHookchains() { }
Expand Down Expand Up @@ -312,6 +316,7 @@ class IRehldsHookchains {
virtual IRehldsHookRegistry_EV_Precache* EV_Precache() = 0;
virtual IRehldsHookRegistry_SV_AddResource* SV_AddResource() = 0;
virtual IRehldsHookRegistry_SV_ClientPrintf* SV_ClientPrintf() = 0;
virtual IRehldsHookRegistry_SV_AllowPhysent* SV_AllowPhysent() = 0;
};

struct RehldsFuncs_t {
Expand Down
10 changes: 10 additions & 0 deletions reapi/src/hook_callback.cpp
Expand Up @@ -140,6 +140,16 @@ void ED_Free(IRehldsHook_ED_Free* chain, edict_t *entity)
callVoidForward(RH_ED_Free, original, indexOfEdict(entity));
}

bool SV_AllowPhysent(IRehldsHook_SV_AllowPhysent* chain, edict_t* check, edict_t* sv_player)
{
auto original = [chain](int _check, int _sv_player)
{
return chain->callNext(edictByIndexAmx(_check), edictByIndexAmx(_sv_player));
};

return callForward<bool>(RH_SV_AllowPhysent, original, indexOfEdict(check), indexOfEdict(sv_player));
}

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)
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_callback.h
Expand Up @@ -378,6 +378,7 @@ void SV_AddResource(IRehldsHook_SV_AddResource *chain, resourcetype_t type, cons
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);
bool SV_AllowPhysent(IRehldsHook_SV_AllowPhysent* chain, edict_t* check, edict_t* sv_player);

// regamedll functions
int GetForceCamera(IReGameHook_GetForceCamera *chain, CBasePlayer *pObserver);
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_list.cpp
Expand Up @@ -103,6 +103,7 @@ hook_t hooklist_engine[] = {
ENG(EV_Precache, _AMXX),
ENG(SV_AddResource),
ENG(SV_ClientPrintf),
ENG(SV_AllowPhysent),

};

Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_list.h
Expand Up @@ -112,6 +112,7 @@ enum EngineFunc
RH_EV_Precache,
RH_SV_AddResource,
RH_SV_ClientPrintf,
RH_SV_AllowPhysent,

// [...]
};
Expand Down
2 changes: 1 addition & 1 deletion reapi/version/version.h
Expand Up @@ -6,5 +6,5 @@
#pragma once

#define VERSION_MAJOR 5
#define VERSION_MINOR 22
#define VERSION_MINOR 23
#define VERSION_MAINTENANCE 0

0 comments on commit aeabd1f

Please sign in to comment.