Skip to content
Permalink
Browse files

Autobackstab.cpp: Improve rage/low latency backtrack autobackstab

  • Loading branch information...
TotallyNotElite committed May 19, 2019
1 parent c5dca45 commit c97a2f02e4c8533d527c9319d34a86cb9c595441
Showing with 147 additions and 43 deletions.
  1. +2 −0 .gitignore
  2. +142 −40 src/hacks/AutoBackstab.cpp
  3. +3 −3 src/trace.cpp
@@ -288,3 +288,5 @@ scripts/updater-preferences
!/modules/CMakeLists.txt

scripts/partybypass-preferences

*.autosave
@@ -15,6 +15,41 @@ namespace hacks::tf2::autobackstab
static settings::Bool enabled("autobackstab.enabled", "false");
static settings::Int mode("autobackstab.mode", "0");

// Function to find the closest hitbox to the v_Eye for a given ent
int ClosestDistanceHitbox(CachedEntity *target)
{
int closest = -1;
float closest_dist = FLT_MAX, dist = 0.0f;
for (int i = pelvis; i < spine_3; i++)
{
auto hitbox = target->hitboxes.GetHitbox(i);
if (!hitbox)
continue;
dist = g_pLocalPlayer->v_Eye.DistTo(hitbox->center);
if (dist < closest_dist)
{
closest = i;
closest_dist = dist;
}
}
return closest;
}
int ClosestDistanceHitbox(hacks::shared::backtrack::BacktrackData btd)
{
int closest = -1;
float closest_dist = FLT_MAX, dist = 0.0f;
for (int i = pelvis; i < spine_3; i++)
{
dist = g_pLocalPlayer->v_Eye.DistTo(btd.hitboxes.at(i).center);
if (dist < closest_dist)
{
closest = i;
closest_dist = dist;
}
}
return closest;
}

bool angleCheck(CachedEntity *from, CachedEntity *to, std::optional<Vector> target_pos, Vector from_angle)
{
Vector tarAngle = CE_VECTOR(to, netvar.m_angEyeAngles);
@@ -77,67 +112,111 @@ static bool angleCheck(CachedEntity *target, std::optional<Vector> target_pos, V
return true;
}

static void doLegitBackstab()
static bool doLegitBackstab()
{
trace_t trace;
if (!re::C_TFWeaponBaseMelee::DoSwingTrace(RAW_ENT(LOCAL_W), &trace))
return;
return false;
if (!trace.m_pEnt)
return;
return false;
int index = reinterpret_cast<IClientEntity *>(trace.m_pEnt)->entindex();
auto ent = ENTITY(index);
if (index == 0 || index > g_IEngine->GetMaxClients() || !ent->m_bEnemy() || !player_tools::shouldTarget(ent))
return;
return false;
if (angleCheck(ENTITY(index), std::nullopt, g_pLocalPlayer->v_OrigViewangles))
{
current_user_cmd->buttons |= IN_ATTACK;
return true;
}
return false;
}

static void doRageBackstab()
static bool doRageBackstab()
{
if (doLegitBackstab())
return true;
float swingrange = re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W));
Vector newangle = g_pLocalPlayer->v_OrigViewangles;
std::vector<float> yangles;
for (newangle.y = -180.0f; newangle.y < 180.0f; newangle.y += 5.0f)
// AimAt Autobackstab
{
trace_t trace;
Ray_t ray;
trace::filter_default.SetSelf(RAW_ENT(g_pLocalPlayer->entity));
ray.Init(g_pLocalPlayer->v_Eye, GetForwardVector(g_pLocalPlayer->v_Eye, newangle, swingrange));
g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_default, &trace);
if (trace.m_pEnt)
for (int i = 1; i < g_IEngine->GetMaxClients(); i++)
{
int index = reinterpret_cast<IClientEntity *>(trace.m_pEnt)->entindex();
auto ent = ENTITY(index);
if (index == 0 || index > g_IEngine->GetMaxClients() || !ent->m_bEnemy() || !player_tools::shouldTarget(ent))
auto ent = ENTITY(i);
if (CE_BAD(ent) || ent->m_flDistance() > swingrange * 4 || !ent->m_bEnemy() || !ent->m_bAlivePlayer() || g_pLocalPlayer->entity_idx == ent->m_IDX)
continue;
if (angleCheck(ent, std::nullopt, newangle))

auto hitbox = ClosestDistanceHitbox(ent);
if (hitbox == -1)
continue;
auto angle = GetAimAtAngles(g_pLocalPlayer->v_Eye, ent->hitboxes.GetHitbox(hitbox)->center);
if (!angleCheck(ent, std::nullopt, angle))
continue;

trace_t trace;
Ray_t ray;
trace::filter_default.SetSelf(RAW_ENT(g_pLocalPlayer->entity));
ray.Init(g_pLocalPlayer->v_Eye, GetForwardVector(g_pLocalPlayer->v_Eye, angle, swingrange));
g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_default, &trace);
if (trace.m_pEnt)
{
yangles.push_back(newangle.y);
int index = reinterpret_cast<IClientEntity *>(trace.m_pEnt)->entindex();
if (index == ent->m_IDX)
{
current_user_cmd->buttons |= IN_ATTACK;
g_pLocalPlayer->bUseSilentAngles = true;
current_user_cmd->viewangles = angle;
*bSendPackets = true;
return true;
}
}
}
}
if (!yangles.empty())

