Refactor shouldTarget{,SteamId}

Return true if we should target or false otherwise. Makes code shorter in a lot of places because value was tested only for DO_NOT_IGNORE
This commit is contained in:
Unnamed 2019-01-26 01:42:22 +00:00
parent 1b32f49da5
commit d2f1a508a2
12 changed files with 31 additions and 32 deletions

View File

@ -27,8 +27,8 @@ enum class IgnoreReason
OTHER
};
IgnoreReason shouldTargetSteamId(unsigned id);
IgnoreReason shouldTarget(CachedEntity *player);
bool shouldTargetSteamId(unsigned id);
bool shouldTarget(CachedEntity *player);
bool shouldAlwaysRenderEspSteamId(unsigned id);
bool shouldAlwaysRenderEsp(CachedEntity *entity);

View File

@ -29,20 +29,20 @@ static CatCommand forgive_all("pt_forgive_all", "Clear betrayal list", []() { be
namespace player_tools
{
IgnoreReason shouldTargetSteamId(unsigned id)
bool shouldTargetSteamId(unsigned id)
{
if (id == 0)
return IgnoreReason::DO_NOT_IGNORE;
return false;
if (betrayal_limit)
{
if (betrayal_list[id] > int(betrayal_limit))
return IgnoreReason::DO_NOT_IGNORE;
return false;
}
auto &pl = playerlist::AccessData(id);
if (playerlist::IsFriendly(pl.state) || (pl.state == playerlist::k_EState::CAT && *ignoreCathook))
return IgnoreReason::LOCAL_PLAYER_LIST;
return false;
#if ENABLE_ONLINE
auto *co = online::getUserData(id);
if (co)
@ -53,31 +53,31 @@ IgnoreReason shouldTargetSteamId(unsigned id)
if (check_verified && check_anonymous)
{
if (online_notarget && co->no_target)
return IgnoreReason::ONLINE_NO_TARGET;
return false;
if (online_friendly_software && co->is_using_friendly_software)
return IgnoreReason::ONLINE_FRIENDLY_SOFTWARE;
return false;
}
// Always check developer status, no exceptions
if (co->is_developer)
return IgnoreReason::DEVELOPER;
return false;
}
#endif
return IgnoreReason::DO_NOT_IGNORE;
return true;
}
IgnoreReason shouldTarget(CachedEntity *entity)
bool shouldTarget(CachedEntity *entity)
{
if (entity->m_Type() == ENTITY_PLAYER)
{
if (hoovy && IsHoovy(entity))
return IgnoreReason::IS_HOOVY;
return false;
if (taunting && HasCondition<TFCond_Taunting>(entity))
return IgnoreReason::IS_TAUNTING;
return false;
if (HasCondition<TFCond_HalloweenGhostMode>(entity))
return IgnoreReason::OTHER;
return false;
return shouldTargetSteamId(entity->player_info.friendsID);
}
return IgnoreReason::DO_NOT_IGNORE;
return true;
}
bool shouldAlwaysRenderEspSteamId(unsigned id)
@ -141,8 +141,7 @@ std::optional<colors::rgba_t> forceEspColor(CachedEntity *entity)
void onKilledBy(unsigned id)
{
auto reason = shouldTargetSteamId(id);
if (reason != IgnoreReason::DO_NOT_IGNORE)
if (shouldTargetSteamId(id))
{
// We ignored the gamer, but they still shot us
if (betrayal_list.find(id) == betrayal_list.end())

View File

@ -540,7 +540,7 @@ bool IsTargetStateGood(CachedEntity *entity)
}
// Some global checks
if (player_tools::shouldTarget(entity) != player_tools::IgnoreReason::DO_NOT_IGNORE)
if (!player_tools::shouldTarget(entity))
return false;
if (hacks::shared::catbot::should_ignore_player(entity))
return false;

View File

@ -61,7 +61,7 @@ void CreateMove()
{
if (ent->m_bAlivePlayer())
{
if (player_tools::shouldTarget(ent) == player_tools::IgnoreReason::DO_NOT_IGNORE || ent == LOCAL_E)
if (player_tools::shouldTarget(ent) || ent == LOCAL_E)
{
ac::aimbot::Update(ent);
ac::antiaim::Update(ent);

View File

@ -55,7 +55,7 @@ static void doLegitBackstab()
return;
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) != player_tools::IgnoreReason::DO_NOT_IGNORE)
if (index == 0 || index > g_IEngine->GetMaxClients() || !ent->m_bEnemy() || !player_tools::shouldTarget(ent))
return;
if (angleCheck(ENTITY(index), std::nullopt, g_pLocalPlayer->v_OrigViewangles))
{
@ -79,7 +79,7 @@ static void doRageBackstab()
{
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) != player_tools::IgnoreReason::DO_NOT_IGNORE)
if (index == 0 || index > g_IEngine->GetMaxClients() || !ent->m_bEnemy() || !player_tools::shouldTarget(ent))
continue;
if (angleCheck(ent, std::nullopt, newangle))
{
@ -104,7 +104,7 @@ static void doBacktrackStab()
{
return;
}
if (!ent->m_bEnemy() || player_tools::shouldTarget(ent) != player_tools::IgnoreReason::DO_NOT_IGNORE)
if (!ent->m_bEnemy() || !player_tools::shouldTarget(ent))
return;
auto &btd = hacks::shared::backtrack::headPositions[ent->m_IDX];

View File

@ -53,7 +53,7 @@ bool IsTarget(CachedEntity *ent)
return false;
// Global checks
if (player_tools::shouldTarget(ent) != player_tools::IgnoreReason::DO_NOT_IGNORE)
if (!player_tools::shouldTarget(ent))
return false;
IF_GAME(IsTF())
{

View File

@ -56,7 +56,7 @@ bool IsTarget(CachedEntity *ent)
return false;
// Global checks
if (player_tools::shouldTarget(ent) != player_tools::IgnoreReason::DO_NOT_IGNORE)
if (!player_tools::shouldTarget(ent))
return false;
IF_GAME(IsTF())

View File

@ -205,7 +205,7 @@ void reportall()
player_info_s info;
if (g_IEngine->GetPlayerInfo(i, &info))
{
if (player_tools::shouldTargetSteamId(info.friendsID) != player_tools::IgnoreReason::DO_NOT_IGNORE)
if (!player_tools::shouldTargetSteamId(info.friendsID))
continue;
CSteamID id(info.friendsID, EUniverse::k_EUniversePublic, EAccountType::k_EAccountTypeIndividual);
ReportPlayer_fn(id.ConvertToUint64(), 1);
@ -234,7 +234,7 @@ void smart_crouch()
for (int i = 0; i < g_IEngine->GetMaxClients(); i++)
{
auto ent = ENTITY(i);
if (CE_BAD(ent) || ent->m_Type() != ENTITY_PLAYER || ent->m_iTeam() == LOCAL_E->m_iTeam() || !(ent->hitboxes.GetHitbox(0)) || !(ent->m_bAlivePlayer()) || player_tools::shouldTarget(ent) != player_tools::IgnoreReason::DO_NOT_IGNORE || should_ignore_player(ent))
if (CE_BAD(ent) || ent->m_Type() != ENTITY_PLAYER || ent->m_iTeam() == LOCAL_E->m_iTeam() || !(ent->hitboxes.GetHitbox(0)) || !(ent->m_bAlivePlayer()) || !player_tools::shouldTarget(ent) || should_ignore_player(ent))
continue;
bool failedvis = false;
for (int j = 0; j < 18; j++)

View File

@ -34,7 +34,7 @@ std::pair<CachedEntity *, Vector> FindBestEnt(bool teammate, bool Predict, bool
continue;
if (!ent->hitboxes.GetHitbox(1))
continue;
if (!teammate && player_tools::shouldTarget(ent) != player_tools::IgnoreReason::DO_NOT_IGNORE)
if (!teammate && !player_tools::shouldTarget(ent))
continue;
Vector target{};
if (Predict)

View File

@ -123,7 +123,7 @@ static std::pair<CachedEntity *, float> getNearestPlayerDistance()
for (int i = 1; i < g_IEngine->GetMaxClients(); i++)
{
CachedEntity *ent = ENTITY(i);
if (CE_GOOD(ent) && ent->m_bAlivePlayer() && ent->m_bEnemy() && g_pLocalPlayer->v_Origin.DistTo(ent->m_vecOrigin()) < distance && player_tools::shouldTarget(ent) == player_tools::IgnoreReason::DO_NOT_IGNORE && (!hacks::shared::aimbot::ignore_cloak || !IsPlayerInvisible(ent)) && VisCheckEntFromEnt(LOCAL_E, ent))
if (CE_GOOD(ent) && ent->m_bAlivePlayer() && ent->m_bEnemy() && g_pLocalPlayer->v_Origin.DistTo(ent->m_vecOrigin()) < distance && player_tools::shouldTarget(ent) && (!hacks::shared::aimbot::ignore_cloak || !IsPlayerInvisible(ent)) && VisCheckEntFromEnt(LOCAL_E, ent))
{
distance = g_pLocalPlayer->v_Origin.DistTo(ent->m_vecOrigin());
best_ent = ent;
@ -209,7 +209,7 @@ static bool stayNearPlayers(const bot_class_config &config, CachedEntity *&resul
for (int i = 1; i < g_IEngine->GetMaxClients(); i++)
{
CachedEntity *ent = ENTITY(i);
if (CE_BAD(ent) || !ent->m_bAlivePlayer() || !ent->m_bEnemy() || player_tools::shouldTarget(ent) != player_tools::IgnoreReason::DO_NOT_IGNORE || (hacks::shared::aimbot::ignore_cloak && IsPlayerInvisible(ent)))
if (CE_BAD(ent) || !ent->m_bAlivePlayer() || !ent->m_bEnemy() || !player_tools::shouldTarget(ent) || (hacks::shared::aimbot::ignore_cloak && IsPlayerInvisible(ent)))
continue;
players.push_back(ent);
}
@ -267,7 +267,7 @@ static bool stayNear()
if (CE_GOOD(last_target) && stayNearHelpers::isValidNearPosition(last_area->m_center, last_target->m_vecOrigin(), *config))
invalid_area_time.update();
if (CE_GOOD(last_target) && (!last_target->m_bAlivePlayer() || !last_target->m_bEnemy() || player_tools::shouldTarget(last_target) != player_tools::IgnoreReason::DO_NOT_IGNORE || (hacks::shared::aimbot::ignore_cloak && IsPlayerInvisible(last_target))))
if (CE_GOOD(last_target) && (!last_target->m_bAlivePlayer() || !last_target->m_bEnemy() || !player_tools::shouldTarget(last_target) || (hacks::shared::aimbot::ignore_cloak && IsPlayerInvisible(last_target))))
{
nav::clearInstructions();
current_task = task::none;

View File

@ -242,7 +242,7 @@ bool IsTargetStateGood(CachedEntity *entity, bool backtrack)
return false;
// Global checks
if (player_tools::shouldTarget(entity) != player_tools::IgnoreReason::DO_NOT_IGNORE)
if (!player_tools::shouldTarget(entity))
return false;
IF_GAME(IsTF())

View File

@ -56,7 +56,7 @@ bool StolenName()
if (std::strlen(info.name) >= 31)
continue;
// Ignore Friendly
if (player_tools::shouldTargetSteamId(info.friendsID) != player_tools::IgnoreReason::DO_NOT_IGNORE)
if (!player_tools::shouldTargetSteamId(info.friendsID))
continue;
// If our name is the same as current, then change it
if (stolen_name == info.name && *namesteal == 1)