NavBot fixes and more stuffs

This commit is contained in:
LightCat 2018-10-13 21:01:43 +02:00
parent af4a6613b0
commit ce7aecbf97
7 changed files with 154 additions and 58 deletions

View File

@ -26,7 +26,7 @@ void Draw();
int FindInVector(size_t id); int FindInVector(size_t id);
int FindNearestValid(Vector vec); int FindNearestValid(Vector vec);
int FindNearestValidbyDist(Vector vec, float mindist, float maxdist); int FindNearestValidbyDist(Vector vec, float mindist, float maxdist, bool closest);
class inactivityTracker class inactivityTracker
{ {
@ -130,10 +130,8 @@ public:
} }
return false; return false;
} }
void updateSentries() void AddSentries()
{ {
sentryAreas.clear();
sentries.clear();
for (int i = 0; i < HIGHEST_ENTITY; i++) for (int i = 0; i < HIGHEST_ENTITY; i++)
{ {
CachedEntity *ent = ENTITY(i); CachedEntity *ent = ENTITY(i);
@ -155,6 +153,11 @@ public:
} }
} }
} }
void ClearSentries()
{
sentries.clear();
sentryAreas.clear();
}
bool IsIgnored(std::pair<int, int> connection) bool IsIgnored(std::pair<int, int> connection)
{ {
if (!IsPlayerDisguised(LOCAL_E)) if (!IsPlayerDisguised(LOCAL_E))

View File

@ -12,7 +12,7 @@
static settings::Bool enable{ "antibackstab.enable", "0" }; static settings::Bool enable{ "antibackstab.enable", "0" };
static settings::Float distance{ "antibackstab.distance", "200" }; static settings::Float distance{ "antibackstab.distance", "200" };
static settings::Bool silent{ "antibackstab.silent", "1" }; static settings::Bool silent{ "antibackstab.silent", "1" };
static settings::Float angle{ "antibackstab.angle", "90" }; static settings::Float angle{ "antibackstab.angle", "107.5" };
static settings::Bool sayno{ "antibackstab.nope", "0" }; static settings::Bool sayno{ "antibackstab.nope", "0" };
namespace hacks::tf2::antibackstab namespace hacks::tf2::antibackstab
@ -95,22 +95,17 @@ void CreateMove()
if (!enable) if (!enable)
return; return;
spy = ClosestSpy(); spy = ClosestSpy();
ConVar *pitchdown = g_ICvar->FindVar("cl_pitchdown");
static int normal_val = pitchdown->GetInt();
if (spy) if (spy)
{ {
noaa = true; noaa = true;
pitchdown->SetValue(180); current_user_cmd->viewangles.x = 160.0f;
current_user_cmd->viewangles.x = 140.0f;
if (silent) if (silent)
g_pLocalPlayer->bUseSilentAngles = true; g_pLocalPlayer->bUseSilentAngles = true;
if (sayno) if (sayno)
SayNope(); SayNope();
} }
else else
{
pitchdown->SetValue(normal_val);
noaa = false; noaa = false;
}
} }
} // namespace hacks::tf2::antibackstab } // namespace hacks::tf2::antibackstab

View File

