diff --git a/include/hacks/FollowBot.hpp b/include/hacks/FollowBot.hpp index 60b0d445..f907f7fe 100644 --- a/include/hacks/FollowBot.hpp +++ b/include/hacks/FollowBot.hpp @@ -13,5 +13,6 @@ namespace hacks::shared::followbot int ClassPriority(CachedEntity *ent); bool isEnabled(); +bool isIdle(); extern int follow_target; } // namespace hacks::shared::followbot diff --git a/src/hacks/Aimbot.cpp b/src/hacks/Aimbot.cpp index 5dfbec7e..c1214db0 100644 --- a/src/hacks/Aimbot.cpp +++ b/src/hacks/Aimbot.cpp @@ -16,6 +16,7 @@ #include "MiscTemporary.hpp" #include #include "hitrate.hpp" +#include "FollowBot.hpp" #if ENABLE_VISUALS #ifndef FEATURE_EFFECTS_DISABLED @@ -112,6 +113,41 @@ static bool CarryingHeatmaker() return CE_INT(LOCAL_W, netvar.iItemDefinitionIndex) == 752; } +static void doAutoZoom(bool target_found) +{ + bool isIdle = target_found ? false : hacks::shared::followbot::isIdle(); + + // Keep track of our zoom time + static Timer zoomTime{}; + + // Minigun spun up handler + if (auto_spin_up && g_pLocalPlayer->weapon()->m_iClassID() == CL_CLASS(CTFMinigun)) + { + if (target_found) + zoomTime.update(); + if (isIdle || !zoomTime.check(5000)) + { + current_user_cmd->buttons |= IN_ATTACK2; + } + return; + } + + if (auto_zoom && g_pLocalPlayer->holding_sniper_rifle && (target_found || isIdle)) + { + if (target_found) + zoomTime.update(); + if (not g_pLocalPlayer->bZoomed) + current_user_cmd->buttons |= IN_ATTACK2; + } + else if (!target_found) + { + // Auto-Unzoom + if (auto_unzoom) + if (g_pLocalPlayer->holding_sniper_rifle && g_pLocalPlayer->bZoomed && zoomTime.check(3000)) + current_user_cmd->buttons |= IN_ATTACK2; + } +} + // Current Entity int target_eid{ 0 }; CachedEntity *target = 0; @@ -124,8 +160,6 @@ float cur_proj_grav{ 0.0f }; // If slow aimbot allows autoshoot bool slow_can_shoot = false; bool projectileAimbotRequired; -// Keep track of our zoom time -Timer zoomTime{}; // Track Backtrack tick for Entity static std::pair good_tick = { -1, -1 }; @@ -139,14 +173,8 @@ static void CreateMove() return; if (CE_BAD(LOCAL_E) || !LOCAL_E->m_bAlivePlayer() || CE_BAD(LOCAL_W)) return; - // Auto-Unzoom - if (auto_unzoom) - if (g_pLocalPlayer->holding_sniper_rifle && g_pLocalPlayer->bZoomed && zoomTime.test_and_set(3000)) - current_user_cmd->buttons |= IN_ATTACK2; - if (g_pLocalPlayer->weapon()->m_iClassID() == CL_CLASS(CTFMinigun)) - if (auto_spin_up && CE_INT(LOCAL_E, netvar.m_iAmmo + 4) != 0 && !zoomTime.check(1000)) - current_user_cmd->buttons |= IN_ATTACK2; + doAutoZoom(false); if (LOCAL_W->m_iClassID() == CL_CLASS(CTFMinigun) && CE_INT(LOCAL_E, netvar.m_iAmmo + 4) == 0) return; @@ -178,41 +206,16 @@ static void CreateMove() CachedEntity *target_entity = RetrieveBestTarget(aimkey_status); if (CE_BAD(target_entity) || !foundTarget) return; + // Auto-zoom - IF_GAME(IsTF()) - { - if (auto_zoom) - { - if (g_pLocalPlayer->holding_sniper_rifle) - { - zoomTime.update(); - if (not g_pLocalPlayer->bZoomed) - current_user_cmd->buttons |= IN_ATTACK2; - } - } - } + doAutoZoom(true); + // If zoomed only is on, check if zoomed if (zoomed_only && g_pLocalPlayer->holding_sniper_rifle) { if (!g_pLocalPlayer->bZoomed && !(current_user_cmd->buttons & IN_ATTACK)) return; } - // Minigun spun up handler - if (g_pLocalPlayer->weapon()->m_iClassID() == CL_CLASS(CTFMinigun)) - { - int weapon_state = CE_INT(g_pLocalPlayer->weapon(), netvar.iWeaponState); - // If user setting for autospin isnt true, then we check if minigun - // is already zoomed - if ((weapon_state == MinigunState_t::AC_STATE_IDLE || weapon_state == MinigunState_t::AC_STATE_STARTFIRING) && !auto_spin_up) - return; - if (auto_spin_up) - { - zoomTime.update(); - current_user_cmd->buttons |= IN_ATTACK2; - } - if (!(current_user_cmd->buttons & (IN_ATTACK2 | IN_ATTACK))) - return; - } if (!g_IEntityList->GetClientEntity(target_entity->m_IDX)) return; if (!target_entity->hitboxes.GetHitbox(calculated_data_array[target_entity->m_IDX].hitbox)) diff --git a/src/hacks/FollowBot.cpp b/src/hacks/FollowBot.cpp index cfe52470..b6392c4d 100644 --- a/src/hacks/FollowBot.cpp +++ b/src/hacks/FollowBot.cpp @@ -35,6 +35,7 @@ static settings::Boolean corneractivate{ "follow-bot.corners", "true" }; static settings::Int steam_var{ "follow-bot.steamid", "0" }; static settings::Boolean ignore_textmode{ "follow-bot.ignore-textmode", "true" }; static settings::Boolean mimic_crouch{ "follow-bot.mimic-crouch", "true" }; +static settings::Boolean autozoom_if_idle{ "follow-bot.autozoom-if-idle", "true" }; namespace nb = hacks::tf2::NavBot; @@ -83,6 +84,30 @@ static Timer lastJump{}; static Timer crouch_timer{}; // Mimic crouch static std::array afkTicks; // for how many ms the player hasn't been moving +bool isIdle() +{ + if (!enable || !autozoom_if_idle || !follow_target) + return false; + float follow_dist = *follow_distance; +#if ENABLE_IPC + if (ipc::peer) + follow_dist += *additional_distance * ipc::peer->client_id; +#endif + + auto target = ENTITY(follow_target); + if (CE_BAD(target)) + return false; + auto tar_orig = target->m_vecOrigin(); + auto loc_orig = LOCAL_E->m_vecOrigin(); + float dist_to_target = loc_orig.DistTo(tar_orig); + + // If we are zoomed, we should stop zooming a bit later to avoid zooming in again in a few CMs + float multiplier = (g_pLocalPlayer->holding_sniper_rifle && g_pLocalPlayer->bZoomed) ? 1.05f : 0.95f; + follow_dist = std::clamp(follow_dist * 1.5f * multiplier, 200.0f * multiplier, std::max(500.0f * multiplier, follow_dist)); + + return dist_to_target <= follow_dist; +} + static void checkAFK() { for (int i = 1; i < g_GlobalVars->maxClients; i++) @@ -598,12 +623,12 @@ static void cm() // Follow the crumbs when too far away, or just starting to follow #if ENABLE_IPC - float follow_dist = (float) follow_distance; + float follow_dist = *follow_distance; if (ipc::peer) - follow_dist += (float) additional_distance * ipc::peer->client_id; + follow_dist += *additional_distance * ipc::peer->client_id; if (dist_to_target > follow_dist) #else - if (dist_to_target > (float) follow_distance) + if (dist_to_target > *follow_distance) #endif { // Check for jump diff --git a/src/hooks/SendNetMsg.cpp b/src/hooks/SendNetMsg.cpp index f56f550b..abc44ee8 100644 --- a/src/hooks/SendNetMsg.cpp +++ b/src/hooks/SendNetMsg.cpp @@ -62,8 +62,6 @@ std::vector Iterate(KeyValues *event, int depth) void ProcessAchievement(IGameEvent *ach) { - if (CE_BAD(LOCAL_E)) - return; int player_idx = ach->GetInt("player", 0xDEAD); int achievement = ach->GetInt("achievement", 0xDEAD); if (player_idx != 0xDEAD && (achievement == CAT_IDENTIFY || achievement == CAT_REPLY)) @@ -173,8 +171,8 @@ static InitRoutine run_identify([]() { sendIdentifyMessage(true); queue_ca8 = false; } - // 5 minutes between each identify seems ok? - if (!*identify || CE_BAD(LOCAL_E) || !identify_timer.test_and_set(1000 * 60 * 5)) + // 2 minutes between each identify seems ok? + if (!*identify || CE_BAD(LOCAL_E) || !identify_timer.test_and_set(1000 * 60 * 2)) return; sendIdentifyMessage(false); },