This commit is contained in:
nullifiedcat 2016-12-03 14:13:01 +03:00
parent af1333817c
commit b4b2f8eee7
3 changed files with 105 additions and 0 deletions

View File

@ -38,6 +38,7 @@
#include "localplayer.h" #include "localplayer.h"
#include "playerresource.h" #include "playerresource.h"
#include "targeting/ITargetSystem.h" #include "targeting/ITargetSystem.h"
#include "hacks/AutoHeal.h"
#include "profiler.h" #include "profiler.h"
@ -188,6 +189,7 @@ void hack::InitHacks() {
ADD_HACK(Triggerbot); ADD_HACK(Triggerbot);
ADD_HACK(AutoSticky); ADD_HACK(AutoSticky);
ADD_HACK(Airstuck); ADD_HACK(Airstuck);
ADD_HACK(AutoHeal);
} }
void hack::Initialize() { void hack::Initialize() {

View File

@ -7,6 +7,102 @@
#include "AutoHeal.h" #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 <client_class.h>
#include <icliententity.h>
#include <icliententitylist.h>
#include <convar.h>
DEFINE_HACK_SINGLETON(AutoHeal); 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<int>(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<char>(ent, eoffsets.iLifeState)) return false;
if (g_pLocalPlayer->team != GetEntityValue<int>(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));
}

View File

@ -13,7 +13,14 @@
class AutoHeal : public IHack { class AutoHeal : public IHack {
public: public:
DECLARE_HACK_METHODS(); 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_bEnabled;
ConVar* v_bSilent;
}; };
DECLARE_HACK_SINGLETON(AutoHeal); DECLARE_HACK_SINGLETON(AutoHeal);