CFramework/CFramework/Cheat/SDK/CPlayer/CPlayer.cpp

134 lines
4.2 KiB
C++

#include "CPlayer.h"
std::vector<int> PlayerBoneList{ BONE_PELVIS, BONE_LEFT_THIGH, BONE_LEFT_FOOT, BONE_RIGHT_THIGH, BONE_RIGHT_FOOT, BONE_LEFT_FOREARM, BONE_LEFT_PALM, BONE_RIGHT_FOREARM, BONE_RIGHT_PALM };
bool CPlayer::Update()
{
m_vecOrigin = GetBonePosition(BONE_ORIGIN);
return !Vec3_Empty(m_vecOrigin);
}
void CPlayer::UpdateStatic()
{
m_pHealthController = 0;
m_pProfile = 0;
m_pInfo = 0;
m_pSetting = 0;
m_pWeaponAnimation = 0;
m_iSpawnType = 0;
m_pBoneArray = {};
m_vecBoneList.clear();
if (!m_address)
return;
// EFT.Player fields from dump.txt.
m_pHealthController = m.Read<uintptr_t>(m_address + offset::Player::pHealthController);
m_pWeaponAnimation = m.Read<uintptr_t>(m_address + offset::Player::pWeaponAnimation);
m_pProfile = m.Read<uintptr_t>(m_address + offset::Player::pProfile);
if (m_pProfile)
{
m_pInfo = m.Read<uintptr_t>(m_pProfile + offset::Profile::pInfoClass);
if (m_pInfo)
{
m_pSetting = m.Read<uintptr_t>(m_pInfo + offset::InfoClass::profileInfoSettingsClass);
if (m_pSetting)
m_iSpawnType = m.Read<int>(m_pSetting + 0x10); // ProfileInfoSettingsClass.Role
}
}
// PlayerBody +0x30 = SkeletonRootJoint; Skeleton +0x30 = values List;
// List +0x10 = Transform[] data pointer, as described by dump.txt.
const uintptr_t boneMatrix = m.ReadChain(m_address, { offset::Player::pPlayerBody, 0x30, 0x30, 0x10 });
if (boneMatrix)
m_pBoneArray = m.Read<CBoneArray>(boneMatrix + 0x20);
}
void CPlayer::UpdateHealth()
{
m_fHealth = 0.f;
m_fHealthMax = 0.f;
if (!m_address)
return;
const uintptr_t healthController = m_pHealthController != 0
? m_pHealthController
: m.Read<uintptr_t>(m_address + offset::Player::pHealthController);
if (!healthController)
return;
// GClass3009<T>.Dictionary_0_1 contains BodyPartState<T> entries.
const uintptr_t bodyParts = m.Read<uintptr_t>(healthController + offset::HealthController::BodyParts);
if (!bodyParts)
return;
const uintptr_t entries = m.Read<uintptr_t>(bodyParts + offset::HealthController::DictionaryEntries);
const int entryCount = m.Read<int>(bodyParts + offset::HealthController::DictionaryCount);
if (!entries || entryCount <= 0 || entryCount > 64)
return;
for (int i = 0; i < entryCount; ++i)
{
const uintptr_t entry = entries + offset::HealthController::ArrayData
+ static_cast<uintptr_t>(i) * offset::HealthController::EntryStride;
const uintptr_t bodyPartState = m.Read<uintptr_t>(entry + offset::HealthController::EntryValue);
if (!bodyPartState)
continue;
const uintptr_t healthValue = m.Read<uintptr_t>(bodyPartState + offset::HealthController::BodyPartHealth);
if (!healthValue)
continue;
m_fHealth += m.Read<float>(healthValue + offset::HealthController::HealthValue + offset::HealthController::Current);
m_fHealthMax += m.Read<float>(healthValue + offset::HealthController::HealthValue + offset::HealthController::Maximum);
}
}
void CPlayer::UpdateBone()
{
m_vecHeadOrigin = GetBonePosition(BONE_HEAD);
m_vecNeckOrigin = GetBonePosition(BONE_NECK);
m_vecBoneList.clear();
if (!g.g_ESP_Skeleton)
return;
m_vecBoneList.reserve(PlayerBoneList.size());
for (const auto id : PlayerBoneList)
{
const Vector3 bone = GetBonePosition(id);
if (Vec3_Empty(bone))
{
m_vecBoneList.clear();
return;
}
m_vecBoneList.push_back(bone);
}
}
bool CPlayer::IsAiming()
{
return m_pWeaponAnimation != 0 && m.Read<bool>(m_pWeaponAnimation + offset::WeaponAnimations::isAiming);
}
Vector3 CPlayer::GetBonePosition(const int BoneId)
{
constexpr int kBoneCount = static_cast<int>(sizeof(m_pBoneArray.address) / sizeof(m_pBoneArray.address[0]));
if (BoneId < 0 || BoneId >= kBoneCount)
return {};
const uintptr_t bone = m_pBoneArray.address[BoneId];
if (!bone)
return {};
uintptr_t transform = m.Read<uintptr_t>(bone + 0x10);
if (!transform)
return {};
return GetTransformPosition(transform);
}