WIP do not commit to newui k thx

This commit is contained in:
TotallyNotElite 2018-08-29 12:46:55 +02:00
parent 904eddf1b6
commit 460c2d752f

View File

@ -17,6 +17,20 @@ namespace hacks::tf2::autobackstab
namespace backtrack = hacks::shared::backtrack; namespace backtrack = hacks::shared::backtrack;
static settings::Bool enable{ "autobackstab.enable", "0" }; static settings::Bool enable{ "autobackstab.enable", "0" };
static settings::Bool silent{ "autobackstab.silent", "1" }; static settings::Bool silent{ "autobackstab.silent", "1" };
void testingFunc();
void AngleVectors2 (const QAngle &angles, Vector *forward)
{
float sp, sy, cp, cy;
SinCos( DEG2RAD( angles[YAW] ), &sy, &cy );
SinCos( DEG2RAD( angles[PITCH] ), &sp, &cp );
forward->x = cp*cy;
forward->y = cp*sy;
forward->z = -sp;
}
// Not required anymore, keeping for future reference // Not required anymore, keeping for future reference
Vector rotateVector(Vector center, float radianAngle, Vector p) Vector rotateVector(Vector center, float radianAngle, Vector p)
@ -114,6 +128,7 @@ bool unifiedCanBackstab(Vector &vecAngle, Vector min, Vector max,
void CreateMove() void CreateMove()
{ {
// testingFunc();
if (!enable) if (!enable)
return; return;
if (CE_BAD(LOCAL_E) || CE_BAD(LOCAL_W) || !LOCAL_E->m_bAlivePlayer()) if (CE_BAD(LOCAL_E) || CE_BAD(LOCAL_W) || !LOCAL_E->m_bAlivePlayer())
@ -264,41 +279,131 @@ const Vector GetWorldSpaceCenter(CachedEntity *ent)
vWorldSpaceCenter.z += (vMin.z + vMax.z) / 2; vWorldSpaceCenter.z += (vMin.z + vMax.z) / 2;
return vWorldSpaceCenter; return vWorldSpaceCenter;
} }
static bool InBackstabAngleRange = false;
static bool LookingAtVic = false;
static bool IsBehind = false;
void Draw() void Draw()
{ {
int idx = -1; // if (CE_BAD(LOCAL_E) || CE_BAD(LOCAL_W) || !LOCAL_E->m_bAlivePlayer())
Vector result{}; // return;
WhatIAmLookingAt(&idx, &result); // if (g_pLocalPlayer->weapon()->m_iClassID() != CL_CLASS(CTFKnife))
if (idx == -1) // return;
return; // CachedEntity *besttarget = nullptr;
CachedEntity *target = ENTITY(idx); // for (int i = 0; i < g_IEngine->GetMaxClients(); i++)
if (CE_BAD(target)) // {
return; // CachedEntity *target = ENTITY(i);
Vector angle = NET_VECTOR(RAW_ENT(LOCAL_E), netvar.m_angEyeAngles); // if (CE_BAD(target))
Vector tarAngle = NET_VECTOR(RAW_ENT(target), netvar.m_angEyeAngles); // continue;
Vector wsc_spy_to_victim = GetWorldSpaceCenter(target) - GetWorldSpaceCenter(LOCAL_E); // if (target == LOCAL_E || target->m_iTeam() ==
wsc_spy_to_victim.z = 0; // LOCAL_E->m_iTeam() ||
wsc_spy_to_victim.NormalizeInPlace(); // !target->m_bAlivePlayer() || target->m_Type() !=
// ENTITY_PLAYER) continue;
// if (target->m_vecOrigin().DistTo(
// g_pLocalPlayer->v_Eye) <= 200.0f)
// {
// if (CE_GOOD(besttarget))
// {
// if (besttarget->m_vecOrigin().DistTo(
// g_pLocalPlayer->v_Eye) <
// besttarget->m_vecOrigin().DistTo(
// g_pLocalPlayer->v_Eye))
// besttarget = target;
// }
// else
// {
// besttarget = target;
// }
// }
// }
Vector eye_spy = angle; // if (CE_BAD(besttarget))
eye_spy.z = 0; // return;
eye_spy.NormalizeInPlace(); // Vector angle = NET_VECTOR(RAW_ENT(LOCAL_E), netvar.m_angEyeAngles);
// Vector tarAngle = NET_VECTOR(RAW_ENT(besttarget),
// netvar.m_angEyeAngles);
Vector eye_victim = tarAngle; // //bool IsBehind = dot1 <= 0.0f;
eye_victim.z = 0; // bool LookingAtVic = GetFov(angle, g_pLocalPlayer->v_Eye,
eye_victim.NormalizeInPlace(); // GetWorldSpaceCenter(besttarget)) <= 60.0f; bool InBackstabAngleRange =
// fabsf(tarAngle.y - angle.y) <= 107.5f;
float dot1 = DotProduct(wsc_spy_to_victim, eye_victim);
float dot2 = DotProduct(wsc_spy_to_victim, eye_spy);
float dot3 = DotProduct(eye_spy, eye_victim);
bool IsBehind = dot1 <= 0.0f; // rgba_t col1 = IsBehind ? colors::green : colors::red;
bool LookingAtVic = dot2 <= 0.5f; // rgba_t col2 = LookingAtVic ? colors::green : colors::red;
bool InBackstabAngleRange = dot3 <= -0.3f; // rgba_t col3 = InBackstabAngleRange ? colors::green : colors::red;
rgba_t col1 = IsBehind ? colors::red : colors::green; // AddCenterString(format("Behind target" /*, dot1*/), col1);
rgba_t col2 = LookingAtVic ? colors::red : colors::green; // AddCenterString(format("Looking at Target" /*, dot2*/), col2);
rgba_t col3 = InBackstabAngleRange ? colors::red : colors::green; // AddCenterString(format("In Angle Range" /*, dot3*/), col3);
AddCenterString(format("Behind target: ", dot1), col1);
AddCenterString(format("Looking at Target: ", dot2), col2);
AddCenterString(format("In Angle Range: ", dot3), col3);
} }
void testingFunc()
{
if (CE_BAD(LOCAL_E) || CE_BAD(LOCAL_W) || !LOCAL_E->m_bAlivePlayer())
return;
if (g_pLocalPlayer->weapon()->m_iClassID() != CL_CLASS(CTFKnife))
return;
CachedEntity *besttarget = nullptr;
for (int i = 0; i < g_IEngine->GetMaxClients(); i++)
{
CachedEntity *target = ENTITY(i);
if (CE_BAD(target))
continue;
if (target == LOCAL_E || target->m_iTeam() == LOCAL_E->m_iTeam() ||
!target->m_bAlivePlayer() || target->m_Type() != ENTITY_PLAYER)
continue;
if (target->m_vecOrigin().DistTo(g_pLocalPlayer->v_Eye) <= 200.0f)
{
if (CE_GOOD(besttarget))
{
if (besttarget->m_vecOrigin().DistTo(g_pLocalPlayer->v_Eye) <
besttarget->m_vecOrigin().DistTo(g_pLocalPlayer->v_Eye))
besttarget = target;
}
else
{
besttarget = target;
}
}
}
if (CE_BAD(besttarget))
return;
Vector angle = NET_VECTOR(RAW_ENT(LOCAL_E), 4104);
Vector tarAngle = NET_VECTOR(RAW_ENT(besttarget), netvar.m_angEyeAngles);
logging::Info("Loc: %f; Tar: %f", angle.y, tarAngle.y);
float toclamp = tarAngle.y - angle.y;
while (toclamp > 180)
toclamp -= 360;
while (toclamp < -180)
toclamp += 360;
// Get the forward view vector of the target, ignore Z
Vector vecVictimForward;
AngleVectors2(VectorToQAngle(tarAngle), &vecVictimForward);
vecVictimForward.z = 0.0f;
vecVictimForward.NormalizeInPlace();
// Get a vector from my origin to my targets origin
Vector vecToTarget;
vecToTarget = GetWorldSpaceCenter(besttarget) - GetWorldSpaceCenter(LOCAL_E);
vecToTarget.z = 0.0f;
vecToTarget.NormalizeInPlace();
float dot = DotProduct(vecVictimForward, vecToTarget);
LookingAtVic = GetFov(angle, g_pLocalPlayer->v_Eye,
GetWorldSpaceCenter(besttarget)) <= 60.0f;
InBackstabAngleRange = fabsf(toclamp) <= 107.5f;
IsBehind = (dot > 0.0f);
logging::Info("Dot: %f", dot);
}
} // namespace hacks::tf2::autobackstab } // namespace hacks::tf2::autobackstab