From 6758f019d2a07f972e8a8beb4668aa49ca37e48b Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 19 Aug 2018 23:35:02 +0200 Subject: [PATCH 01/43] Last ouf (for now) --- src/hooks/LevelInit.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/hooks/LevelInit.cpp b/src/hooks/LevelInit.cpp index 978b7a01..ba5b3b74 100644 --- a/src/hooks/LevelInit.cpp +++ b/src/hooks/LevelInit.cpp @@ -11,9 +11,6 @@ #include "HookedMethods.hpp" #include "MiscTemporary.hpp" #include "navparser.hpp" -#if !LAGBOT_MODE -#include "hacks/Backtrack.hpp" -#endif static settings::Bool halloween_mode{ "misc.force-halloween", "false" }; static settings::Int skybox_changer{ "misc.skybox-override", "0" }; From 074b75079f05642689394995ce181ee93cdca6e4 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Mon, 20 Aug 2018 13:15:45 +0200 Subject: [PATCH 02/43] Threading support tf Fixes lags with navbot init --- include/navparser.hpp | 1 + src/navparser.cpp | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/navparser.hpp b/include/navparser.hpp index 1cbbc524..aa89c629 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -3,6 +3,7 @@ #include "common.hpp" #include "micropather.h" #include "pwd.h" +#include #if ENABLE_VISUALS #include #endif diff --git a/src/navparser.cpp b/src/navparser.cpp index 19b5d0d9..a1c433db 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -11,6 +11,7 @@ bool ReadyForCommands = false; inactivityTracker inactiveTracker; static settings::Bool enabled{ "misc.pathing", "true" }; static settings::Bool draw{ "misc.pathing.draw", "false" }; +static bool threadingFinished = false; // Todo fix size_t FindInVector(size_t id) @@ -161,7 +162,9 @@ void Init() // Initiate "Map", contains micropather object TF2MAP = std::make_unique(size); } - pathfinding = true; + if (!areas.empty()) + pathfinding = true; + threadingFinished = true; } static std::string lastmap; @@ -181,10 +184,12 @@ bool Prepare() lastmap = g_IEngine->GetLevelName(); pathfinding = false; init = true; - Init(); + threadingFinished = false; + std::thread initer(Init); + initer.detach(); } } - if (!pathfinding) + if (!pathfinding || !threadingFinished) return false; return true; } @@ -345,7 +350,7 @@ void clearIgnores() // Main movement function, gets path from NavTo void CreateMove() { - if (!enabled) + if (!enabled || !threadingFinished) return; if (CE_BAD(LOCAL_E)) return; From 9cb761abbe0862ac9b2c0e1036f720faacce5f37 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Mon, 20 Aug 2018 15:18:55 +0200 Subject: [PATCH 03/43] Fix small issues --- src/navparser.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/navparser.cpp b/src/navparser.cpp index a1c433db..8c6c5fad 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -211,7 +211,7 @@ int findClosestNavSquare(Vector vec) // Make sure we're not stuck on the same area for too long if (std::count(findClosestNavSquare_localAreas.begin(), findClosestNavSquare_localAreas.end(), i) < 3) - overlapping.push_back({ i, &areas.at(i) }); + overlapping.emplace_back( i, &areas.at(i) ); } } @@ -267,7 +267,7 @@ std::vector findPath(Vector loc, Vector dest, int &id_loc, int &id_dest) int result = TF2MAP->pather->Solve(static_cast(&areas.at(id_loc)), static_cast(&areas.at(id_dest)), &pathNodes, &cost); - logging::Info(format(result).c_str()); + logging::Info(format("Pathing: Pather result: ", result).c_str()); // If no result found, return empty Vector if (result == micropather::MicroPather::NO_SOLUTION) return std::vector(0); @@ -321,7 +321,8 @@ bool NavTo(Vector dest, bool navToLocalCenter, bool persistent, } crumbs.clear(); crumbs = std::move(path); - if (!navToLocalCenter) + lastArea = crumbs.at(0); + if (!navToLocalCenter && crumbs.size() > 1) crumbs.erase(crumbs.begin()); ensureArrival = persistent; findClosestNavSquare_localAreas.clear(); @@ -489,4 +490,15 @@ CatCommand navpath("nav_path", "Debug nav path", [](const CCommand &args) { } }); +CatCommand navpathnolocal("nav_path_nolocal", "Debug nav path", [](const CCommand &args) { + if (NavTo(loc, false, true, 50 + priority)) + { + logging::Info("Pathing: Success! Walking to path..."); + } + else + { + logging::Info("Pathing: Failed!"); + } +}); + } // namespace nav From e8f9133764354e5bedb2c70fd05ce6babecc4ae7 Mon Sep 17 00:00:00 2001 From: LightCat Date: Mon, 20 Aug 2018 15:53:38 +0200 Subject: [PATCH 04/43] NavBot fixes! --- src/hacks/NavBot.cpp | 71 +++++++++++++++++++++++++++++-------------- src/hacks/Trigger.cpp | 5 +-- src/navparser.cpp | 2 +- 3 files changed, 52 insertions(+), 26 deletions(-) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 78792fdd..7a642aaa 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -1,6 +1,7 @@ // // Created by bencat07 on 17.08.18. // +#include #include "common.hpp" #include "navparser.hpp" #include "FollowBot.hpp" @@ -120,30 +121,38 @@ CachedEntity *nearestAmmo() } return bestent; } +int last_tar = -1; CachedEntity *NearestEnemy() { - float bestscr = FLT_MAX; - CachedEntity *bestent = nullptr; - for (int i = 0; i < g_IEngine->GetMaxClients(); i++) - { - CachedEntity *ent = ENTITY(i); - if (CE_BAD(ent) || ent->m_Type() != ENTITY_PLAYER) - continue; - if (ent == LOCAL_E || !ent->m_bAlivePlayer() || - ent->m_iTeam() == LOCAL_E->m_iTeam()) - continue; - float scr = ent->m_flDistance(); - if (g_pPlayerResource->GetClass(ent) == tf_engineer) - scr *= 5.0f; - if (g_pPlayerResource->GetClass(ent) == tf_pyro) - scr *= 7.0f; - if (scr < bestscr) - { - bestscr = scr; - bestent = ent; + if (last_tar == -1 || nav::ReadyForCommands) { + float bestscr = FLT_MAX; + CachedEntity *bestent = nullptr; + for (int i = 0; i < g_IEngine->GetMaxClients(); i++) { + CachedEntity *ent = ENTITY(i); + if (CE_BAD(ent) || ent->m_Type() != ENTITY_PLAYER) + continue; + if (ent == LOCAL_E || !ent->m_bAlivePlayer() || + ent->m_iTeam() == LOCAL_E->m_iTeam()) + continue; + float scr = ent->m_flDistance(); + if (g_pPlayerResource->GetClass(ent) == tf_engineer) + scr *= 5.0f; + if (g_pPlayerResource->GetClass(ent) == tf_pyro) + scr *= 7.0f; + if (scr < bestscr) { + bestscr = scr; + bestent = ent; + } } + if (!bestent) + last_tar = -1; + else + last_tar = bestent->m_IDX; + return bestent; } - return bestent; + if (CE_GOOD(ENTITY(last_tar))) + return ENTITY(last_tar); + return nullptr; } Timer cdr{}; Timer cd2{}; @@ -215,6 +224,8 @@ void CreateMove() nav::NavTo(ammo->m_vecOrigin(), true, true, 6); } } + if ((!HasLowHealth() && nav::priority == 7) || (!HasLowAmmo() && nav::priority == 6)) + nav::clearInstructions(); if (enable) { if (!nav::ReadyForCommands && !spy_mode && !heavy_mode) @@ -236,10 +247,10 @@ void CreateMove() if (random_spot.z) nav::NavTo(random_spot, true, true); } - else if (cdr.check(5000)) + else { CachedEntity *tar = NearestEnemy(); - if (CE_BAD(tar)) + if (CE_BAD(tar) && last_tar == -1 && nav::ReadyForCommands) { Vector random_spot; if (cd2.test_and_set(5000)) @@ -252,7 +263,21 @@ void CreateMove() nav::NavTo(random_spot, false); return; } - nav::NavTo(tar->m_vecOrigin(), false); + if (CE_GOOD(tar)) + { + if (!spy_mode || !hacks::shared::backtrack::isBacktrackEnabled) + nav::NavTo(tar->m_vecOrigin(), false); + else + { + for (auto i : hacks::shared::backtrack::headPositions[tar->m_IDX]) + { + if (!hacks::shared::backtrack::ValidTick(i, tar)) + continue; + nav::NavTo(i.entorigin, false, false); + break; + } + } + } } } } diff --git a/src/hacks/Trigger.cpp b/src/hacks/Trigger.cpp index fe7c254c..be9bfe3e 100644 --- a/src/hacks/Trigger.cpp +++ b/src/hacks/Trigger.cpp @@ -115,8 +115,9 @@ void CreateMove() CachedEntity *ent = FindEntInSight(EffectiveTargetingRange()); // Check if can backtrack, shoot if we can - if (!CanBacktrack() || hacks::shared::backtrack::isBacktrackEnabled) - return; + if (hacks::shared::backtrack::isBacktrackEnabled) + if (!CanBacktrack()) + return; // Check if dormant or null to prevent crashes if (CE_BAD(ent)) diff --git a/src/navparser.cpp b/src/navparser.cpp index 8c6c5fad..758f5058 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -437,7 +437,7 @@ void Draw() draw::WorldToScreen(crumbs[i + 1], wts2)) { glez::draw::line(wts1.x, wts1.y, wts2.x - wts1.x, wts2.y - wts1.y, - colors::white, 0.1f); + colors::white, 0.3f); } } Vector wts; From f2f58403a9628b65065c5e92812a25555c7047f1 Mon Sep 17 00:00:00 2001 From: LightCat Date: Mon, 20 Aug 2018 21:44:01 +0200 Subject: [PATCH 05/43] Engie mode --- build_names | 1 - data/menu/nullifiedcat/catbot.xml | 1 + include/core/netvars.hpp | 1 + src/core/netvars.cpp | 2 + src/hacks/NavBot.cpp | 230 +++++++++++++++++++++++++++--- 5 files changed, 217 insertions(+), 18 deletions(-) diff --git a/build_names b/build_names index 04cd2951..5e199666 100755 --- a/build_names +++ b/build_names @@ -23,4 +23,3 @@ libtinfo.so.5.9.4.2 libudev.so.1.6.6.4.7 libwrap.so.0.7.6.1.5 libz.so.1.2.1.1.2.4 - diff --git a/data/menu/nullifiedcat/catbot.xml b/data/menu/nullifiedcat/catbot.xml index a8e78ecf..9ecace83 100755 --- a/data/menu/nullifiedcat/catbot.xml +++ b/data/menu/nullifiedcat/catbot.xml @@ -61,6 +61,7 @@ + diff --git a/include/core/netvars.hpp b/include/core/netvars.hpp index cee7796b..bf3170fc 100755 --- a/include/core/netvars.hpp +++ b/include/core/netvars.hpp @@ -63,6 +63,7 @@ public: offset_t hActiveWeapon; offset_t flChargedDamage; offset_t iUpgradeLevel; + offset_t m_hBuilder; offset_t iPipeType; offset_t iBuildingHealth; offset_t iBuildingMaxHealth; diff --git a/src/core/netvars.cpp b/src/core/netvars.cpp index 9ac29553..d94f25b9 100644 --- a/src/core/netvars.cpp +++ b/src/core/netvars.cpp @@ -120,6 +120,8 @@ void NetVars::Init() "DT_TFSniperRifle", "SniperRifleLocalData", "m_flChargedDamage"); this->iUpgradeLevel = gNetvars.get_offset("DT_BaseObject", "m_iUpgradeLevel"); + this->m_hBuilder = + gNetvars.get_offset("DT_BaseObject", "m_hBuilder"); this->iPipeType = gNetvars.get_offset("DT_TFProjectile_Pipebomb", "m_iType"); this->iBuildingHealth = diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 7a642aaa..46a22fc5 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -12,6 +12,7 @@ namespace hacks::tf2::NavBot static settings::Bool enable("navbot.enable", "false"); static settings::Bool spy_mode("navbot.spy-mode", "false"); static settings::Bool heavy_mode("navbot.heavy-mode", "false"); +static settings::Bool engi_mode("navbot.engi-mode", "false"); static settings::Bool primary_only("navbot.primary-only", "true"); static settings::Bool enable_fb{ "navbot.medbot", "false" }; @@ -157,16 +158,27 @@ CachedEntity *NearestEnemy() Timer cdr{}; Timer cd2{}; Timer cd3{}; +Timer engi_spot_cd{}; +std::vector preferred_sniper_spots; std::vector sniper_spots; +std::vector nest_spots; void Init() { sniper_spots.clear(); + preferred_sniper_spots.clear(); + nest_spots.clear(); for (auto area : nav::areas) + { + if (area.m_attributeFlags & NAV_MESH_NO_HOSTAGES) + preferred_sniper_spots.push_back(area.m_center); + if (area.m_attributeFlags & NAV_MESH_RUN) + nest_spots.push_back(area.m_center); for (auto hide : area.m_hidingSpots) if (hide.IsGoodSniperSpot() || hide.IsIdealSniperSpot() || hide.IsExposed()) sniper_spots.push_back(hide.m_pos); - logging::Info("%d", sniper_spots.size()); + } + logging::Info("Sniper spots: %d, Manual Sniper Spots: %d, Sentry Spots: %d", sniper_spots.size(), preferred_sniper_spots.size(), nest_spots.size()); } void initonce() { @@ -175,6 +187,7 @@ void initonce() cdr.update(); cd2.update(); cd3.update(); + engi_spot_cd.update(); return; } @@ -191,7 +204,7 @@ void UpdateSlot() { int slot = re::C_BaseCombatWeapon::GetSlot(weapon); int newslot = 1; - if (spy_mode) + if (spy_mode || engi_mode) newslot = 3; if (slot != newslot - 1) g_IEngine->ClientCmd_Unrestricted( @@ -199,6 +212,76 @@ void UpdateSlot() } } } +enum BuildingNum +{ + DISPENSER = 0, + TELEPORT_ENT, + SENTRY, + TELEPORT_EXT, +}; +std::vector GetBuildings() + { + float bestscr = FLT_MAX; + std::vector buildings; + for (int i = 0; i < HIGHEST_ENTITY; i++) + { + CachedEntity *ent = ENTITY(i); + if (CE_BAD(ent)) + continue; + if (ent->m_Type() != ENTITY_BUILDING) + continue; + if ((CE_INT(ent, netvar.m_hBuilder) & 0xFFF) != g_pLocalPlayer->entity_idx) + continue; + if (ent->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()) < bestscr) + { + buildings.push_back(i); + bestscr = ent->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()); + } + } + return buildings; +} +int cost[4] = {100, 50, 130, 50}; +int GetBestBuilding(int metal) +{ + bool hasSentry, hasDispenser; + if (!GetBuildings().empty()) + for (auto build : GetBuildings()) + { + CachedEntity *building = ENTITY(build); + if (building->m_iClassID() == CL_CLASS(CObjectSentrygun)) + hasSentry = true; + if (building->m_iClassID() == CL_CLASS(CObjectDispenser)) + hasDispenser = true; + } + if (metal >= cost[SENTRY] && !hasSentry) + return SENTRY; + else if (metal >= cost[DISPENSER] && !hasDispenser) + return DISPENSER; + if (hasSentry && hasDispenser) + return 3; + return -1; +} +int GetClosestBuilding() +{ + float bestscr = FLT_MAX; + int BestBuilding = -1; + for (int i = 0; i < HIGHEST_ENTITY; i++) + { + CachedEntity *ent = ENTITY(i); + if (CE_BAD(ent)) + continue; + if (ent->m_Type() != ENTITY_BUILDING) + continue; + if ((CE_INT(ent, netvar.m_hBuilder) & 0xFFF) != g_pLocalPlayer->entity_idx) + continue; + if (ent->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()) < bestscr) + { + BestBuilding = i; + bestscr = ent->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()); + } + } + return BestBuilding; +} int follow_target = 0; void CreateMove() { @@ -212,42 +295,40 @@ void CreateMove() { CachedEntity *med = nearestHealth(); if (CE_GOOD(med)) - { nav::NavTo(med->m_vecOrigin(), true, true, 7); - } } if (HasLowAmmo() && cdr.test_and_set(5000)) { CachedEntity *ammo = nearestAmmo(); if (CE_GOOD(ammo)) - { nav::NavTo(ammo->m_vecOrigin(), true, true, 6); - } } if ((!HasLowHealth() && nav::priority == 7) || (!HasLowAmmo() && nav::priority == 6)) nav::clearInstructions(); if (enable) { - if (!nav::ReadyForCommands && !spy_mode && !heavy_mode) + if (!nav::ReadyForCommands && !spy_mode && !heavy_mode && !engi_mode) cd3.update(); - bool isready = (spy_mode || heavy_mode) ? 1 : nav::ReadyForCommands; - int waittime = (spy_mode || heavy_mode) ? 100 : 5000; + bool isready = (spy_mode || heavy_mode || engi_mode) ? 1 : nav::ReadyForCommands; + int waittime = (spy_mode || heavy_mode || engi_mode) ? 100 : 5000; if (isready && cd3.test_and_set(waittime)) { - if (!spy_mode && !heavy_mode) + if (!spy_mode && !heavy_mode && !engi_mode) { cd3.update(); Vector random_spot; if (cd2.test_and_set(5000)) Init(); - if (!sniper_spots.size()) + if (!sniper_spots.size() && !preferred_sniper_spots.size()) return; - int rng = rand() % sniper_spots.size(); - random_spot = sniper_spots.at(rng); + auto snip_spot = preferred_sniper_spots.size() ? preferred_sniper_spots : sniper_spots; + int rng = rand() % snip_spot.size(); + random_spot = snip_spot.at(rng); if (random_spot.z) nav::NavTo(random_spot, true, true); + return; } - else + else if (!engi_mode) { CachedEntity *tar = NearestEnemy(); if (CE_BAD(tar) && last_tar == -1 && nav::ReadyForCommands) @@ -255,10 +336,11 @@ void CreateMove() Vector random_spot; if (cd2.test_and_set(5000)) Init(); - if (!sniper_spots.size()) + if (!sniper_spots.size() && !preferred_sniper_spots.size()) return; - int rng = rand() % sniper_spots.size(); - random_spot = sniper_spots.at(rng); + auto snip_spot = preferred_sniper_spots.size() ? preferred_sniper_spots : sniper_spots; + int rng = rand() % snip_spot.size(); + random_spot = snip_spot.at(rng); if (random_spot.z) nav::NavTo(random_spot, false); return; @@ -279,6 +361,120 @@ void CreateMove() } } } + // Engi Mode + else + { + // Init things + if (cd2.test_and_set(5000)) + Init(); + // If No spots set just return + if (nest_spots.empty()) + return; + // Get Metal (offset of MAX metal is +8 and current metal +12) + int metal = CE_INT(LOCAL_E, netvar.m_iAmmo + 12); + // Best spot storage + static Vector best_spot{}; + // Get Best spot based on distance + if (engi_spot_cd.test_and_set(10000)) + { + float bestscr = FLT_MAX; + for (auto spot : nest_spots) + { + if (spot.DistTo(LOCAL_E->m_vecOrigin()) < bestscr) + { + bestscr = spot.DistTo(LOCAL_E->m_vecOrigin()); + best_spot = spot; + } + } + } + if (nav::priority == 1) + { + CachedEntity *ammo = nearestAmmo(); + if (CE_GOOD(ammo)) + { + nav::NavTo(ammo->m_vecOrigin(), false, true); + return; + } + } + // If Near The best spot and ready for commands + if (best_spot.DistTo(LOCAL_E->m_vecOrigin()) < 300.0f && (nav::ReadyForCommands || nav::priority == 1)) + { + // Get the closest Building + int ClosestBuilding = GetClosestBuilding(); + // If A Building was found + if (ClosestBuilding != -1) + { + CachedEntity *ent = ENTITY(ClosestBuilding); + // If we have more than 25 metal and the building is damaged or not fully upgraded hit it with the wrench + if (metal > 25 && (CE_INT(ent, netvar.iUpgradeLevel) < 3 || CE_INT(ent, netvar.iBuildingHealth) < CE_INT(ent, netvar.iBuildingMaxHealth))) + { + auto collide = RAW_ENT(ent)->GetCollideable(); + Vector min = ent->m_vecOrigin() + collide->OBBMins(); + Vector max = ent->m_vecOrigin() + collide->OBBMaxs(); + // Distance check + if (min.DistTo(g_pLocalPlayer->v_Eye) > re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W)) && max.DistTo(g_pLocalPlayer->v_Eye) > re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W)) && GetBuildingPosition(ent).DistTo(g_pLocalPlayer->v_Eye) > re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W))) + { + float min = min.DistTo(g_pLocalPlayer->v_Eye); + float max = max.DistTo(g_pLocalPlayer->v_Eye); + float center = GetBuildingPosition(ent).DistTo(g_pLocalPlayer->v_Eye); + float closest = fminf(min, fminf(max, center)); + nav::NavTo(closest, false, false); + } + Vector tr = GetBuildingPosition(ent) - g_pLocalPlayer->v_Eye; + Vector angles; + VectorAngles(tr, angles); + // Clamping is important + fClampAngle(angles); + current_user_cmd->viewangles = angles; + current_user_cmd->buttons |= IN_ATTACK; + g_pLocalPlayer->bUseSilentAngles = true; + return; + } + } + // Get A building, Sentry > Dispenser + int tobuild = GetBestBuilding(metal); + // If not enough metal then Find ammo + if (tobuild == -1) + { + CachedEntity *ammo = nearestAmmo(); + if (CE_GOOD(ammo)) + { + nav::NavTo(ammo->m_vecOrigin(), false, true); + return; + } + // Ammo is dormant, go and find it! + else if (sniper_spots.size() && nav::ReadyForCommands) + { + Vector random_spot; + if (cd2.test_and_set(5000)) + Init(); + if (!sniper_spots.size() && !preferred_sniper_spots.size()) + return; + auto snip_spot = preferred_sniper_spots.size() ? preferred_sniper_spots : sniper_spots; + int rng = rand() % snip_spot.size(); + random_spot = snip_spot.at(rng); + if (random_spot.z) + nav::NavTo(random_spot, false, false, 1); + return; + } + } + // Build Building + else if (tobuild != 3) + { + // Make ENgi look slightly down + current_user_cmd->viewangles.x = 20.0f; + // Build buildings in a 360° angle around player + current_user_cmd->viewangles.y = 90.0f * (tobuild + 1); + // Build new one + g_IEngine->ServerCmd(format("build ", tobuild).c_str(), true); + current_user_cmd->buttons |= IN_ATTACK; + g_pLocalPlayer->bUseSilentAngles = true; + } + } + // If not near best spot then navigate to it + else if (nav::ReadyForCommands) + nav::NavTo(best_spot, false, true); + } } } else if (enable_fb) From 9fccf7e76d1b53fe6961a3f2f08e407fb63589d1 Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 00:28:42 +0200 Subject: [PATCH 06/43] Update NavBot.cpp --- src/hacks/NavBot.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 46a22fc5..2c1feaea 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -414,10 +414,11 @@ void CreateMove() // Distance check if (min.DistTo(g_pLocalPlayer->v_Eye) > re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W)) && max.DistTo(g_pLocalPlayer->v_Eye) > re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W)) && GetBuildingPosition(ent).DistTo(g_pLocalPlayer->v_Eye) > re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W))) { - float min = min.DistTo(g_pLocalPlayer->v_Eye); - float max = max.DistTo(g_pLocalPlayer->v_Eye); + float minf = min.DistTo(g_pLocalPlayer->v_Eye); + float maxf = max.DistTo(g_pLocalPlayer->v_Eye); float center = GetBuildingPosition(ent).DistTo(g_pLocalPlayer->v_Eye); - float closest = fminf(min, fminf(max, center)); + float closest = fminf(minf, fminf(maxf, center)); + Vector tonav = (minf == closest) ? min : (maxf == closest) ? max : GetBuildingPosition(ent); nav::NavTo(closest, false, false); } Vector tr = GetBuildingPosition(ent) - g_pLocalPlayer->v_Eye; From 737adc5e9c9feaf36f14a43a323bdee26741a76a Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 00:31:11 +0200 Subject: [PATCH 07/43] Update NavBot.cpp --- src/hacks/NavBot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 2c1feaea..26efd86d 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -419,7 +419,7 @@ void CreateMove() float center = GetBuildingPosition(ent).DistTo(g_pLocalPlayer->v_Eye); float closest = fminf(minf, fminf(maxf, center)); Vector tonav = (minf == closest) ? min : (maxf == closest) ? max : GetBuildingPosition(ent); - nav::NavTo(closest, false, false); + nav::NavTo(tonav, false, false); } Vector tr = GetBuildingPosition(ent) - g_pLocalPlayer->v_Eye; Vector angles; From 1d8cef9520ba96d0f45ecccd90dbe065b1c67794 Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 12:06:56 +0200 Subject: [PATCH 08/43] More fixes, textmode.club --- data/menu/nullifiedcat/catbot.xml | 2 +- include/tfmm.hpp | 1 + src/core/netvars.cpp | 3 +- src/hacks/AutoJoin.cpp | 2 +- src/hacks/NavBot.cpp | 133 +++++++++++++++++++---------- src/hooks/Shutdown.cpp | 4 +- src/hooks/visual/PaintTraverse.cpp | 23 +++-- src/navparser.cpp | 32 +++---- src/online/Online.cpp | 1 - src/textmode.cpp | 4 +- src/tfmm.cpp | 13 ++- 11 files changed, 140 insertions(+), 78 deletions(-) mode change 100755 => 100644 src/textmode.cpp diff --git a/data/menu/nullifiedcat/catbot.xml b/data/menu/nullifiedcat/catbot.xml index 9ecace83..e873011d 100755 --- a/data/menu/nullifiedcat/catbot.xml +++ b/data/menu/nullifiedcat/catbot.xml @@ -64,7 +64,7 @@ - + diff --git a/include/tfmm.hpp b/include/tfmm.hpp index fd7f252a..43236a2d 100644 --- a/include/tfmm.hpp +++ b/include/tfmm.hpp @@ -14,5 +14,6 @@ void startQueue(); void leaveQueue(); void disconnectAndAbandon(); void abandon(); +bool isMMBanned(); int getQueue(); } // namespace tfmm diff --git a/src/core/netvars.cpp b/src/core/netvars.cpp index d94f25b9..6e057904 100644 --- a/src/core/netvars.cpp +++ b/src/core/netvars.cpp @@ -120,8 +120,7 @@ void NetVars::Init() "DT_TFSniperRifle", "SniperRifleLocalData", "m_flChargedDamage"); this->iUpgradeLevel = gNetvars.get_offset("DT_BaseObject", "m_iUpgradeLevel"); - this->m_hBuilder = - gNetvars.get_offset("DT_BaseObject", "m_hBuilder"); + this->m_hBuilder = gNetvars.get_offset("DT_BaseObject", "m_hBuilder"); this->iPipeType = gNetvars.get_offset("DT_TFProjectile_Pipebomb", "m_iType"); this->iBuildingHealth = diff --git a/src/hacks/AutoJoin.cpp b/src/hacks/AutoJoin.cpp index 6c662090..5397ff92 100644 --- a/src/hacks/AutoJoin.cpp +++ b/src/hacks/AutoJoin.cpp @@ -97,7 +97,7 @@ void updateSearch() logging::Info("Starting queue"); tfmm::startQueue(); } -#if LAGBOT_MODE +#if not ENABLE_VISUALS if (req_timer.test_and_set(1800000)) { logging::Info("Stuck in queue, segfaulting"); diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 26efd86d..d498a7aa 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -125,10 +125,12 @@ CachedEntity *nearestAmmo() int last_tar = -1; CachedEntity *NearestEnemy() { - if (last_tar == -1 || nav::ReadyForCommands) { - float bestscr = FLT_MAX; + if (last_tar == -1 || nav::ReadyForCommands) + { + float bestscr = FLT_MAX; CachedEntity *bestent = nullptr; - for (int i = 0; i < g_IEngine->GetMaxClients(); i++) { + for (int i = 0; i < g_IEngine->GetMaxClients(); i++) + { CachedEntity *ent = ENTITY(i); if (CE_BAD(ent) || ent->m_Type() != ENTITY_PLAYER) continue; @@ -140,7 +142,8 @@ CachedEntity *NearestEnemy() scr *= 5.0f; if (g_pPlayerResource->GetClass(ent) == tf_pyro) scr *= 7.0f; - if (scr < bestscr) { + if (scr < bestscr) + { bestscr = scr; bestent = ent; } @@ -178,7 +181,9 @@ void Init() hide.IsExposed()) sniper_spots.push_back(hide.m_pos); } - logging::Info("Sniper spots: %d, Manual Sniper Spots: %d, Sentry Spots: %d", sniper_spots.size(), preferred_sniper_spots.size(), nest_spots.size()); + logging::Info("Sniper spots: %d, Manual Sniper Spots: %d, Sentry Spots: %d", + sniper_spots.size(), preferred_sniper_spots.size(), + nest_spots.size()); } void initonce() { @@ -220,27 +225,28 @@ enum BuildingNum TELEPORT_EXT, }; std::vector GetBuildings() +{ + float bestscr = FLT_MAX; + std::vector buildings; + for (int i = 0; i < HIGHEST_ENTITY; i++) { - float bestscr = FLT_MAX; - std::vector buildings; - for (int i = 0; i < HIGHEST_ENTITY; i++) + CachedEntity *ent = ENTITY(i); + if (CE_BAD(ent)) + continue; + if (ent->m_Type() != ENTITY_BUILDING) + continue; + if ((CE_INT(ent, netvar.m_hBuilder) & 0xFFF) != + g_pLocalPlayer->entity_idx) + continue; + if (ent->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()) < bestscr) { - CachedEntity *ent = ENTITY(i); - if (CE_BAD(ent)) - continue; - if (ent->m_Type() != ENTITY_BUILDING) - continue; - if ((CE_INT(ent, netvar.m_hBuilder) & 0xFFF) != g_pLocalPlayer->entity_idx) - continue; - if (ent->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()) < bestscr) - { - buildings.push_back(i); - bestscr = ent->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()); - } + buildings.push_back(i); + bestscr = ent->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()); } - return buildings; + } + return buildings; } -int cost[4] = {100, 50, 130, 50}; +int cost[4] = { 100, 50, 130, 50 }; int GetBestBuilding(int metal) { bool hasSentry, hasDispenser; @@ -263,7 +269,7 @@ int GetBestBuilding(int metal) } int GetClosestBuilding() { - float bestscr = FLT_MAX; + float bestscr = FLT_MAX; int BestBuilding = -1; for (int i = 0; i < HIGHEST_ENTITY; i++) { @@ -272,12 +278,13 @@ int GetClosestBuilding() continue; if (ent->m_Type() != ENTITY_BUILDING) continue; - if ((CE_INT(ent, netvar.m_hBuilder) & 0xFFF) != g_pLocalPlayer->entity_idx) + if ((CE_INT(ent, netvar.m_hBuilder) & 0xFFF) != + g_pLocalPlayer->entity_idx) continue; if (ent->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()) < bestscr) { BestBuilding = i; - bestscr = ent->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()); + bestscr = ent->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()); } } return BestBuilding; @@ -303,13 +310,15 @@ void CreateMove() if (CE_GOOD(ammo)) nav::NavTo(ammo->m_vecOrigin(), true, true, 6); } - if ((!HasLowHealth() && nav::priority == 7) || (!HasLowAmmo() && nav::priority == 6)) + if ((!HasLowHealth() && nav::priority == 7) || + (!HasLowAmmo() && nav::priority == 6)) nav::clearInstructions(); if (enable) { if (!nav::ReadyForCommands && !spy_mode && !heavy_mode && !engi_mode) cd3.update(); - bool isready = (spy_mode || heavy_mode || engi_mode) ? 1 : nav::ReadyForCommands; + bool isready = + (spy_mode || heavy_mode || engi_mode) ? 1 : nav::ReadyForCommands; int waittime = (spy_mode || heavy_mode || engi_mode) ? 100 : 5000; if (isready && cd3.test_and_set(waittime)) { @@ -321,7 +330,9 @@ void CreateMove() Init(); if (!sniper_spots.size() && !preferred_sniper_spots.size()) return; - auto snip_spot = preferred_sniper_spots.size() ? preferred_sniper_spots : sniper_spots; + auto snip_spot = preferred_sniper_spots.size() + ? preferred_sniper_spots + : sniper_spots; int rng = rand() % snip_spot.size(); random_spot = snip_spot.at(rng); if (random_spot.z) @@ -338,7 +349,9 @@ void CreateMove() Init(); if (!sniper_spots.size() && !preferred_sniper_spots.size()) return; - auto snip_spot = preferred_sniper_spots.size() ? preferred_sniper_spots : sniper_spots; + auto snip_spot = preferred_sniper_spots.size() + ? preferred_sniper_spots + : sniper_spots; int rng = rand() % snip_spot.size(); random_spot = snip_spot.at(rng); if (random_spot.z) @@ -347,11 +360,13 @@ void CreateMove() } if (CE_GOOD(tar)) { - if (!spy_mode || !hacks::shared::backtrack::isBacktrackEnabled) + if (!spy_mode || + !hacks::shared::backtrack::isBacktrackEnabled) nav::NavTo(tar->m_vecOrigin(), false); else { - for (auto i : hacks::shared::backtrack::headPositions[tar->m_IDX]) + for (auto i : hacks::shared::backtrack::headPositions + [tar->m_IDX]) { if (!hacks::shared::backtrack::ValidTick(i, tar)) continue; @@ -382,7 +397,7 @@ void CreateMove() { if (spot.DistTo(LOCAL_E->m_vecOrigin()) < bestscr) { - bestscr = spot.DistTo(LOCAL_E->m_vecOrigin()); + bestscr = spot.DistTo(LOCAL_E->m_vecOrigin()); best_spot = spot; } } @@ -397,7 +412,8 @@ void CreateMove() } } // If Near The best spot and ready for commands - if (best_spot.DistTo(LOCAL_E->m_vecOrigin()) < 300.0f && (nav::ReadyForCommands || nav::priority == 1)) + if (best_spot.DistTo(LOCAL_E->m_vecOrigin()) < 300.0f && + (nav::ReadyForCommands || nav::priority == 1)) { // Get the closest Building int ClosestBuilding = GetClosestBuilding(); @@ -405,23 +421,46 @@ void CreateMove() if (ClosestBuilding != -1) { CachedEntity *ent = ENTITY(ClosestBuilding); - // If we have more than 25 metal and the building is damaged or not fully upgraded hit it with the wrench - if (metal > 25 && (CE_INT(ent, netvar.iUpgradeLevel) < 3 || CE_INT(ent, netvar.iBuildingHealth) < CE_INT(ent, netvar.iBuildingMaxHealth))) + // If we have more than 25 metal and the building is + // damaged or not fully upgraded hit it with the wrench + if (metal > 25 && + (CE_INT(ent, netvar.iUpgradeLevel) < 3 || + CE_INT(ent, netvar.iBuildingHealth) < + CE_INT(ent, netvar.iBuildingMaxHealth))) { auto collide = RAW_ENT(ent)->GetCollideable(); - Vector min = ent->m_vecOrigin() + collide->OBBMins(); - Vector max = ent->m_vecOrigin() + collide->OBBMaxs(); + Vector min = + ent->m_vecOrigin() + collide->OBBMins(); + Vector max = + ent->m_vecOrigin() + collide->OBBMaxs(); // Distance check - if (min.DistTo(g_pLocalPlayer->v_Eye) > re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W)) && max.DistTo(g_pLocalPlayer->v_Eye) > re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W)) && GetBuildingPosition(ent).DistTo(g_pLocalPlayer->v_Eye) > re::C_TFWeaponBaseMelee::GetSwingRange(RAW_ENT(LOCAL_W))) + if (min.DistTo(g_pLocalPlayer->v_Eye) > + re::C_TFWeaponBaseMelee::GetSwingRange( + RAW_ENT(LOCAL_W)) && + max.DistTo(g_pLocalPlayer->v_Eye) > + re::C_TFWeaponBaseMelee::GetSwingRange( + RAW_ENT(LOCAL_W)) && + GetBuildingPosition(ent).DistTo( + g_pLocalPlayer->v_Eye) > + re::C_TFWeaponBaseMelee::GetSwingRange( + RAW_ENT(LOCAL_W))) { float minf = min.DistTo(g_pLocalPlayer->v_Eye); float maxf = max.DistTo(g_pLocalPlayer->v_Eye); - float center = GetBuildingPosition(ent).DistTo(g_pLocalPlayer->v_Eye); - float closest = fminf(minf, fminf(maxf, center)); - Vector tonav = (minf == closest) ? min : (maxf == closest) ? max : GetBuildingPosition(ent); + float center = GetBuildingPosition(ent).DistTo( + g_pLocalPlayer->v_Eye); + float closest = + fminf(minf, fminf(maxf, center)); + Vector tonav = + (minf == closest) + ? min + : (maxf == closest) + ? max + : GetBuildingPosition(ent); nav::NavTo(tonav, false, false); } - Vector tr = GetBuildingPosition(ent) - g_pLocalPlayer->v_Eye; + Vector tr = GetBuildingPosition(ent) - + g_pLocalPlayer->v_Eye; Vector angles; VectorAngles(tr, angles); // Clamping is important @@ -449,9 +488,12 @@ void CreateMove() Vector random_spot; if (cd2.test_and_set(5000)) Init(); - if (!sniper_spots.size() && !preferred_sniper_spots.size()) + if (!sniper_spots.size() && + !preferred_sniper_spots.size()) return; - auto snip_spot = preferred_sniper_spots.size() ? preferred_sniper_spots : sniper_spots; + auto snip_spot = preferred_sniper_spots.size() + ? preferred_sniper_spots + : sniper_spots; int rng = rand() % snip_spot.size(); random_spot = snip_spot.at(rng); if (random_spot.z) @@ -467,7 +509,8 @@ void CreateMove() // Build buildings in a 360° angle around player current_user_cmd->viewangles.y = 90.0f * (tobuild + 1); // Build new one - g_IEngine->ServerCmd(format("build ", tobuild).c_str(), true); + g_IEngine->ServerCmd(format("build ", tobuild).c_str(), + true); current_user_cmd->buttons |= IN_ATTACK; g_pLocalPlayer->bUseSilentAngles = true; } diff --git a/src/hooks/Shutdown.cpp b/src/hooks/Shutdown.cpp index ad18fd3f..80ad2fb4 100644 --- a/src/hooks/Shutdown.cpp +++ b/src/hooks/Shutdown.cpp @@ -21,11 +21,11 @@ DEFINE_HOOKED_METHOD(Shutdown, void, INetChannel *this_, const char *reason) // This is a INetChannel hook - it SHOULDN'T be static because netchannel // changes. logging::Info("Disconnect: %s", reason); - if (strstr(reason, "banned")) + if (strstr(reason, "banned") || strstr(reason, "Generic_Kicked")) { if (die_if_vac) { - logging::Info("VAC banned"); + logging::Info("VAC/Matchmaking banned"); *(int *) 0 = 0; exit(1); } diff --git a/src/hooks/visual/PaintTraverse.cpp b/src/hooks/visual/PaintTraverse.cpp index 627dfa2c..23f65dfe 100644 --- a/src/hooks/visual/PaintTraverse.cpp +++ b/src/hooks/visual/PaintTraverse.cpp @@ -70,7 +70,7 @@ and no [])", [](const CCommand &args) { bool replaced = false; namespace hooked_methods { - +Timer checkmmban{}; DEFINE_HOOKED_METHOD(PaintTraverse, void, vgui::IPanel *this_, unsigned int panel, bool force, bool allow_force) { @@ -96,21 +96,28 @@ DEFINE_HOOKED_METHOD(PaintTraverse, void, vgui::IPanel *this_, if (switcherido && spamdur && !joinspam.check(spamdur * 1000)) { auto gc = re::CTFGCClientSystem::GTFGCClientSystem(); - if (!gc) - goto label1; - gc->JoinMMMatch(); + if (gc) + gc->JoinMMMatch(); } else if (!joinspam.check(spamdur * 1000) && spamdur) { INetChannel *ch = (INetChannel *) g_IEngine->GetNetChannelInfo(); - if (!ch) - goto label1; - ch->Shutdown(""); + if (ch) + ch->Shutdown(""); } } -label1: scndwait++; switcherido = !switcherido; +#if not ENABLE_VISUALS + if (checkmmban.test_and_set(1000)) + { + if (tfmm::isMMBanned()) + { + *(int *) nullptr = 0; + exit(1); + } + } +#endif /*static bool replacedparty = false; static int callcnt = 0; if (party_bypass && !replacedparty && callcnt < 5) diff --git a/src/navparser.cpp b/src/navparser.cpp index 758f5058..1c39a9f8 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -181,9 +181,9 @@ bool Prepare() } else { - lastmap = g_IEngine->GetLevelName(); - pathfinding = false; - init = true; + lastmap = g_IEngine->GetLevelName(); + pathfinding = false; + init = true; threadingFinished = false; std::thread initer(Init); initer.detach(); @@ -211,7 +211,7 @@ int findClosestNavSquare(Vector vec) // Make sure we're not stuck on the same area for too long if (std::count(findClosestNavSquare_localAreas.begin(), findClosestNavSquare_localAreas.end(), i) < 3) - overlapping.emplace_back( i, &areas.at(i) ); + overlapping.emplace_back(i, &areas.at(i)); } } @@ -320,7 +320,7 @@ bool NavTo(Vector dest, bool navToLocalCenter, bool persistent, TF2MAP->pather->Reset(); } crumbs.clear(); - crumbs = std::move(path); + crumbs = std::move(path); lastArea = crumbs.at(0); if (!navToLocalCenter && crumbs.size() > 1) crumbs.erase(crumbs.begin()); @@ -490,15 +490,17 @@ CatCommand navpath("nav_path", "Debug nav path", [](const CCommand &args) { } }); -CatCommand navpathnolocal("nav_path_nolocal", "Debug nav path", [](const CCommand &args) { - if (NavTo(loc, false, true, 50 + priority)) - { - logging::Info("Pathing: Success! Walking to path..."); - } - else - { - logging::Info("Pathing: Failed!"); - } -}); +CatCommand navpathnolocal("nav_path_nolocal", "Debug nav path", + [](const CCommand &args) { + if (NavTo(loc, false, true, 50 + priority)) + { + logging::Info( + "Pathing: Success! Walking to path..."); + } + else + { + logging::Info("Pathing: Failed!"); + } + }); } // namespace nav diff --git a/src/online/Online.cpp b/src/online/Online.cpp index a9080929..6addb4a6 100644 --- a/src/online/Online.cpp +++ b/src/online/Online.cpp @@ -13,7 +13,6 @@ #undef null - #include #include #include diff --git a/src/textmode.cpp b/src/textmode.cpp old mode 100755 new mode 100644 index 925fe849..63620d44 --- a/src/textmode.cpp +++ b/src/textmode.cpp @@ -21,8 +21,8 @@ void EXPOSED_Epic_VACBypass_1337_DoNotSteal_xXx_$1_xXx_MLG() static unsigned char patch[] = { 0x55, 0x89, 0xE5, 0x83, 0xEC, 0x18, 0xB8, 0x01, 0x00, 0x00, 0x00, 0xC9, 0xC3 }; uintptr_t Host_IsSecureServerAllowed_addr = gSignatures.GetEngineSignature( - "55 89 E5 83 EC 18 E8 ? ? ? ? 8B 10 C7 44 24 04 ? ? ? ? 89 04 24 FF 52 " - "2C 85 C0 74 11"); + "55 89 E5 83 EC ? E8 ? ? ? ? 8B 10 C7 44 24 ? ? ? ? ? 89 04 24 FF 52 ? " + "85 C0 74 ? C6 05"); // +0x21 = allowSecureServers // logging::Info("1337 VAC bypass: 0x%08x", // Host_IsSecureServerAllowed_addr); diff --git a/src/tfmm.cpp b/src/tfmm.cpp index c4f9deb4..81617b0c 100644 --- a/src/tfmm.cpp +++ b/src/tfmm.cpp @@ -32,7 +32,17 @@ CatCommand get_state("mm_state", "Get party state", []() { namespace tfmm { - +int queuecount = 0; +bool isMMBanned() +{ + auto client = re::CTFPartyClient::GTFPartyClient(); + if (!client || (client->BInQueueForMatchGroup(7) && queuecount < 10)) + { + queuecount = 0; + return false; + } + return true; +} int getQueue() { return *queue; @@ -47,6 +57,7 @@ void startQueue() client->LoadSavedCasualCriteria(); client->RequestQueueForMatch((int) queue); hacks::shared::autojoin::resetQueueTimer(); + queuecount++; } else logging::Info("queue_start: CTFPartyClient == null!"); From 448d676007b5a5fca23e3440f20ffd6c48f28c7c Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 14:21:27 +0200 Subject: [PATCH 09/43] why would this not ignore players --- src/trace.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/trace.cpp b/src/trace.cpp index f54885eb..4dce6d1f 100755 --- a/src/trace.cpp +++ b/src/trace.cpp @@ -1,4 +1,4 @@ -/* +fixi/* * trace.cpp * * Created on: Oct 10, 2016 @@ -42,6 +42,8 @@ bool trace::FilterDefault::ShouldHitEntity(IHandleEntity *handle, int mask) switch (clazz->m_ClassID) { // TODO magic numbers: invisible entity ids + case 246: + case 248: case 64: case 225: case 55: @@ -79,7 +81,6 @@ void trace::FilterNoPlayer::SetSelf(IClientEntity *self) bool trace::FilterNoPlayer::ShouldHitEntity(IHandleEntity *handle, int mask) { - return false; IClientEntity *entity; ClientClass *clazz; @@ -91,6 +92,7 @@ bool trace::FilterNoPlayer::ShouldHitEntity(IHandleEntity *handle, int mask) switch (clazz->m_ClassID) { // TODO magic numbers: invisible entity ids + case case 64: case 225: case 55: From 3ee9703317b78b0585448f8a45b74dae59617228 Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 14:21:27 +0200 Subject: [PATCH 10/43] why would this not ignore players --- src/trace.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/trace.cpp b/src/trace.cpp index f54885eb..4dce6d1f 100755 --- a/src/trace.cpp +++ b/src/trace.cpp @@ -1,4 +1,4 @@ -/* +fixi/* * trace.cpp * * Created on: Oct 10, 2016 @@ -42,6 +42,8 @@ bool trace::FilterDefault::ShouldHitEntity(IHandleEntity *handle, int mask) switch (clazz->m_ClassID) { // TODO magic numbers: invisible entity ids + case 246: + case 248: case 64: case 225: case 55: @@ -79,7 +81,6 @@ void trace::FilterNoPlayer::SetSelf(IClientEntity *self) bool trace::FilterNoPlayer::ShouldHitEntity(IHandleEntity *handle, int mask) { - return false; IClientEntity *entity; ClientClass *clazz; @@ -91,6 +92,7 @@ bool trace::FilterNoPlayer::ShouldHitEntity(IHandleEntity *handle, int mask) switch (clazz->m_ClassID) { // TODO magic numbers: invisible entity ids + case case 64: case 225: case 55: From a8f902ca68d6e86889bf82d3ab675915581c481a Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 14:25:27 +0200 Subject: [PATCH 11/43] ""fixi"" --- src/trace.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trace.cpp b/src/trace.cpp index 4dce6d1f..586fdd2e 100755 --- a/src/trace.cpp +++ b/src/trace.cpp @@ -1,4 +1,4 @@ -fixi/* +/* * trace.cpp * * Created on: Oct 10, 2016 From 3f0e247e6ac06efe594424bc9b4ec01dca43d15a Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 14:25:27 +0200 Subject: [PATCH 12/43] ""fixi"" --- src/trace.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trace.cpp b/src/trace.cpp index 4dce6d1f..586fdd2e 100755 --- a/src/trace.cpp +++ b/src/trace.cpp @@ -1,4 +1,4 @@ -fixi/* +/* * trace.cpp * * Created on: Oct 10, 2016 From 323cee6363dceb89a47e4e9973d9bd603fa8af7c Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 14:31:35 +0200 Subject: [PATCH 13/43] gay --- src/trace.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/trace.cpp b/src/trace.cpp index 586fdd2e..3100dfe7 100755 --- a/src/trace.cpp +++ b/src/trace.cpp @@ -92,7 +92,8 @@ bool trace::FilterNoPlayer::ShouldHitEntity(IHandleEntity *handle, int mask) switch (clazz->m_ClassID) { // TODO magic numbers: invisible entity ids - case + case 248: + case 246: case 64: case 225: case 55: From d5c135df8984341f79d3d53d2c3059452dbab6a5 Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 14:31:35 +0200 Subject: [PATCH 14/43] gay --- src/trace.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/trace.cpp b/src/trace.cpp index 586fdd2e..3100dfe7 100755 --- a/src/trace.cpp +++ b/src/trace.cpp @@ -92,7 +92,8 @@ bool trace::FilterNoPlayer::ShouldHitEntity(IHandleEntity *handle, int mask) switch (clazz->m_ClassID) { // TODO magic numbers: invisible entity ids - case + case 248: + case 246: case 64: case 225: case 55: From 5f2613ef96fe76348d1021749b66baf7f2eea22d Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 15:27:34 +0200 Subject: [PATCH 15/43] Unsiged overflow, great --- src/hacks/AutoJoin.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/hacks/AutoJoin.cpp b/src/hacks/AutoJoin.cpp index 5397ff92..d5b6ba65 100644 --- a/src/hacks/AutoJoin.cpp +++ b/src/hacks/AutoJoin.cpp @@ -97,14 +97,6 @@ void updateSearch() logging::Info("Starting queue"); tfmm::startQueue(); } -#if not ENABLE_VISUALS - if (req_timer.test_and_set(1800000)) - { - logging::Info("Stuck in queue, segfaulting"); - *(int *) nullptr; - exit(1); - } -#endif } void update() From 126cd0028ea54933b8689de7a8f4452c9c79476d Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Tue, 21 Aug 2018 17:54:54 +0200 Subject: [PATCH 16/43] Type 2 connections for navbot (vischeck) --- include/navparser.hpp | 224 ++++++++++++++++++++++++++++++++++++------ src/navparser.cpp | 223 ++++++++++++++--------------------------- 2 files changed, 269 insertions(+), 178 deletions(-) diff --git a/include/navparser.hpp b/include/navparser.hpp index aa89c629..e02ef230 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -24,32 +24,22 @@ bool Prepare(); void CreateMove(); void Draw(); -struct inactivityTracker +size_t FindInVector(size_t id); + +class inactivityTracker { // Map for storing inactivity per connection - std::map, unsigned int> inactives; - - void reset() + std::map, std::pair> inactives; + bool vischeckConnection(std::pair &connection) { - // inactives.clear(); + Vector begin = areas.at(FindInVector(connection.first)).m_center; + Vector end = areas.at(FindInVector(connection.second)).m_center; + begin.z += 72; + end.z += 72; + bool result = IsVectorVisible(begin, end, false); + return result; } - void addTime(std::pair connection, Timer &timer, - bool &resetPather) - { - if (inactives.find(connection) == inactives.end()) - { - inactives[connection] = 0; - } - inactives[connection] = - inactives[connection] + - (std::chrono::duration_cast( - std::chrono::system_clock::now() - timer.last) - .count()); - if (inactives[connection] >= 5000) - resetPather = true; - } - void addTime(std::pair connection, Timer &timer, - bool &resetPather) + std::pair VectorToId(std::pair &connection) { CNavArea *currnode = nullptr; for (size_t i = 0; i < areas.size(); i++) @@ -61,7 +51,7 @@ struct inactivityTracker } } if (!currnode) - return; + return { -1, -1 }; CNavArea *nextnode = nullptr; for (size_t i = 0; i < areas.size(); i++) @@ -73,21 +63,197 @@ struct inactivityTracker } } if (!nextnode) - return; + return { -1, -1 }; for (auto i : currnode->m_connections) { if (i.area->m_id == nextnode->m_id) { - addTime(std::pair{ currnode->m_id, nextnode->m_id }, timer, - resetPather); - return; + return { currnode->m_id, nextnode->m_id }; } } } - unsigned int getTime(std::pair connection) + +public: + void reset() + { + for (auto i : inactives) + { + // What is this tf + i.second.second = 0; + } + } + bool IsIgnored(std::pair connection) + { + if (inactives.find(connection) == inactives.end()) + { + return false; + } + auto &pair = inactives.at(connection); + if (pair.second >= 5000) + { + pair.first = 1; + return true; + } + if (pair.first == 2 && !vischeckConnection(connection)) + { + logging::Info( + "Ignored a connection due to type 2 connection type."); + return true; + } + return false; + } + + void AddTime(std::pair connection, Timer &timer, + bool &resetPather) + { + if (inactives.find(connection) == inactives.end()) + { + inactives[connection] = { 0, 0 }; + } + auto &pair = inactives.at(connection); + + pair.second = pair.second + + (std::chrono::duration_cast( + std::chrono::system_clock::now() - timer.last) + .count()); + if (pair.second >= 5000) + resetPather = true; + } + void AddTime(std::pair connection, Timer &timer, + bool &resetPather) + { + auto pair = VectorToId(connection); + if (pair.first == -1 || pair.second == -1) + return; + AddTime(pair, timer, resetPather); + } + bool CheckType2(std::pair connection) + { + // Fix calls vischeckConnection too often + if (inactives.find(connection) == inactives.end()) + { + inactives[connection] = { 0, 0 }; + } + auto pair = inactives.at(connection); + switch (pair.first) + { + case 0: + if (!vischeckConnection(connection)) + { + inactives[connection].first = 2; + return true; + } + case 1: + case 2: + return false; + } + } + bool CheckType2(std::pair connection) + { + auto pair = VectorToId(connection); + if (pair.first == -1 || pair.second == -1) + return false; + return CheckType2(pair); + } +}; // namespace nav + +struct MAP : public micropather::Graph +{ + std::unique_ptr pather; + // Maps already utilize dynamic allocation and we don't need a custom + // constructor + inactivityTracker inactiveTracker; + Vector GetClosestCornerToArea(CNavArea *CornerOf, CNavArea *Target) + { + std::array corners; + corners.at(0) = CornerOf->m_nwCorner; // NW + corners.at(1) = CornerOf->m_seCorner; // SE + corners.at(2) = Vector{ CornerOf->m_seCorner.x, CornerOf->m_nwCorner.y, + CornerOf->m_nwCorner.z }; // NE + corners.at(3) = Vector{ CornerOf->m_nwCorner.x, CornerOf->m_seCorner.y, + CornerOf->m_seCorner.z }; // SW + + Vector bestVec; + float bestDist = FLT_MAX; + + for (size_t i = 0; i < corners.size(); i++) + { + float dist = corners.at(i).DistTo(Target->m_center); + if (dist < bestDist) + { + bestVec = corners.at(i); + bestDist = dist; + } + } + + Vector bestVec2; + float bestDist2 = FLT_MAX; + + for (size_t i = 0; i < corners.size(); i++) + { + if (corners.at(i) == bestVec2) + continue; + float dist = corners.at(i).DistTo(Target->m_center); + if (dist < bestDist2) + { + bestVec2 = corners.at(i); + bestDist2 = dist; + } + } + return (bestVec + bestVec2) / 2; + } + + float GetZBetweenAreas(CNavArea *start, CNavArea *end) + { + float z1 = GetClosestCornerToArea(start, end).z; + float z2 = GetClosestCornerToArea(end, start).z; + + return z2 - z1; + } + // Function required by MicroPather for getting an estimated cost + float LeastCostEstimate(void *stateStart, void *stateEnd) + { + CNavArea *start = static_cast(stateStart); + CNavArea *end = static_cast(stateEnd); + float dist = start->m_center.DistTo(end->m_center); + return dist; + } + // Function required by MicroPather to retrieve neighbours and their + // associated costs. + void AdjacentCost(void *state, MP_VECTOR *adjacent) + { + CNavArea *area = static_cast(state); + auto &neighbours = area->m_connections; + for (auto i : neighbours) + { + if (GetZBetweenAreas(area, i.area) > 42) + continue; + if (inactiveTracker.IsIgnored( + std::pair{ area->m_id, i.area->m_id })) + continue; + micropather::StateCost cost; + cost.state = + static_cast(&areas.at(FindInVector(i.area->m_id))); + cost.cost = area->m_center.DistTo(i.area->m_center); + adjacent->push_back(cost); + } + } + void PrintStateInfo(void *state) + { + CNavArea *area = static_cast(state); + logging::Info(format(area->m_center.x, " ", area->m_center.y, " ", + area->m_center.z) + .c_str()); + } + MAP(size_t size) + { + pather = + std::make_unique(this, size, 6, true); + } + + ~MAP() { - return inactives[connection]; } }; diff --git a/src/navparser.cpp b/src/navparser.cpp index 758f5058..9872bfc8 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -8,12 +8,15 @@ std::vector areas; bool init = false; static bool pathfinding = true; bool ReadyForCommands = false; -inactivityTracker inactiveTracker; static settings::Bool enabled{ "misc.pathing", "true" }; static settings::Bool draw{ "misc.pathing.draw", "false" }; -static bool threadingFinished = false; +static std::atomic threadingFinished; -// Todo fix +static std::unique_ptr TF2MAP; + +// Function to get place in Vector by connection ID +// Todo: find an alternative for this, maybe a map for storing ptrs to the +// std::vector? size_t FindInVector(size_t id) { for (size_t i = 0; i < areas.size(); i++) @@ -23,110 +26,6 @@ size_t FindInVector(size_t id) } } -struct MAP : public micropather::Graph -{ - std::unique_ptr pather; - // Function to check if a connection is ignored - bool IsIgnored(size_t currState, size_t connectionID) - { - if (inactiveTracker.getTime({ currState, connectionID }) >= 5000) - return true; - return false; - } - Vector GetClosestCornerToArea(CNavArea *CornerOf, CNavArea *Target) - { - std::array corners; - corners.at(0) = CornerOf->m_nwCorner; // NW - corners.at(1) = CornerOf->m_seCorner; // SE - corners.at(2) = Vector{ CornerOf->m_seCorner.x, CornerOf->m_nwCorner.y, - CornerOf->m_nwCorner.z }; // NE - corners.at(3) = Vector{ CornerOf->m_nwCorner.x, CornerOf->m_seCorner.y, - CornerOf->m_seCorner.z }; // SW - - Vector bestVec; - float bestDist = FLT_MAX; - - for (size_t i = 0; i < corners.size(); i++) - { - float dist = corners.at(i).DistTo(Target->m_center); - if (dist < bestDist) - { - bestVec = corners.at(i); - bestDist = dist; - } - } - - Vector bestVec2; - float bestDist2 = FLT_MAX; - - for (size_t i = 0; i < corners.size(); i++) - { - if (corners.at(i) == bestVec2) - continue; - float dist = corners.at(i).DistTo(Target->m_center); - if (dist < bestDist2) - { - bestVec2 = corners.at(i); - bestDist2 = dist; - } - } - return (bestVec + bestVec2) / 2; - } - - float GetZBetweenAreas(CNavArea *start, CNavArea *end) - { - float z1 = GetClosestCornerToArea(start, end).z; - float z2 = GetClosestCornerToArea(end, start).z; - - return z2 - z1; - } - // Function required by MicroPather for getting an estimated cost - float LeastCostEstimate(void *stateStart, void *stateEnd) - { - CNavArea *start = static_cast(stateStart); - CNavArea *end = static_cast(stateEnd); - float dist = start->m_center.DistTo(end->m_center); - return dist; - } - // Function required by MicroPather to retrieve neighbours and their - // associated costs. - void AdjacentCost(void *state, MP_VECTOR *adjacent) - { - CNavArea *area = static_cast(state); - auto &neighbours = area->m_connections; - for (auto i : neighbours) - { - if (GetZBetweenAreas(area, i.area) > 42) - continue; - if (IsIgnored(area->m_id, i.area->m_id)) - continue; - micropather::StateCost cost; - cost.state = - static_cast(&areas.at(FindInVector(i.area->m_id))); - cost.cost = area->m_center.DistTo(i.area->m_center); - adjacent->push_back(cost); - } - } - void PrintStateInfo(void *state) - { - CNavArea *area = static_cast(state); - logging::Info(format(area->m_center.x, " ", area->m_center.y, " ", - area->m_center.z) - .c_str()); - } - MAP(size_t size) - { - pather = - std::make_unique(this, size, 6, true); - } - - ~MAP() - { - } -}; - -static std::unique_ptr TF2MAP; - void Init() { // Get NavFile location @@ -161,10 +60,11 @@ void Init() size = 7000; // Initiate "Map", contains micropather object TF2MAP = std::make_unique(size); + TF2MAP->inactiveTracker.reset(); } if (!areas.empty()) pathfinding = true; - threadingFinished = true; + threadingFinished.store(true); } static std::string lastmap; @@ -175,6 +75,7 @@ bool Prepare() return false; if (!init) { + // Don't reinit if same map if (lastmap == g_IEngine->GetLevelName()) { init = true; @@ -184,12 +85,14 @@ bool Prepare() lastmap = g_IEngine->GetLevelName(); pathfinding = false; init = true; - threadingFinished = false; + threadingFinished.store(false); + // Parsing CNavFile takes time, run it in a seperate thread std::thread initer(Init); + // We need to either detach or join to avoid std::terminate initer.detach(); } } - if (!pathfinding || !threadingFinished) + if (!pathfinding || !threadingFinished.load()) return false; return true; } @@ -211,7 +114,7 @@ int findClosestNavSquare(Vector vec) // Make sure we're not stuck on the same area for too long if (std::count(findClosestNavSquare_localAreas.begin(), findClosestNavSquare_localAreas.end(), i) < 3) - overlapping.emplace_back( i, &areas.at(i) ); + overlapping.emplace_back(i, &areas.at(i)); } } @@ -290,8 +193,8 @@ static Timer lastJump{}; static std::vector crumbs; // Bot will keep trying to get to the target even if it fails a few times static bool ensureArrival; -// Priority value for current instructions, only higher priority can overwrite -// itlocalAreas +// Priority value for current instructions, only higher or equal priorites can +// overwrite it int priority = 0; static Vector lastArea = { 0.0f, 0.0f, 0.0f }; @@ -315,12 +218,13 @@ bool NavTo(Vector dest, bool navToLocalCenter, bool persistent, if (!crumbs.empty()) { bool reset = false; - inactiveTracker.addTime({ lastArea, crumbs.at(0) }, inactivity, reset); + TF2MAP->inactiveTracker.AddTime({ lastArea, crumbs.at(0) }, inactivity, + reset); if (reset) TF2MAP->pather->Reset(); } crumbs.clear(); - crumbs = std::move(path); + crumbs = std::move(path); lastArea = crumbs.at(0); if (!navToLocalCenter && crumbs.size() > 1) crumbs.erase(crumbs.begin()); @@ -337,21 +241,43 @@ void clearInstructions() } static Timer ignoreReset{}; +static Timer patherReset{}; // Function for removing ignores void clearIgnores() { - if (ignoreReset.test_and_set(180000)) + if (!TF2MAP || !TF2MAP->pather) + return; + if (ignoreReset.test_and_set(120000)) + TF2MAP->inactiveTracker.reset(); + if (patherReset.test_and_set(30000)) + TF2MAP->pather->Reset(); +} + +void Repath() +{ + if (ensureArrival) { - inactiveTracker.reset(); - if (TF2MAP && TF2MAP->pather) - TF2MAP->pather->Reset(); + logging::Info("Pathing: NavBot inactive for too long. Ignoring " + "connection and finding another path..."); + // Throwaway int + int i1, i2; + // Find a new path + crumbs = findPath(g_pLocalPlayer->v_Origin, crumbs.back(), i1, i2); + } + else + { + logging::Info( + "Pathing: NavBot inactive for too long. Canceling tasks and " + "ignoring connection..."); + // Wait for new instructions + crumbs.clear(); } } // Main movement function, gets path from NavTo void CreateMove() { - if (!enabled || !threadingFinished) + if (!enabled || !threadingFinished.load()) return; if (CE_BAD(LOCAL_E)) return; @@ -386,30 +312,26 @@ void CreateMove() if (crumbs.at(0).z - g_pLocalPlayer->v_Origin.z > 18 && lastJump.test_and_set(200)) current_user_cmd->buttons |= IN_JUMP; + // Check if were dealing with a type 2 connection + if (inactivity.check(3000) && + TF2MAP->inactiveTracker.CheckType2({ lastArea, crumbs.at(0) })) + { + logging::Info("Pathing: Type 2 connection detected!"); + TF2MAP->pather->Reset(); + Repath(); + inactivity.update(); + return; + } // If inactive for too long if (inactivity.check(5000)) { // Ignore connection - bool i3 = false; - inactiveTracker.addTime({ lastArea, crumbs.at(0) }, inactivity, i3); - if (i3) + bool resetPather = false; + TF2MAP->inactiveTracker.AddTime({ lastArea, crumbs.at(0) }, inactivity, + resetPather); + if (resetPather) TF2MAP->pather->Reset(); - if (ensureArrival) - { - logging::Info("Pathing: NavBot inactive for too long. Ignoring " - "connection and finding another path..."); - // Find a new path - int i1, i2; - crumbs = findPath(g_pLocalPlayer->v_Origin, crumbs.back(), i1, i2); - } - else - { - logging::Info( - "Pathing: NavBot inactive for too long. Canceling tasks and " - "ignoring connection..."); - // Wait for new instructions - crumbs.clear(); - } + Repath(); inactivity.update(); return; } @@ -490,15 +412,18 @@ CatCommand navpath("nav_path", "Debug nav path", [](const CCommand &args) { } }); -CatCommand navpathnolocal("nav_path_nolocal", "Debug nav path", [](const CCommand &args) { - if (NavTo(loc, false, true, 50 + priority)) - { - logging::Info("Pathing: Success! Walking to path..."); - } - else - { - logging::Info("Pathing: Failed!"); - } -}); +// Clang format pls +CatCommand navpathnolocal("nav_path_nolocal", "Debug nav path", + [](const CCommand &args) { + if (NavTo(loc, false, true, 50 + priority)) + { + logging::Info( + "Pathing: Success! Walking to path..."); + } + else + { + logging::Info("Pathing: Failed!"); + } + }); } // namespace nav From 783b747d5ce2ccbe448382697d9208096ade6890 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Tue, 21 Aug 2018 18:41:30 +0200 Subject: [PATCH 17/43] Fix door closing on bot and then ignoring --- include/navparser.hpp | 10 ++++++---- src/hacks/NavBot.cpp | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/navparser.hpp b/include/navparser.hpp index e02ef230..00dc8743 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -113,10 +113,12 @@ public: } auto &pair = inactives.at(connection); - pair.second = pair.second + - (std::chrono::duration_cast( - std::chrono::system_clock::now() - timer.last) - .count()); + unsigned int newTime = std::chrono::duration_cast( + std::chrono::system_clock::now() - timer.last) + .count(); + if (pair.first == 2 && !vischeckConnection(connection)) + newTime = (newTime > 2500 ? 2500 : newTime); + pair.second = pair.second + newTime; if (pair.second >= 5000) resetPather = true; } diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index d498a7aa..8079f98f 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -467,7 +467,7 @@ void CreateMove() fClampAngle(angles); current_user_cmd->viewangles = angles; current_user_cmd->buttons |= IN_ATTACK; - g_pLocalPlayer->bUseSilentAngles = true; + g_pLocalPlayer->bUseSilentAngles = false; return; } } From 97a7c0c23865bb2df8399c586a16f1a5b279c691 Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 20:32:35 +0200 Subject: [PATCH 18/43] Ammo <= 5 --- src/hacks/NavBot.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 8079f98f..39975ffe 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -66,9 +66,9 @@ bool HasLowAmmo() { IClientEntity *weapon = g_IEntityList->GetClientEntity(eid); if (weapon and - re::C_BaseCombatWeapon::IsBaseCombatWeapon(weapon) and - re::C_TFWeaponBase::UsesPrimaryAmmo(weapon) and - not re::C_TFWeaponBase::HasPrimaryAmmo(weapon)) + re::C_BaseCombatWeapon::IsBaseCombatWeapon(weapon) && + re::C_TFWeaponBase::UsesPrimaryAmmo(weapon) && + (!re::C_TFWeaponBase::HasPrimaryAmmo(weapon) || NET_INT(weapon, netvar.m_iAmmo + 4) <= 5)) return true; } } From 67797f379c5073555712feeaf5bc6eabd9d6d0df Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 20:45:21 +0200 Subject: [PATCH 19/43] Ammo check fix pls --- src/hacks/NavBot.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 39975ffe..f82e181e 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -58,6 +58,8 @@ bool HasLowAmmo() { int *weapon_list = (int *) ((unsigned) (RAW_ENT(LOCAL_E)) + netvar.hMyWeapons); + if (g_pLocalPlayer->holding_sniper_rifle && NET_INT(LOCAL_W, netvar.m_iAmmo + 4) <= 5) + return true; for (int i = 0; weapon_list[i]; i++) { int handle = weapon_list[i]; @@ -68,7 +70,7 @@ bool HasLowAmmo() if (weapon and re::C_BaseCombatWeapon::IsBaseCombatWeapon(weapon) && re::C_TFWeaponBase::UsesPrimaryAmmo(weapon) && - (!re::C_TFWeaponBase::HasPrimaryAmmo(weapon) || NET_INT(weapon, netvar.m_iAmmo + 4) <= 5)) + !re::C_TFWeaponBase::HasPrimaryAmmo(weapon)) return true; } } From 4a8f96353641e49cd300eac4cf128ae5d4a3042f Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 20:50:19 +0200 Subject: [PATCH 20/43] this is so sad --- src/hacks/NavBot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index f82e181e..28ed0a1a 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -58,7 +58,7 @@ bool HasLowAmmo() { int *weapon_list = (int *) ((unsigned) (RAW_ENT(LOCAL_E)) + netvar.hMyWeapons); - if (g_pLocalPlayer->holding_sniper_rifle && NET_INT(LOCAL_W, netvar.m_iAmmo + 4) <= 5) + if (g_pLocalPlayer->holding_sniper_rifle && CE_INT(LOCAL_W, netvar.m_iAmmo + 4) <= 5) return true; for (int i = 0; weapon_list[i]; i++) { From f0ee53b3d6f986617bf789ec7a67f587a55fc686 Mon Sep 17 00:00:00 2001 From: LightCat Date: Tue, 21 Aug 2018 21:02:29 +0200 Subject: [PATCH 21/43] fixix --- src/hacks/NavBot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 28ed0a1a..dd1589f3 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -58,7 +58,7 @@ bool HasLowAmmo() { int *weapon_list = (int *) ((unsigned) (RAW_ENT(LOCAL_E)) + netvar.hMyWeapons); - if (g_pLocalPlayer->holding_sniper_rifle && CE_INT(LOCAL_W, netvar.m_iAmmo + 4) <= 5) + if (g_pLocalPlayer->holding_sniper_rifle && CE_INT(LOCAL_E, netvar.m_iAmmo + 4) <= 5) return true; for (int i = 0; weapon_list[i]; i++) { From 546702cb63a36f6586c0ff6ee1968c1893f1c125 Mon Sep 17 00:00:00 2001 From: LightCat Date: Wed, 22 Aug 2018 13:01:20 +0200 Subject: [PATCH 22/43] sniper spot changes --- src/hacks/NavBot.cpp | 81 +++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index dd1589f3..e52999e6 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -187,10 +187,14 @@ void Init() sniper_spots.size(), preferred_sniper_spots.size(), nest_spots.size()); } +// I doubtwe'd use more than 128 Sniper spots +std::array priority_spots; void initonce() { for (int i = 0; i < afkTicks.size(); i++) afkTicks[i].update(); + for (auto &e :priority_spots) + e = 0; cdr.update(); cd2.update(); cd3.update(); @@ -291,6 +295,43 @@ int GetClosestBuilding() } return BestBuilding; } + +void NavToSniperSpot(int priority) +{ + Vector random_spot; + if (!sniper_spots.size() && !preferred_sniper_spots.size()) + return; + auto snip_spot = preferred_sniper_spots.size() + ? preferred_sniper_spots + : sniper_spots; + int best_spot = -1; + float maxscr = FLT_MAX; + int lowest_priority = 9999; + for (int i = 0; i < snip_spot.size();i++) + { + if ((priority_spots[i] < lowest_priority)) + lowest_priority = priority_spots[i]; + } + for (int i = 0; i < snip_spot.size();i++) + { + if ((priority_spots[i] > lowest_priority)) + continue; + float scr = snip_spot[i].DistTo(g_pLocalPlayer->v_Eye); + if (scr < maxscr) + { + maxscr = scr; + best_spot = i; + } + } + + if (best_spot == -1) + return; + random_spot = snip_spot.at(best_spot); + if (random_spot.z) + nav::NavTo(random_spot, false, true, priority); + priority_spots[best_spot]++; + return; +} int follow_target = 0; void CreateMove() { @@ -327,38 +368,18 @@ void CreateMove() if (!spy_mode && !heavy_mode && !engi_mode) { cd3.update(); - Vector random_spot; if (cd2.test_and_set(5000)) Init(); - if (!sniper_spots.size() && !preferred_sniper_spots.size()) - return; - auto snip_spot = preferred_sniper_spots.size() - ? preferred_sniper_spots - : sniper_spots; - int rng = rand() % snip_spot.size(); - random_spot = snip_spot.at(rng); - if (random_spot.z) - nav::NavTo(random_spot, true, true); - return; + NavToSniperSpot(5); } else if (!engi_mode) { CachedEntity *tar = NearestEnemy(); if (CE_BAD(tar) && last_tar == -1 && nav::ReadyForCommands) { - Vector random_spot; if (cd2.test_and_set(5000)) Init(); - if (!sniper_spots.size() && !preferred_sniper_spots.size()) - return; - auto snip_spot = preferred_sniper_spots.size() - ? preferred_sniper_spots - : sniper_spots; - int rng = rand() % snip_spot.size(); - random_spot = snip_spot.at(rng); - if (random_spot.z) - nav::NavTo(random_spot, false); - return; + NavToSniperSpot(5); } if (CE_GOOD(tar)) { @@ -414,7 +435,7 @@ void CreateMove() } } // If Near The best spot and ready for commands - if (best_spot.DistTo(LOCAL_E->m_vecOrigin()) < 300.0f && + if (best_spot.DistTo(LOCAL_E->m_vecOrigin()) < 200.0f && (nav::ReadyForCommands || nav::priority == 1)) { // Get the closest Building @@ -469,7 +490,7 @@ void CreateMove() fClampAngle(angles); current_user_cmd->viewangles = angles; current_user_cmd->buttons |= IN_ATTACK; - g_pLocalPlayer->bUseSilentAngles = false; + g_pLocalPlayer->bUseSilentAngles = true; return; } } @@ -487,19 +508,9 @@ void CreateMove() // Ammo is dormant, go and find it! else if (sniper_spots.size() && nav::ReadyForCommands) { - Vector random_spot; if (cd2.test_and_set(5000)) Init(); - if (!sniper_spots.size() && - !preferred_sniper_spots.size()) - return; - auto snip_spot = preferred_sniper_spots.size() - ? preferred_sniper_spots - : sniper_spots; - int rng = rand() % snip_spot.size(); - random_spot = snip_spot.at(rng); - if (random_spot.z) - nav::NavTo(random_spot, false, false, 1); + NavToSniperSpot(1); return; } } From c31313d81d35abc50b9494e956eba18b5366fe27 Mon Sep 17 00:00:00 2001 From: LightCat Date: Wed, 22 Aug 2018 19:17:52 +0200 Subject: [PATCH 23/43] Comp bypass:tm: --- include/reclasses/CTFPartyClient.hpp | 12 +++++++++++- include/reclasses/reclasses.hpp | 1 + src/hack.cpp | 11 +++++++++++ src/hacks/NavBot.cpp | 2 -- src/reclasses/CTFPartyClient.cpp | 11 +++++++++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/include/reclasses/CTFPartyClient.hpp b/include/reclasses/CTFPartyClient.hpp index b901eb30..b8d97be7 100644 --- a/include/reclasses/CTFPartyClient.hpp +++ b/include/reclasses/CTFPartyClient.hpp @@ -6,7 +6,7 @@ */ #pragma once - +#include "reclasses.hpp" namespace re { @@ -26,4 +26,14 @@ public: int BRequestJoinPlayer(CSteamID steamid); static bool BInQueue(CTFPartyClient *this_); }; + class ITFMatchGroupDescription + { + public: + char pad0[4]; + int m_iID; + char pad1[63]; + bool m_bForceCompetitiveSettings; + }; + + ITFMatchGroupDescription* GetMatchGroupDescription(int& idx); } // namespace re diff --git a/include/reclasses/reclasses.hpp b/include/reclasses/reclasses.hpp index 45e15514..320dd084 100755 --- a/include/reclasses/reclasses.hpp +++ b/include/reclasses/reclasses.hpp @@ -10,6 +10,7 @@ #include "common.hpp" #include "C_BaseEntity.hpp" +#include "ITFGroupMatchCriteria.hpp" #include "CTFPlayerShared.hpp" #include "C_BasePlayer.hpp" #include "C_BaseCombatWeapon.hpp" diff --git a/src/hack.cpp b/src/hack.cpp index 988edbc2..7784697d 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -403,6 +403,17 @@ free(logname);*/ logging::Info("Initializer stack done"); hack::initialized = true; + for (int i = 0; i < 12; i++) + { + re::ITFMatchGroupDescription* desc = re::GetMatchGroupDescription(i); + if (!desc || desc->m_iID > 9) //ID's over 9 are invalid + continue; + if (desc->m_bForceCompetitiveSettings) + { + desc->m_bForceCompetitiveSettings = false; + logging::Info("Bypassed force competitive cvars!"); + } + } } void hack::Think() diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index e52999e6..997148c3 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -48,9 +48,7 @@ void checkAFK() if (CE_BAD(entity)) continue; if (!CE_VECTOR(entity, netvar.vVelocity).IsZero(60.0f)) - { afkTicks[i].update(); - } } } diff --git a/src/reclasses/CTFPartyClient.cpp b/src/reclasses/CTFPartyClient.cpp index a326101b..7d3fa76a 100755 --- a/src/reclasses/CTFPartyClient.cpp +++ b/src/reclasses/CTFPartyClient.cpp @@ -119,3 +119,14 @@ int re::CTFPartyClient::BRequestJoinPlayer(CSteamID steamid) BRequestJoinPlayer_t(addr); return BRequestJoinPlayer_fn(this, steamid, false); } +re::ITFMatchGroupDescription * +re::GetMatchGroupDescription(int &idx) +{ + typedef re::ITFMatchGroupDescription *( + *GetMatchGroupDescription_t)(int&); + static uintptr_t addr = gSignatures.GetClientSignature("55 89 E5 8B 45 08 8B 00 83 F8 FF"); + static GetMatchGroupDescription_t GetMatchGroupDescription_fn = + GetMatchGroupDescription_t(addr); + + return GetMatchGroupDescription_fn(idx); +} From 84e23a4eac6ad7017be78717ffa4465948f36510 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Wed, 22 Aug 2018 20:11:12 +0200 Subject: [PATCH 24/43] Fix #556 --- src/settings/SettingCommands.cpp | 95 +++++++++++++++++++++++++++++--- src/settings/SettingsIO.cpp | 4 +- 2 files changed, 88 insertions(+), 11 deletions(-) diff --git a/src/settings/SettingCommands.cpp b/src/settings/SettingCommands.cpp index cdb501ee..cc28ca01 100755 --- a/src/settings/SettingCommands.cpp +++ b/src/settings/SettingCommands.cpp @@ -11,6 +11,8 @@ Created on 29.07.18. */ +static void getAndSortAllConfigs(); + static CatCommand cat("cat", "", [](const CCommand &args) { if (args.ArgC() < 3) { @@ -69,6 +71,8 @@ static CatCommand save("save", "", [](const CCommand &args) { writer.saveTo( std::string(DATA_PATH "/configs/") + args.Arg(1) + ".conf", false); } + getAndSortAllConfigs(); + closedir(config_directory); }); static CatCommand load("load", "", [](const CCommand &args) { @@ -84,21 +88,50 @@ static CatCommand load("load", "", [](const CCommand &args) { } }); -static std::vector sorted{}; +static std::vector sortedVariables{}; static void getAndSortAllVariables() { for (auto &v : settings::Manager::instance().registered) { - sorted.push_back(v.first); + sortedVariables.push_back(v.first); } - std::sort(sorted.begin(), sorted.end()); + std::sort(sortedVariables.begin(), sortedVariables.end()); - logging::Info("Sorted %u variables\n", sorted.size()); + logging::Info("Sorted %u variables\n", sortedVariables.size()); } -static int completionCallback( +static std::vector sortedConfigs{}; + +static void getAndSortAllConfigs() +{ + DIR *config_directory = opendir(DATA_PATH "/configs"); + if (!config_directory) + { + logging::Info("Config directoy does not exist."); + closedir(config_directory); + return; + } + sortedConfigs.clear(); + + struct dirent *ent; + while ((ent = readdir(config_directory))) + { + std::string s(ent->d_name); + s = s.substr(0, s.find_last_of(".")); + logging::Info(s.c_str()); + sortedConfigs.push_back(s); + } + std::sort(sortedConfigs.begin(), sortedConfigs.end()); + sortedConfigs.erase(sortedConfigs.begin()); + sortedConfigs.erase(sortedConfigs.begin()); + + closedir(config_directory); + logging::Info("Sorted %u config files\n", sortedConfigs.size()); +} + +static int cat_completionCallback( const char *c_partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH]) { @@ -144,7 +177,7 @@ static int completionCallback( return count; } - for (const auto &s : sorted) + for (const auto &s : sortedVariables) { if (s.find(parts[1]) == 0) { @@ -162,8 +195,52 @@ static int completionCallback( return count; } +static int load_completionCallback( + const char *c_partial, + char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH]) +{ + std::string partial = c_partial; + std::string parts[2]{}; + auto j = 0u; + auto f = false; + int count = 0; + + for (auto i = 0u; i < partial.size() && j < 3; ++i) + { + auto space = (bool) isspace(partial[i]); + if (!space) + { + if (j) + parts[j - 1].push_back(partial[i]); + f = true; + } + + if (i == partial.size() - 1 || (f && space)) + { + if (space) + ++j; + f = false; + } + } + + for (const auto &s : sortedConfigs) + { + if (s.find(parts[0]) == 0) + { + snprintf(commands[count++], COMMAND_COMPLETION_ITEM_LENGTH - 1, + "cat_load %s", s.c_str()); + if (count == COMMAND_COMPLETION_MAXITEMS) + break; + } + } + return count; +} + static InitRoutine init([]() { getAndSortAllVariables(); - cat.cmd->m_bHasCompletionCallback = true; - cat.cmd->m_fnCompletionCallback = completionCallback; -}); \ No newline at end of file + getAndSortAllConfigs(); + cat.cmd->m_bHasCompletionCallback = true; + cat.cmd->m_fnCompletionCallback = cat_completionCallback; + load.cmd->m_bHasCompletionCallback = true; + load.cmd->m_fnCompletionCallback = load_completionCallback; +}); diff --git a/src/settings/SettingsIO.cpp b/src/settings/SettingsIO.cpp index d688f508..df79c369 100755 --- a/src/settings/SettingsIO.cpp +++ b/src/settings/SettingsIO.cpp @@ -17,7 +17,7 @@ bool settings::SettingsWriter::saveTo(std::string path, bool only_changed) stream.open(path, std::ios::out); - if (stream.bad()) + if (stream.bad() || !stream.is_open()) return false; using pair_type = std::pair; @@ -38,7 +38,7 @@ bool settings::SettingsWriter::saveTo(std::string path, bool only_changed) { write(v.first, v.second); } - + stream.close(); return true; } From 48715b89e9804d516a844c48d1ae208cff2a5ef2 Mon Sep 17 00:00:00 2001 From: LightCat Date: Wed, 22 Aug 2018 22:42:51 +0200 Subject: [PATCH 25/43] more sniper spot things stuff --- src/hacks/NavBot.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 997148c3..1d4044b4 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -185,14 +185,13 @@ void Init() sniper_spots.size(), preferred_sniper_spots.size(), nest_spots.size()); } -// I doubtwe'd use more than 128 Sniper spots -std::array priority_spots; + +std::unordered_map priority_spots; void initonce() { for (int i = 0; i < afkTicks.size(); i++) afkTicks[i].update(); - for (auto &e :priority_spots) - e = 0; + priority_spots.clear(); cdr.update(); cd2.update(); cd3.update(); From ed63cca1c6ef0ea739c6ded3c6937af6d8b28018 Mon Sep 17 00:00:00 2001 From: LightCat Date: Thu, 23 Aug 2018 14:14:41 +0200 Subject: [PATCH 26/43] more sniper stuff --- src/hacks/NavBot.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 1d4044b4..e4ffa29d 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -293,11 +293,11 @@ int GetClosestBuilding() return BestBuilding; } -void NavToSniperSpot(int priority) +bool NavToSniperSpot(int priority) { Vector random_spot; if (!sniper_spots.size() && !preferred_sniper_spots.size()) - return; + return false; auto snip_spot = preferred_sniper_spots.size() ? preferred_sniper_spots : sniper_spots; @@ -322,12 +322,13 @@ void NavToSniperSpot(int priority) } if (best_spot == -1) - return; + return false; random_spot = snip_spot.at(best_spot); + bool toret = false; if (random_spot.z) - nav::NavTo(random_spot, false, true, priority); + toret = nav::NavTo(random_spot, false, true, priority); priority_spots[best_spot]++; - return; + return toret; } int follow_target = 0; void CreateMove() @@ -359,15 +360,17 @@ void CreateMove() cd3.update(); bool isready = (spy_mode || heavy_mode || engi_mode) ? 1 : nav::ReadyForCommands; - int waittime = (spy_mode || heavy_mode || engi_mode) ? 100 : 5000; + static int waittime = (spy_mode || heavy_mode || engi_mode) ? 100 : 2000; if (isready && cd3.test_and_set(waittime)) { + waittime = (spy_mode || heavy_mode || engi_mode) ? 100 : 2000; if (!spy_mode && !heavy_mode && !engi_mode) { cd3.update(); if (cd2.test_and_set(5000)) Init(); - NavToSniperSpot(5); + if (!NavToSniperSpot(5)) + waittime = 1; } else if (!engi_mode) { @@ -376,13 +379,17 @@ void CreateMove() { if (cd2.test_and_set(5000)) Init(); - NavToSniperSpot(5); + if (!NavToSniperSpot(5)) + waittime = 1; } if (CE_GOOD(tar)) { if (!spy_mode || !hacks::shared::backtrack::isBacktrackEnabled) - nav::NavTo(tar->m_vecOrigin(), false); + { + if (!nav::NavTo(tar->m_vecOrigin(), false)) + last_tar = -1; + } else { for (auto i : hacks::shared::backtrack::headPositions @@ -507,7 +514,8 @@ void CreateMove() { if (cd2.test_and_set(5000)) Init(); - NavToSniperSpot(1); + if (!NavToSniperSpot(1)) + waittime = 1; return; } } From 1d4fdf2121b2583c783defdd94b15a4f2f1a1160 Mon Sep 17 00:00:00 2001 From: Olek <23708759+Roguezilla@users.noreply.github.com> Date: Thu, 23 Aug 2018 13:31:48 +0100 Subject: [PATCH 27/43] Update CatBot.cpp [VALVE] BenCat07, [23.08.18 13:29] [In reply to roguezilla] no u [VALVE] BenCat07, [23.08.18 13:29] it's open source --- src/hacks/CatBot.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hacks/CatBot.cpp b/src/hacks/CatBot.cpp index 0b670a80..f61988ac 100644 --- a/src/hacks/CatBot.cpp +++ b/src/hacks/CatBot.cpp @@ -118,7 +118,9 @@ void update_catbot_list() strcasestr(info.name, "zCat") || strcasestr(info.name, "lagger bot") || strcasestr(info.name, "zLag-bot") || - strcasestr(info.name, "crash-bot")) + strcasestr(info.name, "crash-bot") || + strcasestr(info.name, "reichstagbot") + ) { if (human_detecting_map.find(info.friendsID) == human_detecting_map.end()) From 5177709fe8ec5f7a40e7c9f0d2a38feb47b06f52 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Thu, 23 Aug 2018 17:14:29 +0200 Subject: [PATCH 28/43] Wot why does this not work --- include/navparser.hpp | 47 +++++++++++++++++++++++++++++++++++++++---- src/navparser.cpp | 7 +++++-- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/include/navparser.hpp b/include/navparser.hpp index 00dc8743..efd3b794 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -4,6 +4,7 @@ #include "micropather.h" #include "pwd.h" #include +#include #if ENABLE_VISUALS #include #endif @@ -29,7 +30,11 @@ size_t FindInVector(size_t id); class inactivityTracker { // Map for storing inactivity per connection - std::map, std::pair> inactives; + std::unordered_map, std::pair, + boost::hash>> + inactives; + std::vector sentryAreas; + bool vischeckConnection(std::pair &connection) { Vector begin = areas.at(FindInVector(connection.first)).m_center; @@ -39,6 +44,7 @@ class inactivityTracker bool result = IsVectorVisible(begin, end, false); return result; } + std::pair VectorToId(std::pair &connection) { CNavArea *currnode = nullptr; @@ -83,6 +89,30 @@ public: i.second.second = 0; } } + void updateSentries() + { + logging::Info("1"); + sentryAreas.clear(); + + for (int i = 0; i < HIGHEST_ENTITY; i++) + { + CachedEntity *ent = ENTITY(i); + if (CE_BAD(ent) || ent->m_iClassID() != CL_CLASS(CObjectSentrygun)) + continue; + Vector sentryloc = GetBuildingPosition(ent); + for (auto i : areas) + { + Vector area = i.m_center; + area.z += 30.0f; + if (area.DistTo(sentryloc) > 1100.0f) + continue; + if (!IsVectorVisible(area, sentryloc, true)) + continue; + logging::Info("5"); + sentryAreas.push_back(i.m_id); + } + } + } bool IsIgnored(std::pair connection) { if (inactives.find(connection) == inactives.end()) @@ -101,6 +131,14 @@ public: "Ignored a connection due to type 2 connection type."); return true; } + if (std::find(sentryAreas.begin(), sentryAreas.end(), + connection.first) != sentryAreas.end() || + std::find(sentryAreas.begin(), sentryAreas.end(), + connection.second) != sentryAreas.end()) + { + logging::Info("Ignored a connection due to sentry gun coverage"); + return true; + } return false; } @@ -113,9 +151,10 @@ public: } auto &pair = inactives.at(connection); - unsigned int newTime = std::chrono::duration_cast( - std::chrono::system_clock::now() - timer.last) - .count(); + unsigned int newTime = + std::chrono::duration_cast( + std::chrono::system_clock::now() - timer.last) + .count(); if (pair.first == 2 && !vischeckConnection(connection)) newTime = (newTime > 2500 ? 2500 : newTime); pair.second = pair.second + newTime; diff --git a/src/navparser.cpp b/src/navparser.cpp index 9872bfc8..c2676055 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -242,8 +242,9 @@ void clearInstructions() static Timer ignoreReset{}; static Timer patherReset{}; +static Timer sentryUpdate{}; // Function for removing ignores -void clearIgnores() +void ignoreManagerCM() { if (!TF2MAP || !TF2MAP->pather) return; @@ -251,6 +252,8 @@ void clearIgnores() TF2MAP->inactiveTracker.reset(); if (patherReset.test_and_set(30000)) TF2MAP->pather->Reset(); + if(sentryUpdate.test_and_set(2000)) + TF2MAP->inactiveTracker.updateSentries(); } void Repath() @@ -287,7 +290,7 @@ void CreateMove() crumbs.clear(); return; } - clearIgnores(); + ignoreManagerCM(); // Crumbs empty, prepare for next instruction if (crumbs.empty()) { From a13188317ff8d18b2dcfa863d844f9125bf53043 Mon Sep 17 00:00:00 2001 From: LightCat Date: Fri, 24 Aug 2018 13:00:28 +0200 Subject: [PATCH 29/43] Sentry ignore for NavBots! --- include/navparser.hpp | 43 ++++++++++++++++++++++++++----------------- include/trace.hpp | 14 ++++++++++++++ src/helpers.cpp | 24 +++++++++++++++++------- src/navparser.cpp | 14 ++++++++++++-- src/trace.cpp | 28 ++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 26 deletions(-) diff --git a/include/navparser.hpp b/include/navparser.hpp index efd3b794..afa010e9 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -33,7 +33,8 @@ class inactivityTracker std::unordered_map, std::pair, boost::hash>> inactives; - std::vector sentryAreas; + std::unordered_map sentryAreas; + std::vector sentries; bool vischeckConnection(std::pair &connection) { @@ -89,36 +90,52 @@ public: i.second.second = 0; } } + bool ShouldCancelPath(std::vector crumbs) + { + for (auto sentry : sentries) + for (auto crumb : crumbs) + { + if (crumb.DistTo(sentry) > 1100) + continue; + if (!IsVectorVisible(crumb, sentry, true)) + continue; + return true; + } + return false; + } void updateSentries() { - logging::Info("1"); sentryAreas.clear(); - + sentries.clear(); for (int i = 0; i < HIGHEST_ENTITY; i++) { CachedEntity *ent = ENTITY(i); - if (CE_BAD(ent) || ent->m_iClassID() != CL_CLASS(CObjectSentrygun)) + if (CE_BAD(ent) || ent->m_iClassID() != CL_CLASS(CObjectSentrygun) || ent->m_iTeam() == LOCAL_E->m_iTeam()) continue; Vector sentryloc = GetBuildingPosition(ent); + sentries.push_back(sentryloc); for (auto i : areas) { Vector area = i.m_center; - area.z += 30.0f; + area.z += 83.0f; if (area.DistTo(sentryloc) > 1100.0f) continue; if (!IsVectorVisible(area, sentryloc, true)) continue; - logging::Info("5"); - sentryAreas.push_back(i.m_id); + sentryAreas[i.m_id] = true; } } } bool IsIgnored(std::pair connection) { - if (inactives.find(connection) == inactives.end()) + if (sentryAreas[connection.first] || + sentryAreas[connection.second]) { - return false; + logging::Info("Ignored a connection due to sentry gun coverage"); + return true; } + if (inactives.find(connection) == inactives.end()) + return false; auto &pair = inactives.at(connection); if (pair.second >= 5000) { @@ -131,14 +148,6 @@ public: "Ignored a connection due to type 2 connection type."); return true; } - if (std::find(sentryAreas.begin(), sentryAreas.end(), - connection.first) != sentryAreas.end() || - std::find(sentryAreas.begin(), sentryAreas.end(), - connection.second) != sentryAreas.end()) - { - logging::Info("Ignored a connection due to sentry gun coverage"); - return true; - } return false; } diff --git a/include/trace.hpp b/include/trace.hpp index bc3f47b2..5bdb9b0d 100644 --- a/include/trace.hpp +++ b/include/trace.hpp @@ -42,6 +42,19 @@ public: virtual TraceType_t GetTraceType() const; }; +class FilterNoEntity : public ITraceFilter +{ +public: + IClientEntity *m_pSelf; + +public: + virtual ~FilterNoEntity(); + FilterNoEntity(); + virtual bool ShouldHitEntity(IHandleEntity *entity, int mask); + void SetSelf(IClientEntity *self); + virtual TraceType_t GetTraceType() const; +}; + class FilterPenetration : public ITraceFilter { public: @@ -59,5 +72,6 @@ public: extern FilterDefault filter_default; extern FilterNoPlayer filter_no_player; +extern FilterNoEntity filter_no_entity; extern FilterPenetration filter_penetration; } // namespace trace diff --git a/src/helpers.cpp b/src/helpers.cpp index 11e808b6..63a9bf4b 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -1107,19 +1107,29 @@ netvar.iHealth)); bool IsVectorVisible(Vector origin, Vector target, bool enviroment_only) { - trace_t trace_visible; - Ray_t ray; - trace::filter_no_player.SetSelf(RAW_ENT(g_pLocalPlayer->entity)); - ray.Init(origin, target); if (!enviroment_only) + { + trace_t trace_visible; + Ray_t ray; + + trace::filter_no_player.SetSelf(RAW_ENT(g_pLocalPlayer->entity)); + ray.Init(origin, target); g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_no_player, &trace_visible); + return (trace_visible.fraction == 1.0f); + } else - g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, - &trace_visible); + { + trace_t trace_visible; + Ray_t ray; - return (trace_visible.fraction == 1.0f); + trace::filter_no_entity.SetSelf(RAW_ENT(g_pLocalPlayer->entity)); + ray.Init(origin, target); + g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_no_entity, + &trace_visible); + return (trace_visible.fraction == 1.0f); + } } void WhatIAmLookingAt(int *result_eindex, Vector *result_pos) diff --git a/src/navparser.cpp b/src/navparser.cpp index c2676055..46a38e97 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -243,6 +243,7 @@ void clearInstructions() static Timer ignoreReset{}; static Timer patherReset{}; static Timer sentryUpdate{}; +static Timer sentryCheck{}; // Function for removing ignores void ignoreManagerCM() { @@ -252,8 +253,8 @@ void ignoreManagerCM() TF2MAP->inactiveTracker.reset(); if (patherReset.test_and_set(30000)) TF2MAP->pather->Reset(); - if(sentryUpdate.test_and_set(2000)) - TF2MAP->inactiveTracker.updateSentries(); + if(sentryUpdate.test_and_set(1000)) + TF2MAP->inactiveTracker.updateSentries(); } void Repath() @@ -265,6 +266,7 @@ void Repath() // Throwaway int int i1, i2; // Find a new path + TF2MAP->pather->Reset(); crumbs = findPath(g_pLocalPlayer->v_Origin, crumbs.back(), i1, i2); } else @@ -273,6 +275,7 @@ void Repath() "Pathing: NavBot inactive for too long. Canceling tasks and " "ignoring connection..."); // Wait for new instructions + TF2MAP->pather->Reset(); crumbs.clear(); } } @@ -325,6 +328,13 @@ void CreateMove() inactivity.update(); return; } + // Check for new sentries + if (sentryCheck.test_and_set(1000) && TF2MAP->inactiveTracker.ShouldCancelPath(crumbs)) + { + logging::Info("Pathing: New Sentry found!"); + TF2MAP->pather->Reset(); + Repath(); + } // If inactive for too long if (inactivity.check(5000)) { diff --git a/src/trace.cpp b/src/trace.cpp index 3100dfe7..384d7e69 100755 --- a/src/trace.cpp +++ b/src/trace.cpp @@ -110,7 +110,34 @@ TraceType_t trace::FilterNoPlayer::GetTraceType() const { return TRACE_EVERYTHING; } +/* No-Entity filter */ +trace::FilterNoEntity::FilterNoEntity() +{ + m_pSelf = nullptr; +} + +trace::FilterNoEntity::~FilterNoEntity(){}; + +void trace::FilterNoEntity::SetSelf(IClientEntity *self) +{ + if (self == nullptr) + { + logging::Info("nullptr in FilterNoPlayer::SetSelf"); + return; + } + m_pSelf = self; +} + +bool trace::FilterNoEntity::ShouldHitEntity(IHandleEntity *handle, int mask) +{ + return false; +} + +TraceType_t trace::FilterNoEntity::GetTraceType() const +{ + return TRACE_EVERYTHING; +} /* Penetration Filter */ trace::FilterPenetration::FilterPenetration() @@ -172,4 +199,5 @@ void trace::FilterPenetration::Reset() trace::FilterDefault trace::filter_default{}; trace::FilterNoPlayer trace::filter_no_player{}; +trace::FilterNoEntity trace::filter_no_entity{}; trace::FilterPenetration trace::filter_penetration{}; From 059b801e1ae06c348e5ccea624b6200ab9f145bc Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Fri, 24 Aug 2018 15:18:55 +0200 Subject: [PATCH 30/43] Support gcc optimizations / fix undefined behaviour --- include/hacks/Aimbot.hpp | 1 - include/settings/Key.hpp | 6 +++--- src/hacks/Aimbot.cpp | 2 +- src/hacks/ESP.cpp | 2 +- src/hacks/LightESP.cpp | 2 +- src/hooks/SendDatagram.cpp | 4 ++-- src/reclasses/C_TEFireBullets.cpp | 1 - 7 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/hacks/Aimbot.hpp b/include/hacks/Aimbot.hpp index 51c0fe3f..c1f4f3c4 100644 --- a/include/hacks/Aimbot.hpp +++ b/include/hacks/Aimbot.hpp @@ -8,7 +8,6 @@ #pragma once #include "common.hpp" -#include "config.h" class ConVar; class IClientEntity; diff --git a/include/settings/Key.hpp b/include/settings/Key.hpp index eb1e749b..f535bb99 100644 --- a/include/settings/Key.hpp +++ b/include/settings/Key.hpp @@ -61,8 +61,8 @@ public: { fromString(string); } - - Variable &reset() + // Variable & causes segfault with gcc optimizations + void reset() { setInternal(Key{}); } @@ -139,4 +139,4 @@ protected: std::string string{}; Key value{}; }; -} // namespace settings \ No newline at end of file +} // namespace settings diff --git a/src/hacks/Aimbot.cpp b/src/hacks/Aimbot.cpp index ae4e89aa..425727b6 100644 --- a/src/hacks/Aimbot.cpp +++ b/src/hacks/Aimbot.cpp @@ -353,7 +353,7 @@ CachedEntity *RetrieveBestTarget(bool aimkey_state) target_last = nullptr; target_eid = -1; - float target_highest_score, scr; + float target_highest_score, scr = 0.0f; CachedEntity *ent; CachedEntity *target_highest_ent = 0; target_highest_score = -256; diff --git a/src/hacks/ESP.cpp b/src/hacks/ESP.cpp index 01443feb..76c50de0 100644 --- a/src/hacks/ESP.cpp +++ b/src/hacks/ESP.cpp @@ -351,7 +351,7 @@ void _FASTCALL emoji(CachedEntity *ent) if (emoji_esp_scaling && (size < *emoji_min_size)) size = *emoji_min_size; player_info_s info{}; - unsigned int steamID; + unsigned int steamID = 0; unsigned int steamidarray[32]{}; bool hascall = false; steamidarray[0] = 479487126; diff --git a/src/hacks/LightESP.cpp b/src/hacks/LightESP.cpp index c05b16bd..51678356 100644 --- a/src/hacks/LightESP.cpp +++ b/src/hacks/LightESP.cpp @@ -61,7 +61,7 @@ void draw() Vector out; if (draw::WorldToScreen(hitp[i], out)) { - float size; + float size = 0.0f; Vector pout, pout2; if (draw::WorldToScreen(minp[i], pout) && draw::WorldToScreen(maxp[i], pout2)) diff --git a/src/hooks/SendDatagram.cpp b/src/hooks/SendDatagram.cpp index e70bf1af..def9bd5c 100644 --- a/src/hooks/SendDatagram.cpp +++ b/src/hooks/SendDatagram.cpp @@ -11,8 +11,8 @@ namespace hooked_methods DEFINE_HOOKED_METHOD(SendDatagram, int, INetChannel *ch, bf_write *buf) { #if !LAGBOT_MODE - int in; - int state; + int in = 0; + int state = 0; if (CE_GOOD(LOCAL_E)) { in = ch->m_nInSequenceNr; diff --git a/src/reclasses/C_TEFireBullets.cpp b/src/reclasses/C_TEFireBullets.cpp index ece4991e..fee3b9ae 100755 --- a/src/reclasses/C_TEFireBullets.cpp +++ b/src/reclasses/C_TEFireBullets.cpp @@ -5,7 +5,6 @@ * Author: bencat07 */ #include "reclasses.hpp" -#pragma once C_BaseTempEntity *C_TEFireBullets::GTEFireBullets() { From 74b299ca59cf597d8cd5985a614d1896ee617775 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Fri, 24 Aug 2018 15:44:58 +0200 Subject: [PATCH 31/43] Fully remove BPTF --- CMakeLists.txt | 3 - include/CMakeLists.txt | 3 +- include/https_request.hpp | 40 ----------- install-all | 4 +- src/CMakeLists.txt | 1 - src/https_request.cpp | 144 -------------------------------------- 6 files changed, 3 insertions(+), 192 deletions(-) delete mode 100644 include/https_request.hpp delete mode 100644 src/https_request.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 602eecf6..32fc86bd 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,5 @@ # Current dependencies: # Git -# OpenSSL (maybe should be removed, only used by backpack.tf esp) # SDL2 # GLEW @@ -40,7 +39,6 @@ if(NOT EnableVisuals) endif() find_package(Git REQUIRED) -find_package(OpenSSL REQUIRED) # cat packages @@ -87,7 +85,6 @@ endif() configure_file(include/config.h.in ${CMAKE_SOURCE_DIR}/include/config.h @ONLY) configure_file(include/version.h.in ${CMAKE_SOURCE_DIR}/include/version.h @ONLY) -set_target_properties(cathook PROPERTIES COMPILE_FLAGS "-m32 -msse -msse2 -msse3 -fexceptions" LINK_FLAGS "-m32 -fno-gnu-unique -fexceptions -DNDEBUG") target_compile_definitions(cathook PRIVATE _GLIBCXX_USE_CXX11_ABI=0 diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index e8dd5d4b..f7d4793d 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -18,7 +18,6 @@ target_sources(cathook PRIVATE "${CMAKE_CURRENT_LIST_DIR}/hitrate.hpp" "${CMAKE_CURRENT_LIST_DIR}/hooks.hpp" "${CMAKE_CURRENT_LIST_DIR}/hoovy.hpp" - "${CMAKE_CURRENT_LIST_DIR}/https_request.hpp" "${CMAKE_CURRENT_LIST_DIR}/init.hpp" "${CMAKE_CURRENT_LIST_DIR}/ipc.hpp" "${CMAKE_CURRENT_LIST_DIR}/itemtypes.hpp" @@ -38,7 +37,7 @@ target_sources(cathook PRIVATE "${CMAKE_CURRENT_LIST_DIR}/velocity.hpp" "${CMAKE_CURRENT_LIST_DIR}/votelogger.hpp" "${CMAKE_CURRENT_LIST_DIR}/MiscTemporary.hpp" - "${CMAKE_CURRENT_LIST_DIR}/navparser.hpp" + "${CMAKE_CURRENT_LIST_DIR}/navparser.hpp" "${CMAKE_CURRENT_LIST_DIR}/Options.hpp" "${CMAKE_CURRENT_LIST_DIR}/PlayerTools.hpp") diff --git a/include/https_request.hpp b/include/https_request.hpp deleted file mode 100644 index b087a345..00000000 --- a/include/https_request.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * https_request.hpp - * - * Created on: Jul 23, 2017 - * Author: nullifiedcat - */ - -#pragma once - -#include -#include - -#include - -namespace https -{ - -extern SSL_CTX *ssl_context; - -class RAII_HTTPS_Socket -{ -public: - RAII_HTTPS_Socket(const std::string &host); - ~RAII_HTTPS_Socket(); - - bool ssl_connect(); - void ssl_die(); - - std::string get(const std::string &path); - - const std::string hostname_; - - hostent *host_{ nullptr }; - sockaddr_in addr_{}; - int sock_{ -1 }; - SSL *connection_{ nullptr }; -}; - -void initialize(); -} // namespace https diff --git a/install-all b/install-all index c200a0b5..994cea56 100755 --- a/install-all +++ b/install-all @@ -11,11 +11,11 @@ rm ../install-all # remove install file # Install base Dependencies # if [ -f "/etc/arch-release" ]; then - sudo pacman -S --needed --noconfirm boost cmake make lib32-openssl lib32-libpng gcc gdb lib32-sdl2 lib32-glew freetype2 rsync + sudo pacman -S --needed --noconfirm boost cmake make lib32-libpng gcc gdb lib32-sdl2 lib32-glew freetype2 rsync else sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y sudo apt update - sudo apt install build-essential git gcc-multilib g++-multilib software-properties-common gcc-snapshot g++-7-multilib gcc-7 g++-7 libssl-dev:i386 libboost-all-dev libc6-dev:i386 gdb libsdl2-dev libglew-dev:i386 libglew-dev libfreetype6-dev libfreetype6-dev:i386 cmake libpng-dev libssl-dev cmake gcc-multilib g++-multilib -y + sudo apt install build-essential git gcc-multilib g++-multilib software-properties-common gcc-snapshot g++-7-multilib gcc-7 g++-7 libboost-all-dev libc6-dev:i386 gdb libsdl2-dev libglew-dev:i386 libglew-dev libfreetype6-dev libfreetype6-dev:i386 cmake libpng-dev cmake gcc-multilib g++-multilib -y fi # # Update cathook diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 963d3daa..08b5b548 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,6 @@ target_sources(cathook PRIVATE "${CMAKE_CURRENT_LIST_DIR}/hitrate.cpp" "${CMAKE_CURRENT_LIST_DIR}/hooks.cpp" "${CMAKE_CURRENT_LIST_DIR}/hoovy.cpp" - "${CMAKE_CURRENT_LIST_DIR}/https_request.cpp" "${CMAKE_CURRENT_LIST_DIR}/ipc.cpp" "${CMAKE_CURRENT_LIST_DIR}/itemtypes.cpp" "${CMAKE_CURRENT_LIST_DIR}/localplayer.cpp" diff --git a/src/https_request.cpp b/src/https_request.cpp deleted file mode 100644 index 7da88bd4..00000000 --- a/src/https_request.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * https_request.cpp - * - * Created on: Jul 23, 2017 - * Author: nullifiedcat - */ - -#include -#include "https_request.hpp" - -#include -#include -#include - -#include - -#include -#include - -namespace https -{ - -SSL_CTX *ssl_context; - -bool initialized = false; - -RAII_HTTPS_Socket::RAII_HTTPS_Socket(const std::string &host) : hostname_(host) -{ - if (!initialized) - { - logging::Info("Initializing SSL"); - initialize(); - } - sock_ = socket(AF_INET, SOCK_STREAM, 0); - if (sock_ < 0) - { - throw std::runtime_error("Socket creation error"); - } - host_ = gethostbyname(hostname_.c_str()); - if (not host_) - { - throw std::runtime_error("Could not resolve hostname: " + host); - } - memset(&addr_, 0, sizeof(addr_)); - addr_.sin_family = AF_INET; - addr_.sin_port = htons(443); - memcpy(&addr_.sin_addr.s_addr, host_->h_addr, host_->h_length); - if (connect(sock_, (sockaddr *) &addr_, sizeof(addr_)) < 0) - { - close(sock_); - sock_ = -1; - throw std::runtime_error("Couldn't connect to host"); - } - ssl_connect(); -} - -RAII_HTTPS_Socket::~RAII_HTTPS_Socket() -{ - ssl_die(); - if (sock_ >= 0) - close(sock_); -} - -bool RAII_HTTPS_Socket::ssl_connect() -{ - connection_ = SSL_new(ssl_context); - SSL_set_fd(connection_, sock_); - int ret = SSL_connect(connection_); - if (ret != 1) - { - logging::Info("SSL connection error: %d, %d, %x\n", ret, - SSL_get_error(connection_, ret), ERR_get_error()); - return false; - } - return true; -} - -void RAII_HTTPS_Socket::ssl_die() -{ - if (connection_) - { - SSL_free(connection_); - connection_ = nullptr; - } -} - -std::string RAII_HTTPS_Socket::get(const std::string &path) -{ - constexpr size_t rq_size = 1024 * 8; - constexpr size_t rs_size = 1024 * 1024; - - std::unique_ptr buffer_rq(new char[rq_size]), - buffer_rs(new char[rs_size]); - - memset(buffer_rq.get(), 0, rq_size); - int rq_length = snprintf(buffer_rq.get(), rq_size, - "GET %s HTTP/1.0\r\nHost: %s\r\n\r\n", - path.c_str(), hostname_.c_str()); - int sent = 0; - int chunk = 0; - do - { - chunk = - SSL_write(connection_, buffer_rq.get() + sent, rq_length - sent); - if (chunk < 0) - { - throw std::runtime_error("Error writing to Secure Socket: " + - std::to_string(ERR_get_error())); - } - else if (chunk == 0) - { - break; - } - sent += chunk; - } while (sent < rq_length); - - memset(buffer_rs.get(), 0, rs_size); - int total = rs_size - 1; - int received = 0; - do - { - chunk = - SSL_read(connection_, buffer_rs.get() + received, total - received); - if (chunk < 0) - throw std::runtime_error("Error reading from socket"); - if (chunk == 0) - break; - received += chunk; - } while (received < total); - - if (received == total) - throw std::runtime_error("Response too large"); - - return std::string(buffer_rs.get()); -} - -void initialize() -{ - SSL_load_error_strings(); - SSL_library_init(); - ssl_context = SSL_CTX_new(SSLv23_client_method()); - initialized = true; -} -} // namespace https From 634be683192f848a0c21c072bf0f463ccbb663f8 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Fri, 24 Aug 2018 16:50:48 +0200 Subject: [PATCH 32/43] Do some debug safe optimizations by default --- CMakeLists.txt | 12 +++++------- include/settings/Key.hpp | 9 +++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32fc86bd..0b2faa42 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,11 @@ endif() configure_file(include/config.h.in ${CMAKE_SOURCE_DIR}/include/config.h @ONLY) configure_file(include/version.h.in ${CMAKE_SOURCE_DIR}/include/version.h @ONLY) +#set_target_properties(cathook PROPERTIES COMPILE_FLAGS "-m32 -msse -msse2 -msse3 -fexceptions" LINK_FLAGS "-m32 -fno-gnu-unique -fexceptions -DNDEBUG") +set(CMAKE_CXX_FLAGS "-m32 -msse -msse2 -msse3 -fexceptions -fno-gnu-unique -DNDEBUG") +set(CMAKE_CXX_FLAGS_DEBUG "-Og -g") +set(CMAKE_CXX_FLAGS_RELEASE "-O3") + target_compile_definitions(cathook PRIVATE _GLIBCXX_USE_CXX11_ABI=0 @@ -125,13 +130,6 @@ add_custom_target(data target_link_libraries(cathook ${ValveLibraryTier0} ${ValveLibraryVStdLib} ssl) set_target_properties(cathook PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -# Strip -if(CMAKE_BUILD_TYPE STREQUAL "Release") - message("Stripping info from library") - add_custom_command(TARGET cathook POST_BUILD - COMMAND strip --strip-all "$") -endif() - add_subdirectory(src) add_subdirectory(include) add_subdirectory(external) diff --git a/include/settings/Key.hpp b/include/settings/Key.hpp index f535bb99..186c6ca5 100644 --- a/include/settings/Key.hpp +++ b/include/settings/Key.hpp @@ -57,24 +57,25 @@ public: setInternal(key); } - Variable &operator=(const std::string &string) + // Variable & causes segfault with gcc optimizations + these dont even return anything + void operator=(const std::string &string) { fromString(string); } - // Variable & causes segfault with gcc optimizations + void reset() { setInternal(Key{}); } - Variable &key(SDL_Scancode key) + void key(SDL_Scancode key) { Key k{}; k.scan = key; setInternal(k); } - Variable &mouse(int mouse_key) + void mouse(int mouse_key) { Key k{}; k.mouse = mouse_key; From 8460b06876d977659ba0f98583bd2300fef04fc4 Mon Sep 17 00:00:00 2001 From: LightCat Date: Fri, 24 Aug 2018 20:48:11 +0200 Subject: [PATCH 33/43] Fix crash --- include/hacks/SeedPrediction.hpp | 8 ++-- include/hooks/CMakeLists.txt | 3 +- include/hooks/HookedMethods.hpp | 2 - include/hooks/PreDataUpdate.hpp | 10 ++++ include/navparser.hpp | 2 +- include/reclasses/C_TEFireBullets.hpp | 4 +- src/hacks/NavBot.cpp | 67 +++++++++++++++------------ src/hacks/SeedPrediction.cpp | 60 +++++++++++++----------- src/hooks/CreateMove.cpp | 3 ++ src/hooks/PreDataUpdate.cpp | 28 +++++++++-- src/navparser.cpp | 3 ++ src/reclasses/C_TEFireBullets.cpp | 9 ++-- 12 files changed, 125 insertions(+), 74 deletions(-) create mode 100644 include/hooks/PreDataUpdate.hpp diff --git a/include/hacks/SeedPrediction.hpp b/include/hacks/SeedPrediction.hpp index add7124e..8484fb40 100644 --- a/include/hacks/SeedPrediction.hpp +++ b/include/hacks/SeedPrediction.hpp @@ -12,7 +12,7 @@ #pragma once namespace hacks::tf2::seedprediction { -extern settings::Bool prediction; +bool predon(); void handleFireBullets(C_TEFireBullets *); struct seedstruct { @@ -28,7 +28,7 @@ struct predictSeed2 { seedstruct base; int tickcount; - double resolution; + float resolution; bool operator<(const predictSeed2 &rhs) const { return tickcount < rhs.tickcount; @@ -37,7 +37,7 @@ struct predictSeed2 struct IntervalEdge { int pos; - double val; + float val; bool operator<(const IntervalEdge &rhs) const { return val < rhs.val; @@ -50,5 +50,5 @@ extern buf bases; extern buf2 rebased; extern buf3 intervals; void selectBase(); -double predictOffset(const seedstruct &entry, int targetTick, double clockRes); +float predictOffset(const seedstruct &entry, int targetTick, float clockRes); } // namespace hacks::tf2::seedprediction diff --git a/include/hooks/CMakeLists.txt b/include/hooks/CMakeLists.txt index 2151284f..9588f1d1 100755 --- a/include/hooks/CMakeLists.txt +++ b/include/hooks/CMakeLists.txt @@ -1,4 +1,5 @@ target_sources(cathook PRIVATE - "${CMAKE_CURRENT_LIST_DIR}/HookedMethods.hpp") + "${CMAKE_CURRENT_LIST_DIR}/HookedMethods.hpp" + "${CMAKE_CURRENT_LIST_DIR}/PreDataUpdate.hpp") target_include_directories(cathook PRIVATE "${CMAKE_CURRENT_LIST_DIR}") \ No newline at end of file diff --git a/include/hooks/HookedMethods.hpp b/include/hooks/HookedMethods.hpp index 4e71a2ef..fe49f141 100644 --- a/include/hooks/HookedMethods.hpp +++ b/include/hooks/HookedMethods.hpp @@ -36,8 +36,6 @@ struct SDL_Window; &hooked_methods::original::name namespace hooked_methods { -// FireBullets -DECLARE_HOOKED_METHOD(PreDataUpdate, void, void *, int); // ClientMode DECLARE_HOOKED_METHOD(CreateMove, bool, void *, float, CUserCmd *); DECLARE_HOOKED_METHOD(LevelInit, void, void *, const char *); diff --git a/include/hooks/PreDataUpdate.hpp b/include/hooks/PreDataUpdate.hpp new file mode 100644 index 00000000..ddf6fdf5 --- /dev/null +++ b/include/hooks/PreDataUpdate.hpp @@ -0,0 +1,10 @@ +// +// Created by bencat07 on 24.08.18. +// + +#pragma once +#include "HookedMethods.hpp" +namespace hooked_methods +{ + void CreateMove(); +} diff --git a/include/navparser.hpp b/include/navparser.hpp index afa010e9..28951982 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -34,7 +34,7 @@ class inactivityTracker boost::hash>> inactives; std::unordered_map sentryAreas; - std::vector sentries; + std::vector sentries{}; bool vischeckConnection(std::pair &connection) { diff --git a/include/reclasses/C_TEFireBullets.hpp b/include/reclasses/C_TEFireBullets.hpp index 0344b49b..3d87d6d2 100755 --- a/include/reclasses/C_TEFireBullets.hpp +++ b/include/reclasses/C_TEFireBullets.hpp @@ -6,11 +6,11 @@ */ #pragma once #include "reclasses.hpp" -class C_TEFireBullets : public C_BaseTempEntity +class C_TEFireBullets { public: C_TEFireBullets() = delete; - static C_BaseTempEntity *GTEFireBullets(); + static C_TEFireBullets *GTEFireBullets(); public: int m_iSeed(); diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index e4ffa29d..9ecaf141 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -295,39 +295,48 @@ int GetClosestBuilding() bool NavToSniperSpot(int priority) { - Vector random_spot; + Vector random_spot{}; if (!sniper_spots.size() && !preferred_sniper_spots.size()) return false; - auto snip_spot = preferred_sniper_spots.size() + bool use_preferred = !preferred_sniper_spots.empty(); + auto snip_spot = use_preferred ? preferred_sniper_spots : sniper_spots; - int best_spot = -1; - float maxscr = FLT_MAX; - int lowest_priority = 9999; - for (int i = 0; i < snip_spot.size();i++) - { - if ((priority_spots[i] < lowest_priority)) - lowest_priority = priority_spots[i]; - } - for (int i = 0; i < snip_spot.size();i++) - { - if ((priority_spots[i] > lowest_priority)) - continue; - float scr = snip_spot[i].DistTo(g_pLocalPlayer->v_Eye); - if (scr < maxscr) - { - maxscr = scr; - best_spot = i; - } - } - - if (best_spot == -1) - return false; - random_spot = snip_spot.at(best_spot); bool toret = false; - if (random_spot.z) - toret = nav::NavTo(random_spot, false, true, priority); - priority_spots[best_spot]++; + if (use_preferred) + { + int best_spot = -1; + float maxscr = FLT_MAX; + int lowest_priority = 9999; + for (int i = 0; i < snip_spot.size(); i++) + { + if ((priority_spots[i] < lowest_priority)) + lowest_priority = priority_spots[i]; + } + for (int i = 0; i < snip_spot.size(); i++) { + if ((priority_spots[i] > lowest_priority)) + continue; + float scr = snip_spot[i].DistTo(g_pLocalPlayer->v_Eye); + if (scr < maxscr) { + maxscr = scr; + best_spot = i; + } + } + + if (best_spot == -1) + return false; + random_spot = snip_spot.at(best_spot); + if (random_spot.z) + toret = nav::NavTo(random_spot, false, true, priority); + priority_spots[best_spot]++; + } + else if (!snip_spot.empty()) + { + int rng = rand() % snip_spot.size(); + random_spot = snip_spot.at(rng); + if (random_spot.z) + toret = nav::NavTo(random_spot, false, true, priority); + } return toret; } int follow_target = 0; @@ -359,7 +368,7 @@ void CreateMove() if (!nav::ReadyForCommands && !spy_mode && !heavy_mode && !engi_mode) cd3.update(); bool isready = - (spy_mode || heavy_mode || engi_mode) ? 1 : nav::ReadyForCommands; + (spy_mode || heavy_mode || engi_mode) ? true : nav::ReadyForCommands; static int waittime = (spy_mode || heavy_mode || engi_mode) ? 100 : 2000; if (isready && cd3.test_and_set(waittime)) { diff --git a/src/hacks/SeedPrediction.cpp b/src/hacks/SeedPrediction.cpp index 8566bd56..1ac86b02 100644 --- a/src/hacks/SeedPrediction.cpp +++ b/src/hacks/SeedPrediction.cpp @@ -8,13 +8,17 @@ #include "common.hpp" #include "SeedPrediction.hpp" #include "reclasses.hpp" -constexpr double MIN_CLOCKRES = 0.25; -constexpr double MAX_CLOCKRES = 8192.5; -double clockRes; +constexpr float MIN_CLOCKRES = 0.25; +constexpr float MAX_CLOCKRES = 8192.5; +float clockRes; float seedFraction = 0.0f; namespace hacks::tf2::seedprediction { -settings::Bool prediction{ "seed-prediction.enable", "false" }; +static settings::Bool prediction{ "seed-prediction.enable", "false" }; +bool predon() +{ + return *prediction; +} buf bases{ 9999 }; buf2 rebased{ 9999 }; buf3 intervals{ 9999 }; @@ -27,7 +31,7 @@ void handleFireBullets(C_TEFireBullets *ent) if (g_IEngine->IsInGame()) { INetChannel *ch = (INetChannel *) g_IEngine->GetNetChannelInfo(); - double time = g_GlobalVars->curtime * g_GlobalVars->interval_per_tick - + float time = g_GlobalVars->curtime * g_GlobalVars->interval_per_tick - (ch ? ch->GetLatency(MAX_FLOWS) / 2 : 0.0f); bases.push_back(seedstruct{ g_GlobalVars->tickcount, ent->m_iSeed(), time }); // It's circular buffer @@ -54,9 +58,9 @@ void selectBase() // between). int bestGap = 0; - double newClockRes = 1.0; + float newClockRes = 1.0; - for (double res = MIN_CLOCKRES; res < MAX_CLOCKRES + 1.0; res *= 2.0) + for (float res = MIN_CLOCKRES; res < MAX_CLOCKRES + 1.0; res *= 2.0) { rebased.clear(); for (seedstruct &base : bases) @@ -93,21 +97,21 @@ void selectBase() // interpret them as intervals of size 1 and find offset which covers most // of them. - double maxDisp = 5.0 / clockRes; + float maxDisp = 5.0 / clockRes; intervals.clear(); for (seedstruct &base : bases) { - double disp = double(base.seed) - double(selected.seed); + float disp = float(base.seed) - float(selected.seed); disp = fmod(disp - predictOffset(selected, base.tickcount, clockRes), 256); - disp = (disp > 128.0 ? disp - 256.0 : disp); + disp = (disp > 128.0f ? disp - 256.0f : disp); - if (abs(disp) < max(1.2, maxDisp)) + if (abs(disp) < fmaxf(1.2, maxDisp)) { intervals.push_back( - { 1, disp - 0.5 }); // Actually "interval ends", not "intervals" - intervals.push_back({ -1, disp + 0.5 }); + { 1, disp - 0.5f }); // Actually "interval ends", not "intervals" + intervals.push_back({ -1, disp + 0.5f }); } } @@ -122,7 +126,7 @@ void selectBase() if (curChance > bestChance) { bestChance = curChance; - seedFraction = (inter.pos + intervals[i + 1].pos) / 2; + seedFraction = (inter.pos + intervals[i + 1].pos) / 2.0f; } } @@ -131,14 +135,14 @@ void selectBase() bestChance * 100 / total); } -double predictOffset(const seedstruct &entry, int targetTick, double clockRes) +float predictOffset(const seedstruct &entry, int targetTick, float clockRes) { - return (1000.0 * g_GlobalVars->interval_per_tick / clockRes) * - double(targetTick - entry.tickcount); + return (1000.0f * g_GlobalVars->interval_per_tick / clockRes) * + float(targetTick - entry.tickcount); } -int predictSeed(const seedstruct &entry, int targetTick, double clockRes, - double SeedOffset) +int predictSeed(const seedstruct &entry, int targetTick, float clockRes, + float SeedOffset) { return (entry.seed + int(roundeven(predictOffset(entry, targetTick, clockRes)) + @@ -146,12 +150,12 @@ int predictSeed(const seedstruct &entry, int targetTick, double clockRes, 256; } -int predictTick(double targetTime) +int predictTick(float targetTime) { INetChannel *ch = (INetChannel *) g_IEngine->GetNetChannelInfo(); - double ping = ch ? ch->GetLatency(MAX_FLOWS) / 2 : 0.0f; - double deltaTime = targetTime - selected.time + ping; - return int(double(selected.tickcount) + + float ping = ch ? ch->GetLatency(MAX_FLOWS) / 2 : 0.0f; + float deltaTime = targetTime - selected.time + ping; + return int(float(selected.tickcount) + deltaTime / g_GlobalVars->interval_per_tick + 0.7); } @@ -160,14 +164,14 @@ int predictTick() return predictTick(g_GlobalVars->curtime * g_GlobalVars->interval_per_tick); } -int predictSeed(double targetTime) +int predictSeed(float targetTime) { INetChannel *ch = (INetChannel *) g_IEngine->GetNetChannelInfo(); - double ping = ch ? ch->GetLatency(MAX_FLOWS) / 2 : 0.0f; - double deltaTime = targetTime - selected.time + ping; - int tick = int(double(selected.tickcount) + + float ping = ch ? ch->GetLatency(MAX_FLOWS) / 2 : 0.0f; + float deltaTime = targetTime - selected.time + ping; + int tick = int(float(selected.tickcount) + deltaTime / g_GlobalVars->interval_per_tick + 0.7); - double SeedOffset = predictOffset(selected, tick, clockRes); + float SeedOffset = predictOffset(selected, tick, clockRes); int seed = predictSeed(selected, tick, clockRes, SeedOffset); logging::Info("seedpred-pred", diff --git a/src/hooks/CreateMove.cpp b/src/hooks/CreateMove.cpp index e75e30ac..83a494e5 100644 --- a/src/hooks/CreateMove.cpp +++ b/src/hooks/CreateMove.cpp @@ -16,6 +16,7 @@ #include "NavBot.hpp" #include "HookedMethods.hpp" +#include "PreDataUpdate.hpp" static settings::Bool minigun_jump{ "misc.minigun-jump-tf2c", "false" }; static settings::Bool roll_speedhack{ "misc.roll-speedhack", "false" }; @@ -197,6 +198,8 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time, ipc::UpdateServerAddress(); #endif } + hooked_methods::CreateMove(); + if (nolerp) { // current_user_cmd->tick_count += 1; diff --git a/src/hooks/PreDataUpdate.cpp b/src/hooks/PreDataUpdate.cpp index 3c2c23c1..41ffa1e8 100644 --- a/src/hooks/PreDataUpdate.cpp +++ b/src/hooks/PreDataUpdate.cpp @@ -6,12 +6,34 @@ */ #include "HookedMethods.hpp" #include "SeedPrediction.hpp" +#include "PreDataUpdate.hpp" namespace hooked_methods { -DEFINE_HOOKED_METHOD(PreDataUpdate, void, void *_this, int ok) + static void *PreData_Original = nullptr; + void PreDataUpdate(void *_this, int ok) + { + hacks::tf2::seedprediction::handleFireBullets((C_TEFireBullets *) _this); + ((bool (*)(C_TEFireBullets *, int)) PreData_Original)((C_TEFireBullets *)_this, ok); + + } + static void tryPatchLocalPlayerPreData() + { + // Patching C_TEFireBullets + void **vtable = *(void ***) (C_TEFireBullets::GTEFireBullets()); + if (vtable[offsets::PreDataUpdate()] != PreDataUpdate) + { + logging::Info("0x%08X, 0x%08X", unsigned(C_TEFireBullets::GTEFireBullets()), unsigned(vtable[offsets::PreDataUpdate()])); + PreData_Original = vtable[offsets::PreDataUpdate()]; + void *page = (void *) ((uintptr_t) vtable & ~0xFFF); + mprotect(page, 0xFFF, PROT_READ | PROT_WRITE | PROT_EXEC); + vtable[offsets::PreDataUpdate()] = (void *) PreDataUpdate; + mprotect(page, 0xFFF, PROT_READ | PROT_EXEC); + } + } +void CreateMove() { - hacks::tf2::seedprediction::handleFireBullets((C_TEFireBullets *) _this); - original::PreDataUpdate(_this, ok); + if (hacks::tf2::seedprediction::predon() && CE_GOOD(LOCAL_E)) + tryPatchLocalPlayerPreData(); } } // namespace hooked_methods diff --git a/src/navparser.cpp b/src/navparser.cpp index 46a38e97..2f5686c8 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -225,6 +225,8 @@ bool NavTo(Vector dest, bool navToLocalCenter, bool persistent, } crumbs.clear(); crumbs = std::move(path); + if (crumbs.empty()) + return false; lastArea = crumbs.at(0); if (!navToLocalCenter && crumbs.size() > 1) crumbs.erase(crumbs.begin()); @@ -334,6 +336,7 @@ void CreateMove() logging::Info("Pathing: New Sentry found!"); TF2MAP->pather->Reset(); Repath(); + return; } // If inactive for too long if (inactivity.check(5000)) diff --git a/src/reclasses/C_TEFireBullets.cpp b/src/reclasses/C_TEFireBullets.cpp index fee3b9ae..c59b4150 100755 --- a/src/reclasses/C_TEFireBullets.cpp +++ b/src/reclasses/C_TEFireBullets.cpp @@ -5,14 +5,15 @@ * Author: bencat07 */ #include "reclasses.hpp" +#include "C_TEFireBullets.hpp" -C_BaseTempEntity *C_TEFireBullets::GTEFireBullets() +C_TEFireBullets *C_TEFireBullets::GTEFireBullets() { static uintptr_t fireaddr = (gSignatures.GetClientSignature( - "C7 40 ? ? ? ? ? C7 40 ? ? ? ? ? A3 ? ? ? ? 89 50") - - 0x4); - C_BaseTempEntity *fire = *(C_BaseTempEntity **) fireaddr; + "55 B8 ? ? ? ? 89 E5 5D C3 8D B6 00 00 00 00 55 89 E5 56 53 83 EC ? C7 45") + + 0x2); + C_TEFireBullets *fire = *(C_TEFireBullets **) fireaddr; return fire; } int C_TEFireBullets::m_iSeed() From 766eefec29a98120f93739a853b1aed5c409fff2 Mon Sep 17 00:00:00 2001 From: LightCat Date: Fri, 24 Aug 2018 23:20:08 +0200 Subject: [PATCH 34/43] cat_load crash prevent --- src/hacks/Misc.cpp | 8 ++++++-- src/settings/SettingsIO.cpp | 6 ++---- src/visual/menu/menu/objects/input/Checkbox.cpp | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/hacks/Misc.cpp b/src/hacks/Misc.cpp index 99b82b0b..3af1b013 100644 --- a/src/hacks/Misc.cpp +++ b/src/hacks/Misc.cpp @@ -233,9 +233,13 @@ void CreateMove() } #if ENABLE_VISUALS - +//Timer ussr{}; void DrawText() { + /*if (ussr.test_and_set(207000)) + { + g_ISurface->PlaySound() + }*/ if (god_mode) for (int i = 0; i < 40000; i++) { @@ -255,7 +259,7 @@ void DrawText() { // Get Color and set opacity to %50 colors::rgba_t gaybow = colors::FromHSL( - fabs(sin((g_GlobalVars->curtime / 2.0f) + (i / 1.41241))) * + fabs(sin((g_GlobalVars->curtime / 2.0f) + (i / 1.41241f))) * 360.0f, 0.85f, 0.9f); gaybow.a = .5; diff --git a/src/settings/SettingsIO.cpp b/src/settings/SettingsIO.cpp index df79c369..eac465f1 100755 --- a/src/settings/SettingsIO.cpp +++ b/src/settings/SettingsIO.cpp @@ -33,11 +33,9 @@ bool settings::SettingsWriter::saveTo(std::string path, bool only_changed) [](const pair_type &a, const pair_type &b) -> bool { return a.first.compare(b.first) < 0; }); - for (auto &v : all_registered) - { - write(v.first, v.second); - } + if (!v.first.empty()) + write(v.first, v.second); stream.close(); return true; } diff --git a/src/visual/menu/menu/objects/input/Checkbox.cpp b/src/visual/menu/menu/objects/input/Checkbox.cpp index 1b35c61f..ce1cca30 100755 --- a/src/visual/menu/menu/objects/input/Checkbox.cpp +++ b/src/visual/menu/menu/objects/input/Checkbox.cpp @@ -40,7 +40,7 @@ zerokernel::Checkbox::Checkbox(settings::Variable &option) void zerokernel::Checkbox::render() { - if (option) + if (option && *option) { renderBorder(*color_border); auto cb = bb.getContentBox(); From 618f6961a8107fc46b20267cc7867a299dc02f9b Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sat, 25 Aug 2018 00:29:09 +0200 Subject: [PATCH 35/43] Untested navbot changes + gui free mouse --- include/navparser.hpp | 46 +++++++++++++++++++++----------- src/navparser.cpp | 6 ++--- src/visual/menu/GuiInterface.cpp | 10 +++++++ 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/include/navparser.hpp b/include/navparser.hpp index 28951982..0ce9f71c 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -46,7 +46,7 @@ class inactivityTracker return result; } - std::pair VectorToId(std::pair &connection) + std::pair VectorsToId(std::pair &connection) { CNavArea *currnode = nullptr; for (size_t i = 0; i < areas.size(); i++) @@ -81,6 +81,22 @@ class inactivityTracker } } + int VectorToID(Vector vec) + { + CNavArea *currnode = nullptr; + for (size_t i = 0; i < areas.size(); i++) + { + if (areas.at(i).m_center == vec) + { + currnode = &areas.at(i); + break; + } + } + if (!currnode) + return -1; + return currnode->m_id; + } + public: void reset() { @@ -92,16 +108,15 @@ public: } bool ShouldCancelPath(std::vector crumbs) { - for (auto sentry : sentries) - for (auto crumb : crumbs) - { - if (crumb.DistTo(sentry) > 1100) - continue; - if (!IsVectorVisible(crumb, sentry, true)) - continue; + for (auto crumb : crumbs) + { + int id = VectorToID(crumb); + if (id == -1) + continue; + if (sentryAreas[id]) return true; - } - return false; + } + return false; } void updateSentries() { @@ -110,7 +125,9 @@ public: for (int i = 0; i < HIGHEST_ENTITY; i++) { CachedEntity *ent = ENTITY(i); - if (CE_BAD(ent) || ent->m_iClassID() != CL_CLASS(CObjectSentrygun) || ent->m_iTeam() == LOCAL_E->m_iTeam()) + if (CE_BAD(ent) || + ent->m_iClassID() != CL_CLASS(CObjectSentrygun) /*|| + ent->m_iTeam() == LOCAL_E->m_iTeam()*/) continue; Vector sentryloc = GetBuildingPosition(ent); sentries.push_back(sentryloc); @@ -128,8 +145,7 @@ public: } bool IsIgnored(std::pair connection) { - if (sentryAreas[connection.first] || - sentryAreas[connection.second]) + if (sentryAreas[connection.first] || sentryAreas[connection.second]) { logging::Info("Ignored a connection due to sentry gun coverage"); return true; @@ -173,7 +189,7 @@ public: void AddTime(std::pair connection, Timer &timer, bool &resetPather) { - auto pair = VectorToId(connection); + auto pair = VectorsToId(connection); if (pair.first == -1 || pair.second == -1) return; AddTime(pair, timer, resetPather); @@ -201,7 +217,7 @@ public: } bool CheckType2(std::pair connection) { - auto pair = VectorToId(connection); + auto pair = VectorsToId(connection); if (pair.first == -1 || pair.second == -1) return false; return CheckType2(pair); diff --git a/src/navparser.cpp b/src/navparser.cpp index 2f5686c8..f9739f5f 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -211,7 +211,7 @@ bool NavTo(Vector dest, bool navToLocalCenter, bool persistent, // Only allow instructions to overwrite others if their priority is higher if (instructionPriority < priority) return false; - int locNav, tarNav; + int locNav = 0, tarNav = 0; auto path = findPath(g_pLocalPlayer->v_Origin, dest, locNav, tarNav); if (path.empty()) return false; @@ -266,7 +266,7 @@ void Repath() logging::Info("Pathing: NavBot inactive for too long. Ignoring " "connection and finding another path..."); // Throwaway int - int i1, i2; + int i1 = 0, i2 = 0; // Find a new path TF2MAP->pather->Reset(); crumbs = findPath(g_pLocalPlayer->v_Origin, crumbs.back(), i1, i2); @@ -402,7 +402,7 @@ CatCommand navprint("nav_print", "Debug nav print", [](const CCommand &args) { }); CatCommand navfind("nav_find", "Debug nav find", [](const CCommand &args) { - int i1, i2; + int i1 = 0, i2 = 0; std::vector path = findPath(g_pLocalPlayer->v_Origin, loc, i1, i2); if (path.empty()) { diff --git a/src/visual/menu/GuiInterface.cpp b/src/visual/menu/GuiInterface.cpp index 3f18372d..2cc1e177 100755 --- a/src/visual/menu/GuiInterface.cpp +++ b/src/visual/menu/GuiInterface.cpp @@ -156,6 +156,16 @@ bool gui::handleSdlEvent(SDL_Event *event) logging::Info("GUI open button pressed"); zerokernel::Menu::instance->setInGame( !zerokernel::Menu::instance->isInGame()); + if (!zerokernel::Menu::instance->isInGame()) + { + g_ISurface->UnlockCursor(); + g_ISurface->SetCursorAlwaysVisible(true); + } + else + { + g_ISurface->LockCursor(); + g_ISurface->SetCursorAlwaysVisible(false); + } return true; } } From afe840e2c350d29e6e97204034ec02b576289bf7 Mon Sep 17 00:00:00 2001 From: LightCat Date: Sat, 25 Aug 2018 13:22:31 +0200 Subject: [PATCH 36/43] one crash fix tm --- include/navparser.hpp | 4 ++-- src/hacks/NavBot.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/navparser.hpp b/include/navparser.hpp index 28951982..daa3604f 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -224,7 +224,7 @@ struct MAP : public micropather::Graph corners.at(3) = Vector{ CornerOf->m_nwCorner.x, CornerOf->m_seCorner.y, CornerOf->m_seCorner.z }; // SW - Vector bestVec; + Vector bestVec{}; float bestDist = FLT_MAX; for (size_t i = 0; i < corners.size(); i++) @@ -237,7 +237,7 @@ struct MAP : public micropather::Graph } } - Vector bestVec2; + Vector bestVec2{}; float bestDist2 = FLT_MAX; for (size_t i = 0; i < corners.size(); i++) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 9ecaf141..3defd195 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -303,6 +303,7 @@ bool NavToSniperSpot(int priority) ? preferred_sniper_spots : sniper_spots; bool toret = false; + if (use_preferred) { int best_spot = -1; From 2e2105a1a3a282c77812ee5700b84a7d1de788af Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sat, 25 Aug 2018 13:26:04 +0200 Subject: [PATCH 37/43] Fix crash tm --- include/navparser.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/navparser.hpp b/include/navparser.hpp index 16f43e8a..d56045c2 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -79,6 +79,7 @@ class inactivityTracker return { currnode->m_id, nextnode->m_id }; } } + return { -1, -1 }; } int VectorToID(Vector vec) From 3e5d274bfd9577d7b3930b170037ca0bee964d21 Mon Sep 17 00:00:00 2001 From: LightCat Date: Sat, 25 Aug 2018 14:20:22 +0200 Subject: [PATCH 38/43] another crash fix --- include/navparser.hpp | 8 ++++++-- src/navparser.cpp | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/navparser.hpp b/include/navparser.hpp index d56045c2..8b96ab2a 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -38,8 +38,12 @@ class inactivityTracker bool vischeckConnection(std::pair &connection) { - Vector begin = areas.at(FindInVector(connection.first)).m_center; - Vector end = areas.at(FindInVector(connection.second)).m_center; + int id0 = FindInVector(connection.first); + int id1 = FindInVector(connection.second); + if (id0 == -1 || id1 == -1) + return false; + Vector begin = areas.at(id0).m_center; + Vector end = areas.at(id1).m_center; begin.z += 72; end.z += 72; bool result = IsVectorVisible(begin, end, false); diff --git a/src/navparser.cpp b/src/navparser.cpp index f9739f5f..ea4ec0e5 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -24,6 +24,7 @@ size_t FindInVector(size_t id) if (areas.at(i).m_id == id) return i; } + return -1; } void Init() From 37cc89345844da00e6b29019c8875480a7143cef Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sat, 25 Aug 2018 18:07:31 +0200 Subject: [PATCH 39/43] Fix small error --- include/navparser.hpp | 7 +++++-- src/navparser.cpp | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/navparser.hpp b/include/navparser.hpp index 8b96ab2a..e1e90a3c 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -25,7 +25,7 @@ bool Prepare(); void CreateMove(); void Draw(); -size_t FindInVector(size_t id); +int FindInVector(size_t id); class inactivityTracker { @@ -303,9 +303,12 @@ struct MAP : public micropather::Graph if (inactiveTracker.IsIgnored( std::pair{ area->m_id, i.area->m_id })) continue; + int id = FindInVector(i.area->m_id); + if (id == -1) + return; micropather::StateCost cost; cost.state = - static_cast(&areas.at(FindInVector(i.area->m_id))); + static_cast(&areas.at(id)); cost.cost = area->m_center.DistTo(i.area->m_center); adjacent->push_back(cost); } diff --git a/src/navparser.cpp b/src/navparser.cpp index ea4ec0e5..c3e30478 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -17,9 +17,9 @@ static std::unique_ptr TF2MAP; // Function to get place in Vector by connection ID // Todo: find an alternative for this, maybe a map for storing ptrs to the // std::vector? -size_t FindInVector(size_t id) +int FindInVector(size_t id) { - for (size_t i = 0; i < areas.size(); i++) + for (int i = 0; i < areas.size(); i++) { if (areas.at(i).m_id == id) return i; From c3e5215abaa8230c207fb7a43d31d3f27f8c44d8 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sat, 25 Aug 2018 19:28:22 +0200 Subject: [PATCH 40/43] Oof i forgot to readd this --- include/navparser.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/navparser.hpp b/include/navparser.hpp index e1e90a3c..83228b8b 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -131,8 +131,8 @@ public: { CachedEntity *ent = ENTITY(i); if (CE_BAD(ent) || - ent->m_iClassID() != CL_CLASS(CObjectSentrygun) /*|| - ent->m_iTeam() == LOCAL_E->m_iTeam()*/) + ent->m_iClassID() != CL_CLASS(CObjectSentrygun) || + ent->m_iTeam() == LOCAL_E->m_iTeam()) continue; Vector sentryloc = GetBuildingPosition(ent); sentries.push_back(sentryloc); From acc7c2798b1e3e87a086a073e1d89c0781a65bc9 Mon Sep 17 00:00:00 2001 From: LightCat Date: Sat, 25 Aug 2018 19:40:03 +0200 Subject: [PATCH 41/43] Autoqueue updates:tm: --- src/hacks/AutoJoin.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hacks/AutoJoin.cpp b/src/hacks/AutoJoin.cpp index d5b6ba65..0057c3c5 100644 --- a/src/hacks/AutoJoin.cpp +++ b/src/hacks/AutoJoin.cpp @@ -83,6 +83,12 @@ void updateSearch() if (g_IEngine->IsInGame()) return; + static uintptr_t addr = gSignatures.GetClientSignature("C7 04 24 ? ? ? ? 8D 7D ? 31 F6"); + static uintptr_t offset0 = uintptr_t(*(uintptr_t *)(addr + 0x3)); + static uintptr_t offset1 = gSignatures.GetClientSignature("55 89 E5 83 EC ? 8B 45 ? 8B 80 ? ? ? ? 85 C0 74 ? C7 44 24 ? ? ? ? ? 89 04 24 E8 ? ? ? ? 85 C0 74 ? 8B 40"); + typedef int (*GetPendingInvites_t)(uintptr_t); + GetPendingInvites_t GetPendingInvites = GetPendingInvites_t(offset1); + int invites = GetPendingInvites(offset0); re::CTFGCClientSystem *gc = re::CTFGCClientSystem::GTFGCClientSystem(); re::CTFPartyClient *pc = re::CTFPartyClient::GTFPartyClient(); if (current_user_cmd && gc && gc->BConnectedToMatchServer(false) && @@ -91,10 +97,10 @@ void updateSearch() if (gc && !gc->BConnectedToMatchServer(false) && queuetime.test_and_set(10 * 1000 * 60) && !gc->BHaveLiveMatch()) tfmm::leaveQueue(); - if (gc && !gc->BConnectedToMatchServer(false) && !gc->BHaveLiveMatch()) + if (gc && !gc->BConnectedToMatchServer(false) && !gc->BHaveLiveMatch() && !invites) if (!(pc && pc->BInQueueForMatchGroup(tfmm::getQueue()))) { - logging::Info("Starting queue"); + logging::Info("Starting queue, Invites %d", invites); tfmm::startQueue(); } } From 2f8e01c4523f6991d15c800a0ab6a234fbace497 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 26 Aug 2018 16:05:39 +0200 Subject: [PATCH 42/43] Autocrash on long queue --- src/hacks/AutoJoin.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/hacks/AutoJoin.cpp b/src/hacks/AutoJoin.cpp index d5b6ba65..e977fdb3 100644 --- a/src/hacks/AutoJoin.cpp +++ b/src/hacks/AutoJoin.cpp @@ -79,7 +79,12 @@ void updateSearch() } }*/ if (!auto_queue) + { +#if not ENABLE_VISUALS + req_timer.update(); +#endif return; + } if (g_IEngine->IsInGame()) return; @@ -87,7 +92,12 @@ void updateSearch() re::CTFPartyClient *pc = re::CTFPartyClient::GTFPartyClient(); if (current_user_cmd && gc && gc->BConnectedToMatchServer(false) && gc->BHaveLiveMatch()) + { +#if not ENABLE_VISUALS + req_timer.update(); +#endif tfmm::leaveQueue(); + } if (gc && !gc->BConnectedToMatchServer(false) && queuetime.test_and_set(10 * 1000 * 60) && !gc->BHaveLiveMatch()) tfmm::leaveQueue(); @@ -97,6 +107,14 @@ void updateSearch() logging::Info("Starting queue"); tfmm::startQueue(); } +#if not ENABLE_VISUALS + if (req_timer.test_and_set(600000)) + { + logging::Info("Stuck in queue, segfaulting"); + *(int *) nullptr; + exit(1); + } +#endif } void update() From f717659927aba56dfe3224d56409a01446c2fdd1 Mon Sep 17 00:00:00 2001 From: LightCat Date: Sun, 26 Aug 2018 17:09:10 +0200 Subject: [PATCH 43/43] Auto teleporter --- include/core/netvars.hpp | 7 ++ include/hooks/PreDataUpdate.hpp | 2 +- include/navparser.hpp | 10 +- include/reclasses/CTFPartyClient.hpp | 18 ++-- include/settings/Key.hpp | 3 +- src/core/netvars.cpp | 15 ++- src/hack.cpp | 4 +- src/hacks/AutoJoin.cpp | 14 ++- src/hacks/CatBot.cpp | 3 +- src/hacks/Misc.cpp | 2 +- src/hacks/NavBot.cpp | 136 ++++++++++++++++++++++----- src/hacks/SeedPrediction.cpp | 15 +-- src/hooks/PreDataUpdate.cpp | 40 ++++---- src/hooks/SendDatagram.cpp | 2 +- src/navparser.cpp | 51 +++++++++- src/reclasses/CTFPartyClient.cpp | 11 +-- src/reclasses/C_TEFireBullets.cpp | 4 +- 17 files changed, 250 insertions(+), 87 deletions(-) mode change 100755 => 100644 src/reclasses/CTFPartyClient.cpp mode change 100755 => 100644 src/reclasses/C_TEFireBullets.cpp diff --git a/include/core/netvars.hpp b/include/core/netvars.hpp index bf3170fc..575aacd2 100755 --- a/include/core/netvars.hpp +++ b/include/core/netvars.hpp @@ -64,6 +64,13 @@ public: offset_t flChargedDamage; offset_t iUpgradeLevel; offset_t m_hBuilder; + offset_t m_iObjectType; + offset_t m_bBuilding; + offset_t m_iTeleState; + offset_t m_flTeleRechargeTime; + offset_t m_flTeleCurrentRechargeDuration; + offset_t m_iTeleTimesUsed; + offset_t m_flTeleYawToExit; offset_t iPipeType; offset_t iBuildingHealth; offset_t iBuildingMaxHealth; diff --git a/include/hooks/PreDataUpdate.hpp b/include/hooks/PreDataUpdate.hpp index ddf6fdf5..22626500 100644 --- a/include/hooks/PreDataUpdate.hpp +++ b/include/hooks/PreDataUpdate.hpp @@ -6,5 +6,5 @@ #include "HookedMethods.hpp" namespace hooked_methods { - void CreateMove(); +void CreateMove(); } diff --git a/include/navparser.hpp b/include/navparser.hpp index 83228b8b..b117f18d 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -26,6 +26,7 @@ void CreateMove(); void Draw(); int FindInVector(size_t id); +int FindNearestValid(Vector vec); class inactivityTracker { @@ -33,7 +34,11 @@ class inactivityTracker std::unordered_map, std::pair, boost::hash>> inactives; + +public: std::unordered_map sentryAreas; + +private: std::vector sentries{}; bool vischeckConnection(std::pair &connection) @@ -307,9 +312,8 @@ struct MAP : public micropather::Graph if (id == -1) return; micropather::StateCost cost; - cost.state = - static_cast(&areas.at(id)); - cost.cost = area->m_center.DistTo(i.area->m_center); + cost.state = static_cast(&areas.at(id)); + cost.cost = area->m_center.DistTo(i.area->m_center); adjacent->push_back(cost); } } diff --git a/include/reclasses/CTFPartyClient.hpp b/include/reclasses/CTFPartyClient.hpp index b8d97be7..731bcd25 100644 --- a/include/reclasses/CTFPartyClient.hpp +++ b/include/reclasses/CTFPartyClient.hpp @@ -26,14 +26,14 @@ public: int BRequestJoinPlayer(CSteamID steamid); static bool BInQueue(CTFPartyClient *this_); }; - class ITFMatchGroupDescription - { - public: - char pad0[4]; - int m_iID; - char pad1[63]; - bool m_bForceCompetitiveSettings; - }; +class ITFMatchGroupDescription +{ +public: + char pad0[4]; + int m_iID; + char pad1[63]; + bool m_bForceCompetitiveSettings; +}; - ITFMatchGroupDescription* GetMatchGroupDescription(int& idx); +ITFMatchGroupDescription *GetMatchGroupDescription(int &idx); } // namespace re diff --git a/include/settings/Key.hpp b/include/settings/Key.hpp index 186c6ca5..0fb86b82 100644 --- a/include/settings/Key.hpp +++ b/include/settings/Key.hpp @@ -57,7 +57,8 @@ public: setInternal(key); } - // Variable & causes segfault with gcc optimizations + these dont even return anything + // Variable & causes segfault with gcc optimizations + these dont even + // return anything void operator=(const std::string &string) { fromString(string); diff --git a/src/core/netvars.cpp b/src/core/netvars.cpp index 6e057904..ba451101 100644 --- a/src/core/netvars.cpp +++ b/src/core/netvars.cpp @@ -120,7 +120,20 @@ void NetVars::Init() "DT_TFSniperRifle", "SniperRifleLocalData", "m_flChargedDamage"); this->iUpgradeLevel = gNetvars.get_offset("DT_BaseObject", "m_iUpgradeLevel"); - this->m_hBuilder = gNetvars.get_offset("DT_BaseObject", "m_hBuilder"); + this->m_hBuilder = gNetvars.get_offset("DT_BaseObject", "m_hBuilder"); + this->m_bBuilding = gNetvars.get_offset("DT_BaseObject", "m_hBuilding"); + this->m_iObjectType = + gNetvars.get_offset("DT_BaseObject", "m_iObjectType"); + this->m_iTeleState = + gNetvars.get_offset("DT_ObjectTeleporter", "m_iState"); + this->m_flTeleRechargeTime = + gNetvars.get_offset("DT_ObjectTeleporter", "m_flRechargeTime"); + this->m_flTeleCurrentRechargeDuration = gNetvars.get_offset( + "DT_ObjectTeleporter", "m_flCurrentRechargeDuration"); + this->m_iTeleTimesUsed = + gNetvars.get_offset("DT_ObjectTeleporter", "m_iTimesUsed"); + this->m_flTeleYawToExit = + gNetvars.get_offset("DT_ObjectTeleporter", "m_flYawToExit"); this->iPipeType = gNetvars.get_offset("DT_TFProjectile_Pipebomb", "m_iType"); this->iBuildingHealth = diff --git a/src/hack.cpp b/src/hack.cpp index 7784697d..56ff1b4e 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -405,8 +405,8 @@ free(logname);*/ hack::initialized = true; for (int i = 0; i < 12; i++) { - re::ITFMatchGroupDescription* desc = re::GetMatchGroupDescription(i); - if (!desc || desc->m_iID > 9) //ID's over 9 are invalid + re::ITFMatchGroupDescription *desc = re::GetMatchGroupDescription(i); + if (!desc || desc->m_iID > 9) // ID's over 9 are invalid continue; if (desc->m_bForceCompetitiveSettings) { diff --git a/src/hacks/AutoJoin.cpp b/src/hacks/AutoJoin.cpp index bd2b40e9..de6829ef 100644 --- a/src/hacks/AutoJoin.cpp +++ b/src/hacks/AutoJoin.cpp @@ -88,12 +88,15 @@ void updateSearch() if (g_IEngine->IsInGame()) return; - static uintptr_t addr = gSignatures.GetClientSignature("C7 04 24 ? ? ? ? 8D 7D ? 31 F6"); - static uintptr_t offset0 = uintptr_t(*(uintptr_t *)(addr + 0x3)); - static uintptr_t offset1 = gSignatures.GetClientSignature("55 89 E5 83 EC ? 8B 45 ? 8B 80 ? ? ? ? 85 C0 74 ? C7 44 24 ? ? ? ? ? 89 04 24 E8 ? ? ? ? 85 C0 74 ? 8B 40"); + static uintptr_t addr = + gSignatures.GetClientSignature("C7 04 24 ? ? ? ? 8D 7D ? 31 F6"); + static uintptr_t offset0 = uintptr_t(*(uintptr_t *) (addr + 0x3)); + static uintptr_t offset1 = gSignatures.GetClientSignature( + "55 89 E5 83 EC ? 8B 45 ? 8B 80 ? ? ? ? 85 C0 74 ? C7 44 24 ? ? ? ? ? " + "89 04 24 E8 ? ? ? ? 85 C0 74 ? 8B 40"); typedef int (*GetPendingInvites_t)(uintptr_t); GetPendingInvites_t GetPendingInvites = GetPendingInvites_t(offset1); - int invites = GetPendingInvites(offset0); + int invites = GetPendingInvites(offset0); re::CTFGCClientSystem *gc = re::CTFGCClientSystem::GTFGCClientSystem(); re::CTFPartyClient *pc = re::CTFPartyClient::GTFPartyClient(); if (current_user_cmd && gc && gc->BConnectedToMatchServer(false) && @@ -107,7 +110,8 @@ void updateSearch() if (gc && !gc->BConnectedToMatchServer(false) && queuetime.test_and_set(10 * 1000 * 60) && !gc->BHaveLiveMatch()) tfmm::leaveQueue(); - if (gc && !gc->BConnectedToMatchServer(false) && !gc->BHaveLiveMatch() && !invites) + if (gc && !gc->BConnectedToMatchServer(false) && !gc->BHaveLiveMatch() && + !invites) if (!(pc && pc->BInQueueForMatchGroup(tfmm::getQueue()))) { logging::Info("Starting queue, Invites %d", invites); diff --git a/src/hacks/CatBot.cpp b/src/hacks/CatBot.cpp index f61988ac..edee64c5 100644 --- a/src/hacks/CatBot.cpp +++ b/src/hacks/CatBot.cpp @@ -119,8 +119,7 @@ void update_catbot_list() strcasestr(info.name, "lagger bot") || strcasestr(info.name, "zLag-bot") || strcasestr(info.name, "crash-bot") || - strcasestr(info.name, "reichstagbot") - ) + strcasestr(info.name, "reichstagbot")) { if (human_detecting_map.find(info.friendsID) == human_detecting_map.end()) diff --git a/src/hacks/Misc.cpp b/src/hacks/Misc.cpp index 3af1b013..2cb84178 100644 --- a/src/hacks/Misc.cpp +++ b/src/hacks/Misc.cpp @@ -233,7 +233,7 @@ void CreateMove() } #if ENABLE_VISUALS -//Timer ussr{}; +// Timer ussr{}; void DrawText() { /*if (ussr.test_and_set(207000)) diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 3defd195..1d3fd479 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -15,6 +15,8 @@ static settings::Bool heavy_mode("navbot.heavy-mode", "false"); static settings::Bool engi_mode("navbot.engi-mode", "false"); static settings::Bool primary_only("navbot.primary-only", "true"); +static settings::Bool target_sentry{ "navbot.target-sentry", "true" }; +static settings::Bool take_tele{ "navbot.take-teleporters", "true" }; static settings::Bool enable_fb{ "navbot.medbot", "false" }; static settings::Bool roambot{ "navbot.roaming", "true" }; static settings::Float follow_activation{ "navbot.max-range", "1000" }; @@ -56,7 +58,8 @@ bool HasLowAmmo() { int *weapon_list = (int *) ((unsigned) (RAW_ENT(LOCAL_E)) + netvar.hMyWeapons); - if (g_pLocalPlayer->holding_sniper_rifle && CE_INT(LOCAL_E, netvar.m_iAmmo + 4) <= 5) + if (g_pLocalPlayer->holding_sniper_rifle && + CE_INT(LOCAL_E, netvar.m_iAmmo + 4) <= 5) return true; for (int i = 0; weapon_list[i]; i++) { @@ -65,9 +68,8 @@ bool HasLowAmmo() if (eid >= 32 && eid <= HIGHEST_ENTITY) { IClientEntity *weapon = g_IEntityList->GetClientEntity(eid); - if (weapon and - re::C_BaseCombatWeapon::IsBaseCombatWeapon(weapon) && - re::C_TFWeaponBase::UsesPrimaryAmmo(weapon) && + if (weapon and re::C_BaseCombatWeapon::IsBaseCombatWeapon(weapon) && + re::C_TFWeaponBase::UsesPrimaryAmmo(weapon) && !re::C_TFWeaponBase::HasPrimaryAmmo(weapon)) return true; } @@ -80,6 +82,24 @@ bool HasLowHealth() return float(LOCAL_E->m_iHealth()) / float(LOCAL_E->m_iMaxHealth()) < 0.64; } +CachedEntity *nearestSentry() +{ + float bestscr = FLT_MAX; + CachedEntity *bestent = nullptr; + for (int i = 0; i < HIGHEST_ENTITY; i++) + { + CachedEntity *ent = ENTITY(i); + if (CE_BAD(ent) || ent->m_iClassID() != CL_CLASS(CObjectSentrygun) || + ent->m_iTeam() == LOCAL_E->m_iTeam()) + continue; + if (ent->m_flDistance() < bestscr) + { + bestscr = ent->m_flDistance(); + bestent = ent; + } + } + return bestent; +} CachedEntity *nearestHealth() { float bestscr = FLT_MAX; @@ -125,6 +145,10 @@ CachedEntity *nearestAmmo() int last_tar = -1; CachedEntity *NearestEnemy() { + if (last_tar != -1 && CE_GOOD(ENTITY(last_tar))) + return ENTITY(last_tar); + else + last_tar = -1; if (last_tar == -1 || nav::ReadyForCommands) { float bestscr = FLT_MAX; @@ -148,14 +172,12 @@ CachedEntity *NearestEnemy() bestent = ent; } } - if (!bestent) + if (CE_BAD(bestent)) last_tar = -1; else last_tar = bestent->m_IDX; return bestent; } - if (CE_GOOD(ENTITY(last_tar))) - return ENTITY(last_tar); return nullptr; } Timer cdr{}; @@ -252,7 +274,8 @@ std::vector GetBuildings() int cost[4] = { 100, 50, 130, 50 }; int GetBestBuilding(int metal) { - bool hasSentry, hasDispenser; + bool hasSentry = false; + bool hasDispenser = false; if (!GetBuildings().empty()) for (auto build : GetBuildings()) { @@ -292,34 +315,65 @@ int GetClosestBuilding() } return BestBuilding; } - +int GetClosestTeleporter() +{ + float bestscr = FLT_MAX; + int BestBuilding = -1; + for (int i = 0; i < HIGHEST_ENTITY; i++) + { + CachedEntity *ent = ENTITY(i); + if (CE_BAD(ent)) + continue; + if (ent->m_iClassID() != CL_CLASS(CObjectTeleporter)) + continue; + if (ent->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()) < bestscr) + { + BestBuilding = i; + bestscr = ent->m_vecOrigin().DistTo(LOCAL_E->m_vecOrigin()); + } + } + return BestBuilding; +} +bool NavToSentry(int priority) +{ + CachedEntity *Sentry = nearestSentry(); + if (CE_BAD(Sentry)) + return false; + int num = nav::FindNearestValid(GetBuildingPosition(Sentry)); + if (num == -1) + return false; + auto area = nav::areas[num]; + if (nav::NavTo(area.m_center, false, true, priority)) + return true; + return false; +} bool NavToSniperSpot(int priority) { Vector random_spot{}; if (!sniper_spots.size() && !preferred_sniper_spots.size()) return false; bool use_preferred = !preferred_sniper_spots.empty(); - auto snip_spot = use_preferred - ? preferred_sniper_spots - : sniper_spots; - bool toret = false; + auto snip_spot = use_preferred ? preferred_sniper_spots : sniper_spots; + bool toret = false; if (use_preferred) { - int best_spot = -1; - float maxscr = FLT_MAX; + int best_spot = -1; + float maxscr = FLT_MAX; int lowest_priority = 9999; for (int i = 0; i < snip_spot.size(); i++) { if ((priority_spots[i] < lowest_priority)) lowest_priority = priority_spots[i]; } - for (int i = 0; i < snip_spot.size(); i++) { + for (int i = 0; i < snip_spot.size(); i++) + { if ((priority_spots[i] > lowest_priority)) continue; float scr = snip_spot[i].DistTo(g_pLocalPlayer->v_Eye); - if (scr < maxscr) { - maxscr = scr; + if (scr < maxscr) + { + maxscr = scr; best_spot = i; } } @@ -333,13 +387,29 @@ bool NavToSniperSpot(int priority) } else if (!snip_spot.empty()) { - int rng = rand() % snip_spot.size(); + int rng = rand() % snip_spot.size(); random_spot = snip_spot.at(rng); if (random_spot.z) toret = nav::NavTo(random_spot, false, true, priority); } return toret; } +CatCommand debug_tele("navbot_debug", "debug", []() { + int idx = GetClosestBuilding(); + if (idx == -1) + return; + CachedEntity *ent = ENTITY(idx); + if (CE_BAD(ent)) + return; + logging::Info( + "%d %d %d %f %f %d %f %f %f", CE_INT(ent, netvar.m_iObjectType), + CE_INT(ent, netvar.m_bBuilding), CE_INT(ent, netvar.m_iTeleState), + CE_FLOAT(ent, netvar.m_flTeleRechargeTime), + CE_FLOAT(ent, netvar.m_flTeleCurrentRechargeDuration), + CE_INT(ent, netvar.m_iTeleTimesUsed), + CE_FLOAT(ent, netvar.m_flTeleYawToExit), g_GlobalVars->curtime, + g_GlobalVars->curtime * g_GlobalVars->interval_per_tick); +}); int follow_target = 0; void CreateMove() { @@ -364,13 +434,33 @@ void CreateMove() if ((!HasLowHealth() && nav::priority == 7) || (!HasLowAmmo() && nav::priority == 6)) nav::clearInstructions(); + static int waittime = (spy_mode || heavy_mode || engi_mode) ? 100 : 2000; + if (*take_tele) + { + int idx = GetClosestTeleporter(); + if (idx != -1) + { + CachedEntity *ent = ENTITY(idx); + if (CE_GOOD(ent) && ent->m_flDistance() < 300.0f) + if (CE_FLOAT(ent, netvar.m_flTeleYawToExit) && + CE_FLOAT(ent, netvar.m_flTeleRechargeTime) < + g_GlobalVars->curtime) + { + waittime = 1000; + cd3.update(); + nav::NavTo(GetBuildingPosition(ent), false, false); + } + } + } if (enable) { if (!nav::ReadyForCommands && !spy_mode && !heavy_mode && !engi_mode) cd3.update(); - bool isready = - (spy_mode || heavy_mode || engi_mode) ? true : nav::ReadyForCommands; - static int waittime = (spy_mode || heavy_mode || engi_mode) ? 100 : 2000; + if (target_sentry && NavToSentry(3)) + return; + bool isready = (spy_mode || heavy_mode || engi_mode) + ? true + : nav::ReadyForCommands; if (isready && cd3.test_and_set(waittime)) { waittime = (spy_mode || heavy_mode || engi_mode) ? 100 : 2000; @@ -389,7 +479,7 @@ void CreateMove() { if (cd2.test_and_set(5000)) Init(); - if (!NavToSniperSpot(5)) + if (!NavToSniperSpot(4)) waittime = 1; } if (CE_GOOD(tar)) diff --git a/src/hacks/SeedPrediction.cpp b/src/hacks/SeedPrediction.cpp index 1ac86b02..ead700ac 100644 --- a/src/hacks/SeedPrediction.cpp +++ b/src/hacks/SeedPrediction.cpp @@ -32,7 +32,7 @@ void handleFireBullets(C_TEFireBullets *ent) { INetChannel *ch = (INetChannel *) g_IEngine->GetNetChannelInfo(); float time = g_GlobalVars->curtime * g_GlobalVars->interval_per_tick - - (ch ? ch->GetLatency(MAX_FLOWS) / 2 : 0.0f); + (ch ? ch->GetLatency(MAX_FLOWS) / 2 : 0.0f); bases.push_back(seedstruct{ g_GlobalVars->tickcount, ent->m_iSeed(), time }); // It's circular buffer selectBase(); @@ -57,7 +57,7 @@ void selectBase() // and check if they are close to each other (by looking for largest gap // between). - int bestGap = 0; + int bestGap = 0; float newClockRes = 1.0; for (float res = MIN_CLOCKRES; res < MAX_CLOCKRES + 1.0; res *= 2.0) @@ -110,7 +110,8 @@ void selectBase() if (abs(disp) < fmaxf(1.2, maxDisp)) { intervals.push_back( - { 1, disp - 0.5f }); // Actually "interval ends", not "intervals" + { 1, + disp - 0.5f }); // Actually "interval ends", not "intervals" intervals.push_back({ -1, disp + 0.5f }); } } @@ -152,7 +153,7 @@ int predictSeed(const seedstruct &entry, int targetTick, float clockRes, int predictTick(float targetTime) { - INetChannel *ch = (INetChannel *) g_IEngine->GetNetChannelInfo(); + INetChannel *ch = (INetChannel *) g_IEngine->GetNetChannelInfo(); float ping = ch ? ch->GetLatency(MAX_FLOWS) / 2 : 0.0f; float deltaTime = targetTime - selected.time + ping; return int(float(selected.tickcount) + @@ -166,13 +167,13 @@ int predictTick() int predictSeed(float targetTime) { - INetChannel *ch = (INetChannel *) g_IEngine->GetNetChannelInfo(); + INetChannel *ch = (INetChannel *) g_IEngine->GetNetChannelInfo(); float ping = ch ? ch->GetLatency(MAX_FLOWS) / 2 : 0.0f; float deltaTime = targetTime - selected.time + ping; - int tick = int(float(selected.tickcount) + + int tick = int(float(selected.tickcount) + deltaTime / g_GlobalVars->interval_per_tick + 0.7); float SeedOffset = predictOffset(selected, tick, clockRes); - int seed = predictSeed(selected, tick, clockRes, SeedOffset); + int seed = predictSeed(selected, tick, clockRes, SeedOffset); logging::Info("seedpred-pred", "Last shot: guessed server tick = %d, guessed seed = %03d\n", diff --git a/src/hooks/PreDataUpdate.cpp b/src/hooks/PreDataUpdate.cpp index 41ffa1e8..6f19ce75 100644 --- a/src/hooks/PreDataUpdate.cpp +++ b/src/hooks/PreDataUpdate.cpp @@ -10,27 +10,29 @@ namespace hooked_methods { - static void *PreData_Original = nullptr; - void PreDataUpdate(void *_this, int ok) +static void *PreData_Original = nullptr; +void PreDataUpdate(void *_this, int ok) +{ + hacks::tf2::seedprediction::handleFireBullets((C_TEFireBullets *) _this); + ((bool (*)(C_TEFireBullets *, int)) PreData_Original)( + (C_TEFireBullets *) _this, ok); +} +static void tryPatchLocalPlayerPreData() +{ + // Patching C_TEFireBullets + void **vtable = *(void ***) (C_TEFireBullets::GTEFireBullets()); + if (vtable[offsets::PreDataUpdate()] != PreDataUpdate) { - hacks::tf2::seedprediction::handleFireBullets((C_TEFireBullets *) _this); - ((bool (*)(C_TEFireBullets *, int)) PreData_Original)((C_TEFireBullets *)_this, ok); - - } - static void tryPatchLocalPlayerPreData() - { - // Patching C_TEFireBullets - void **vtable = *(void ***) (C_TEFireBullets::GTEFireBullets()); - if (vtable[offsets::PreDataUpdate()] != PreDataUpdate) - { - logging::Info("0x%08X, 0x%08X", unsigned(C_TEFireBullets::GTEFireBullets()), unsigned(vtable[offsets::PreDataUpdate()])); - PreData_Original = vtable[offsets::PreDataUpdate()]; - void *page = (void *) ((uintptr_t) vtable & ~0xFFF); - mprotect(page, 0xFFF, PROT_READ | PROT_WRITE | PROT_EXEC); - vtable[offsets::PreDataUpdate()] = (void *) PreDataUpdate; - mprotect(page, 0xFFF, PROT_READ | PROT_EXEC); - } + logging::Info("0x%08X, 0x%08X", + unsigned(C_TEFireBullets::GTEFireBullets()), + unsigned(vtable[offsets::PreDataUpdate()])); + PreData_Original = vtable[offsets::PreDataUpdate()]; + void *page = (void *) ((uintptr_t) vtable & ~0xFFF); + mprotect(page, 0xFFF, PROT_READ | PROT_WRITE | PROT_EXEC); + vtable[offsets::PreDataUpdate()] = (void *) PreDataUpdate; + mprotect(page, 0xFFF, PROT_READ | PROT_EXEC); } +} void CreateMove() { if (hacks::tf2::seedprediction::predon() && CE_GOOD(LOCAL_E)) diff --git a/src/hooks/SendDatagram.cpp b/src/hooks/SendDatagram.cpp index def9bd5c..8a20b9aa 100644 --- a/src/hooks/SendDatagram.cpp +++ b/src/hooks/SendDatagram.cpp @@ -11,7 +11,7 @@ namespace hooked_methods DEFINE_HOOKED_METHOD(SendDatagram, int, INetChannel *ch, bf_write *buf) { #if !LAGBOT_MODE - int in = 0; + int in = 0; int state = 0; if (CE_GOOD(LOCAL_E)) { diff --git a/src/navparser.cpp b/src/navparser.cpp index c3e30478..98940dcb 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -26,7 +26,49 @@ int FindInVector(size_t id) } return -1; } - +static int bestarea = -1; +Timer reselect{}; +int FindNearestValid(Vector vec) +{ + if (reselect.test_and_set(500)) + { + float bestscr = FLT_MAX; + if (bestarea != -1) + { + bool success = false; + Vector area = areas[bestarea].m_center; + area.z += 72.0f; + if (!TF2MAP->inactiveTracker.sentryAreas[bestarea]) + { + float scr = area.DistTo(vec); + if (scr < 2000.0f) + if (IsVectorVisible(vec, area, false)) + success = true; + } + if (!success) + bestarea = -1; + } + else + for (int ar = 0; ar < areas.size(); ar++) + { + Vector area = areas[ar].m_center; + area.z += 72.0f; + if (TF2MAP->inactiveTracker.sentryAreas[ar]) + continue; + float scr = area.DistTo(vec); + if (scr > 2000.0f) + continue; + if (scr > bestscr) + continue; + if (IsVectorVisible(vec, area, false)) + { + bestscr = scr; + bestarea = ar; + } + } + } + return bestarea; +} void Init() { // Get NavFile location @@ -225,7 +267,7 @@ bool NavTo(Vector dest, bool navToLocalCenter, bool persistent, TF2MAP->pather->Reset(); } crumbs.clear(); - crumbs = std::move(path); + crumbs = std::move(path); if (crumbs.empty()) return false; lastArea = crumbs.at(0); @@ -256,7 +298,7 @@ void ignoreManagerCM() TF2MAP->inactiveTracker.reset(); if (patherReset.test_and_set(30000)) TF2MAP->pather->Reset(); - if(sentryUpdate.test_and_set(1000)) + if (sentryUpdate.test_and_set(1000)) TF2MAP->inactiveTracker.updateSentries(); } @@ -332,7 +374,8 @@ void CreateMove() return; } // Check for new sentries - if (sentryCheck.test_and_set(1000) && TF2MAP->inactiveTracker.ShouldCancelPath(crumbs)) + if (sentryCheck.test_and_set(1000) && + TF2MAP->inactiveTracker.ShouldCancelPath(crumbs)) { logging::Info("Pathing: New Sentry found!"); TF2MAP->pather->Reset(); diff --git a/src/reclasses/CTFPartyClient.cpp b/src/reclasses/CTFPartyClient.cpp old mode 100755 new mode 100644 index 7d3fa76a..ba230beb --- a/src/reclasses/CTFPartyClient.cpp +++ b/src/reclasses/CTFPartyClient.cpp @@ -119,14 +119,13 @@ int re::CTFPartyClient::BRequestJoinPlayer(CSteamID steamid) BRequestJoinPlayer_t(addr); return BRequestJoinPlayer_fn(this, steamid, false); } -re::ITFMatchGroupDescription * -re::GetMatchGroupDescription(int &idx) +re::ITFMatchGroupDescription *re::GetMatchGroupDescription(int &idx) { - typedef re::ITFMatchGroupDescription *( - *GetMatchGroupDescription_t)(int&); - static uintptr_t addr = gSignatures.GetClientSignature("55 89 E5 8B 45 08 8B 00 83 F8 FF"); + typedef re::ITFMatchGroupDescription *(*GetMatchGroupDescription_t)(int &); + static uintptr_t addr = + gSignatures.GetClientSignature("55 89 E5 8B 45 08 8B 00 83 F8 FF"); static GetMatchGroupDescription_t GetMatchGroupDescription_fn = - GetMatchGroupDescription_t(addr); + GetMatchGroupDescription_t(addr); return GetMatchGroupDescription_fn(idx); } diff --git a/src/reclasses/C_TEFireBullets.cpp b/src/reclasses/C_TEFireBullets.cpp old mode 100755 new mode 100644 index c59b4150..e6bfbc9c --- a/src/reclasses/C_TEFireBullets.cpp +++ b/src/reclasses/C_TEFireBullets.cpp @@ -10,8 +10,8 @@ C_TEFireBullets *C_TEFireBullets::GTEFireBullets() { static uintptr_t fireaddr = - (gSignatures.GetClientSignature( - "55 B8 ? ? ? ? 89 E5 5D C3 8D B6 00 00 00 00 55 89 E5 56 53 83 EC ? C7 45") + + (gSignatures.GetClientSignature("55 B8 ? ? ? ? 89 E5 5D C3 8D B6 00 00 " + "00 00 55 89 E5 56 53 83 EC ? C7 45") + 0x2); C_TEFireBullets *fire = *(C_TEFireBullets **) fireaddr; return fire;