From 8357790778ed4fba2d49efff2bddc71c157d93e5 Mon Sep 17 00:00:00 2001 From: LIghty Date: Wed, 21 Mar 2018 15:37:22 +0100 Subject: [PATCH] added auto detonator detonator cat_detonator_enabled cat_detonator_legit --- include/hacks/AutoDetonator.hpp | 27 ++++++ include/hacks/hacklist.hpp | 1 + src/hacks/AutoDetonator.cpp | 143 ++++++++++++++++++++++++++++++++ src/hooks/CreateMove.cpp | 5 ++ 4 files changed, 176 insertions(+) create mode 100644 include/hacks/AutoDetonator.hpp create mode 100644 src/hacks/AutoDetonator.cpp diff --git a/include/hacks/AutoDetonator.hpp b/include/hacks/AutoDetonator.hpp new file mode 100644 index 00000000..172d89ee --- /dev/null +++ b/include/hacks/AutoDetonator.hpp @@ -0,0 +1,27 @@ +/* + * AutoDetonator.cpp + * + * Created on: Mar 21, 2018 + * Author: nullifiedcat & Lighty + */ + +#ifndef HACKS_AUTODETONATOR_HPP_ +#define HACKS_AUTODETONATOR_HPP_ + +#include "common.hpp" + +namespace hacks +{ +namespace tf +{ +namespace autodetonator +{ + +extern CatVar enabled; + +void CreateMove(); +} +} +} + +#endif /* HACKS_AUTODETONATOR_HPP_ */ diff --git a/include/hacks/hacklist.hpp b/include/hacks/hacklist.hpp index 09f02f15..65344faa 100644 --- a/include/hacks/hacklist.hpp +++ b/include/hacks/hacklist.hpp @@ -23,6 +23,7 @@ #include "AutoHeal.hpp" #include "AutoReflect.hpp" #include "AutoSticky.hpp" +#include "AutoDetonator.hpp" #include "AntiCheat.hpp" #include "Events.hpp" #include "Bunnyhop.hpp" diff --git a/src/hacks/AutoDetonator.cpp b/src/hacks/AutoDetonator.cpp new file mode 100644 index 00000000..8b18e093 --- /dev/null +++ b/src/hacks/AutoDetonator.cpp @@ -0,0 +1,143 @@ +/* + * AutoDetonator.cpp + * + * Created on: Mar 21, 2018 + * Author: nullifiedcat & Lighty + */ + +#include "common.hpp" + +namespace hacks +{ +namespace tf +{ +namespace autodetonator +{ + +// Vars for user settings +CatVar enabled(CV_SWITCH, "detonator_enabled", "0", "Auto-Detonator-detonator", + "Master AutoSticky switch"); +CatVar legit(CV_SWITCH, "detonator_legit", "0", "Ignore invis", + "Ignores invis spies"); + +// A storage array for ents +std::vector flares; +std::vector targets; + +// Function to tell when an ent is the local players own flare +bool IsFlare(CachedEntity *ent) +{ + // Check if ent is a flare + if (ent->m_iClassID != CL_CLASS(CTFProjectile_Flare)) + return false; + + // Check if we're the owner of the flare + if ((CE_INT(ent, 0x894) & 0xFFF) != LOCAL_W->m_IDX) + return false; + + // Check passed, return true + return true; +} + +// Function to check ent if it is a good target +bool IsTarget(CachedEntity *ent) +{ + // Check if target is The local player + if (ent == LOCAL_E) + return false; + + // Check if target is an enemy + if (!ent->m_bEnemy) + return false; + + // Player specific + if (ent->m_Type == ENTITY_PLAYER) + { + // Dont detonate on dead players + if (!ent->m_bAlivePlayer) + return false; + // Dont detonate on friendly players + if (playerlist::IsFriendly(playerlist::AccessData(ent).state)) + return false; + + IF_GAME(IsTF()) + { + // Dont target invulnerable players, ex: uber, bonk + if (IsPlayerInvulnerable(ent)) + return false; + + // If settings allow, ignore taunting players + if (ignore_taunting && HasCondition(ent)) + return false; + + // If settings allow, dont target cloaked players + if (legit && IsPlayerInvisible(ent)) + return false; + } + + // Target is good + return true; + } + // Target isnt a good type + return false; +} + +// Function called by game for movement +void CreateMove() +{ + // Check user settings if auto detonator is enabled + if (!enabled) + return; + + // Check if player is pyro + if (g_pLocalPlayer->clazz != tf_pyro) + return; + + // Clear the arrays + flares.clear(); + targets.clear(); + + // Cycle through the ents and search for valid ents + for (int i = 0; i < HIGHEST_ENTITY; i++) + { + // Assign the for loops tick number to an ent + CachedEntity *ent = ENTITY(i); + // Check for dormancy and if valid + if (CE_BAD(ent)) + continue; + // Check if ent is a flare or suitable target and push to respective + // arrays + if (IsFlare(ent)) + { + flares.push_back(ent); + } + else if (IsTarget(ent)) + { + targets.push_back(ent); + } + } + for (auto flare : flares) + { + // Loop through every target + for (auto target : targets) + { + // Check distance to the target to see if the flare will hit + if (flare->m_vecOrigin.DistToSqr(target->m_vecOrigin) < 22000) + { + // Vis check the target from the flare + if (VisCheckEntFromEnt(flare, target)) + { + // Detonate + g_pUserCmd->buttons |= IN_ATTACK2; + + return; + } + } + } + } + // End of function, just return + return; +} +} +} +} diff --git a/src/hooks/CreateMove.cpp b/src/hooks/CreateMove.cpp index 55c58550..812f69e4 100644 --- a/src/hooks/CreateMove.cpp +++ b/src/hooks/CreateMove.cpp @@ -393,6 +393,11 @@ bool CreateMove_hook(void *thisptr, float inputSample, CUserCmd *cmd) hacks::tf::autosticky::CreateMove(); } IF_GAME(IsTF()) + { + PROF_SECTION(CM_autodetonator); + hacks::tf::autodetonator::CreateMove(); + } + IF_GAME(IsTF()) { PROF_SECTION(CM_autoreflect); hacks::tf::autoreflect::CreateMove();