Update SDKHooks_TakeDamage for CS:GO changes ()

See 
This commit is contained in:
PerfectLaugh 2020-07-25 10:45:35 +08:00 committed by GitHub
parent b7650b11d6
commit af76f757b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 3 deletions

View File

@ -30,6 +30,7 @@
* Version: $Id$
*/
#include "extension.h"
#include "takedamageinfohack.h"
CTakeDamageInfo::CTakeDamageInfo(){}
@ -39,11 +40,11 @@ CTakeDamageInfoHack::CTakeDamageInfoHack( CBaseEntity *pInflictor, CBaseEntity *
m_hInflictor = pInflictor;
if ( pAttacker )
{
m_hAttacker = pAttacker;
SetAttacker(pAttacker);
}
else
{
m_hAttacker = pInflictor;
SetAttacker(pInflictor);
}
#if SOURCE_ENGINE >= SE_ORANGEBOX && SOURCE_ENGINE != SE_LEFT4DEAD
@ -95,3 +96,43 @@ CTakeDamageInfoHack::CTakeDamageInfoHack( CBaseEntity *pInflictor, CBaseEntity *
m_uiRecoilIndex = 0;
#endif
}
#if SOURCE_ENGINE == SE_CSGO
int CTakeDamageInfoHack::GetAttacker() const
{
return m_CSGOAttacker.m_hHndl.IsValid() ? m_CSGOAttacker.m_hHndl.GetEntryIndex() : -1;
}
void CTakeDamageInfoHack::SetAttacker(CBaseEntity *pAttacker)
{
m_CSGOAttacker.m_bNeedInit = false;
m_CSGOAttacker.m_hHndl = pAttacker;
m_CSGOAttacker.m_bIsWorld = true;
int entity = gamehelpers->EntityToBCompatRef(pAttacker);
IGamePlayer *player = playerhelpers->GetGamePlayer(entity);
if (player) {
m_CSGOAttacker.m_bIsWorld = false;
m_CSGOAttacker.m_bIsPlayer = true;
m_CSGOAttacker.m_iClientIndex = player->GetIndex();
m_CSGOAttacker.m_iUserId = player->GetUserId();
IPlayerInfo *playerinfo = player->GetPlayerInfo();
if (!playerinfo) {
return;
}
m_CSGOAttacker.m_iTeamChecked = playerinfo->GetTeamIndex();
m_CSGOAttacker.m_iTeamNum = playerinfo->GetTeamIndex();
}
}
#else
int CTakeDamageInfoHack::GetAttacker() const
{
return m_hAttacker.IsValid() ? m_hAttacker.GetEntryIndex() : -1;
}
void CTakeDamageInfoHack::SetAttacker(CBaseEntity *pAttacker)
{
CTakeDamageInfo::SetAttacker(pAttacker);
}
#endif

View File

@ -59,7 +59,8 @@ class CTakeDamageInfoHack : public CTakeDamageInfo
{
public:
CTakeDamageInfoHack( CBaseEntity *pInflictor, CBaseEntity *pAttacker, float flDamage, int bitsDamageType, CBaseEntity *pWeapon, Vector vecDamageForce, Vector vecDamagePosition );
inline int GetAttacker() const { return m_hAttacker.IsValid() ? m_hAttacker.GetEntryIndex() : -1; }
int GetAttacker() const;
void SetAttacker(CBaseEntity *pAttacker);
inline int GetInflictor() const { return m_hInflictor.IsValid() ? m_hInflictor.GetEntryIndex() : -1; }
#if SOURCE_ENGINE >= SE_ORANGEBOX && SOURCE_ENGINE != SE_LEFT4DEAD
inline int GetWeapon() const { return m_hWeapon.IsValid() ? m_hWeapon.GetEntryIndex() : -1; }