Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve player reads #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Improve player reads
  • Loading branch information
hir0xygen committed Jun 10, 2024
commit 4e90f1ec3e54069a2b0190606e318e6c2e7a044b
70 changes: 36 additions & 34 deletions Core/Player.hpp
Original file line number Diff line number Diff line change
@@ -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<long>(OFF_REGION + OFF_ENTITY_LIST + ((Index + 1) << 5));
void ShortRead() {
BasePointer = Memory::Read<long>(OFF_REGION + OFF_ENTITY_LIST + (Index + 1 << 5));
if (BasePointer == 0)
return;

LocalOrigin = Memory::Read<Vector3D>(BasePointer + OFF_LOCAL_ORIGIN);
AbsoluteVelocity = Memory::Read<Vector3D>(BasePointer + OFF_ABSVELOCITY);
ViewAngles = Memory::Read<Vector2D>(BasePointer + OFF_VIEW_ANGLES);
ViewYaw = Memory::Read<float>(BasePointer + OFF_YAW);
}

void FullRead() {
BasePointer = Memory::Read<long>(OFF_REGION + OFF_ENTITY_LIST + (Index + 1 << 5));
if (BasePointer == 0)
return;

@@ -151,30 +160,30 @@ struct Player {

if (!IsPlayer() && !IsDummy()) { BasePointer = 0; return; }

IsDead = (IsDummy()) ? false : Memory::Read<short>(BasePointer + OFF_LIFE_STATE) > 0;
IsKnocked = (IsDummy()) ? false : Memory::Read<short>(BasePointer + OFF_BLEEDOUT_STATE) > 0;
IsDead = !IsDummy() && Memory::Read<short>(BasePointer + OFF_LIFE_STATE) > 0;
IsKnocked = !IsDummy() && Memory::Read<short>(BasePointer + OFF_BLEEDOUT_STATE) > 0;

LocalOrigin = Memory::Read<Vector3D>(BasePointer + OFF_LOCAL_ORIGIN);

LastTimeAimedAt = Memory::Read<int>(BasePointer + OFF_LAST_AIMEDAT_TIME);
IsAimedAt = LastTimeAimedAtPrevious < LastTimeAimedAt;
LastTimeAimedAtPrevious = LastTimeAimedAt;
float WorldTime = Memory::Read<float>(Myself->BasePointer + OFF_TIME_BASE);
float Time1 = Memory::Read<float>(BasePointer + OFF_LAST_VISIBLE_TIME);
IsVisible = (Time1 + 0.2) >= WorldTime || IsAimedAt;
const auto WorldTime = Memory::Read<float>(Myself->BasePointer + OFF_TIME_BASE);
const auto Time1 = Memory::Read<float>(BasePointer + OFF_LAST_VISIBLE_TIME);
IsVisible = Time1 + 0.2 >= WorldTime || IsAimedAt;

Health = Memory::Read<int>(BasePointer + OFF_HEALTH);
MaxHealth = Memory::Read<int>(BasePointer + OFF_MAXHEALTH);
Shield = Memory::Read<int>(BasePointer + OFF_SHIELD);
MaxShield = Memory::Read<int>(BasePointer + OFF_MAXSHIELD);

if (!IsDead && !IsKnocked && IsHostile) {
long WeaponHandle = Memory::Read<long>(BasePointer + OFF_WEAPON_HANDLE);
long WeaponHandleMasked = WeaponHandle & 0xffff;
const auto WeaponHandle = Memory::Read<long>(BasePointer + OFF_WEAPON_HANDLE);
const long WeaponHandleMasked = WeaponHandle & 0xffff;
WeaponEntity = Memory::Read<long>(OFF_REGION + OFF_ENTITY_LIST + (WeaponHandleMasked << 5));

int OffHandWeaponID = Memory::Read<int>(BasePointer + OFF_OFFHAND_WEAPON);
IsHoldingGrenade = OffHandWeaponID == -251 ? true : false;
const auto OffHandWeaponID = Memory::Read<int>(BasePointer + OFF_OFFHAND_WEAPON);
IsHoldingGrenade = OffHandWeaponID == -251;

WeaponIndex = Memory::Read<int>(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::milliseconds>(std::chrono::system_clock::now().time_since_epoch()); Now >= LastRead + std::chrono::milliseconds(50)) {
LastRead = Now;
AbsoluteVelocity = Memory::Read<Vector3D>(BasePointer + OFF_ABSVELOCITY);
ViewAngles = Memory::Read<Vector2D>(BasePointer + OFF_VIEW_ANGLES);
ViewYaw = Memory::Read<float>(BasePointer + OFF_YAW);
if (Myself->IsValid()) {
if (IsVisible) { // For AimbotMode Grinder
aimbotDesiredAngles = calcDesiredAngles();
aimbotDesiredAnglesIncrement = calcDesiredAnglesIncrement();
aimbotScore = calcAimbotScore();
}
}
AbsoluteVelocity = Memory::Read<Vector3D>(BasePointer + OFF_ABSVELOCITY);
ViewAngles = Memory::Read<Vector2D>(BasePointer + OFF_VIEW_ANGLES);
ViewYaw = Memory::Read<float>(BasePointer + OFF_YAW);

// For AimbotMode Grinder
localOrigin = Memory::Read<FloatVector3D>(BasePointer + OFF_LOCAL_ORIGIN);
absoluteVelocity = Memory::Read<FloatVector3D>(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<FloatVector3D>(BasePointer + OFF_LOCAL_ORIGIN);
absoluteVelocity = Memory::Read<FloatVector3D>(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() {
37 changes: 16 additions & 21 deletions zap.cpp
Original file line number Diff line number Diff line change
@@ -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::milliseconds>(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 //