diff --git a/include/core/netvars.hpp b/include/core/netvars.hpp index bd097619..87141b8f 100644 --- a/include/core/netvars.hpp +++ b/include/core/netvars.hpp @@ -56,9 +56,11 @@ public: offset_t flChargedDamage; offset_t iUpgradeLevel; offset_t m_hBuilder; + offset_t m_bCanPlace; offset_t m_iObjectType; offset_t m_bMiniBuilding; offset_t m_bHasSapper; + offset_t m_bPlacing; offset_t m_bBuilding; offset_t m_iTeleState; offset_t m_flTeleRechargeTime; @@ -145,6 +147,7 @@ public: offset_t m_rgflCoordinateFrame; offset_t m_bFeignDeathReady; offset_t m_bCarryingObject; + offset_t m_hCarriedObject; offset_t m_iTauntConcept; offset_t m_iTauntIndex; diff --git a/src/core/netvars.cpp b/src/core/netvars.cpp index d06a0966..cc6928f9 100644 --- a/src/core/netvars.cpp +++ b/src/core/netvars.cpp @@ -56,6 +56,7 @@ void NetVars::Init() this->m_flChargeLevel = gNetvars.get_offset("DT_WeaponMedigun", "NonLocalTFWeaponMedigunData", "m_flChargeLevel"); m_bFeignDeathReady = gNetvars.get_offset("DT_TFPlayer", "m_Shared", "m_bFeignDeathReady"); m_bCarryingObject = gNetvars.get_offset("DT_TFPlayer", "m_Shared", "m_bCarryingObject"); + m_hCarriedObject = gNetvars.get_offset("DT_TFPlayer", "m_Shared", "m_hCarriedObject"); m_nSequence = gNetvars.get_offset("DT_BaseAnimating", "m_nSequence"); m_iTauntIndex = gNetvars.get_offset("DT_TFPlayer", "m_Shared", "m_iTauntIndex"); m_iTauntConcept = gNetvars.get_offset("DT_TFPlayer", "m_Shared", "m_iTauntConcept"); @@ -76,9 +77,11 @@ void NetVars::Init() this->flChargedDamage = gNetvars.get_offset("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_bCanPlace = gNetvars.get_offset("DT_BaseObject", "m_bServerOverridePlacement"); this->m_bBuilding = gNetvars.get_offset("DT_BaseObject", "m_bBuilding"); this->m_iObjectType = gNetvars.get_offset("DT_BaseObject", "m_iObjectType"); this->m_bHasSapper = gNetvars.get_offset("DT_BaseObject", "m_bHasSapper"); + this->m_bPlacing = gNetvars.get_offset("DT_BaseObject", "m_bPlacing"); this->m_bMiniBuilding = gNetvars.get_offset("DT_BaseObject", "m_bMiniBuilding"); this->m_iTeleState = gNetvars.get_offset("DT_ObjectTeleporter", "m_iState"); this->m_flTeleRechargeTime = gNetvars.get_offset("DT_ObjectTeleporter", "m_flRechargeTime"); diff --git a/src/hacks/NavBot.cpp b/src/hacks/NavBot.cpp index 52c4fc42..04984c25 100644 --- a/src/hacks/NavBot.cpp +++ b/src/hacks/NavBot.cpp @@ -588,9 +588,29 @@ void OutOfBoundsrun(const CCommand &args) to_path.usepitch = usepitch; to_path.active = true; } + +int getCarriedBuilding() +{ + if (CE_BYTE(LOCAL_E, netvar.m_bCarryingObject)) + return HandleToIDX(CE_INT(LOCAL_E, netvar.m_hCarriedObject)); + for (int i = 1; i < MAX_ENTITIES; i++) + { + auto ent = ENTITY(i); + if (CE_BAD(ent) || ent->m_Type() != ENTITY_BUILDING) + continue; + if (HandleToIDX(CE_INT(ent, netvar.m_hBuilder)) != LOCAL_E->m_IDX) + continue; + if (!CE_BYTE(ent, netvar.m_bPlacing)) + continue; + return i; + } + return -1; +} + static CatCommand Outofbounds{ "outofbounds", "Out of bounds", OutOfBoundsrun }; static Timer timeout{}; +static float yaw_offset = 0.0f; void oobcm() { if (to_path.active) @@ -600,18 +620,69 @@ void oobcm() Vector topath = { to_path.x, to_path.y, LOCAL_E->m_vecOrigin().z }; if (LOCAL_E->m_vecOrigin().AsVector2D().DistTo(topath.AsVector2D()) <= 0.01f || timeout.test_and_set(10000)) { - to_path.active = false; - if (to_path.usepitch) - current_user_cmd->viewangles.x = to_path.pitch; - current_user_cmd->viewangles.y = to_path.yaw; if (LOCAL_E->m_vecOrigin().AsVector2D().DistTo(topath.AsVector2D()) <= 0.01f) - logging::Info("Arrived at the destination! offset: %f %f", fabsf(LOCAL_E->m_vecOrigin().x - topath.x), fabsf(LOCAL_E->m_vecOrigin().y - topath.y)); + { + if (re::C_BaseCombatWeapon::GetSlot(RAW_ENT(LOCAL_W)) != 5) + { + yaw_offset = 0.0f; + to_path.active = false; + if (to_path.usepitch) + current_user_cmd->viewangles.x = to_path.pitch; + current_user_cmd->viewangles.y = to_path.yaw; + logging::Info("Arrived at the destination! offset: %f %f", fabsf(LOCAL_E->m_vecOrigin().x - topath.x), fabsf(LOCAL_E->m_vecOrigin().y - topath.y)); + } + else + { + timeout.update(); + if (to_path.usepitch) + current_user_cmd->viewangles.x = to_path.pitch; + current_user_cmd->viewangles.y = to_path.yaw; + int carried_build = getCarriedBuilding(); + if (carried_build == -1) + { + logging::Info("No building held"); + return; + } + auto ent = ENTITY(carried_build); + if (CE_BAD(ent)) + { + logging::Info("No Building held"); + to_path.active = false; + return; + } + else + { + if (CE_BYTE(ent, netvar.m_bCanPlace)) + current_user_cmd->buttons |= IN_ATTACK; + if (yaw_offset >= 0.1f) + { + logging::Info("Failed getting out of bounds, Yaw offset too large"); + to_path.active = false; + return; + } + yaw_offset = -yaw_offset; + if (yaw_offset >= 0.0f) + yaw_offset += 0.0001f; + current_user_cmd->viewangles.y = to_path.yaw + yaw_offset; + } + } + } else + { + yaw_offset = 0.0f; + to_path.active = false; + if (to_path.usepitch) + current_user_cmd->viewangles.x = to_path.pitch; + current_user_cmd->viewangles.y = to_path.yaw; logging::Info("Timed out trying to get to spot"); + } + } + if (yaw_offset == 0.0f) + { + auto move = ComputeMovePrecise(LOCAL_E->m_vecOrigin(), topath); + current_user_cmd->forwardmove = move.first; + current_user_cmd->sidemove = move.second; } - auto move = ComputeMovePrecise(LOCAL_E->m_vecOrigin(), topath); - current_user_cmd->forwardmove = move.first; - current_user_cmd->sidemove = move.second; } } else diff --git a/src/helpers.cpp b/src/helpers.cpp index c1a4ce48..e59307db 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -436,13 +436,19 @@ std::pair ComputeMovePrecise(const Vector &a, const Vector &b) const float x = diff.x; const float y = diff.y; Vector vsilent(x, y, 0); - float speed = sqrt(vsilent.x * vsilent.x + vsilent.y * vsilent.y); Vector ang; VectorAngles(vsilent, ang); float yaw = DEG2RAD(ang.y - current_user_cmd->viewangles.y); if (g_pLocalPlayer->bUseSilentAngles) yaw = DEG2RAD(ang.y - g_pLocalPlayer->v_OrigViewangles.y); - return { cos(yaw) * MIN(MAX(diff.Length2D(), 1.05f), 450.0f), -sin(yaw) * MIN(MAX(diff.Length2D(), 1.05f), 450.0f) }; + float speed = 450.0f; + if (diff.Length() <= 5.0f) + speed = 1.05f; + else if (diff.Length() <= 20.0f) + speed = 10.0f; + else if (diff.Length() <= 100.0f) + speed = 225.0f; + return { cos(yaw) * speed, -sin(yaw) * speed }; } std::pair ComputeMove(const Vector &a, const Vector &b)