diff --git a/Core/Player.hpp b/Core/Player.hpp index 7230330..95b57d6 100644 --- a/Core/Player.hpp +++ b/Core/Player.hpp @@ -78,8 +78,6 @@ struct Player { float aimbotScore; FloatVector2D aimbotDesiredAnglesSmoothedNoRecoil; - std::chrono::milliseconds LastRead; - Player(int PlayerIndex, LocalPlayer* Me) { this->Index = PlayerIndex; this->Myself = Me; @@ -141,8 +139,19 @@ struct Player { aimbotDesiredAnglesSmoothedNoRecoil = {}; } - void Read() { - BasePointer = Memory::Read(OFF_REGION + OFF_ENTITY_LIST + ((Index + 1) << 5)); + void ShortRead() { + BasePointer = Memory::Read(OFF_REGION + OFF_ENTITY_LIST + (Index + 1 << 5)); + if (BasePointer == 0) + return; + + LocalOrigin = Memory::Read(BasePointer + OFF_LOCAL_ORIGIN); + AbsoluteVelocity = Memory::Read(BasePointer + OFF_ABSVELOCITY); + ViewAngles = Memory::Read(BasePointer + OFF_VIEW_ANGLES); + ViewYaw = Memory::Read(BasePointer + OFF_YAW); + } + + void FullRead() { + BasePointer = Memory::Read(OFF_REGION + OFF_ENTITY_LIST + (Index + 1 << 5)); if (BasePointer == 0) return; @@ -151,17 +160,17 @@ struct Player { if (!IsPlayer() && !IsDummy()) { BasePointer = 0; return; } - IsDead = (IsDummy()) ? false : Memory::Read(BasePointer + OFF_LIFE_STATE) > 0; - IsKnocked = (IsDummy()) ? false : Memory::Read(BasePointer + OFF_BLEEDOUT_STATE) > 0; + IsDead = !IsDummy() && Memory::Read(BasePointer + OFF_LIFE_STATE) > 0; + IsKnocked = !IsDummy() && Memory::Read(BasePointer + OFF_BLEEDOUT_STATE) > 0; LocalOrigin = Memory::Read(BasePointer + OFF_LOCAL_ORIGIN); LastTimeAimedAt = Memory::Read(BasePointer + OFF_LAST_AIMEDAT_TIME); IsAimedAt = LastTimeAimedAtPrevious < LastTimeAimedAt; LastTimeAimedAtPrevious = LastTimeAimedAt; - float WorldTime = Memory::Read(Myself->BasePointer + OFF_TIME_BASE); - float Time1 = Memory::Read(BasePointer + OFF_LAST_VISIBLE_TIME); - IsVisible = (Time1 + 0.2) >= WorldTime || IsAimedAt; + const auto WorldTime = Memory::Read(Myself->BasePointer + OFF_TIME_BASE); + const auto Time1 = Memory::Read(BasePointer + OFF_LAST_VISIBLE_TIME); + IsVisible = Time1 + 0.2 >= WorldTime || IsAimedAt; Health = Memory::Read(BasePointer + OFF_HEALTH); MaxHealth = Memory::Read(BasePointer + OFF_MAXHEALTH); @@ -169,12 +178,12 @@ struct Player { MaxShield = Memory::Read(BasePointer + OFF_MAXSHIELD); if (!IsDead && !IsKnocked && IsHostile) { - long WeaponHandle = Memory::Read(BasePointer + OFF_WEAPON_HANDLE); - long WeaponHandleMasked = WeaponHandle & 0xffff; + const auto WeaponHandle = Memory::Read(BasePointer + OFF_WEAPON_HANDLE); + const long WeaponHandleMasked = WeaponHandle & 0xffff; WeaponEntity = Memory::Read(OFF_REGION + OFF_ENTITY_LIST + (WeaponHandleMasked << 5)); - int OffHandWeaponID = Memory::Read(BasePointer + OFF_OFFHAND_WEAPON); - IsHoldingGrenade = OffHandWeaponID == -251 ? true : false; + const auto OffHandWeaponID = Memory::Read(BasePointer + OFF_OFFHAND_WEAPON); + IsHoldingGrenade = OffHandWeaponID == -251; WeaponIndex = Memory::Read(WeaponEntity + OFF_WEAPON_INDEX); } @@ -187,29 +196,22 @@ struct Player { Distance2DToLocalPlayer = Myself->LocalOrigin.To2D().Distance(LocalOrigin.To2D()); } - // Update Once Per Tick - hir0xygen - // Reading Most Of The Info Above Every Tick Caused Errors Such As Wrong Weapon IDs And ESP To Be Drawn Wrong - // If You Only Use Glow (And Maybe Aimbot, Haven't Tested), You May Be Able To Move Info Above To Below To Increase Performance - if (const auto Now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); Now >= LastRead + std::chrono::milliseconds(50)) { - LastRead = Now; - AbsoluteVelocity = Memory::Read(BasePointer + OFF_ABSVELOCITY); - ViewAngles = Memory::Read(BasePointer + OFF_VIEW_ANGLES); - ViewYaw = Memory::Read(BasePointer + OFF_YAW); - if (Myself->IsValid()) { - if (IsVisible) { // For AimbotMode Grinder - aimbotDesiredAngles = calcDesiredAngles(); - aimbotDesiredAnglesIncrement = calcDesiredAnglesIncrement(); - aimbotScore = calcAimbotScore(); - } - } + AbsoluteVelocity = Memory::Read(BasePointer + OFF_ABSVELOCITY); + ViewAngles = Memory::Read(BasePointer + OFF_VIEW_ANGLES); + ViewYaw = Memory::Read(BasePointer + OFF_YAW); - // For AimbotMode Grinder - localOrigin = Memory::Read(BasePointer + OFF_LOCAL_ORIGIN); - absoluteVelocity = Memory::Read(BasePointer + OFF_ABSVELOCITY); - FloatVector3D localOrigin_diff = localOrigin.subtract(localOrigin_prev).normalize().multiply(20); - localOrigin_predicted = localOrigin.add(localOrigin_diff); - localOrigin_prev = FloatVector3D(localOrigin.x, localOrigin.y, localOrigin.z); + if (Myself->IsValid() && IsVisible) { + aimbotDesiredAngles = calcDesiredAngles(); + aimbotDesiredAnglesIncrement = calcDesiredAnglesIncrement(); + aimbotScore = calcAimbotScore(); } + + // For AimbotMode Grinder + localOrigin = Memory::Read(BasePointer + OFF_LOCAL_ORIGIN); + absoluteVelocity = Memory::Read(BasePointer + OFF_ABSVELOCITY); + FloatVector3D localOrigin_diff = localOrigin.subtract(localOrigin_prev).normalize().multiply(20); + localOrigin_predicted = localOrigin.add(localOrigin_diff); + localOrigin_prev = FloatVector3D(localOrigin.x, localOrigin.y, localOrigin.z); } bool IsSpectating() { diff --git a/zap.cpp b/zap.cpp index b49dba1..f946113 100644 --- a/zap.cpp +++ b/zap.cpp @@ -74,6 +74,8 @@ ConfigManager* Configs = new ConfigManager(Legit, Rage, Flick, Trigger, GlowESP, // Booleans and Variables bool IsMenuOpened = true; +std::chrono::milliseconds LastRead; +std::chrono::milliseconds LastReset; // Thread std::atomic_bool StopThread(false); @@ -303,7 +305,7 @@ void RenderUI() { // Core bool UpdateCore() { try { - // Map Checking // + // Map Checking // Map->Read(); if (!Map->IsPlayable) { return true; @@ -315,30 +317,23 @@ bool UpdateCore() { return true; } - // Populate Players // - /*Players->clear(); - if (Map->IsFiringRange) { - for (int i = 0; i < Dummies->size(); i++) { - Player* p = Dummies->at(i); - p->Read(); + const auto Now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); + if (Now >= LastReset + std::chrono::milliseconds(5000)) { // update entire entity list (10k in practice range) every 5s + Players->clear(); + LastReset = LastRead = Now; + for (auto p: Map->IsFiringRange ? *Dummies : *HumanPlayers) { + p->FullRead(); if (p->BasePointer != 0 && (p->IsPlayer() || p->IsDummy())) Players->push_back(p); } - } - else { - for (int i = 0; i < HumanPlayers->size(); i++) { - Player* p = HumanPlayers->at(i); - p->Read(); - if (p->BasePointer != 0 && (p->IsPlayer() || p->IsDummy())) - Players->push_back(p); + } else if (Now >= LastRead + std::chrono::milliseconds(50)) { // update known players every tick + LastRead = Now; + for (const auto p : *Players) + p->FullRead(); + } else { // update *some* things constantly to keep ESP & aimbot smooth + for (const auto p : *Players) { // update important data about known players constantly + p->ShortRead(); } - }*/ - - Players->clear(); - for (auto p : Map->IsFiringRange ? *Dummies : *HumanPlayers) { - p->Read(); - if (p->BasePointer != 0 && (p->IsPlayer() || p->IsDummy())) - Players->push_back(p); } // Updates //