-
Notifications
You must be signed in to change notification settings - Fork 46
/
Player.hpp
198 lines (155 loc) · 5.47 KB
/
Player.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#pragma once
#include <string>
#include "Offsets.hpp"
#include "LocalPlayer.hpp"
#include "Level.hpp"
#include "DMALibrary/Memory/Memory.h"
#include "HitboxType.hpp"
#include "Vector2D.hpp"
#include "Vector3D.hpp"
#include "Matrix.hpp"
struct Player {
LocalPlayer* Myself;
Level* Map;
int Index;
uint64_t BasePointer = 0;
uint64_t ModelPointer = 0;
uint64_t BonePointer = 0;
char NameBuffer[8] = { 0 };
std::string Name;
int Team;
int GlowEnable;
int GlowThroughWall;
int HighlightID;
bool IsDead;
bool IsKnocked;
Vector3D LocalOrigin;
Vector3D AbsoluteVelocity;
int Health;
float ViewYaw;
int LastTimeAimedAt;
int LastTimeAimedAtPrevious;
bool IsAimedAt;
uint64_t LastVisibleCheckTime = 0;
int LastVisibleTime;
int LastTimeVisiblePrevious = 0;
bool LastVisibleState = false;
int VisCheckCount = 0;
const int VisCheckThreshold = 10;
bool IsVisible;
bool IsLocal;
bool IsAlly;
bool IsHostile;
float DistanceToLocalPlayer;
float Distance2DToLocalPlayer;
bool IsLockedOn;
uint64_t Valid = 0;
Player(int PlayerIndex, LocalPlayer* Me, Level* Map) {
this->Index = PlayerIndex;
this->Myself = Me;
this->Map = Map;
}
uint64_t GetMilliseconds()
{
LARGE_INTEGER PerformanceFrequency;
QueryPerformanceFrequency(&PerformanceFrequency);
LARGE_INTEGER CurrentPerformanceCount;
QueryPerformanceCounter(&CurrentPerformanceCount);
return (CurrentPerformanceCount.QuadPart/*microseconds*/ * 1000/*milliseconds*/) / PerformanceFrequency.QuadPart/*microseconds*/;
}
bool VisCheck() {
uint64_t VisibleCheckTime = GetMilliseconds();
if (VisibleCheckTime >= LastVisibleCheckTime + 10) {
LastVisibleState = false;
if (LastVisibleTime > LastTimeVisiblePrevious) {
LastVisibleState = true;
VisCheckCount = 0;
}
else if (LastVisibleTime < 0 && LastTimeVisiblePrevious > 0) {
LastVisibleState = true;
VisCheckCount = 0;
}
else if(LastVisibleTime == LastTimeVisiblePrevious) {
VisCheckCount++;
if (VisCheckCount < VisCheckThreshold) {
LastVisibleState = true;
}
}
LastTimeVisiblePrevious = LastVisibleTime;
LastVisibleCheckTime = VisibleCheckTime;
}
return LastVisibleState;
}
void ValidCheck() {
if (Valid) {
if (Valid > 0x7FFFFFFEFFFF || Valid < 0x7FF000000000) {
BasePointer = 0;
Valid = 0;
}
}
}
void Read() {
if (!mem.IsValidPointer(BasePointer)) { BasePointer = 0; return; }
if (!IsPlayer() && !IsDummy()) { BasePointer = 0; return; }
IsAimedAt = LastTimeAimedAtPrevious < LastTimeAimedAt;
LastTimeAimedAtPrevious = LastTimeAimedAt;
IsVisible = IsDummy() || IsAimedAt || VisCheck();
if (Myself->IsValid()) {
IsLocal = Myself->BasePointer == BasePointer;
IsAlly = Myself->Team == Team;
IsHostile = !IsAlly;
DistanceToLocalPlayer = Myself->LocalOrigin.Distance(LocalOrigin);
Distance2DToLocalPlayer = Myself->LocalOrigin.To2D().Distance(LocalOrigin.To2D());
}
}
bool IsValid() {
return mem.IsValidPointer(BasePointer) && !IsDead && Health > 0 && (IsPlayer() || IsDummy() && Map->IsFiringRange);
}
bool IsCombatReady() {
if (!IsValid())return false;
if (IsDummy()) return true;
if (IsDead) return false;
if (IsKnocked) return false;
return true;
}
bool IsPlayer() {
return Name == "player";
}
bool IsDummy() {
return Team == 97;
}
// Bones //
int GetBoneFromHitbox(HitboxType HitBox) const {
if (!mem.IsValidPointer(ModelPointer))
return -1;
uint64_t StudioHDR = mem.Read<uint64_t>(ModelPointer + 0x8, true);
if (!mem.IsValidPointer(StudioHDR + 0x34))
return -1;
auto HitboxCache = mem.Read<uint16_t>(StudioHDR + 0x34, true);
auto HitboxArray = StudioHDR + ((uint16_t)(HitboxCache & 0xFFFE) << (4 * (HitboxCache & 1)));
if (!mem.IsValidPointer(HitboxArray + 0x4))
return -1;
auto IndexCache = mem.Read<uint16_t>(HitboxArray + 0x4, true);
auto HitboxIndex = ((uint16_t)(IndexCache & 0xFFFE) << (4 * (IndexCache & 1)));
auto BonePtr = HitboxIndex + HitboxArray + (static_cast<int>(HitBox) * 0x20);
if (!mem.IsValidPointer(BonePtr))
return -1;
return mem.Read<uint16_t>(BonePtr, true);
}
Vector3D GetBonePosition(HitboxType HitBox) const {
Vector3D Offset = Vector3D(0.0f, 0.0f, 0.0f);
int Bone = GetBoneFromHitbox(HitBox);
if (Bone < 0 || Bone > 255)
return LocalOrigin.Add(Offset);
uint64_t TempBonePointer = BonePointer; // Create a temporary non-const variable
TempBonePointer += (Bone * sizeof(Matrix3x4));
if (!mem.IsValidPointer(TempBonePointer))
return LocalOrigin.Add(Offset);
Matrix3x4 BoneMatrix = mem.Read<Matrix3x4>(TempBonePointer);
Vector3D BonePosition = BoneMatrix.GetPosition();
if (!BonePosition.IsValid())
return LocalOrigin.Add(Vector3D(0, 0, 0));
BonePosition += LocalOrigin;
return BonePosition;
}
};