mirror of
https://github.com/rehlds/reapi.git
synced 2025-03-13 05:50:16 +03:00
parent
cc739f1551
commit
0a03f20f91
@ -275,8 +275,7 @@ CBasePlayer *CBasePlayer_Observer_IsValidTarget(IReGameHook_CBasePlayer_Observer
|
||||
{
|
||||
auto original = [chain](int _pthis, int _iPlayerIndex, bool _bSameTeam)
|
||||
{
|
||||
auto pPlayer = chain->callNext(getPrivate<CBasePlayer>(_pthis), _iPlayerIndex, _bSameTeam);
|
||||
return pPlayer ? indexOfEdict(pPlayer->pev) : 0;
|
||||
return indexOfPDataAmx(chain->callNext(getPrivate<CBasePlayer>(_pthis), _iPlayerIndex, _bSameTeam));
|
||||
};
|
||||
|
||||
return getPrivate<CBasePlayer>(callForward<size_t>(RG_CBasePlayer_Observer_IsValidTarget, original, indexOfEdict(pthis->pev), iPlayerIndex, bSameTeam));
|
||||
@ -526,24 +525,24 @@ void CSGameRules_ClientUserInfoChanged(IReGameHook_CSGameRules_ClientUserInfoCha
|
||||
callVoidForward(RG_CSGameRules_ClientUserInfoChanged, original, indexOfEdict(pPlayer->pev), infobuffer);
|
||||
}
|
||||
|
||||
void CSGameRules_PlayerKilled(IReGameHook_CSGameRules_PlayerKilled *chain, CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor)
|
||||
void CSGameRules_PlayerKilled(IReGameHook_CSGameRules_PlayerKilled *chain, CBasePlayer *pVictim, entvars_t *pevKiller, entvars_t *pevInflictor)
|
||||
{
|
||||
auto original = [chain](int _pVictim, int _pKiller, int _pInflictor)
|
||||
auto original = [chain](int _pVictim, int _pevKiller, int _pevInflictor)
|
||||
{
|
||||
chain->callNext(getPrivate<CBasePlayer>(_pVictim), PEV(_pKiller), PEV(_pInflictor));
|
||||
chain->callNext(getPrivate<CBasePlayer>(_pVictim), PEV(_pevKiller), PEV(_pevInflictor));
|
||||
};
|
||||
|
||||
callVoidForward(RG_CSGameRules_PlayerKilled, original, indexOfEdict(pVictim->pev), indexOfEdict(pKiller), pInflictor ? indexOfEdict(pInflictor) : -1);
|
||||
callVoidForward(RG_CSGameRules_PlayerKilled, original, indexOfEdict(pVictim->pev), indexOfEdict(pevKiller), indexOfEdictAmx(pevInflictor));
|
||||
}
|
||||
|
||||
void CSGameRules_DeathNotice(IReGameHook_CSGameRules_DeathNotice *chain, CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pevInflictor)
|
||||
void CSGameRules_DeathNotice(IReGameHook_CSGameRules_DeathNotice *chain, CBasePlayer *pVictim, entvars_t *pevKiller, entvars_t *pevInflictor)
|
||||
{
|
||||
auto original = [chain](int _pVictim, int _pKiller, int _pevInflictor)
|
||||
auto original = [chain](int _pVictim, int _pevKiller, int _pevInflictor)
|
||||
{
|
||||
chain->callNext(getPrivate<CBasePlayer>(_pVictim), PEV(_pKiller), PEV(_pevInflictor));
|
||||
chain->callNext(getPrivate<CBasePlayer>(_pVictim), PEV(_pevKiller), PEV(_pevInflictor));
|
||||
};
|
||||
|
||||
callVoidForward(RG_CSGameRules_DeathNotice, original, indexOfEdict(pVictim->pev), indexOfEdict(pKiller), pevInflictor ? indexOfEdict(pevInflictor) : -1);
|
||||
callVoidForward(RG_CSGameRules_DeathNotice, original, indexOfEdict(pVictim->pev), indexOfEdict(pevKiller), indexOfEdictAmx(pevInflictor));
|
||||
}
|
||||
|
||||
int CSGameRules_CanHavePlayerItem(IReGameHook_CSGameRules_CanHavePlayerItem *chain, CBasePlayer *pPlayer, CBasePlayerItem *pItem)
|
||||
|
@ -338,8 +338,8 @@ void CSGameRules_PlayerSpawn(IReGameHook_CSGameRules_PlayerSpawn *chain, CBasePl
|
||||
BOOL CSGameRules_FPlayerCanRespawn(IReGameHook_CSGameRules_FPlayerCanRespawn *chain, CBasePlayer *pPlayer);
|
||||
edict_t *CSGameRules_GetPlayerSpawnSpot(IReGameHook_CSGameRules_GetPlayerSpawnSpot *chain, CBasePlayer *pPlayer);
|
||||
void CSGameRules_ClientUserInfoChanged(IReGameHook_CSGameRules_ClientUserInfoChanged *chain, CBasePlayer *pPlayer, char *infobuffer);
|
||||
void CSGameRules_PlayerKilled(IReGameHook_CSGameRules_PlayerKilled *chain, CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor);
|
||||
void CSGameRules_DeathNotice(IReGameHook_CSGameRules_DeathNotice *chain, CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pevInflictor);
|
||||
void CSGameRules_PlayerKilled(IReGameHook_CSGameRules_PlayerKilled *chain, CBasePlayer *pVictim, entvars_t *pevKiller, entvars_t *pevInflictor);
|
||||
void CSGameRules_DeathNotice(IReGameHook_CSGameRules_DeathNotice *chain, CBasePlayer *pVictim, entvars_t *pevKiller, entvars_t *pevInflictor);
|
||||
int CSGameRules_CanHavePlayerItem(IReGameHook_CSGameRules_CanHavePlayerItem *chain, CBasePlayer *pPlayer, CBasePlayerItem *pItem);
|
||||
int CSGameRules_DeadPlayerWeapons(IReGameHook_CSGameRules_DeadPlayerWeapons *chain, CBasePlayer *pPlayer);
|
||||
void CSGameRules_ServerDeactivate(IReGameHook_CSGameRules_ServerDeactivate *chain);
|
||||
|
@ -31,6 +31,11 @@ extern hook_t hooklist_animating[];
|
||||
extern hook_t hooklist_player[];
|
||||
extern hook_t hooklist_gamerules[];
|
||||
|
||||
enum
|
||||
{
|
||||
INVALID_HOOKCHAIN = 0
|
||||
};
|
||||
|
||||
struct hooklist_t
|
||||
{
|
||||
hook_t *operator[](size_t hook) const
|
||||
|
@ -22,13 +22,13 @@ cell AMX_NATIVE_CALL RegisterHookChain(AMX *amx, cell *params)
|
||||
if (unlikely(hook == nullptr))
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "%s: function with id (%d) doesn't exist in current API version.", __FUNCTION__, func);
|
||||
return 0;
|
||||
return INVALID_HOOKCHAIN;
|
||||
}
|
||||
|
||||
if (unlikely(!hook->checkRequirements()))
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "%s: function (%s) is not available, %s required.", __FUNCTION__, hook->func_name, hook->depend_name);
|
||||
return 0;
|
||||
return INVALID_HOOKCHAIN;
|
||||
}
|
||||
|
||||
int funcid;
|
||||
@ -36,14 +36,14 @@ cell AMX_NATIVE_CALL RegisterHookChain(AMX *amx, cell *params)
|
||||
if (unlikely(g_amxxapi.amx_FindPublic(amx, funcname, &funcid) != AMX_ERR_NONE))
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "%s: public function \"%s\" not found.", __FUNCTION__, funcname);
|
||||
return 0;
|
||||
return INVALID_HOOKCHAIN;
|
||||
}
|
||||
|
||||
int fwid = hook->registerForward(amx, funcname);
|
||||
if (unlikely(fwid == -1))
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "%s: register forward failed.", __FUNCTION__);
|
||||
return 0;
|
||||
return INVALID_HOOKCHAIN;
|
||||
}
|
||||
|
||||
return g_hookManager.addHandler(amx, func, fwid, post != 0);
|
||||
|
@ -1,47 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
// C
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h> // for strncpy(), etc
|
||||
|
||||
// C++
|
||||
#include <vector> // std::vector
|
||||
|
||||
// platform defs
|
||||
#include <platform.h>
|
||||
|
||||
// cssdk
|
||||
#include <extdll.h>
|
||||
#include <eiface.h>
|
||||
#include <meta_api.h>
|
||||
|
||||
#include <cbase.h>
|
||||
#include <pm_defs.h>
|
||||
#include <pm_defs.h>
|
||||
#include <pm_movevars.h>
|
||||
#include <com_progdefs.h>
|
||||
#include <gamerules.h>
|
||||
|
||||
#include <osdep.h> // win32 vsnprintf, etc
|
||||
#include <osconfig.h>
|
||||
#include <sdk_util.h>
|
||||
#include <platform.h>
|
||||
// metamod SDK
|
||||
#include <meta_api.h>
|
||||
|
||||
// regamedll API
|
||||
#include "gamerules.h"
|
||||
#include "regamedll_api.h"
|
||||
#include <regamedll_api.h>
|
||||
#include "mod_regamedll_api.h"
|
||||
|
||||
// rehlds API
|
||||
#include "rehlds_api.h"
|
||||
#include <rehlds_api.h>
|
||||
#include "mod_rehlds_api.h"
|
||||
|
||||
// VTC API
|
||||
#include "vtc_api.h"
|
||||
#include <vtc_api.h>
|
||||
#include "mod_vtc_api.h"
|
||||
|
||||
// Reunion API
|
||||
#include "reunion_api.h"
|
||||
#include <reunion_api.h>
|
||||
#include "mod_reunion_api.h"
|
||||
|
||||
// AmxModX API
|
||||
#include "amxxmodule.h"
|
||||
|
||||
// reapi main
|
||||
#include "main.h"
|
||||
#include "reapi_utils.h"
|
||||
#include "api_config.h"
|
||||
@ -49,6 +53,7 @@
|
||||
#include "hook_callback.h"
|
||||
#include "member_list.h"
|
||||
|
||||
// natives
|
||||
#include "natives_hookchains.h"
|
||||
#include "natives_members.h"
|
||||
#include "natives_misc.h"
|
||||
|
@ -6,6 +6,7 @@ char(&ArraySizeHelper(T(&array)[N]))[N];
|
||||
|
||||
#define INDEXENT edictByIndex
|
||||
#define ENTINDEX indexOfEdict
|
||||
#define AMX_NULLENT -1
|
||||
|
||||
extern enginefuncs_t* g_pengfuncsTable;
|
||||
extern DLL_FUNCTIONS *g_pFunctionTable;
|
||||
@ -35,13 +36,13 @@ inline size_t indexOfEdict(entvars_t* pev)
|
||||
return indexOfEdict(pev->pContainingEntity);
|
||||
}
|
||||
|
||||
// safe to index -1
|
||||
inline edict_t* edictByIndexAmx(int index)
|
||||
// safe to nullptr
|
||||
inline size_t indexOfEdictAmx(entvars_t* pev)
|
||||
{
|
||||
auto ed = g_pEdicts + index;
|
||||
if (unlikely(index < 0))
|
||||
ed = nullptr;
|
||||
return ed;
|
||||
size_t index = AMX_NULLENT;
|
||||
if (likely(pev != nullptr))
|
||||
index = indexOfEdict(pev);
|
||||
return index;
|
||||
}
|
||||
|
||||
// fast
|
||||
@ -50,11 +51,20 @@ inline edict_t* edictByIndex(int index)
|
||||
return g_pEdicts + index;
|
||||
}
|
||||
|
||||
// safe to index -1
|
||||
inline edict_t* edictByIndexAmx(int index)
|
||||
{
|
||||
auto ed = g_pEdicts + index;
|
||||
if (unlikely(index < 0)) // == AMX_NULLENT
|
||||
ed = nullptr;
|
||||
return ed;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T* getPrivate(int index)
|
||||
{
|
||||
T* pdata = nullptr;
|
||||
if (likely(index >= 0))
|
||||
if (likely(index >= 0)) // != AMX_NULLENT
|
||||
pdata = (T *)g_pEdicts[index].pvPrivateData;
|
||||
return pdata;
|
||||
}
|
||||
@ -62,11 +72,20 @@ inline T* getPrivate(int index)
|
||||
inline entvars_t* PEV(int index)
|
||||
{
|
||||
entvars_t* pvars = nullptr;
|
||||
if (likely(index >= 0))
|
||||
if (likely(index >= 0)) // != AMX_NULLENT
|
||||
pvars = &g_pEdicts[index].v;
|
||||
return pvars;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline size_t indexOfPDataAmx(T* pdata)
|
||||
{
|
||||
size_t index = AMX_NULLENT;
|
||||
if (likely(pdata != nullptr))
|
||||
index = indexOfEdict(pdata->pev);
|
||||
return index;
|
||||
}
|
||||
|
||||
// HLTypeConversion.h -> AMXModX
|
||||
template <typename T>
|
||||
inline T &ref_member(void *ptr, int offset, int element = 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user