AntiBackstab

This commit is contained in:
nullifiedcat 2017-04-14 13:49:19 +03:00
parent 1c887af6f6
commit 0798698b9d
6 changed files with 132 additions and 0 deletions

107
src/hacks/AntiBackstab.cpp Normal file
View File

@ -0,0 +1,107 @@
/*
* AntiBackstab.cpp
*
* Created on: Apr 14, 2017
* Author: nullifiedcat
*/
#include "../common.h"
#include "../hack.h"
namespace hacks { namespace tf2 { namespace antibackstab {
static CatVar enabled(CV_SWITCH, "antibackstab", "0", "Enable");
static CatVar distance(CV_FLOAT, "antibackstab_distance", "200", "Distance");
static CatVar silent(CV_SWITCH, "antibackstab_silent", "1", "Silent");
static CatVar angle(CV_FLOAT, "antibackstab_angle", "150", "Detection Angle");
static CatVar sayno(CV_SWITCH, "antibackstab_nope", "0", "Nope!", "Memes (non-silent only)");
void SayNope() {
static float last_say = 0.0f;
if (g_GlobalVars->curtime < last_say) last_say = 0.0f;
if (g_GlobalVars->curtime - last_say < 1.5f) return;
hack::ExecuteCommand("voicemenu 0 7");
last_say = g_GlobalVars->curtime;
}
float GetAngle(CachedEntity* spy) {
const Vector& A = LOCAL_E->m_vecOrigin;
const Vector& B = spy->m_vecOrigin;
const float yaw = g_pLocalPlayer->v_OrigViewangles.y;
const Vector diff = (A - B);
float yaw2 = acos(diff.x / diff.Length()) * 180.0f / PI;
if (diff.y < 0) yaw2 = -yaw2;
float anglediff = yaw - yaw2;
if (anglediff > 180) anglediff -= 360;
if (anglediff < -180) anglediff += 360;
//logging::Info("Angle: %.2f | %.2f | %.2f | %.2f", yaw, yaw2, anglediff, yaw - yaw2);
return anglediff;
}
CachedEntity* ClosestSpy() {
CachedEntity* closest = nullptr;
float closest_dist = 0.0f;
for (int i = 1; i < 32 && i < g_IEntityList->GetHighestEntityIndex(); i++) {
CachedEntity* ent = ENTITY(i);
if (CE_BAD(ent)) continue;
if (CE_BYTE(ent, netvar.iLifeState)) continue;
if (CE_INT(ent, netvar.iClass) != tf_class::tf_spy) continue;
if (CE_INT(ent, netvar.iTeamNum) == g_pLocalPlayer->team) continue;
float dist = ent->m_flDistance;
if (fabs(GetAngle(ent)) > (float)angle) {
break;
//logging::Info("Backstab???");
}
if (dist < (float)distance && (dist < closest_dist || !closest_dist)) {
closest_dist = dist;
closest = ent;
}
}
return closest;
}
void CreateMove() {
if (!enabled) return;
CachedEntity* spy = ClosestSpy();
if (spy) {
const Vector& A = LOCAL_E->m_vecOrigin;
const Vector& B = spy->m_vecOrigin;
const Vector diff = (A - B);
float yaw2 = acos(diff.x / diff.Length()) * 180.0f / PI;
if (diff.y < 0) yaw2 = -yaw2;
if (yaw2 < -180) yaw2 += 360;
if (yaw2 > 180) yaw2 -= 360;
float resultangle = -180 + yaw2;
if (resultangle < -180) resultangle += 360;
g_pUserCmd->viewangles.y = resultangle;
if (silent) {
// This isn't a spy aimbot.
if (!(g_pUserCmd->buttons & IN_ATTACK))
g_pLocalPlayer->bUseSilentAngles = true;
}
if (sayno) SayNope();
}
}
void PaintTraverse() {
if (!enabled) return;
CachedEntity* spy = ClosestSpy();
if (!spy) return;
const Vector& A = LOCAL_E->m_vecOrigin;
const Vector& B = spy->m_vecOrigin;
const float yaw = g_pLocalPlayer->v_OrigViewangles.y;
const Vector diff = (A - B);
float yaw2 = acos(diff.x / diff.Length()) * 180.0f / PI;
if (diff.y < 0) yaw2 = -yaw2;
float anglediff = yaw - yaw2;
if (anglediff > 180) anglediff -= 360;
if (anglediff < -180) anglediff += 360;
AddSideString(format("closest: ", B.x, ' ', B.y, ' ', B.z));
AddSideString(format("yaw: ", yaw));
AddSideString(format("diff: ", diff.x, ' ', diff.y, ' ', diff.z));
AddSideString(format("yaw2: ", yaw2));
AddSideString(format("anglediff: ", anglediff));
}
}}}

