From aff77d2d2ca629ca9f8fed23873a63a5562f5aa9 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 1 Jul 2018 12:25:17 +0200 Subject: [PATCH 1/4] wip playerfit check --- include/helpers.hpp | 6 +++- src/hacks/FollowBot.cpp | 45 +++++++++------------------ src/helpers.cpp | 69 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 87 insertions(+), 33 deletions(-) diff --git a/include/helpers.hpp b/include/helpers.hpp index 3a1aba5a..823fbf14 100755 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -77,7 +77,11 @@ bool IsEntityVectorVisible(CachedEntity *entity, Vector endpos); bool VisCheckEntFromEnt(CachedEntity *startEnt, CachedEntity *endEnt); bool VisCheckEntFromEntVector(Vector startVector, CachedEntity *startEnt, CachedEntity *endEnt); -Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist); +Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist, + bool checkWalkable = false); +float vectorMax(Vector i); +Vector vectorAbs(Vector i); +bool canReachVector(Vector loc); bool LineIntersectsBox(Vector &bmin, Vector &bmax, Vector &lmin, Vector &lmax); diff --git a/src/hacks/FollowBot.cpp b/src/hacks/FollowBot.cpp index 7e0cae1b..a0ef78bc 100644 --- a/src/hacks/FollowBot.cpp +++ b/src/hacks/FollowBot.cpp @@ -82,13 +82,6 @@ void checkAFK() } } -float vectormax(Vector i) // TODO: Move to helpers.cpp soon tm -{ -float res = fmaxf(i.x, i.y); -return fmaxf(res, i.z); -} - - void init() { for (int i = 0; i < afkTicks.size(); i++) @@ -100,19 +93,19 @@ void init() } -bool canReachVector(Vector loc) -{ - trace_t trace; - Ray_t ray; - Vector down = loc; - down.z = down.z - 5; - ray.Init(loc, down); - g_ITrace->TraceRay(ray, MASK_PLAYERSOLID, &trace::filter_no_player, - &trace); - if (trace.startpos.z - trace.endpos.z <= 75) // higher as to avoid small false positives, player can jump 72 hu - return true; - return false; -} +//bool canReachVector(Vector loc) +//{ +// trace_t trace; +// Ray_t ray; +// Vector down = loc; +// down.z = down.z - 5; +// ray.Init(loc, down); +// g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, +// &trace); +// if (trace.startpos.z - trace.endpos.z <= 75) // higher as to avoid small false positives, player can jump 72 hu +// return true; +// return false; +//} // auto add checked crumbs for the walbot to follow bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin) @@ -120,14 +113,10 @@ bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin) if (g_pLocalPlayer->v_Origin != corner) { Vector dist = corner - g_pLocalPlayer->v_Origin; - Vector distabs = dist; - distabs.x = fabsf(distabs.x); - distabs.y = fabsf(distabs.y); - distabs.z = fabsf(distabs.z); int maxiterations = floor(corner.DistTo(g_pLocalPlayer->v_Origin)) / 40; for (int i = 0; i < maxiterations; i++) { - Vector result = g_pLocalPlayer->v_Origin + dist / vectormax(distabs) * 40.0f * (i + 1); + Vector result = g_pLocalPlayer->v_Origin + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1); if (!canReachVector(result)) return false; breadcrumbs.push_back(result); @@ -135,14 +124,10 @@ bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin) } Vector dist = target->m_vecOrigin() - corner; - Vector distabs = dist; - distabs.x = fabsf(distabs.x); - distabs.y = fabsf(distabs.y); - distabs.z = fabsf(distabs.z); int maxiterations = floor(corner.DistTo(target->m_vecOrigin())) / 40; for (int i = 0; i < maxiterations; i++) { - Vector result = corner + dist / vectormax(distabs) * 40.0f * (i + 1); + Vector result = corner + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1); if (!canReachVector(result)) return false; breadcrumbs.push_back(result); diff --git a/src/helpers.cpp b/src/helpers.cpp index 9cdb1243..9981e824 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -108,7 +108,8 @@ void WalkTo(const Vector &vector) // Function to get the corner location that a vischeck to an entity is possible // from -Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist) +Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist, + bool checkWalkable) { int maxiterations = maxdist / 40; Vector origin = player->m_vecOrigin(); @@ -141,9 +142,13 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist) virtualOrigin)) // check if player can see the // players virtualOrigin continue; - if (VisCheckEntFromEntVector( + if (!VisCheckEntFromEntVector( virtualOrigin, player, target)) // check if the virtualOrigin can see the target + continue; + if (!checkWalkable) + return virtualOrigin; + if (canReachVector(virtualOrigin)) return virtualOrigin; // return the corner position that we know // can see the target } @@ -151,6 +156,66 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist) return { 0, 0, 0 }; } +float vectorMax(Vector i) // Returns a vectors max value. For example: {123, + // -150, 125} = 125 +{ + float res = fmaxf(i.x, i.y); + return fmaxf(res, i.z); +} + +Vector vectorABS(Vector i) +{ + Vector result = i; + result.x = fabsf(i.x); + result.y = fabsf(i.y); + result.z = fabsf(i.z); + return result; +} + +// check to see if we can reach a vector or if it is too high / doesn't leave +// enough space for the player +bool canReachVector(Vector loc) +{ + // check if the vector is too high above ground + { + trace_t trace; + Ray_t ray; + Vector down = loc; + down.z = down.z - 5; + ray.Init(loc, down); + g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace); + if (!(trace.startpos.z - trace.endpos.z <= + 75)) // higher as to avoid small false positives, player can jump + // 72 hu + return false; + } + for (int i = 0; i < 4; i++) // for loop for all 4 directions + { + Vector directionalLoc = loc; + switch (i) // what to check + { + case 0: + directionalLoc.x = directionalLoc.x + 40; + break; + case 1: + directionalLoc.x = directionalLoc.x - 40; + break; + case 2: + directionalLoc.y = directionalLoc.y + 40; + break; + case 3: + directionalLoc.y = directionalLoc.y - 40; + break; + } + trace_t trace; + Ray_t ray; + g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace); + if (trace.startpos.DistTo(trace.endpos) < 26.0f) + return false; + } + return true; +} + std::string GetLevelName() { From 97410d38996cd4d11128cd16b872237a4a1414ab Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 1 Jul 2018 14:29:26 +0200 Subject: [PATCH 2/4] Fix --- include/helpers.hpp | 4 ++-- src/hacks/FollowBot.cpp | 8 ++++---- src/helpers.cpp | 38 +++++++++++++++++++------------------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/helpers.hpp b/include/helpers.hpp index 823fbf14..326aec72 100755 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -78,9 +78,9 @@ bool VisCheckEntFromEnt(CachedEntity *startEnt, CachedEntity *endEnt); bool VisCheckEntFromEntVector(Vector startVector, CachedEntity *startEnt, CachedEntity *endEnt); Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist, - bool checkWalkable = false); + bool checkWalkable); float vectorMax(Vector i); -Vector vectorAbs(Vector i); +Vector vectorABS(Vector i); bool canReachVector(Vector loc); bool LineIntersectsBox(Vector &bmin, Vector &bmax, Vector &lmin, Vector &lmax); diff --git a/src/hacks/FollowBot.cpp b/src/hacks/FollowBot.cpp index a0ef78bc..89624bd3 100644 --- a/src/hacks/FollowBot.cpp +++ b/src/hacks/FollowBot.cpp @@ -116,7 +116,7 @@ bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin) int maxiterations = floor(corner.DistTo(g_pLocalPlayer->v_Origin)) / 40; for (int i = 0; i < maxiterations; i++) { - Vector result = g_pLocalPlayer->v_Origin + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1); + Vector result = g_pLocalPlayer->v_Origin + dist / vectorMax(vectorABS(dist)) * 40.0f * (i + 1); if (!canReachVector(result)) return false; breadcrumbs.push_back(result); @@ -127,7 +127,7 @@ bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin) int maxiterations = floor(corner.DistTo(target->m_vecOrigin())) / 40; for (int i = 0; i < maxiterations; i++) { - Vector result = corner + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1); + Vector result = corner + dist / vectorMax(vectorABS(dist)) * 40.0f * (i + 1); if (!canReachVector(result)) return false; breadcrumbs.push_back(result); @@ -188,7 +188,7 @@ void WorldTick() continue; if (corneractivate) { - Vector indirectOrigin = VischeckWall(LOCAL_E, entity, 250); //get the corner location that the future target is visible from + Vector indirectOrigin = VischeckWall(LOCAL_E, entity, 250, true); //get the corner location that the future target is visible from if (!indirectOrigin.z) //if we couldn't find it, exit continue; breadcrumbs.clear(); //we need to ensure that the breadcrumbs std::vector is empty @@ -248,7 +248,7 @@ void WorldTick() continue; if (corneractivate) { - Vector indirectOrigin = VischeckWall(LOCAL_E, entity, 250); //get the corner location that the future target is visible from + Vector indirectOrigin = VischeckWall(LOCAL_E, entity, 250, true); //get the corner location that the future target is visible from if (!indirectOrigin.z) //if we couldn't find it, exit continue; //breadcrumbs.clear(); //we need to ensure that the breadcrumbs std::vector is empty diff --git a/src/helpers.cpp b/src/helpers.cpp index 9981e824..9cccea43 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -166,9 +166,9 @@ float vectorMax(Vector i) // Returns a vectors max value. For example: {123, Vector vectorABS(Vector i) { Vector result = i; - result.x = fabsf(i.x); - result.y = fabsf(i.y); - result.z = fabsf(i.z); + result.x = fabsf(result.x); + result.y = fabsf(result.y); + result.z = fabsf(result.z); return result; } @@ -177,18 +177,17 @@ Vector vectorABS(Vector i) bool canReachVector(Vector loc) { // check if the vector is too high above ground - { - trace_t trace; - Ray_t ray; - Vector down = loc; - down.z = down.z - 5; - ray.Init(loc, down); - g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace); - if (!(trace.startpos.z - trace.endpos.z <= - 75)) // higher as to avoid small false positives, player can jump - // 72 hu - return false; - } + trace_t trace; + Ray_t ray; + Vector down = loc; + down.z = down.z - 5; + ray.Init(loc, down); + g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace); + if (!(trace.startpos.z - trace.endpos.z <= + 75)) // higher as to avoid small false positives, player can jump + // 72 hu + return false; + for (int i = 0; i < 4; i++) // for loop for all 4 directions { Vector directionalLoc = loc; @@ -207,10 +206,11 @@ bool canReachVector(Vector loc) directionalLoc.y = directionalLoc.y - 40; break; } - trace_t trace; - Ray_t ray; - g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace); - if (trace.startpos.DistTo(trace.endpos) < 26.0f) + trace_t trace2; + Ray_t ray2; + ray2.Init(loc, directionalLoc); + g_ITrace->TraceRay(ray2, 0x4200400B, &trace::filter_no_player, &trace); + if (trace2.startpos.DistTo(trace2.endpos) < 26.0f) return false; } return true; From 0c0c40a4547914da93ce5f4060824409ff03be1e Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Mon, 2 Jul 2018 20:07:49 +0200 Subject: [PATCH 3/4] Added isJumping and fixed canReachVector --- include/helpers.hpp | 3 +- src/hacks/FollowBot.cpp | 43 ++++++++++++------------- src/helpers.cpp | 71 ++++++++++++++++++++++++++++------------- 3 files changed, 72 insertions(+), 45 deletions(-) diff --git a/include/helpers.hpp b/include/helpers.hpp index 326aec72..24ebddbd 100755 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -80,8 +80,9 @@ bool VisCheckEntFromEntVector(Vector startVector, CachedEntity *startEnt, Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist, bool checkWalkable); float vectorMax(Vector i); -Vector vectorABS(Vector i); +Vector vectorAbs(Vector i); bool canReachVector(Vector loc); +bool isJumping(Vector vec); bool LineIntersectsBox(Vector &bmin, Vector &bmax, Vector &lmin, Vector &lmax); diff --git a/src/hacks/FollowBot.cpp b/src/hacks/FollowBot.cpp index 89624bd3..a28dce72 100644 --- a/src/hacks/FollowBot.cpp +++ b/src/hacks/FollowBot.cpp @@ -92,33 +92,22 @@ void init() return; } - -//bool canReachVector(Vector loc) -//{ -// trace_t trace; -// Ray_t ray; -// Vector down = loc; -// down.z = down.z - 5; -// ray.Init(loc, down); -// g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, -// &trace); -// if (trace.startpos.z - trace.endpos.z <= 75) // higher as to avoid small false positives, player can jump 72 hu -// return true; -// return false; -//} - // auto add checked crumbs for the walbot to follow bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin) { + breadcrumbs.clear(); if (g_pLocalPlayer->v_Origin != corner) { Vector dist = corner - g_pLocalPlayer->v_Origin; int maxiterations = floor(corner.DistTo(g_pLocalPlayer->v_Origin)) / 40; for (int i = 0; i < maxiterations; i++) { - Vector result = g_pLocalPlayer->v_Origin + dist / vectorMax(vectorABS(dist)) * 40.0f * (i + 1); + Vector result = g_pLocalPlayer->v_Origin + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1); if (!canReachVector(result)) + { + breadcrumbs.clear(); return false; + } breadcrumbs.push_back(result); } } @@ -127,12 +116,15 @@ bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin) int maxiterations = floor(corner.DistTo(target->m_vecOrigin())) / 40; for (int i = 0; i < maxiterations; i++) { - Vector result = corner + dist / vectorMax(vectorABS(dist)) * 40.0f * (i + 1); + Vector result = corner + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1); if (!canReachVector(result)) + { + breadcrumbs.clear(); return false; + } breadcrumbs.push_back(result); } - return false; + return true; } void WorldTick() @@ -178,6 +170,8 @@ void WorldTick() auto entity = ENTITY(i); if (CE_BAD(entity)) // Exist + dormant continue; + if (i == follow_target) + break; if (entity->m_Type() != ENTITY_PLAYER) continue; if (steamid != entity->player_info.friendsID) // steamid check @@ -253,7 +247,8 @@ void WorldTick() continue; //breadcrumbs.clear(); //we need to ensure that the breadcrumbs std::vector is empty //breadcrumbs.push_back(indirectOrigin); //add the corner location to the breadcrumb list - addCrumbs(entity, indirectOrigin); + if (!addCrumbs(entity, indirectOrigin)) + continue; } else { @@ -275,8 +270,11 @@ void WorldTick() CachedEntity *followtar = ENTITY(follow_target); // wtf is this needed - if (CE_BAD(followtar)) + if (CE_BAD(followtar) || !followtar->m_bAlivePlayer()) + { + follow_target = 0; return; + } // Check if we are following a disguised/spy if (IsPlayerDisguised(followtar) || IsPlayerInvisible(followtar)) { @@ -343,9 +341,10 @@ void WorldTick() // Follow the crumbs when too far away, or just starting to follow if (dist_to_target > (float) follow_distance) { - // Check for idle - if (autojump && idle_time.check(2000)) + // Check for jump + if (autojump && (idle_time.check(2000) || isJumping(breadcrumbs[0]))) g_pUserCmd->buttons |= IN_JUMP; + // Check for idle if (idle_time.test_and_set(5000)) { follow_target = 0; diff --git a/src/helpers.cpp b/src/helpers.cpp index 9cccea43..daefa326 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -114,16 +114,18 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist, int maxiterations = maxdist / 40; Vector origin = player->m_vecOrigin(); - if (VisCheckEntFromEnt(player, target)) // if we can see an entity, we don't - // need to run calculations + // if we can see an entity, we don't need to run calculations + if (VisCheckEntFromEnt(player, target)) + return origin; for (int i = 0; i < 4; i++) // for loop for all 4 directions { - for (int j = 0; j < maxiterations; - j++) // 40 * maxiterations = range in HU + // 40 * maxiterations = range in HU + for (int j = 0; j < maxiterations; j++) { Vector virtualOrigin = origin; - switch (i) // what direction to go in + // what direction to go in + switch (i) { case 0: virtualOrigin.x = virtualOrigin.x + 40 * (j + 1); @@ -138,32 +140,33 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist, virtualOrigin.y = virtualOrigin.y - 40 * (j + 1); break; } - if (!IsVectorVisible(origin, - virtualOrigin)) // check if player can see the - // players virtualOrigin + // check if player can see the players virtualOrigin + if (!IsVectorVisible(origin, virtualOrigin)) continue; - if (!VisCheckEntFromEntVector( - virtualOrigin, player, - target)) // check if the virtualOrigin can see the target + // check if the virtualOrigin can see the target + if (!VisCheckEntFromEntVector(virtualOrigin, player, target)) continue; if (!checkWalkable) return virtualOrigin; + // check if the location is accessible if (canReachVector(virtualOrigin)) - return virtualOrigin; // return the corner position that we know - // can see the target + return virtualOrigin; } } + // if we didn't find anything, return an empty Vector return { 0, 0, 0 }; } -float vectorMax(Vector i) // Returns a vectors max value. For example: {123, - // -150, 125} = 125 +// Returns a vectors max value. For example: {123,-150, 125} = 125 +float vectorMax(Vector i) { float res = fmaxf(i.x, i.y); return fmaxf(res, i.z); } -Vector vectorABS(Vector i) +// Returns a vectors absolute value. For example {123,-150, 125} = {123,150, +// 125} +Vector vectorAbs(Vector i) { Vector result = i; result.x = fabsf(result.x); @@ -180,18 +183,21 @@ bool canReachVector(Vector loc) trace_t trace; Ray_t ray; Vector down = loc; - down.z = down.z - 5; + down.z = down.z - 50; ray.Init(loc, down); g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace); - if (!(trace.startpos.z - trace.endpos.z <= - 75)) // higher as to avoid small false positives, player can jump - // 72 hu + // higher to avoid small false positives, player can jump 42 hu according to + // the tf2 wiki + if (!(trace.startpos.DistTo(trace.endpos) <= 45)) return false; - for (int i = 0; i < 4; i++) // for loop for all 4 directions + // check if there is enough space arround the vector for a player to fit + // for loop for all 4 directions + for (int i = 0; i < 4; i++) { Vector directionalLoc = loc; - switch (i) // what to check + // what direction to check + switch (i) { case 0: directionalLoc.x = directionalLoc.x + 40; @@ -210,12 +216,33 @@ bool canReachVector(Vector loc) Ray_t ray2; ray2.Init(loc, directionalLoc); g_ITrace->TraceRay(ray2, 0x4200400B, &trace::filter_no_player, &trace); + // distance of trace < than 26 if (trace2.startpos.DistTo(trace2.endpos) < 26.0f) return false; } return true; } +// returns if the player is currently jumping/falling. +bool isJumping(Vector vec) +{ + // check if the vector is too high above ground + trace_t trace; + Ray_t ray; + Vector down = vec; + Vector loc = vec; + down.z = down.z - 50; + loc.z = loc.z + 5; + ray.Init(vec, down); + //trace::filter_no_player.SetSelf(RAW_ENT(g_pLocalPlayer->entity)); + g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace); + // lower to avoid small false negatives, player can jump 42 hu according to + // the tf2 wiki, higher because loc.z = loc.z + 5; + if (fabsf(trace.startpos.DistTo(trace.endpos)) > 45) + return true; + return false; +} + std::string GetLevelName() { From 4a200e0c40c3d1aee84d9bb45e1b1ff5222b4754 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Tue, 3 Jul 2018 21:46:52 +0200 Subject: [PATCH 4/4] Refactoring --- include/helpers.hpp | 2 +- src/hack.cpp | 4 -- src/hacks/FollowBot.cpp | 22 ++---- src/helpers.cpp | 151 +++++++++++++++++++++++++++------------- 4 files changed, 109 insertions(+), 70 deletions(-) diff --git a/include/helpers.hpp b/include/helpers.hpp index 24ebddbd..82aa9d55 100755 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -81,7 +81,7 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist, bool checkWalkable); float vectorMax(Vector i); Vector vectorAbs(Vector i); -bool canReachVector(Vector loc); +bool canReachVector(Vector loc, Vector dest = {0,0,0}); bool isJumping(Vector vec); bool LineIntersectsBox(Vector &bmin, Vector &bmax, Vector &lmin, Vector &lmax); diff --git a/src/hack.cpp b/src/hack.cpp index 1d203214..07e04634 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -491,10 +491,6 @@ free(logname);*/ #if ENABLE_VISUALS InitStrings(); -#if ENABLE_GUI - // cat_reloadscheme to load imgui - hack::command_stack().push("cat_reloadscheme"); -#endif #ifndef FEATURE_EFFECTS_DISABLED if (g_ppScreenSpaceRegistrationHead && g_pScreenSpaceEffects) { diff --git a/src/hacks/FollowBot.cpp b/src/hacks/FollowBot.cpp index a28dce72..57d93b23 100644 --- a/src/hacks/FollowBot.cpp +++ b/src/hacks/FollowBot.cpp @@ -102,13 +102,7 @@ bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin) int maxiterations = floor(corner.DistTo(g_pLocalPlayer->v_Origin)) / 40; for (int i = 0; i < maxiterations; i++) { - Vector result = g_pLocalPlayer->v_Origin + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1); - if (!canReachVector(result)) - { - breadcrumbs.clear(); - return false; - } - breadcrumbs.push_back(result); + breadcrumbs.push_back(g_pLocalPlayer->v_Origin + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1)); } } @@ -116,13 +110,7 @@ bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin) int maxiterations = floor(corner.DistTo(target->m_vecOrigin())) / 40; for (int i = 0; i < maxiterations; i++) { - Vector result = corner + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1); - if (!canReachVector(result)) - { - breadcrumbs.clear(); - return false; - } - breadcrumbs.push_back(result); + breadcrumbs.push_back(corner + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1)); } return true; } @@ -245,8 +233,6 @@ void WorldTick() Vector indirectOrigin = VischeckWall(LOCAL_E, entity, 250, true); //get the corner location that the future target is visible from if (!indirectOrigin.z) //if we couldn't find it, exit continue; - //breadcrumbs.clear(); //we need to ensure that the breadcrumbs std::vector is empty - //breadcrumbs.push_back(indirectOrigin); //add the corner location to the breadcrumb list if (!addCrumbs(entity, indirectOrigin)) continue; } @@ -255,9 +241,9 @@ void WorldTick() if (!VisCheckEntFromEnt(LOCAL_E, entity)) continue; } + // favor closer entitys if (follow_target && - ENTITY(follow_target)->m_flDistance() > - entity->m_flDistance()) // favor closer entitys + ENTITY(follow_target)->m_flDistance() > entity->m_flDistance()) continue; // ooooo, a target follow_target = i; diff --git a/src/helpers.cpp b/src/helpers.cpp index daefa326..d7153cec 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -116,8 +116,13 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist, // if we can see an entity, we don't need to run calculations if (VisCheckEntFromEnt(player, target)) + { + if (!checkWalkable) + return origin; + else if (canReachVector(origin, target->m_vecOrigin())) + return origin; + } - return origin; for (int i = 0; i < 4; i++) // for loop for all 4 directions { // 40 * maxiterations = range in HU @@ -148,8 +153,11 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist, continue; if (!checkWalkable) return virtualOrigin; + // check if the location is accessible - if (canReachVector(virtualOrigin)) + if (!canReachVector(origin, virtualOrigin)) + continue; + if (canReachVector(virtualOrigin, target->m_vecOrigin())) return virtualOrigin; } } @@ -160,8 +168,7 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist, // Returns a vectors max value. For example: {123,-150, 125} = 125 float vectorMax(Vector i) { - float res = fmaxf(i.x, i.y); - return fmaxf(res, i.z); + return fmaxf(fmaxf(i.x, i.y), i.z); } // Returns a vectors absolute value. For example {123,-150, 125} = {123,150, @@ -176,49 +183,99 @@ Vector vectorAbs(Vector i) } // check to see if we can reach a vector or if it is too high / doesn't leave -// enough space for the player -bool canReachVector(Vector loc) +// enough space for the player, optional second vector +bool canReachVector(Vector loc, Vector dest) { - // check if the vector is too high above ground - trace_t trace; - Ray_t ray; - Vector down = loc; - down.z = down.z - 50; - ray.Init(loc, down); - g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace); - // higher to avoid small false positives, player can jump 42 hu according to - // the tf2 wiki - if (!(trace.startpos.DistTo(trace.endpos) <= 45)) - return false; - - // check if there is enough space arround the vector for a player to fit - // for loop for all 4 directions - for (int i = 0; i < 4; i++) + if (!dest.IsZero()) { - Vector directionalLoc = loc; - // what direction to check - switch (i) + Vector dist = dest - loc; + int maxiterations = floor(dest.DistTo(loc)) / 40; + for (int i = 0; i < maxiterations; i++) { - case 0: - directionalLoc.x = directionalLoc.x + 40; - break; - case 1: - directionalLoc.x = directionalLoc.x - 40; - break; - case 2: - directionalLoc.y = directionalLoc.y + 40; - break; - case 3: - directionalLoc.y = directionalLoc.y - 40; - break; + Vector vec = loc + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1); + + trace_t trace; + Ray_t ray; + Vector down = vec; + down.z = down.z - 50; + ray.Init(vec, down); + g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, + &trace); + if (!(trace.startpos.DistTo(trace.endpos) <= 45)) + return false; + + for (int j = 0; j < 4; j++) + { + Vector directionalLoc = vec; + // what direction to check + switch (j) + { + case 0: + directionalLoc.x = directionalLoc.x + 40; + break; + case 1: + directionalLoc.x = directionalLoc.x - 40; + break; + case 2: + directionalLoc.y = directionalLoc.y + 40; + break; + case 3: + directionalLoc.y = directionalLoc.y - 40; + break; + } + trace_t trace2; + Ray_t ray2; + ray2.Init(vec, directionalLoc); + g_ITrace->TraceRay(ray2, 0x4200400B, &trace::filter_no_player, + &trace2); + // distance of trace < than 26 + if (trace2.startpos.DistTo(trace2.endpos) < 26.0f) + return false; + } } - trace_t trace2; - Ray_t ray2; - ray2.Init(loc, directionalLoc); - g_ITrace->TraceRay(ray2, 0x4200400B, &trace::filter_no_player, &trace); - // distance of trace < than 26 - if (trace2.startpos.DistTo(trace2.endpos) < 26.0f) + } + else + { + // check if the vector is too high above ground + trace_t trace; + Ray_t ray; + Vector down = loc; + down.z = down.z - 50; + ray.Init(loc, down); + g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace); + // higher to avoid small false positives, player can jump 42 hu according to + // the tf2 wiki + if (!(trace.startpos.DistTo(trace.endpos) <= 45)) return false; + // check if there is enough space arround the vector for a player to fit + // for loop for all 4 directions + for (int i = 0; i < 4; i++) + { + Vector directionalLoc = loc; + // what direction to check + switch (i) + { + case 0: + directionalLoc.x = directionalLoc.x + 40; + break; + case 1: + directionalLoc.x = directionalLoc.x - 40; + break; + case 2: + directionalLoc.y = directionalLoc.y + 40; + break; + case 3: + directionalLoc.y = directionalLoc.y - 40; + break; + } + trace_t trace2; + Ray_t ray2; + ray2.Init(loc, directionalLoc); + g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace2); + // distance of trace < than 26 + if (trace2.startpos.DistTo(trace2.endpos) < 26.0f) + return false; + } } return true; } @@ -230,15 +287,15 @@ bool isJumping(Vector vec) trace_t trace; Ray_t ray; Vector down = vec; - Vector loc = vec; + Vector loc = vec; down.z = down.z - 50; - loc.z = loc.z + 5; + loc.z = loc.z + 5; ray.Init(vec, down); - //trace::filter_no_player.SetSelf(RAW_ENT(g_pLocalPlayer->entity)); + // trace::filter_no_player.SetSelf(RAW_ENT(g_pLocalPlayer->entity)); g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace); // lower to avoid small false negatives, player can jump 42 hu according to // the tf2 wiki, higher because loc.z = loc.z + 5; - if (fabsf(trace.startpos.DistTo(trace.endpos)) > 45) + if (trace.startpos.DistTo(trace.endpos) > 45) return true; return false; } @@ -1173,7 +1230,7 @@ void PrintChat(const char *fmt, ...) CHudBaseChat *chat = (CHudBaseChat *) g_CHUD->FindElement("CHudChat"); if (chat) { - std::unique_ptr buf(new char[1024]); + std::unique_ptr buf(new char[1024]); va_list list; va_start(list, fmt); vsprintf(buf.get(), fmt, list);