From 1f5c90ac682ae322bd558ab9db8ee7e8411d80cf Mon Sep 17 00:00:00 2001 From: rei-2 <174158077+rei-2@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:35:05 -0500 Subject: [PATCH] fix a couple oversights --- .../Aimbot/AutoDetonate/AutoDetonate.cpp | 6 +-- Amalgam/src/Features/CritHack/CritHack.cpp | 17 ++++---- .../src/Hooks/CL_ProcessPacketEntities.cpp | 40 +++++++++---------- .../Definitions/Main/CBaseCombatCharacter.h | 15 +++++-- Amalgam/src/SDK/Definitions/Main/CTFPlayer.h | 7 ---- 5 files changed, 39 insertions(+), 46 deletions(-) diff --git a/Amalgam/src/Features/Aimbot/AutoDetonate/AutoDetonate.cpp b/Amalgam/src/Features/Aimbot/AutoDetonate/AutoDetonate.cpp index 2f2a9727..37d58e53 100644 --- a/Amalgam/src/Features/Aimbot/AutoDetonate/AutoDetonate.cpp +++ b/Amalgam/src/Features/Aimbot/AutoDetonate/AutoDetonate.cpp @@ -96,7 +96,6 @@ bool CAutoDetonate::CheckDetonation(CTFPlayer* pLocal, EGroupType entityGroup, f return false; float flLatency = std::max(F::Backtrack.GetReal() - 0.05f, 0.f); - PredictPlayers(pLocal, flLatency); for (auto pProjectile : vProjectiles) { @@ -137,14 +136,13 @@ bool CAutoDetonate::CheckDetonation(CTFPlayer* pLocal, EGroupType entityGroup, f flRadius = SDK::AttribHookValue(flRadius, "mult_explosion_radius", pWeapon); Vec3 vOrigin = PredictOrigin(pProjectile->m_vecOrigin(), pProjectile->GetAbsVelocity(), flLatency); + PredictPlayers(pLocal, flLatency); bool bCheck = CheckEntities(pLocal, pWeapon, nullptr, pProjectile, flRadius, vOrigin); RestorePlayers(); - bCheck = bCheck && CheckEntities(pLocal, pWeapon, pCmd, pProjectile, flRadius, pProjectile->m_vecOrigin()); - if (bCheck) + if (bCheck && CheckEntities(pLocal, pWeapon, pCmd, pProjectile, flRadius, pProjectile->m_vecOrigin())) return true; } - RestorePlayers(); return false; } diff --git a/Amalgam/src/Features/CritHack/CritHack.cpp b/Amalgam/src/Features/CritHack/CritHack.cpp index ce1d8c74..c0e6e42f 100644 --- a/Amalgam/src/Features/CritHack/CritHack.cpp +++ b/Amalgam/src/Features/CritHack/CritHack.cpp @@ -260,18 +260,15 @@ bool CCritHack::WeaponCanCrit(CTFWeaponBase* pWeapon, bool bWeaponOnly) void CCritHack::ResetWeapons(CTFPlayer* pLocal) { - std::unordered_map mWeapons = {}; - auto hWeapons = pLocal->GetMyWeapons(); - if (!hWeapons) + if (!pLocal->m_hMyWeapons()) return; - for (size_t i = 0; hWeapons[i]; i++) - { - auto pWeapon = pLocal->GetWeaponFromSlot(int(i)); - if (!pWeapon) - break; + std::unordered_map mWeapons = {}; - if (!WeaponCanCrit(pWeapon)) + for (int i = 0; i < MAX_WEAPONS; i++) + { + auto pWeapon = pLocal->GetWeaponFromSlot(i); + if (!pWeapon || !WeaponCanCrit(pWeapon)) continue; int iSlot = pWeapon->GetSlot(); @@ -291,7 +288,7 @@ void CCritHack::ResetWeapons(CTFPlayer* pLocal) for (auto& [iSlot, _] : m_mStorage) { - if (m_mStorage.contains(iSlot) && !mWeapons[iSlot]) + if (m_mStorage.contains(iSlot) && !mWeapons.contains(iSlot)) m_mStorage.erase(iSlot); } } diff --git a/Amalgam/src/Hooks/CL_ProcessPacketEntities.cpp b/Amalgam/src/Hooks/CL_ProcessPacketEntities.cpp index eb37f01b..418d61c6 100644 --- a/Amalgam/src/Hooks/CL_ProcessPacketEntities.cpp +++ b/Amalgam/src/Hooks/CL_ProcessPacketEntities.cpp @@ -36,33 +36,31 @@ MAKE_HOOK(CL_ProcessPacketEntities, S::CL_ProcessPacketEntities(), bool, CTFPlayer* pLocal = I::ClientEntityList->GetClientEntity(I::EngineClient->GetLocalPlayer())->As(); if (!pLocal) { - SDK::Output("ProcessPacketEntities", "Failed to restore weapon crit data! (1)", { 255, 100, 100, 255 }, Vars::Debug::Logging.Value); + SDK::Output("ProcessPacketEntities", "Failed to restore weapon crit data! (1)", { 255, 100, 100, 255 }); return CALL_ORIGINAL(entmsg); } - - auto hWeapons = pLocal->GetMyWeapons(); - if (!hWeapons) + if (!pLocal->m_hMyWeapons()) { - SDK::Output("ProcessPacketEntities", "Failed to restore weapon crit data! (2)", { 255, 100, 100, 255 }, Vars::Debug::Logging.Value); + SDK::Output("ProcessPacketEntities", "Failed to restore weapon crit data! (2)", { 255, 100, 100, 255 }); return CALL_ORIGINAL(entmsg); } std::unordered_map mCriticalStorage = {}; - for (size_t i = 0; hWeapons[i]; i++) - { - auto pWeapon = pLocal->GetWeaponFromSlot(int(i)); - if (!pWeapon) - break; - const int iSlot = pWeapon->GetSlot(); - mCriticalStorage[iSlot].m_flCritTokenBucket = pWeapon->m_flCritTokenBucket(); - mCriticalStorage[iSlot].m_nCritChecks = pWeapon->m_nCritChecks(); - mCriticalStorage[iSlot].m_nCritSeedRequests = pWeapon->m_nCritSeedRequests(); + for (int i = 0; i < MAX_WEAPONS; i++) + { + auto pWeapon = pLocal->GetWeaponFromSlot(i); + if (!pWeapon) + continue; + + mCriticalStorage[i].m_flCritTokenBucket = pWeapon->m_flCritTokenBucket(); + mCriticalStorage[i].m_nCritChecks = pWeapon->m_nCritChecks(); + mCriticalStorage[i].m_nCritSeedRequests = pWeapon->m_nCritSeedRequests(); if (Vars::Debug::Logging.Value) I::CVar->ConsolePrintf("\n"); - SDK::Output("ProcessPacketEntities", std::format("{} ({:#x}): mCriticalStorage[iSlot].m_flCritTokenBucket = {}", iSlot, uintptr_t(pWeapon), pWeapon->m_flCritTokenBucket()).c_str(), { 100, 150, 255, 255 }, Vars::Debug::Logging.Value); - SDK::Output("ProcessPacketEntities", std::format("{} ({:#x}): mCriticalStorage[iSlot].m_nCritChecks = {}", iSlot, uintptr_t(pWeapon), pWeapon->m_nCritChecks()).c_str(), { 100, 150, 255, 255 }, Vars::Debug::Logging.Value); - SDK::Output("ProcessPacketEntities", std::format("{} ({:#x}): mCriticalStorage[iSlot].m_nCritSeedRequests = {}", iSlot, uintptr_t(pWeapon), pWeapon->m_nCritSeedRequests()).c_str(), { 100, 150, 255, 255 }, Vars::Debug::Logging.Value); + SDK::Output("ProcessPacketEntities", std::format("{} ({:#x}): mCriticalStorage[i].m_flCritTokenBucket = {}", i, uintptr_t(pWeapon), pWeapon->m_flCritTokenBucket()).c_str(), { 100, 150, 255, 255 }, Vars::Debug::Logging.Value); + SDK::Output("ProcessPacketEntities", std::format("{} ({:#x}): mCriticalStorage[i].m_nCritChecks = {}", i, uintptr_t(pWeapon), pWeapon->m_nCritChecks()).c_str(), { 100, 150, 255, 255 }, Vars::Debug::Logging.Value); + SDK::Output("ProcessPacketEntities", std::format("{} ({:#x}): mCriticalStorage[i].m_nCritSeedRequests = {}", i, uintptr_t(pWeapon), pWeapon->m_nCritSeedRequests()).c_str(), { 100, 150, 255, 255 }, Vars::Debug::Logging.Value); } bool bReturn = CALL_ORIGINAL(entmsg); @@ -70,14 +68,12 @@ MAKE_HOOK(CL_ProcessPacketEntities, S::CL_ProcessPacketEntities(), bool, pLocal = I::ClientEntityList->GetClientEntity(I::EngineClient->GetLocalPlayer())->As(); if (!pLocal) { - SDK::Output("ProcessPacketEntities", "Failed to restore weapon crit data! (3)", { 255, 100, 100, 255 }, Vars::Debug::Logging.Value); + SDK::Output("ProcessPacketEntities", "Failed to restore weapon crit data! (3)", { 255, 100, 100, 255 }); return bReturn; } - - hWeapons = pLocal->GetMyWeapons(); - if (!hWeapons) + if (!pLocal->m_hMyWeapons()) { - SDK::Output("ProcessPacketEntities", "Failed to restore weapon crit data! (4)", { 255, 100, 100, 255 }, Vars::Debug::Logging.Value); + SDK::Output("ProcessPacketEntities", "Failed to restore weapon crit data! (4)", { 255, 100, 100, 255 }); return bReturn; } diff --git a/Amalgam/src/SDK/Definitions/Main/CBaseCombatCharacter.h b/Amalgam/src/SDK/Definitions/Main/CBaseCombatCharacter.h index aeb10874..ba3f59ba 100644 --- a/Amalgam/src/SDK/Definitions/Main/CBaseCombatCharacter.h +++ b/Amalgam/src/SDK/Definitions/Main/CBaseCombatCharacter.h @@ -1,17 +1,26 @@ #pragma once #include "CBaseFlex.h" +class CTFWeaponBase; + class CBaseCombatCharacter : public CBaseFlex { public: NETVAR(m_flNextAttack, float, "CBaseCombatCharacter", "m_flNextAttack"); NETVAR(m_hActiveWeapon, EHANDLE, "CBaseCombatCharacter", "m_hActiveWeapon"); - NETVAR(m_hMyWeapons, EHANDLE, "CBaseCombatCharacter", "m_hMyWeapons"); + //NETVAR(m_hMyWeapons, EHANDLE, "CBaseCombatCharacter", "m_hMyWeapons"); NETVAR(m_bGlowEnabled, bool, "CBaseCombatCharacter", "m_bGlowEnabled"); - inline size_t* GetMyWeapons() + inline CHandle(&m_hMyWeapons())[MAX_WEAPONS] { static int nOffset = U::NetVars.GetNetVar("CBaseCombatCharacter", "m_hMyWeapons"); - return reinterpret_cast(uintptr_t(this) + nOffset); + return *reinterpret_cast(*)[MAX_WEAPONS]>(uintptr_t(this) + nOffset); + } + + inline CTFWeaponBase* GetWeaponFromSlot(int nSlot) + { + if (nSlot < 0 || nSlot >= MAX_WEAPONS) + return nullptr; + return m_hMyWeapons()[nSlot].Get(); } }; \ No newline at end of file diff --git a/Amalgam/src/SDK/Definitions/Main/CTFPlayer.h b/Amalgam/src/SDK/Definitions/Main/CTFPlayer.h index 833cffb9..70486d0e 100644 --- a/Amalgam/src/SDK/Definitions/Main/CTFPlayer.h +++ b/Amalgam/src/SDK/Definitions/Main/CTFPlayer.h @@ -427,13 +427,6 @@ public: return true; } - inline CTFWeaponBase* GetWeaponFromSlot(int nSlot) - { - static int nOffset = U::NetVars.GetNetVar("CBaseCombatCharacter", "m_hMyWeapons"); - auto& hWeapon = *reinterpret_cast(uintptr_t(this) + nOffset + nSlot * 4); - return hWeapon.Get()->As(); - } - inline float TeamFortress_CalculateMaxSpeed(bool bIgnoreSpecialAbility = false) { return S::TeamFortress_CalculateMaxSpeed.Call(this, bIgnoreSpecialAbility);