diff --git a/uran/src/hack.cpp b/uran/src/hack.cpp index 7fec8387..2548d124 100644 --- a/uran/src/hack.cpp +++ b/uran/src/hack.cpp @@ -38,6 +38,7 @@ #include "localplayer.h" #include "playerresource.h" #include "targeting/ITargetSystem.h" +#include "hacks/AutoHeal.h" #include "profiler.h" @@ -188,6 +189,7 @@ void hack::InitHacks() { ADD_HACK(Triggerbot); ADD_HACK(AutoSticky); ADD_HACK(Airstuck); + ADD_HACK(AutoHeal); } void hack::Initialize() { diff --git a/uran/src/hacks/AutoHeal.cpp b/uran/src/hacks/AutoHeal.cpp index 5a5fd69c..0b36679d 100644 --- a/uran/src/hacks/AutoHeal.cpp +++ b/uran/src/hacks/AutoHeal.cpp @@ -7,6 +7,102 @@ #include "AutoHeal.h" +#include "../entity.h" +#include "../localplayer.h" +#include "../interfaces.h" +#include "../usercmd.h" +#include "../helpers.h" +#include "../playerresource.h" +#include "../entitycache.h" +#include "../drawing.h" +#include "../sdk/in_buttons.h" +#include "../fixsdk.h" +#include +#include +#include +#include DEFINE_HACK_SINGLETON(AutoHeal); + +const char* AutoHeal::GetName() { return "AUTO-HEAL"; } + +int AutoHeal::GetBestHealingTarget() { + int best = -1; + int best_score = -65536; + + for (int i = 0; i < 64 && i < interfaces::entityList->GetHighestEntityIndex(); i++) { + int score = this->GetHealingPriority(i); + if (score > best_score && score != -1) { + best = i; + best_score = score; + } + } + + return best; +} + +int AutoHeal::GetHealingPriority(int idx) { + if (!CanHeal(idx)) return -1; + IClientEntity* ent = interfaces::entityList->GetClientEntity(idx); + int priority = 0; + int health = GetEntityValue(ent, eoffsets.iHealth); + int maxhealth = g_pPlayerResource->GetMaxHealth(ent); + int maxbuffedhealth = maxhealth * 1.5; + int maxoverheal = maxbuffedhealth - maxhealth; + int overheal = maxoverheal - (maxbuffedhealth - health); + float overhealp = ((float)overheal / (float)maxoverheal); + float healthp = ((float)health / (float)maxhealth); + if (GetRelation(ent) == relation::FRIEND) { + priority += 70 * (1 - healthp); + priority += 15 * (1 - overhealp); + } else { + priority += 50 * (1 - healthp); + priority += 10 * (1 - overhealp); + } + return priority; +} + +bool AutoHeal::CanHeal(int idx) { + IClientEntity* ent = interfaces::entityList->GetClientEntity(idx); + if (!ent) return false; + if (ent->GetClientClass()->m_ClassID != ClassID::CTFPlayer) return false; + if (GetEntityValue(ent, eoffsets.iLifeState)) return false; + if (g_pLocalPlayer->team != GetEntityValue(ent, eoffsets.iTeamNum)) return false; + if (g_pLocalPlayer->v_Origin.DistToSqr(ent->GetAbsOrigin()) > 500 * 500) return false; + if (!IsEntityVisible(ent, 7)) return false; + return true; +} + +AutoHeal::AutoHeal() { + this->v_bEnabled = CreateConVar("u_autoheal_enabled", "0", "Enable AutoHeal"); + this->v_bSilent = CreateConVar("u_autoheal_silent", "1", "Silent AutoHeal"); + m_iCurrentHealingTarget = -1; +} + +bool AutoHeal::CreateMove(void*, float, CUserCmd* cmd) { + if (!this->v_bEnabled->GetBool()) return true; + if (GetWeaponMode(g_pLocalPlayer->entity) != weapon_medigun) return true; + if (g_pLocalPlayer->life_state) return true; + int old_target = m_iCurrentHealingTarget; + m_iCurrentHealingTarget = GetBestHealingTarget(); + if (m_iNewTarget > 0 && m_iNewTarget < 10) m_iNewTarget++; + else m_iNewTarget = 0; + bool new_target = (old_target != m_iCurrentHealingTarget); + if (new_target) { + m_iNewTarget = 1; + } + if (m_iCurrentHealingTarget == -1) return true; + IClientEntity* target = interfaces::entityList->GetClientEntity(m_iCurrentHealingTarget); + Vector out; + GetHitboxPosition(target, 7, out); + AimAt(g_pLocalPlayer->v_Eye, out, cmd); + g_pLocalPlayer->bUseSilentAngles = true; + if (!m_iNewTarget) cmd->buttons |= IN_ATTACK; + return false; +} + +void AutoHeal::PaintTraverse(void*, unsigned int, bool, bool) { + //if (m_iCurrentHealingTarget >= 0) + //gEntityCache.GetEntity(m_iCurrentHealingTarget)->AddESPString(colors::white, colors::black, "Healing priority: %i", GetHealingPriority(m_iCurrentHealingTarget)); +} diff --git a/uran/src/hacks/AutoHeal.h b/uran/src/hacks/AutoHeal.h index 67f46456..1b5d5a78 100644 --- a/uran/src/hacks/AutoHeal.h +++ b/uran/src/hacks/AutoHeal.h @@ -13,7 +13,14 @@ class AutoHeal : public IHack { public: DECLARE_HACK_METHODS(); + AutoHeal(); + int GetBestHealingTarget(); + int GetHealingPriority(int idx); + bool CanHeal(int idx); + int m_iCurrentHealingTarget; + int m_iNewTarget; ConVar* v_bEnabled; + ConVar* v_bSilent; }; DECLARE_HACK_SINGLETON(AutoHeal);