View File

@ -0,0 +1,18 @@
/*
* AntiBackstab.hpp
*
* Created on: Apr 14, 2017
* Author: nullifiedcat
*/
#ifndef HACKS_ANTIBACKSTAB_HPP_
#define HACKS_ANTIBACKSTAB_HPP_
namespace hacks { namespace tf2 { namespace antibackstab {
void CreateMove();
void PaintTraverse();
}}}
#endif /* HACKS_ANTIBACKSTAB_HPP_ */

View File

@ -17,6 +17,7 @@
#include "AutoSticky.h"
#include "Bunnyhop.h"
#include "ESP.h"
#include "AntiBackstab.hpp"
#include "FollowBot.h"
#include "Misc.h"
#include "SpyAlert.h"

View File

@ -156,6 +156,7 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) {
//RunEnginePrediction(g_pLocalPlayer->entity, cmd);
SAFE_CALL(hacks::shared::esp::CreateMove());
if (!g_pLocalPlayer->life_state && CE_GOOD(g_pLocalPlayer->weapon())) {
if (TF2) SAFE_CALL(hacks::tf2::antibackstab::CreateMove());
if (TF2) SAFE_CALL(hacks::tf2::noisemaker::CreateMove());
SAFE_CALL(hacks::shared::bunnyhop::CreateMove());
SAFE_CALL(hacks::shared::aimbot::CreateMove());

View File

@ -101,6 +101,8 @@ void PaintTraverse_hook(void* p, unsigned int vp, bool fr, bool ar) {
if (!hacks::shared::airstuck::IsStuck()) {
if (CE_GOOD(g_pLocalPlayer->entity) && !g_Settings.bInvalid) {
// FIXME
//if (TF2) SAFE_CALL(hacks::tf2::antibackstab::PaintTraverse());
if (TF) SAFE_CALL(hacks::tf2::antidisguise::Draw());
SAFE_CALL(hacks::shared::misc::Draw());
SAFE_CALL(hacks::shared::esp::Draw());

View File

@ -97,6 +97,7 @@ void Shutdown_hook(void* thisptr, const char* reason) {
}
static CatVar glow_enabled(CV_SWITCH, "glow_enabled", "0", "Enable", "Make sure to enable glow_outline_effect_enable in tf2 settings");
static CatVar glow_alpha(CV_FLOAT, "glow_alpha", "1", "Alpha", "Glow Transparency", 0.0f, 1.0f);
void FrameStageNotify_hook(void* thisptr, int stage) {
SEGV_BEGIN;
@ -115,6 +116,8 @@ void FrameStageNotify_hook(void* thisptr, int stage) {
int color = GetEntityGlowColor(glowobject.m_hEntity.m_Index & 0xFFF);
if (color == 0) {
glowobject.m_flGlowAlpha = 0.0f;
} else {
glowobject.m_flGlowAlpha = (float)glow_alpha;
}
unsigned char _b = (color >> 16) & 0xFF;
unsigned char _g = (color >> 8) & 0xFF;