@ -12,12 +12,49 @@ static settings::Int aimkey_mode{ "sandwichaim.aimkey-mode", "0" };
float sandwich_speed = 350.0f; float sandwich_speed = 350.0f;
float grav = 0.25f; float grav = 0.25f;
int prevent = -1;
std::pair<CachedEntity *, Vector> FindBestEnt(bool teammate, bool Predict, std::pair<CachedEntity *, Vector> FindBestEnt(bool teammate, bool Predict,
bool zcheck) bool zcheck)
{ {
CachedEntity *bestent = nullptr; CachedEntity *bestent = nullptr;
float bestscr = FLT_MAX; float bestscr = FLT_MAX;
Vector predicted{}; Vector predicted{};
for (int i = 0; i < 1; i++)
{
if (prevent != -1)
{
auto ent = ENTITY(prevent);
if (CE_BAD(ent) || !ent->m_bAlivePlayer() || (teammate && ent->m_iTeam() != LOCAL_E->m_iTeam()) || ent == LOCAL_E)
continue;
if (!teammate && ent->m_iTeam() == LOCAL_E->m_ItemType())
continue;
if (!ent->hitboxes.GetHitbox(1))
continue;
Vector target{};
if (Predict)
target = ProjectilePrediction(ent, 1, sandwich_speed, grav,
PlayerGravityMod(ent));
else
target = ent->hitboxes.GetHitbox(1)->center;
if (!IsEntityVectorVisible(ent, target))
continue;
if (zcheck && (ent->m_vecOrigin().z - LOCAL_E->m_vecOrigin().z) > 80.0f)
continue;
float scr = ent->m_flDistance();
if (g_pPlayerResource->GetClass(ent) == tf_medic)
scr *= 0.1f;
if (scr < bestscr)
{
bestent = ent;
predicted = target;
bestscr = scr;
prevent = ent->m_IDX;
}
}
if (bestent && predicted.z)
return { bestent, predicted };
}
prevent = -1;
for (int i = 0; i < g_IEngine->GetMaxClients(); i++) for (int i = 0; i < g_IEngine->GetMaxClients(); i++)
{ {
CachedEntity *ent = ENTITY(i); CachedEntity *ent = ENTITY(i);
@ -47,6 +84,7 @@ std::pair<CachedEntity *, Vector> FindBestEnt(bool teammate, bool Predict,
bestent = ent; bestent = ent;
predicted = target; predicted = target;
bestscr = scr; bestscr = scr;
prevent = ent->m_IDX;
} }
} }
return { bestent, predicted }; return { bestent, predicted };

View File

@ -352,36 +352,93 @@ bool NavToSentry(int priority)
return true; return true;
return false; return false;
} }
static Vector lastgoal{0, 0, 0};
int lastent = -1;
bool NavToEnemy() bool NavToEnemy()
{ {
if (*stay_near) if (*stay_near)
{ {
static Vector lastgoal{}; if (lastent != -1)
CachedEntity *ent = NearestEnemy(); {
CachedEntity *ent = ENTITY(lastent);
if (CE_BAD(ent) || !ent->m_bAlivePlayer() || ent->m_iTeam() == LOCAL_E->m_iTeam())
{
lastent = -1;
if (lastgoal.x > 1.0f || lastgoal.x < -1.0f)
{
nav::NavTo(lastgoal, false, true, 1337);
return true;
}
}
else
{
int nearestvalid = -1;
if (!*heavy_mode)
nearestvalid = nav::FindNearestValidbyDist(ent->m_vecOrigin(), 200, 2000, true);
else
nearestvalid = nav::FindNearestValidbyDist(ent->m_vecOrigin(), 200, 1000, true);
if (nearestvalid != -1)
{
auto area = nav::areas[nearestvalid];
nav::NavTo(area.m_center, false, true, 1337);
lastgoal = area.m_center;
lastent = ent->m_IDX;
return true;
}
else if ((lastgoal.x > 1.0f || lastgoal.x < -1.0f) && lastgoal.DistTo(LOCAL_E->m_vecOrigin()) > 200.0f)
{
nav::NavTo(lastgoal, false, true, 1337);
lastgoal = {0, 0, 0};
return true;
}
else
{
lastgoal = {0, 0, 0};
lastent = -1;
}
}
}
auto ent = NearestEnemy();
if (CE_GOOD(ent)) if (CE_GOOD(ent))
{ {
int nearestvalid{}; int nearestvalid = -1;
if (!*heavy_mode) if (!*heavy_mode)
nearestvalid = nearestvalid = nav::FindNearestValidbyDist(ent->m_vecOrigin(), 200, 2000, true);
nav::FindNearestValidbyDist(ent->m_vecOrigin(), 2000, 6000);
else else
nearestvalid = nearestvalid = nav::FindNearestValidbyDist(ent->m_vecOrigin(), 200, 1000, true);
nav::FindNearestValidbyDist(ent->m_vecOrigin(), 200, 1000);
if (nearestvalid != -1) if (nearestvalid != -1)
{ {
auto area = nav::areas[nearestvalid]; auto area = nav::areas[nearestvalid];
nav::NavTo(area.m_center, false, true, 1337); nav::NavTo(area.m_center, false, true, 1337);
lastgoal = area.m_center; lastgoal = area.m_center;
lastent = ent->m_IDX;
return true; return true;
} }
else if ((lastgoal.x > 1.0f || lastgoal.x < -1.0f) && lastgoal.DistTo(LOCAL_E->m_vecOrigin()) > 200.0f)
{
nav::NavTo(lastgoal, false, true, 1337);
lastgoal = {0, 0, 0};
return true;
}
else
{
lastgoal = {0, 0, 0};
lastent = -1;
}
} }
else if (lastgoal.z && LOCAL_E->m_vecOrigin().DistTo(lastgoal) > 200.0f) else if ((lastgoal.x > 1.0f || lastgoal.x < -1.0f) && lastgoal.DistTo(LOCAL_E->m_vecOrigin()) > 200.0f)
{ {
nav::NavTo(lastgoal, false, true, 1337); nav::NavTo(lastgoal, false, true, 1337);
lastgoal = {0, 0, 0};
return true; return true;
} }
else else
lastgoal = {}; {
lastgoal = {0, 0, 0};
lastent = -1;
}
} }
return false; return false;
} }
@ -457,9 +514,6 @@ static HookedFunction
return; return;
if (primary_only && enable) if (primary_only && enable)
UpdateSlot(); UpdateSlot();
if (*stay_near && nav_enemy_cd.test_and_set(1000) &&
(!HasLowAmmo()) & (!HasLowHealth()))
NavToEnemy();
if (HasLowHealth() && ammo_health_cooldown.test_and_set(5000)) if (HasLowHealth() && ammo_health_cooldown.test_and_set(5000))
{ {
CachedEntity *med = nearestHealth(); CachedEntity *med = nearestHealth();
@ -504,6 +558,10 @@ static HookedFunction
} }
} }
} }
if (*stay_near && nav_enemy_cd.test_and_set(1000) &&
!HasLowAmmo() && !HasLowHealth())
if (NavToEnemy())
return;
if (enable) if (enable)
{ {
if (!nav::ReadyForCommands && !spy_mode && !heavy_mode && if (!nav::ReadyForCommands && !spy_mode && !heavy_mode &&

View File

@ -101,6 +101,8 @@ void RunEnginePrediction(IClientEntity *ent, CUserCmd *ucmd)
g_GlobalVars->frametime = frameTime; g_GlobalVars->frametime = frameTime;
g_GlobalVars->curtime = curTime; g_GlobalVars->curtime = curTime;
// Adjust tickbase
NET_INT(ent, netvar.nTickBase)++;
return; return;
} }
} // namespace engine_prediction } // namespace engine_prediction

View File

@ -240,24 +240,29 @@ static HookedFunction paint(HookedFunctions_types::HF_Paint, "IRC", 16, []() {
{ {
if (last_steamid_received.test_and_set(10000)) if (last_steamid_received.test_and_set(10000))
{ {
if (!steamidvec.empty()) static uintptr_t addr = gSignatures.GetClientSignature("55 89 E5 57 56 53 83 EC ? 8B 7D ? 8B 77 ? 85 F6 0F 84");
{ typedef int (*GetNumOnlineMembers_t)(re::CTFPartyClient *);
steamidvec.push_back(g_ISteamUser->GetSteamID().GetAccountID()); auto GetNumOnlineMembers_fn = GetNumOnlineMembers_t(addr);
int idx = -1; auto party_client = re::CTFPartyClient::GTFPartyClient();
unsigned lowest = UINT_MAX; if (party_client && GetNumOnlineMembers_fn(party_client) != 6)
for (int i = 0; i < steamidvec.size(); i++) if (!steamidvec.empty())
if (steamidvec[i] < lowest)
{
lowest = steamidvec[i];
idx = i;
}
if (idx != -1 && steamidvec[idx] != g_ISteamUser->GetSteamID().GetAccountID())
{ {
hack::command_stack().push("tf_party_leave"); steamidvec.push_back(g_ISteamUser->GetSteamID().GetAccountID());
hack::command_stack().push(format("tf_party_request_join_user ", steamidvec[idx])); int idx = -1;
unsigned lowest = UINT_MAX;
for (int i = 0; i < steamidvec.size(); i++)
if (steamidvec[i] < lowest)
{
lowest = steamidvec[i];
idx = i;
}
if (idx != -1 && steamidvec[idx] != g_ISteamUser->GetSteamID().GetAccountID())
{
hack::command_stack().push("tf_party_leave");
hack::command_stack().push(format("tf_party_request_join_user ", steamidvec[idx]));
}
steamidvec.clear();
} }
steamidvec.clear();
}
} }
if (irc_party && last_sent_steamid.test_and_set(*party_cooldown * 1000)) if (irc_party && last_sent_steamid.test_and_set(*party_cooldown * 1000))
irc.privmsg(format("cc_partysteam", irc.privmsg(format("cc_partysteam",

View File

@ -28,24 +28,11 @@ int FindInVector(size_t id)
} }
static int bestarea = -1; static int bestarea = -1;
Timer reselect{}; Timer reselect{};
int FindNearestValidbyDist(Vector vec, float mindist, float maxdist) int FindNearestValidbyDist(Vector vec, float mindist, float maxdist, bool closest)
{ {
if (reselect.test_and_set(500)) if (reselect.test_and_set(500))
{ {
float bestscr = FLT_MAX; float bestscr = FLT_MAX;
if (bestarea != -1)
{
bool success = false;
Vector area = areas[bestarea].m_center;
float scr = area.DistTo(vec);
if (scr < maxdist && scr > mindist)
if (IsVectorVisible(vec, area, false))
success = true;
if (!success)
bestarea = -1;
}
else
{
bestarea = -1; bestarea = -1;
for (int ar = 0; ar < areas.size(); ar++) for (int ar = 0; ar < areas.size(); ar++)
{ {
@ -54,7 +41,13 @@ int FindNearestValidbyDist(Vector vec, float mindist, float maxdist)
float scr = area.DistTo(vec); float scr = area.DistTo(vec);
if (scr > maxdist || scr < mindist) if (scr > maxdist || scr < mindist)
continue; continue;
if (scr > bestscr) if (closest)
{
if (scr > bestscr)
continue;
}
else if (scr < bestscr)
continue; continue;
if (IsVectorVisible(vec, area, false)) if (IsVectorVisible(vec, area, false))
{ {
@ -62,7 +55,6 @@ int FindNearestValidbyDist(Vector vec, float mindist, float maxdist)
bestarea = ar; bestarea = ar;
} }
} }
}
} }
return bestarea; return bestarea;
} }
@ -330,6 +322,7 @@ void clearInstructions()
static Timer ignoreReset{}; static Timer ignoreReset{};
static Timer patherReset{}; static Timer patherReset{};
static Timer sentryUpdate{}; static Timer sentryUpdate{};
static Timer sentryClear{};
static Timer sentryCheck{}; static Timer sentryCheck{};
// Function for removing ignores // Function for removing ignores
void ignoreManagerCM() void ignoreManagerCM()
@ -340,8 +333,10 @@ void ignoreManagerCM()
TF2MAP->inactiveTracker.reset(); TF2MAP->inactiveTracker.reset();
if (patherReset.test_and_set(30000)) if (patherReset.test_and_set(30000))
TF2MAP->pather->Reset(); TF2MAP->pather->Reset();
if (sentryUpdate.test_and_set(1000)) if (sentryClear.test_and_set(20000))
TF2MAP->inactiveTracker.updateSentries(); TF2MAP->inactiveTracker.ClearSentries();
if (sentryUpdate.test_and_set(500))
TF2MAP->inactiveTracker.AddSentries();
} }
void Repath() void Repath()