forked from icantstandpeople/potassium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathESP.cpp
More file actions
175 lines (139 loc) · 4.74 KB
/
ESP.cpp
File metadata and controls
175 lines (139 loc) · 4.74 KB
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
#include "ESP.h"
#include "CDrawManager.h"
CESP gESP;
void CESP::Run(CBaseEntity* pLocal)
{
if (!gCvars.esp_active)
return;
for (int i = 1; i <= gInts.Engine->GetMaxClients(); i++)
{
if (i == me)
continue;
CBaseEntity* pEntity = GetBaseEntity(i);
if (!pEntity)
continue;
if (pEntity->IsDormant())
continue;
if (pEntity->GetLifeState() != LIFE_ALIVE)
continue;
if (gCvars.esp_enemyonly && pEntity->GetTeamNum() == pLocal->GetTeamNum())
continue;
Player_ESP(pLocal, pEntity);
}
}
void CESP::Player_ESP(CBaseEntity* pLocal, CBaseEntity* pEntity)
{
player_info_t pInfo;
if (!gInts.Engine->GetPlayerInfo(pEntity->GetIndex(), &pInfo))
return;
const matrix3x4& vMatrix = pEntity->GetRgflCoordinateFrame();
Vector vMin = pEntity->GetCollideableMins();
Vector vMax = pEntity->GetCollideableMaxs();
Vector vPointList[] = {
Vector(vMin.x, vMin.y, vMin.z),
Vector(vMin.x, vMax.y, vMin.z),
Vector(vMax.x, vMax.y, vMin.z),
Vector(vMax.x, vMin.y, vMin.z),
Vector(vMax.x, vMax.y, vMax.z),
Vector(vMin.x, vMax.y, vMax.z),
Vector(vMin.x, vMin.y, vMax.z),
Vector(vMax.x, vMin.y, vMax.z)
};
Vector vTransformed[8];
for (int i = 0; i < 8; i++)
for (int j = 0; j < 3; j++)
vTransformed[i][j] = vPointList[i].Dot((Vector&)vMatrix[j]) + vMatrix[j][3];
Vector flb, brt, blb, frt, frb, brb, blt, flt;
if (!gDrawManager.WorldToScreen(vTransformed[3], flb) ||
!gDrawManager.WorldToScreen(vTransformed[0], blb) ||
!gDrawManager.WorldToScreen(vTransformed[2], frb) ||
!gDrawManager.WorldToScreen(vTransformed[6], blt) ||
!gDrawManager.WorldToScreen(vTransformed[5], brt) ||
!gDrawManager.WorldToScreen(vTransformed[4], frt) ||
!gDrawManager.WorldToScreen(vTransformed[1], brb) ||
!gDrawManager.WorldToScreen(vTransformed[7], flt))
return;
Vector arr[] = { flb, brt, blb, frt, frb, brb, blt, flt };
float left = flb.x;
float top = flb.y;
float right = flb.x;
float bottom = flb.y;
for (int i = 0; i < 8; i++)
{
if (left > arr[i].x)
left = arr[i].x;
if (top < arr[i].y)
top = arr[i].y;
if (right < arr[i].x)
right = arr[i].x;
if (bottom > arr[i].y)
bottom = arr[i].y;
}
float x = left;
float y = bottom;
float w = right - left;
float h = top - bottom;
x += ((right - left) / 8); //pseudo fix for those THICC boxes
w -= ((right - left) / 8) * 2;
Color clrPlayerCol = gDrawManager.GetPlayerColor(pEntity);
Color clrBoneCol = gCvars.esp_bones == 1 ? Color::White() : gCvars.esp_bones == 2 ? Color::Green() : clrPlayerCol;
int iY = 0;
//iHp is only for health bar
int iHp = pEntity->GetHealth(), iMaxHp = pEntity->GetMaxHealth();
if (iHp > iMaxHp)
iHp = iMaxHp;
if (gCvars.esp_box)
{
gDrawManager.OutlineRect(x - 1, y - 1, w + 2, h + 2, Color::Black());
gDrawManager.OutlineRect(x, y, w, h, clrPlayerCol);
gDrawManager.OutlineRect(x + 1, y + 1, w - 2, h - 2, Color::Black());
}
if (gCvars.esp_health == 2 || gCvars.esp_health == 3)
{
gDrawManager.OutlineRect(x - 6, y - 1, 5, h, Color::Black());
gDrawManager.DrawRect(x - 5, y + (h - (h / iMaxHp * iHp)) - 1, 3, h / iMaxHp * iHp, Color::Green());
}
if (gCvars.esp_name)
{
gDrawManager.DrawString(x + w + 2, y + iY, clrPlayerCol, pInfo.name);
iY += gDrawManager.GetESPHeight();
}
if (gCvars.esp_class)
{
gDrawManager.DrawString(x + w + 2, y + iY, clrPlayerCol, "%s", pEntity->szGetClass());
iY += gDrawManager.GetESPHeight();
}
if (gCvars.esp_health == 1 || gCvars.esp_health == 3)
{
gDrawManager.DrawString(x + w + 2, y + iY, Color::Green(), "%d HP", pEntity->GetHealth());
iY += gDrawManager.GetESPHeight();
}
if (gCvars.esp_bones) //bones
{
static int iLeftArmBones[] = { 8, 7, 6, 4 };
static int iRightArmBones[] = { 11, 10, 9, 4 };
static int iHeadBones[] = { 0, 4, 1 };
static int iLeftLegBones[] = { 14, 13, 1 };
static int iRightLegBones[] = { 17, 16, 1 };
DrawBone(pEntity, iLeftArmBones, 4, clrBoneCol);
DrawBone(pEntity, iRightArmBones, 4, clrBoneCol);
DrawBone(pEntity, iHeadBones, 3, clrBoneCol);
DrawBone(pEntity, iLeftLegBones, 3, clrBoneCol);
DrawBone(pEntity, iRightLegBones, 3, clrBoneCol);
}
}
//My code, but creds to f1ssion for giving me the idea
void CESP::DrawBone(CBaseEntity* pEntity, int* iBones, int count, Color clrCol)
{
for (int i = 0; i < count; i++)
{
if (i == count - 1)
continue;
Vector vBone1 = pEntity->GetHitboxPosition(iBones[i]);
Vector vBone2 = pEntity->GetHitboxPosition(iBones[i + 1]);
Vector vScr1, vScr2;
if (!gDrawManager.WorldToScreen(vBone1, vScr1) || !gDrawManager.WorldToScreen(vBone2, vScr2))
continue;
gDrawManager.DrawLine(vScr1.x, vScr1.y, vScr2.x, vScr2.y, clrCol);
}
}