diff --git a/src/hacks/AutoBackstab.cpp b/src/hacks/AutoBackstab.cpp index abf91023..715443b5 100644 --- a/src/hacks/AutoBackstab.cpp +++ b/src/hacks/AutoBackstab.cpp @@ -13,9 +13,10 @@ namespace tf2 { namespace autobackstab { - + static CatVar enabled(CV_SWITCH, "autobackstab", "0", "Auto Backstab", "Does not depend on triggerbot!"); +bool found; // TODO improve void CreateMove() { @@ -31,36 +32,80 @@ void CreateMove() { g_pUserCmd->buttons |= IN_ATTACK; } - else if (HasCondition(LOCAL_E)) { - CachedEntity* ent; - for (int i; i < 32; i++) { - float scr = 0; - float scr_best = 0; - CachedEntity* pEnt = ENTITY(i); - if (!CE_GOOD(pEnt)) - continue; - if (!pEnt->m_Type == ENTITY_PLAYER) - continue; - if (pEnt == LOCAL_E) - continue; - if (LOCAL_E->m_iTeam == pEnt->m_iTeam) - continue; - scr = 4096.0f - - pEnt->m_vecOrigin.DistTo( - LOCAL_E->m_vecOrigin); - if (scr > scr_best) { - scr_best = scr; - ent = pEnt; - } - } - if (!CE_GOOD(ent)) + else if (HasCondition(LOCAL_E)) + { + found = false; + if (!CE_GOOD(LOCAL_E)) return; - if (CE_FLOAT(LOCAL_E, netvar.angEyeAngles + 4) + 35.0f >= CE_FLOAT(ent, netvar.angEyeAngles + 4) || CE_FLOAT(LOCAL_E, netvar.angEyeAngles + 4) - 35.0f <= CE_FLOAT(ent, netvar.angEyeAngles + 4)) - { - if (LOCAL_E->m_vecOrigin.DistTo(ent->m_vecOrigin) <= 67) { - g_pUserCmd->buttons |= IN_ATTACK; - } - } + CachedEntity *ent; + for (int i; i < 32; i++) + { + float scr = 0; + float scr_best = 0; + CachedEntity *pEnt = ENTITY(i); + if (!CE_GOOD(pEnt)) + continue; + if (!pEnt->m_bAlivePlayer) + continue; + if (!pEnt->m_Type == ENTITY_PLAYER) + continue; + if (pEnt == LOCAL_E) + continue; + if (LOCAL_E->m_iTeam == pEnt->m_iTeam) + continue; + scr = 4096.0f - pEnt->m_vecOrigin.DistTo(LOCAL_E->m_vecOrigin); + if (scr > scr_best) + { + scr_best = scr; + ent = pEnt; + found = true; + } + } + logging::Info("1"); + if (!found) + return; + logging::Info("2"); + if (!CE_GOOD(ent)) + return; + float ent_eye = CE_FLOAT(ent, netvar.m_angEyeAngles + 4); + float min = CE_FLOAT(LOCAL_E, netvar.m_angEyeAngles + 4) - 39.0f; + float min2; + if (min < 1.0f) + min2 = 360.0f - min; + float max = CE_FLOAT(LOCAL_E, netvar.m_angEyeAngles + 4) + 39.0f; + float max2; + if (max > 360.0f) + max2 = max - 360.0f; + logging::Info("%f %f %f", ent_eye, min, max); + if (min2 || max2) { + if (min2 && min2 > max) { + if (ent_eye >= max && ent_eye <= min2) { + if (LOCAL_E->m_vecOrigin.DistTo(ent->m_vecOrigin) <= 67) + g_pUserCmd->buttons |= IN_ATTACK; + } + } + else if (min2 && min2 < max) { + if (ent_eye >= min2 && ent_eye <= max) + if (LOCAL_E->m_vecOrigin.DistTo(ent->m_vecOrigin) <= 67) + g_pUserCmd->buttons |= IN_ATTACK; + } + else if (max2 && max2 < min) { + if (ent_eye >= max2 && ent_eye <= min) + if (LOCAL_E->m_vecOrigin.DistTo(ent->m_vecOrigin) <= 67) + g_pUserCmd->buttons |= IN_ATTACK; + } + else if (max && max2 > min) { + if (ent_eye >= min && ent_eye >= min) + if (LOCAL_E->m_vecOrigin.DistTo(ent->m_vecOrigin) <= 67) + g_pUserCmd->buttons |= IN_ATTACK; + } + + } + else if (ent_eye >= min && ent_eye <= max) + { + if (LOCAL_E->m_vecOrigin.DistTo(ent->m_vecOrigin) <= 67) + g_pUserCmd->buttons |= IN_ATTACK; + } } } }