Backtrack Backstab

This commit is contained in:
TotallyNotElite 2018-12-14 23:57:44 +01:00
parent 30cec4f1b8
commit 1133565b1e

View File

@ -7,22 +7,28 @@
#include "common.hpp"
#include "PlayerTools.hpp"
#include "Trigger.hpp"
#include "Backtrack.hpp"
namespace hacks::tf2::autobackstab
{
static settings::Bool enabled("autobackstab.enabled", "false");
static settings::Int mode("autobackstab.mode", "0");
static bool angleCheck(CachedEntity *target, Vector localAngle)
static bool angleCheck(CachedEntity *target, std::optional<Vector> target_pos, Vector local_angle)
{
Vector tarAngle = CE_VECTOR(target, netvar.m_angEyeAngles);
Vector wsc_spy_to_victim = (target->m_vecOrigin() - LOCAL_E->m_vecOrigin());
wsc_spy_to_victim.z = 0;
Vector wsc_spy_to_victim;
if (target_pos)
wsc_spy_to_victim = *target_pos - LOCAL_E->m_vecOrigin();
else
wsc_spy_to_victim = target->m_vecOrigin() - LOCAL_E->m_vecOrigin();
wsc_spy_to_victim.z = 0;
wsc_spy_to_victim.NormalizeInPlace();
Vector eye_spy;
AngleVectors2(VectorToQAngle(localAngle), &eye_spy);
AngleVectors2(VectorToQAngle(local_angle), &eye_spy);
eye_spy.z = 0;
eye_spy.NormalizeInPlace();
@ -48,9 +54,10 @@ static void doLegitBackstab()
if (!trace.m_pEnt)
return;
int index = reinterpret_cast<IClientEntity *>(trace.m_pEnt)->entindex();
if (index == 0 || index > g_IEngine->GetMaxClients())
auto ent = ENTITY(index);
if (index == 0 || index > g_IEngine->GetMaxClients() || !ent->m_bEnemy() || player_tools::shouldTarget(ent) != player_tools::IgnoreReason::DO_NOT_IGNORE)
return;
if (angleCheck(ENTITY(index), g_pLocalPlayer->v_OrigViewangles))
if (angleCheck(ENTITY(index), std::nullopt, g_pLocalPlayer->v_OrigViewangles))
{
current_user_cmd->buttons |= IN_ATTACK;
}
@ -59,7 +66,7 @@ static void doLegitBackstab()
static void doRageBackstab()
{
float swingrange = re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W));
Vector newangle = g_pLocalPlayer->v_OrigViewangles;
Vector newangle = g_pLocalPlayer->v_OrigViewangles;
for (newangle.y = -180.0f; newangle.y < 180.0f; newangle.y += 10.0f)
{
@ -71,13 +78,13 @@ static void doRageBackstab()
if (trace.m_pEnt)
{
int index = reinterpret_cast<IClientEntity *>(trace.m_pEnt)->entindex();
logging::Info("Hit: %i");
if (index == 0 || index > g_IEngine->GetMaxClients())
auto ent = ENTITY(index);
if (index == 0 || index > g_IEngine->GetMaxClients() || !ent->m_bEnemy() || player_tools::shouldTarget(ent) != player_tools::IgnoreReason::DO_NOT_IGNORE)
continue;
if (angleCheck(ENTITY(index), newangle))
if (angleCheck(ent, std::nullopt, newangle))
{
current_user_cmd->buttons |= IN_ATTACK;
current_user_cmd->viewangles = newangle;
current_user_cmd->viewangles = newangle;
g_pLocalPlayer->bUseSilentAngles = true;
return;
}
@ -85,11 +92,43 @@ static void doRageBackstab()
}
}
static void doBacktrackStab()
{
float swingrange = re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W));
CachedEntity *ent;
try {
ent = ENTITY(hacks::shared::backtrack::iBestTarget);
} catch (std::out_of_range) {
return;
}
if (!ent->m_bEnemy() || player_tools::shouldTarget(ent) != player_tools::IgnoreReason::DO_NOT_IGNORE)
return;
auto &btd = hacks::shared::backtrack::headPositions[ent->m_IDX];
for (auto &i : btd)
{
if (!hacks::shared::backtrack::ValidTick(i, ent))
continue;
Vector angle = GetAimAtAngles(g_pLocalPlayer->v_Eye, i.hitboxes[spine_1].center);
if (!angleCheck(ent, i.entorigin, angle))
return;
Vector hit;
if (hacks::shared::triggerbot::CheckLineBox(i.collidable.min, i.collidable.max, g_pLocalPlayer->v_Eye, GetForwardVector(g_pLocalPlayer->v_Eye, angle, swingrange), hit))
{
current_user_cmd->tick_count = i.tickcount;
current_user_cmd->viewangles = angle;
current_user_cmd->buttons |= IN_ATTACK;
g_pLocalPlayer->bUseSilentAngles = true;
}
}
}
void CreateMove()
{
if (!enabled)
return;
if (CE_BAD(LOCAL_E) || g_pLocalPlayer->life_state || g_pLocalPlayer->clazz != tf_spy || CE_BAD(LOCAL_W) || GetWeaponMode() != weapon_melee)
if (CE_BAD(LOCAL_E) || g_pLocalPlayer->life_state || g_pLocalPlayer->clazz != tf_spy || CE_BAD(LOCAL_W) || GetWeaponMode() != weapon_melee || !CanShoot())
return;
switch (*mode)
{
@ -99,6 +138,9 @@ void CreateMove()
case 1:
doRageBackstab();
break;
case 2:
if (hacks::shared::backtrack::isBacktrackEnabled)
doBacktrackStab();
default:
break;
}