Add option to not bypass hooks with TakeDamage and DropWeapon natives.
This commit is contained in:
committed by
Nicholas Hastings
parent
4a6d263dad
commit
97383028e5
@@ -33,6 +33,10 @@
|
||||
#include "extension.h"
|
||||
#include "natives.h"
|
||||
#include <compat_wrappers.h>
|
||||
#include <IBinTools.h>
|
||||
#include <sm_argbuffer.h>
|
||||
|
||||
using namespace SourceMod;
|
||||
|
||||
SH_DECL_MANUALEXTERN1(OnTakeDamage, int, CTakeDamageInfoHack &);
|
||||
SH_DECL_MANUALEXTERN3_void(Weapon_Drop, CBaseCombatWeapon *, const Vector *, const Vector *);
|
||||
@@ -170,7 +174,44 @@ cell_t Native_TakeDamage(IPluginContext *pContext, const cell_t *params)
|
||||
}
|
||||
|
||||
CTakeDamageInfoHack info(pInflictor, pAttacker, flDamage, iDamageType, pWeapon, vecDamageForce, vecDamagePosition);
|
||||
SH_MCALL(pVictim, OnTakeDamage)((CTakeDamageInfoHack &)info);
|
||||
|
||||
if (params[0] < 9 || params[9] != 0)
|
||||
{
|
||||
SH_MCALL(pVictim, OnTakeDamage)((CTakeDamageInfoHack&)info);
|
||||
}
|
||||
else
|
||||
{
|
||||
static ICallWrapper *pCall = nullptr;
|
||||
if (!pCall)
|
||||
{
|
||||
int offset;
|
||||
if (!g_pGameConf->GetOffset("OnTakeDamage", &offset))
|
||||
{
|
||||
return pContext->ThrowNativeError("Could not find OnTakeDamage offset");
|
||||
}
|
||||
|
||||
PassInfo pass[2];
|
||||
pass[0].type = PassType_Object;
|
||||
pass[0].size = sizeof(CTakeDamageInfoHack &);
|
||||
pass[0].flags = PASSFLAG_BYREF | PASSFLAG_OCTOR;
|
||||
pass[1].type = PassType_Basic;
|
||||
pass[1].size = sizeof(int);
|
||||
pass[1].flags = PASSFLAG_BYVAL;
|
||||
|
||||
pCall = g_pBinTools->CreateVCall(offset, 0, 0, &pass[1], &pass[0], 1);
|
||||
}
|
||||
|
||||
// Can't ArgBuffer here until we upgrade our Clang version on the Linux builder
|
||||
unsigned char vstk[sizeof(CBaseEntity *) + sizeof(CTakeDamageInfoHack &)];
|
||||
unsigned char* vptr = vstk;
|
||||
|
||||
*(CBaseEntity **)vptr = pVictim;
|
||||
vptr += sizeof(CBaseEntity *);
|
||||
*(CTakeDamageInfoHack *&)vptr = info;
|
||||
|
||||
int ret;
|
||||
pCall->Execute(vstk, &ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -225,6 +266,7 @@ cell_t Native_DropWeapon(IPluginContext *pContext, const cell_t *params)
|
||||
}
|
||||
|
||||
Vector vecVelocity;
|
||||
Vector *pVecVelocity = nullptr;
|
||||
if ((err = pContext->LocalToPhysAddr(params[4], &addr)) != SP_ERROR_NONE)
|
||||
{
|
||||
return pContext->ThrowNativeError("Could not read vecVelocity vector");
|
||||
@@ -236,14 +278,40 @@ cell_t Native_DropWeapon(IPluginContext *pContext, const cell_t *params)
|
||||
sp_ctof(addr[0]),
|
||||
sp_ctof(addr[1]),
|
||||
sp_ctof(addr[2]));
|
||||
pVecVelocity = &vecVelocity;
|
||||
}
|
||||
|
||||
if (params[0] < 5 || params[5] != 0)
|
||||
{
|
||||
SH_MCALL(pPlayer, Weapon_Drop)((CBaseCombatWeapon*)pWeapon, &vecTarget, pVecVelocity);
|
||||
}
|
||||
else
|
||||
{
|
||||
SH_MCALL(pPlayer, Weapon_Drop)((CBaseCombatWeapon *)pWeapon, &vecTarget, NULL);
|
||||
return 0;
|
||||
}
|
||||
static ICallWrapper* pCall = nullptr;
|
||||
if (!pCall)
|
||||
{
|
||||
int offset;
|
||||
if (!g_pGameConf->GetOffset("Weapon_Drop", &offset))
|
||||
{
|
||||
return pContext->ThrowNativeError("Could not find Weapon_Drop offset");
|
||||
}
|
||||
|
||||
SH_MCALL(pPlayer, Weapon_Drop)((CBaseCombatWeapon *)pWeapon, &vecTarget, &vecVelocity);
|
||||
PassInfo pass[2];
|
||||
pass[0].type = PassType_Basic;
|
||||
pass[0].size = sizeof(CBaseEntity *);
|
||||
pass[0].flags = PASSFLAG_BYVAL;
|
||||
pass[1].type = PassType_Basic;
|
||||
pass[1].size = sizeof(Vector *);
|
||||
pass[1].flags = PASSFLAG_BYVAL;
|
||||
pass[2].type = PassType_Basic;
|
||||
pass[2].size = sizeof(Vector *);
|
||||
pass[2].flags = PASSFLAG_BYVAL;
|
||||
|
||||
pCall = g_pBinTools->CreateVCall(offset, 0, 0, nullptr, pass, 3);
|
||||
}
|
||||
|
||||
pCall->Execute(ArgBuffer<CBaseEntity *, CBaseEntity *, Vector *, Vector *>(pPlayer, pWeapon, &vecTarget, pVecVelocity), nullptr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user