From d2f1a508a29b6d75b27e1f3383990843f8712d9f Mon Sep 17 00:00:00 2001 From: Unnamed Date: Sat, 26 Jan 2019 01:42:22 +0000 Subject: [PATCH] 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 --- include/PlayerTools.hpp | 4 ++-- src/PlayerTools.cpp | 29 ++++++++++++++--------------- src/hacks/Aimbot.cpp | 2 +- src/hacks/AntiCheat.cpp | 2 +- src/hacks/AutoBackstab.cpp | 6 +++--- src/hacks/AutoDetonator.cpp | 2 +- src/hacks/AutoSticky.cpp | 2 +- src/hacks/CatBot.cpp | 4 ++-- src/hacks/MiscAimbot.cpp | 2 +- src/hacks/NavBot.cpp | 6 +++--- src/hacks/Trigger.cpp | 2 +- src/hooks/GetFriendPersonaName.cpp | 2 +- 12 files changed, 31 insertions(+), 32 deletions(-) diff --git a/include/PlayerTools.hpp b/include/PlayerTools.hpp index 5bf8ff35..300d1cf0 100644 --- a/include/PlayerTools.hpp +++ b/include/PlayerTools.hpp @@ -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); diff --git a/src/PlayerTools.cpp b/src/PlayerTools.cpp index 5e083aea..85035ba8 100644 --- a/src/PlayerTools.cpp +++ b/src/PlayerTools.cpp @@ -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(entity)) - return IgnoreReason::IS_TAUNTING; + return false; if (HasCondition(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 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()) diff --git a/src/hacks/Aimbot.cpp b/src/hacks/Aimbot.cpp index 8d43eb6e..dfdb40ea 100644 --- a/src/hacks/Aimbot.cpp +++ b/src/hacks/Aimbot.cpp @@ -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; diff --git a/src/hacks/AntiCheat.cpp b/src/hacks/AntiCheat.cpp index cb1ac0c3..2cc634c1 100644 --- a/src/hacks/AntiCheat.cpp +++ b/src/hacks/AntiCheat.cpp @@ -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); diff --git a/src/hacks/AutoBackstab.cpp b/src/hacks/AutoBackstab.cpp index dc5f6829..bc8c504a 100644 --- a/src/hacks/AutoBackstab.cpp +++ b/src/hacks/AutoBackstab.cpp @@ -55,7 +55,7 @@ static void doLegitBackstab() return; int index = reinterpret_cast(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(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]; diff --git a/src/hacks/AutoDetonator.cpp b/src/hacks/AutoDetonator.cpp index 493d1639..7a073305 100644 --- a/src/hacks/AutoDetonator.cpp +++ b/src/hacks/AutoDetonator.cpp @@ -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()) { diff --git a/src/hacks/AutoSticky.cpp b/src/hacks/AutoSticky.cpp index 46361306..7b6ce039 100644 --- a/src/hacks/AutoSticky.cpp +++ b/src/hacks/AutoSticky.cpp @@ -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()) diff --git a/src/hacks/CatBot.cpp b/src/hacks/CatBot.cpp index 4acda81e..6061f381 100644 --- a/src/hacks/CatBot.cpp +++ b/src/hacks/CatBot.cpp @@ -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++) diff --git a/src/hacks/MiscAimbot.cpp b/src/hacks/MiscAimbot.cpp index ad8b6c14..fa8e19c8 100644 --- a/src/hacks/MiscAimbot.cpp +++ b/src/hacks/MiscAimbot.cpp @@ -34,7 +34,7 @@ std::pair 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) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index f7221215..f85891e5 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -123,7 +123,7 @@ static std::pair 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; diff --git a/src/hacks/Trigger.cpp b/src/hacks/Trigger.cpp index e7152256..490ef670 100644 --- a/src/hacks/Trigger.cpp +++ b/src/hacks/Trigger.cpp @@ -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()) diff --git a/src/hooks/GetFriendPersonaName.cpp b/src/hooks/GetFriendPersonaName.cpp index 13568981..6ff42249 100644 --- a/src/hooks/GetFriendPersonaName.cpp +++ b/src/hooks/GetFriendPersonaName.cpp @@ -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)