This repository was archived by the owner on Mar 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpainttraverse.cpp
executable file
·233 lines (167 loc) · 6.56 KB
/
painttraverse.cpp
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include "main.hpp"
/*
To mention, since we don't have SDL2 added.. YET, we are simply
gonna do a boolean for keypress.
*/
bool bKeys[256];
bool bKeyPressed(int _keyCode) {
return bKeys[_keyCode];
}
#define GetAsyncKeyState(_x) bKeyPressed(_x);
/* Some test drawings */
void DrawBox(int x, int y, int w, int h, Color color) {
pSurface->DrawSetColor(color);
pSurface->DrawOutlinedRect(x, y, x + w, y + h);
}
void DrawBoxOutline(int x, int y, int w, int h, Color color) {
Drawings->DrawBox(x + 1, y + 1, w - 2, h - 2, Color(0, 0, 0, 120));
Drawings->DrawBox(x - 1, y - 1, w + 2, h + 2, Color(0, 0, 0, 120));
Drawings->DrawBox(x, y, w, h, color);
}
/* end */
/* test esp shit */
enum Teams {
Terrorist = 2,
CounterTerrorist = 3
};
bool ScreenTransform( const Vector& point, Vector& screen )
{
auto& worldToScreen = pEngine->GetWorldToScreenMatrix( );
auto tempX = 0.f, tempY = 0.f, w = 0.f;
for ( auto i = 0; i < 3; i++ )
{
tempX += worldToScreen[ 0 ][ i ] * point[ i ];
tempY += worldToScreen[ 1 ][ i ] * point[ i ];
w += worldToScreen[ 3 ][ i ] * point[ i ];
}
screen.x = tempX + worldToScreen[ 0 ][ 3 ];
screen.y = tempY + worldToScreen[ 1 ][ 3 ];
screen.z = 0.0f;
w += worldToScreen[ 3 ][ 3 ];
auto behind = w < 0.001f;
if ( behind )
{
screen *= 100000;
}
else
{
auto invw = 1.0f / w;
screen *= invw;
}
return behind;
}
bool WorldToScreen(Vector& vFrom, Vector& vTo) {
return (pOverlay->ScreenPosition(vFrom, vTo) != 1);
/*
int ScreenWidth, ScreenHeight;
pEngine->GetScreenSize(ScreenWidth, ScreenHeight);
if ( !ScreenTransform( vFrom, vTo ) )
{
float x = ScreenWidth >> 1;
float y = ScreenHeight >> 1;
x += 0.5 * vTo.x * ScreenWidth + 0.5;
y -= 0.5 * vTo.y * ScreenHeight + 0.5;
vTo.x = x;
vTo.y = y;
return true;
}
return false;
*/
}
auto TestTrace(C_BaseEntity* pEntity, C_BaseEntity* pLocal) -> bool { /* Just a simple visible check :^) */
Ray_t ray;
trace_t trace;
CTraceFilter filter;
filter.pSkip = pLocal;
ray.Init(pLocal->GetEyePosition(), pEntity->GetEyePosition());
pEngineTrace->TraceRay(ray, 0x4600400B, &filter, &trace);
return (trace.m_pEnt == pEntity || trace.fraction > 0.99f);
}
void DrawSkeleton(C_BaseEntity* pEntity, Color color) {
studiohdr_t* pStudioModel = pModelInfo->GetStudioModel( pEntity->GetModel() );
if ( pStudioModel ) {
static matrix3x4_t pBoneToWorldOut[128];
if ( pEntity->SetupBones( pBoneToWorldOut, 128, 256, 0) )
{
for ( int i = 0; i < pStudioModel->numbones; i++ )
{
mstudiobone_t* pBone = pStudioModel->pBone( i );
if ( !pBone || !( pBone->flags & 256 ) || pBone->parent == -1 )
continue;
Vector vBone1 = pEntity->GetBonePosition(i);
Vector vBoneOut1;
Vector vBone2 = pEntity->GetBonePosition(pBone->parent);
Vector vBoneOut2;
if(WorldToScreen(vBone1, vBoneOut1) && WorldToScreen(vBone2, vBoneOut2)) {
Drawings->DrawLine(vBoneOut1.x, vBoneOut1.y, vBoneOut2.x, vBoneOut2.y, color);
}
}
}
}
}
/*
*/
void makeshittyesp() {
C_BaseEntity *pLocalPlayer = (C_BaseEntity *) pEntList->GetClientEntity(pEngine->GetLocalPlayer());
Vector vecTop, vecPos;
for (int i = 0; i < pEntList->GetHighestEntityIndex(); i++) {
C_BaseEntity *pEntity = (C_BaseEntity *) pEntList->GetClientEntity(i);
if (!pEntity)
continue;
if (pEntity->GetHealth() < 1)
continue;
if (pEntity->GetDormant())
continue;
if (pEntity == pLocalPlayer)
continue;
if(pEntity->GetTeam() == pLocalPlayer->GetTeam())
continue;
auto isVisible = TestTrace(pEntity, pLocalPlayer);
IEngineClient::player_info_t pInfo;
pEngine->GetPlayerInfo(i, &pInfo);
auto vecTop3D = pEntity->GetVecOrigin();
auto vecMax = pEntity->GetCollideable()->OBBMaxs();
auto vecPos3D = pEntity->GetVecOrigin();
vecTop3D += Vector(0, 0, vecMax.z);
if (WorldToScreen(vecTop3D, vecTop) && WorldToScreen(vecPos3D, vecPos)) {
auto iMiddle = vecPos.y - vecTop.y;
auto iWidth = iMiddle / 4;
Color clr = [&]() -> Color {
if (pEntity->GetTeam() == Terrorist) {
return isVisible ? Color::Red() : Color::Yellow();
}
if (pEntity->GetTeam() == CounterTerrorist) {
return isVisible ? Color::Green() : Color::Blue();
}
return Color(0, 0, 0);
}();
DrawBox(vecTop.x - iWidth, vecTop.y, iWidth * 2, iMiddle, clr);
DrawBox(vecTop.x - iWidth - 1, vecTop.y - 1, (iWidth * 2) + 2, iMiddle + 2, Color(0, 0, 0, 255));
DrawBox(vecTop.x - iWidth + 1, vecTop.y + 1, (iWidth * 2) - 2, iMiddle - 2, Color(0, 0, 0, 255));
Drawings->FillRGBA( vecTop.x - iWidth, vecTop.y + iMiddle + 3, ( iWidth *2 ) + 2, 5, Color( 0, 0, 0, 255 ) );
Drawings->FillRGBA( vecTop.x - iWidth + 1, vecTop.y + iMiddle + 4, (( iWidth * 2 ) / 100.f) * pEntity->GetHealth(), 3, Color( 0, 255, 0, 255 ) );
Drawings->DrawString(vecTop.x, vecTop.y - 12/* 12 = the font size */, Color::White(),
testfont, true, pInfo.name);
DrawSkeleton(pEntity, Color::White());
}
}
}
/* end */
void hkPaintTraverse(void* thisptr, VPANEL vguiPanel, bool forceRepaint, bool allowForce) {
testvmt->GetOriginalMethod<tPaintTraverse>(42)(thisptr, vguiPanel, forceRepaint, allowForce);
static VPANEL currentPanel = 0;
if(!currentPanel) {
if(strstr(pPanel->GetName(vguiPanel), "FocusOverlayPanel")) {
testfont = pSurface->CreateFont();
pSurface->SetFontGlyphSet(testfont, "Tahoma", 12, 250, 0, 0, FONTFLAG_ANTIALIAS | FONTFLAG_DROPSHADOW);
currentPanel = vguiPanel;
}
}
if(vguiPanel == currentPanel) {
/* Draw your stuff here. */
makeshittyesp();
// DrawBoxOutline(10, 20, 30, 40, Color::Black());
/* Test with FontAwesome */
//Drawings->DrawString(10, 20, Color::White(), testfont, "Patanjali Hax");
}
}