// Rotating Autobackstab
{
newangle.y = yangles.at(std::floor((float) yangles.size() / 2));
current_user_cmd->buttons |= IN_ATTACK;
current_user_cmd->viewangles = newangle;
g_pLocalPlayer->bUseSilentAngles = true;
return;
Vector newangle = { 0, 0, g_pLocalPlayer->v_OrigViewangles.z };
std::vector<float> yangles;
for (newangle.y = -180.0f; newangle.y < 180.0f; newangle.y += 10.0f)
{
trace_t trace;
Ray_t ray;
trace::filter_default.SetSelf(RAW_ENT(g_pLocalPlayer->entity));
ray.Init(g_pLocalPlayer->v_Eye, GetForwardVector(g_pLocalPlayer->v_Eye, newangle, swingrange));
g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_default, &trace);
if (trace.m_pEnt)
{
int index = reinterpret_cast<IClientEntity *>(trace.m_pEnt)->entindex();
auto ent = ENTITY(index);
if (index == 0 || index > g_IEngine->GetMaxClients() || !ent->m_bEnemy() || !player_tools::shouldTarget(ent))
continue;
if (angleCheck(ent, std::nullopt, newangle))
{
yangles.push_back(newangle.y);
}
}
}
if (!yangles.empty())
{
newangle.y = yangles.at(std::floor((float) yangles.size() / 2));
current_user_cmd->buttons |= IN_ATTACK;
current_user_cmd->viewangles = newangle;
g_pLocalPlayer->bUseSilentAngles = true;
*bSendPackets = true;
return true;
}
}
return false;
}

static void doBacktrackStab()
static bool doBacktrackStab()
{
float swingrange = re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W));
CachedEntity *ent;
if (hacks::shared::backtrack::iBestTarget < 1)
return;
return false;
// Get the best ent decided by backtrack (no reason to do work twice)
ent = ENTITY(hacks::shared::backtrack::iBestTarget);
if (!ent->m_bEnemy() || !player_tools::shouldTarget(ent))
return;
return false;
// Get the ent's backtrack ticks
auto &btd = hacks::shared::backtrack::headPositions[ent->m_IDX];

@@ -153,7 +232,10 @@ static void doBacktrackStab()
if (distcheck.DistTo(g_pLocalPlayer->v_Eye) < 20.0f)
continue;
// Get and calculate an angle to use to backstab the ent
Vector newangle = GetAimAtAngles(g_pLocalPlayer->v_Eye, btp.hitboxes.at(spine_1).center);
auto hitbox = ClosestDistanceHitbox(btp);
if (hitbox == -1)
continue;
Vector newangle = GetAimAtAngles(g_pLocalPlayer->v_Eye, btp.hitboxes.at(hitbox).center);
if (!angleCheck(ent, btp.entorigin, newangle))
continue;
Vector &min = btp.collidable.min;
@@ -166,22 +248,23 @@ static void doBacktrackStab()
current_user_cmd->viewangles = newangle;
current_user_cmd->buttons |= IN_ATTACK;
g_pLocalPlayer->bUseSilentAngles = true;
if (!*bSendPackets)
*bSendPackets = true;
return;
*bSendPackets = true;
return true;
}
}
return false;
}

static void doLegitBacktrackStab() // lol
// TODO: Don't duplicate these loops
static bool doLegitBacktrackStab() // lol
{
float swingrange = re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W));
CachedEntity *ent;
if (hacks::shared::backtrack::iBestTarget < 1)
return;
return false;
ent = ENTITY(hacks::shared::backtrack::iBestTarget);
if (!ent->m_bEnemy() || !player_tools::shouldTarget(ent))
return;
return false;
auto &btd = hacks::shared::backtrack::headPositions[ent->m_IDX];
Vector newangle = g_pLocalPlayer->v_OrigViewangles;
std::vector<float> yangles;
@@ -237,9 +320,10 @@ static void doLegitBacktrackStab() // lol
current_user_cmd->viewangles = newangle;
current_user_cmd->buttons |= IN_ATTACK;
g_pLocalPlayer->bUseSilentAngles = true;
*bSendPackets = true;
return true;
}
if (!*bSendPackets)
*bSendPackets = true;
return false;
}

void CreateMove()
@@ -261,15 +345,33 @@ void CreateMove()
case 2:
if (hacks::shared::backtrack::isBacktrackEnabled)
{
doBacktrackStab();
break;
if (*hacks::shared::backtrack::latency <= 190 && doRageBackstab())
{
logging::Info("Ragebackstab");
break;
}
if (doBacktrackStab())
logging::Info("Backtrackstab");
}
else
{
doRageBackstab();
}
break;
case 3:
if (hacks::shared::backtrack::isBacktrackEnabled)
{
if (*hacks::shared::backtrack::latency <= 190 && doLegitBackstab())
break;
doLegitBacktrackStab();
break;
}
else
{
doLegitBackstab();
}
break;
default:
break;
}
}

@@ -42,9 +42,9 @@ bool trace::FilterDefault::ShouldHitEntity(IHandleEntity *handle, int mask)
switch (clazz->m_ClassID)
{
// TODO magic numbers: invisible entity ids
case 64:
case 225:
case 55:
case CL_CLASS(CFuncRespawnRoomVisualizer):
case CL_CLASS(CTFKnife):
case CL_CLASS(CFuncAreaPortalWindow):
return false;
}
/* Do not hit yourself. Idiot. */

0 comments on commit c97a2f0

Please sign in to comment.
You can’t perform that action at this time.