From 1b9bbad1fdc8cc7c2584f168828ea3666a97e58a Mon Sep 17 00:00:00 2001 From: rei-2 <174158077+rei-2@users.noreply.github.com> Date: Sun, 16 Feb 2025 19:45:14 -0500 Subject: [PATCH] prevent self damage auto detonate flag --- .../Aimbot/AimbotHitscan/AimbotHitscan.cpp | 2 +- .../Aimbot/AutoDetonate/AutoDetonate.cpp | 144 +++++++++++++----- .../Aimbot/AutoDetonate/AutoDetonate.h | 3 +- Amalgam/src/Features/ImGui/Menu/Menu.cpp | 2 +- Amalgam/src/SDK/Vars.h | 2 +- 5 files changed, 108 insertions(+), 45 deletions(-) diff --git a/Amalgam/src/Features/Aimbot/AimbotHitscan/AimbotHitscan.cpp b/Amalgam/src/Features/Aimbot/AimbotHitscan/AimbotHitscan.cpp index 664f359b..24e28ded 100644 --- a/Amalgam/src/Features/Aimbot/AimbotHitscan/AimbotHitscan.cpp +++ b/Amalgam/src/Features/Aimbot/AimbotHitscan/AimbotHitscan.cpp @@ -93,7 +93,7 @@ std::vector CAimbotHitscan::GetTargets(CTFPlayer* pLocal, CTFWeaponBas if (F::AimbotGlobal.ShouldIgnore(pEntity, pLocal, pWeapon)) continue; - Vec3 vPos = pEntity->GetCenter(); + Vec3 vPos = pEntity->m_vecOrigin(); Vec3 vAngleTo = Math::CalcAngle(vLocalPos, vPos); float flFOVTo = Math::CalcFov(vLocalAngles, vAngleTo); if (flFOVTo > Vars::Aimbot::General::AimFOV.Value) diff --git a/Amalgam/src/Features/Aimbot/AutoDetonate/AutoDetonate.cpp b/Amalgam/src/Features/Aimbot/AutoDetonate/AutoDetonate.cpp index 215dc2cc..0bf73fa7 100644 --- a/Amalgam/src/Features/Aimbot/AutoDetonate/AutoDetonate.cpp +++ b/Amalgam/src/Features/Aimbot/AutoDetonate/AutoDetonate.cpp @@ -2,7 +2,7 @@ static inline Vec3 PredictOrigin(Vec3& vOrigin, Vec3 vVelocity, float flLatency, bool bTrace = true, Vec3 vMins = {}, Vec3 vMaxs = {}, unsigned int nMask = MASK_SOLID) { - if (vVelocity.IsZero()) + if (vVelocity.IsZero() || !flLatency) return vOrigin; Vec3 vTo = vOrigin + vVelocity * flLatency; @@ -16,14 +16,17 @@ static inline Vec3 PredictOrigin(Vec3& vOrigin, Vec3 vVelocity, float flLatency, return vOrigin + (vTo - vOrigin) * trace.fraction; } -void CAutoDetonate::PredictPlayers(CBaseEntity* pLocal, float flLatency) +void CAutoDetonate::PredictPlayers(CTFPlayer* pLocal, float flLatency, bool bLocal) { - m_mRestore.clear(); + if (!m_mRestore.empty()) + RestorePlayers(); for (auto pEntity : H::Entities.GetGroup(EGroupType::PLAYERS_ALL)) { auto pPlayer = pEntity->As(); - if (pPlayer == pLocal || pPlayer->IsDormant() || !pPlayer->IsAlive() || pPlayer->IsAGhost()) + if (!bLocal + ? (pPlayer == pLocal || pPlayer->IsDormant() || !pPlayer->IsAlive() || pPlayer->IsAGhost()) + : (pLocal != pPlayer || !pLocal->IsAlive() || pLocal->IsAGhost())) continue; m_mRestore[pPlayer] = pPlayer->GetAbsOrigin(); @@ -35,9 +38,45 @@ void CAutoDetonate::PredictPlayers(CBaseEntity* pLocal, float flLatency) void CAutoDetonate::RestorePlayers() { for (auto& [pEntity, vRestore] : m_mRestore) - { pEntity->SetAbsOrigin(vRestore); + m_mRestore.clear(); +} + +static inline bool GetRadius(EGroupType entityGroup, CBaseEntity* pProjectile, float& flRadius, CTFWeaponBase*& pWeapon) +{ + if (entityGroup == EGroupType::MISC_LOCAL_STICKIES) + pWeapon = pProjectile->As()->m_hOriginalLauncher().Get()->As(); + else + pWeapon = pProjectile->As()->m_hLauncher().Get()->As(); + if (!pWeapon) + { + pWeapon = H::Entities.GetWeapon(); + if (!pWeapon) + return false; } + + if (entityGroup == EGroupType::MISC_LOCAL_STICKIES) + { + auto pPipebomb = pProjectile->As(); + if (!pPipebomb->m_flCreationTime() || I::GlobalVars->curtime < pPipebomb->m_flCreationTime() + SDK::AttribHookValue(0.8f, "sticky_arm_time", pWeapon)) + return false; + + flRadius *= 146.f; + if (!pPipebomb->m_bTouched()) + { + static auto tf_grenadelauncher_livetime = U::ConVars.FindVar("tf_grenadelauncher_livetime"); + static auto tf_sticky_radius_ramp_time = U::ConVars.FindVar("tf_sticky_radius_ramp_time"); + static auto tf_sticky_airdet_radius = U::ConVars.FindVar("tf_sticky_airdet_radius"); + float flLiveTime = tf_grenadelauncher_livetime ? tf_grenadelauncher_livetime->GetFloat() : 0.8f; + float flRampTime = tf_sticky_radius_ramp_time ? tf_sticky_radius_ramp_time->GetFloat() : 2.f; + float flAirdetRadius = tf_sticky_airdet_radius ? tf_sticky_airdet_radius->GetFloat() : 0.85f; + flRadius *= Math::RemapValClamped(I::GlobalVars->curtime - pPipebomb->m_flCreationTime(), flLiveTime, flLiveTime + flRampTime, flAirdetRadius, 1.f); + } + } + else + flRadius *= 110.f; + flRadius = SDK::AttribHookValue(flRadius, "mult_explosion_radius", pWeapon); + return true; } static inline bool CheckEntities(CTFPlayer* pLocal, CTFWeaponBase* pWeapon, CUserCmd* pCmd, CBaseEntity* pProjectile, float flRadius, Vec3 vOrigin) @@ -102,46 +141,63 @@ bool CAutoDetonate::CheckDetonation(CTFPlayer* pLocal, EGroupType entityGroup, f for (auto pProjectile : vProjectiles) { float flRadius = flRadiusScale; - CTFWeaponBase* pWeapon = nullptr; - if (entityGroup == EGroupType::MISC_LOCAL_STICKIES) - pWeapon = pProjectile->As()->m_hOriginalLauncher().Get()->As(); - else - pWeapon = pProjectile->As()->m_hLauncher().Get()->As(); - if (!pWeapon) - { - pWeapon = H::Entities.GetWeapon(); - if (!pWeapon) - continue; - } + if (!GetRadius(entityGroup, pProjectile, flRadius, pWeapon)) + continue; - if (entityGroup == EGroupType::MISC_LOCAL_STICKIES) - { - auto pPipebomb = pProjectile->As(); - if (!pPipebomb->m_flCreationTime() || I::GlobalVars->curtime < pPipebomb->m_flCreationTime() + SDK::AttribHookValue(0.8f, "sticky_arm_time", pWeapon)) - continue; - - flRadius *= 146.f; - if (!pPipebomb->m_bTouched()) - { - static auto tf_grenadelauncher_livetime = U::ConVars.FindVar("tf_grenadelauncher_livetime"); - static auto tf_sticky_radius_ramp_time = U::ConVars.FindVar("tf_sticky_radius_ramp_time"); - static auto tf_sticky_airdet_radius = U::ConVars.FindVar("tf_sticky_airdet_radius"); - float flLiveTime = tf_grenadelauncher_livetime ? tf_grenadelauncher_livetime->GetFloat() : 0.8f; - float flRampTime = tf_sticky_radius_ramp_time ? tf_sticky_radius_ramp_time->GetFloat() : 2.f; - float flAirdetRadius = tf_sticky_airdet_radius ? tf_sticky_airdet_radius->GetFloat() : 0.85f; - flRadius *= Math::RemapValClamped(I::GlobalVars->curtime - pPipebomb->m_flCreationTime(), flLiveTime, flLiveTime + flRampTime, flAirdetRadius, 1.f); - } - } - else - flRadius *= 110.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); + PredictPlayers(pLocal, 0.f); + bCheck = bCheck && CheckEntities(pLocal, pWeapon, pCmd, pProjectile, flRadius, pProjectile->m_vecOrigin()); RestorePlayers(); - if (bCheck && CheckEntities(pLocal, pWeapon, pCmd, pProjectile, flRadius, pProjectile->m_vecOrigin())) + if (bCheck) + return true; + } + + return false; +} + +static inline bool CheckLocal(CTFPlayer* pLocal, CTFWeaponBase* pWeapon, CBaseEntity* pProjectile, float flRadius, Vec3 vOrigin) +{ + flRadius += 1; + + Vec3 vPos = {}; reinterpret_cast(pLocal->GetCollideable())->CalcNearestPoint(vOrigin, &vPos); + if (vOrigin.DistTo(vPos) > flRadius) + return false; + + if (!SDK::VisPosProjectile(pProjectile, pLocal, vOrigin, pLocal->GetAbsOrigin() + pLocal->m_vecViewOffset(), MASK_SHOT)) + return false; + + return true; +} + +bool CAutoDetonate::CheckSelf(CTFPlayer* pLocal, EGroupType entityGroup) +{ + if (!(Vars::Aimbot::Projectile::AutoDetonate.Value & Vars::Aimbot::Projectile::AutoDetonateEnum::PreventSelfDamage) || !pLocal->IsAlive() || pLocal->IsAGhost()) + return false; + + auto& vProjectiles = H::Entities.GetGroup(entityGroup); + if (vProjectiles.empty()) + return false; + + float flLatency = std::max(F::Backtrack.GetReal() - 0.05f, 0.f); + + for (auto pProjectile : vProjectiles) + { + float flRadius = 1.f; + CTFWeaponBase* pWeapon = nullptr; + if (!GetRadius(entityGroup, pProjectile, flRadius, pWeapon)) + continue; + + Vec3 vOrigin = PredictOrigin(pProjectile->m_vecOrigin(), pProjectile->GetAbsVelocity(), flLatency); + + PredictPlayers(pLocal, 0.f, true); + bool bCheck = CheckLocal(pLocal, pWeapon, pProjectile, flRadius, vOrigin) + && CheckLocal(pLocal, pWeapon, pProjectile, flRadius, pProjectile->m_vecOrigin()); + RestorePlayers(); + if (bCheck) return true; } @@ -153,7 +209,13 @@ void CAutoDetonate::Run(CTFPlayer* pLocal, CTFWeaponBase* pWeapon, CUserCmd* pCm if (!Vars::Aimbot::Projectile::AutoDetonate.Value) return; - if ((Vars::Aimbot::Projectile::AutoDetonate.Value & Vars::Aimbot::Projectile::AutoDetonateEnum::Stickies && CheckDetonation(pLocal, EGroupType::MISC_LOCAL_STICKIES, Vars::Aimbot::Projectile::AutodetRadius.Value / 100, pCmd)) - || (Vars::Aimbot::Projectile::AutoDetonate.Value & Vars::Aimbot::Projectile::AutoDetonateEnum::Flares && CheckDetonation(pLocal, EGroupType::MISC_LOCAL_FLARES, Vars::Aimbot::Projectile::AutodetRadius.Value / 100, pCmd))) + if ((Vars::Aimbot::Projectile::AutoDetonate.Value & Vars::Aimbot::Projectile::AutoDetonateEnum::Stickies + && CheckDetonation(pLocal, EGroupType::MISC_LOCAL_STICKIES, Vars::Aimbot::Projectile::AutodetRadius.Value / 100, pCmd) + && !CheckSelf(pLocal, EGroupType::MISC_LOCAL_STICKIES)) + || (Vars::Aimbot::Projectile::AutoDetonate.Value & Vars::Aimbot::Projectile::AutoDetonateEnum::Flares + && CheckDetonation(pLocal, EGroupType::MISC_LOCAL_FLARES, Vars::Aimbot::Projectile::AutodetRadius.Value / 100, pCmd)) + && !CheckSelf(pLocal, EGroupType::MISC_LOCAL_FLARES)) + { pCmd->buttons |= IN_ATTACK2; -} + } +} \ No newline at end of file diff --git a/Amalgam/src/Features/Aimbot/AutoDetonate/AutoDetonate.h b/Amalgam/src/Features/Aimbot/AutoDetonate/AutoDetonate.h index eb3fc410..95474ae5 100644 --- a/Amalgam/src/Features/Aimbot/AutoDetonate/AutoDetonate.h +++ b/Amalgam/src/Features/Aimbot/AutoDetonate/AutoDetonate.h @@ -6,8 +6,9 @@ class CAutoDetonate { bool CheckDetonation(CTFPlayer* pLocal, EGroupType entityGroup, float flRadiusScale, CUserCmd* pCmd); + bool CheckSelf(CTFPlayer* pLocal, EGroupType entityGroup); - void PredictPlayers(CBaseEntity* pLocal, float flLatency); + void PredictPlayers(CTFPlayer* pLocal, float flLatency, bool bLocal = false); void RestorePlayers(); std::unordered_map m_mRestore = {}; diff --git a/Amalgam/src/Features/ImGui/Menu/Menu.cpp b/Amalgam/src/Features/ImGui/Menu/Menu.cpp index 7f22bf11..ebb2ba8c 100644 --- a/Amalgam/src/Features/ImGui/Menu/Menu.cpp +++ b/Amalgam/src/Features/ImGui/Menu/Menu.cpp @@ -203,7 +203,7 @@ void CMenu::MenuAimbot() { FDropdown("Predict", Vars::Aimbot::Projectile::StrafePrediction, { "Air strafing", "Ground strafing" }, {}, FDropdown_Multi | FDropdown_Left); FDropdown("Splash", Vars::Aimbot::Projectile::SplashPrediction, { "Off", "Include", "Prefer", "Only" }, {}, FDropdown_Right); - FDropdown("Auto detonate", Vars::Aimbot::Projectile::AutoDetonate, { "Stickies", "Flares" }, {}, FDropdown_Multi | FDropdown_Left); + FDropdown("Auto detonate", Vars::Aimbot::Projectile::AutoDetonate, { "Stickies", "Flares", "##Divider", "Ignore self damage" }, {}, FDropdown_Multi | FDropdown_Left); FDropdown("Auto airblast", Vars::Aimbot::Projectile::AutoAirblast, { "Off", "Legit", "Rage" }, {}, FDropdown_Right); FDropdown("Modifiers## Projectile", Vars::Aimbot::Projectile::Modifiers, { "Charge shot", "Cancel charge", "Bodyaim if lethal", "Use prime time", "Aim blast at feet" }, {}, FDropdown_Multi); FSlider("Max simulation time", Vars::Aimbot::Projectile::PredictionTime, 0.1f, 10.f, 0.25f, "%gs", FSlider_Min | FSlider_Precision); diff --git a/Amalgam/src/SDK/Vars.h b/Amalgam/src/SDK/Vars.h index 7c215e5d..463460d2 100644 --- a/Amalgam/src/SDK/Vars.h +++ b/Amalgam/src/SDK/Vars.h @@ -149,7 +149,7 @@ namespace Vars SUBNAMESPACE_BEGIN(Projectile) CVarEnum(StrafePrediction, 0b11, NONE, Air = 1 << 0, Ground = 1 << 1) CVarEnum(SplashPrediction, 0, NONE, Off, Include, Prefer, Only) - CVarEnum(AutoDetonate, 0b00, NONE, Stickies = 1 << 0, Flares = 1 << 1) + CVarEnum(AutoDetonate, 0b00, NONE, Stickies = 1 << 0, Flares = 1 << 1, PreventSelfDamage = 1 << 2) CVarEnum(AutoAirblast, 0, NONE, Off, Legit, Rage) CVarEnum(Modifiers, 0b1010, NONE, ChargeWeapon = 1 << 0, CancelCharge = 1 << 1, BodyaimIfLethal = 1 << 2, UsePrimeTime = 1 << 3, AimBlastAtFeet = 1 << 4) CVar(PredictionTime, 2.f)