forked from KaylinOwO/projectnacl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCDrawManager.cpp
More file actions
268 lines (219 loc) · 8.8 KB
/
CDrawManager.cpp
File metadata and controls
268 lines (219 loc) · 8.8 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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#include "CDrawManager.h"
//===================================================================================
CDrawManager gDrawManager;
void CDrawManager::Initialize() // Create font IDs here
{
if (gInts.Surface == NULL)
return;
InitializeFonts();
Reload();
}
void CDrawManager::Reload() // Create (or reload) your font styles
{
if (gInts.Surface == NULL)
return;
gInts.Engine->GetScreenSize(gScreenSize.iScreenWidth, gScreenSize.iScreenHeight);
ReloadFonts();
}
void CDrawManager::InitializeFonts()
{
m_Font = gInts.Surface->CreateFont();
}
void CDrawManager::ReloadFonts()
{
gInts.Surface->SetFontGlyphSet(m_Font, "Verdana", 12, 500, 0, 0, 0x200);
}
void CDrawManager::DrawStringCenter(int x, int y, Color clrColor, const char* szText, ...)
{
if (!szText)
return;
va_list va_alist = nullptr;
int Wide = 0, Tall = 0;
char szBuffer[256] = { '\0' };
wchar_t szString[128] = { '\0' };
va_start(va_alist, szText);
vsprintf_s(szBuffer, szText, va_alist);
va_end(va_alist);
MultiByteToWideChar(CP_UTF8, 0, szBuffer, -1, szString, 128);
gInts.Surface->GetTextSize(m_Font, szString, Wide, Tall);
x -= Wide / 2;
gInts.Surface->DrawSetTextPos(x, y);
gInts.Surface->DrawSetTextFont(m_Font);
gInts.Surface->DrawSetTextColor(clrColor.r(), clrColor.g(), clrColor.b(), clrColor.a());
gInts.Surface->DrawPrintText(szString, strlen(szBuffer));
}
void CDrawManager::DrawBoxOnEntity(CBaseEntity* entity, Color color)
{
const matrix3x4& vMatrix = entity->GetRgflCoordinateFrame();
Vector vMin = entity->GetCollideableMins();
Vector vMax = entity->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;
gDrawManager.OutlineRect(x, y, w, h, color);
gDrawManager.OutlineRect(x + 1, y + 1, w - 2, h - 2, color);
}
Color CDrawManager::MenuColor(CBaseEntity* pPlayer)
{
if (gCvars.menu_color == 0)
return GetPlayerColor(pPlayer);
if (gCvars.menu_color == 1)
return Color(0, 153, 255, 255);
if (gCvars.menu_color == 2)
return Color(255, 20, 20, 255);
if (gCvars.menu_color == 3)
return Color(255, 255, 0, 255);
if (gCvars.menu_color == 4)
return Color(0, 255, 0, 255);
return Color(0, 0, 0, 0); //no reason for this to be here, i just wanna look smart
}
Color CDrawManager::GetPlayerColor(CBaseEntity* pPlayer)
{
if (gCvars.esp_aimbothighlights && pPlayer->GetIndex() == gCvars.iAimbotIndex)
return Color::Green();
else if (!gCvars.PlayerMode[pPlayer->GetIndex()])
return Color(0, 255, 255, 255);
else if (gCvars.PlayerMode[pPlayer->GetIndex()] == 2)
return Color::Yellow();
else
{
switch (pPlayer->GetTeamNum())
{
case 2: //RED
return Color(255, 20, 20, 255);
case 3: //BLU
return Color(0, 153, 255, 255);
default:
return Color(0, 153, 255, 255);
}
}
return Color(0, 0, 0, 0); //no reason for this to be here, i just wanna look smart
}
//===================================================================================
void CDrawManager::DrawString( int x, int y, Color clrColor, const wchar_t *pszText)
{
if( pszText == NULL )
return;
gInts.Surface->DrawSetTextPos( x, y );
gInts.Surface->DrawSetTextFont( m_Font );
gInts.Surface->DrawSetTextColor( clrColor.r(), clrColor.g(), clrColor.b(), clrColor.a() );
gInts.Surface->DrawPrintText( pszText, wcslen( pszText ) );
}
//===================================================================================
void CDrawManager::DrawString( int x, int y, Color clrColor, const char *pszText, ... )
{
if( pszText == NULL )
return;
va_list va_alist;
char szBuffer[1024] = { '\0' };
wchar_t szString[1024] = { '\0' };
va_start( va_alist, pszText );
vsprintf_s( szBuffer, pszText, va_alist );
va_end( va_alist );
wsprintfW( szString, L"%S", szBuffer );
gInts.Surface->DrawSetTextPos( x, y );
gInts.Surface->DrawSetTextFont( m_Font );
gInts.Surface->DrawSetTextColor( clrColor.r(), clrColor.g(), clrColor.b(), clrColor.a() );
gInts.Surface->DrawPrintText( szString, wcslen( szString ) );
}
//===================================================================================
byte CDrawManager::GetESPHeight( )
{
return 12;
}
//===================================================================================
void CDrawManager::DrawLine(int x, int y, int x1, int y1, Color clrColor)
{
gInts.Surface->DrawSetColor(clrColor.r(), clrColor.g(), clrColor.b(), clrColor.a());
gInts.Surface->DrawLine(x, y, x1, y1);
}
//===================================================================================
void CDrawManager::DrawLineEx(int x, int y, int w, int h, Color clrColor)
{
gInts.Surface->DrawSetColor(clrColor.r(), clrColor.g(), clrColor.b(), clrColor.a());
gInts.Surface->DrawLine(x, y, x + w, y + h);
}
//===================================================================================
void CDrawManager::DrawRect( int x, int y, int w, int h, Color clrColor)
{
gInts.Surface->DrawSetColor( clrColor.r(), clrColor.g(), clrColor.b(), clrColor.a() );
gInts.Surface->DrawFilledRect( x, y, x + w, y + h );
}
//===================================================================================
void CDrawManager::OutlineRect( int x, int y, int w, int h, Color clrColor)
{
gInts.Surface->DrawSetColor( clrColor.r(), clrColor.g(), clrColor.b(), clrColor.a() );
gInts.Surface->DrawOutlinedRect( x, y, x + w, y + h );
}
//===================================================================================
void CDrawManager::DrawBox( Vector vOrigin, int r, int g, int b, int alpha, int box_width, int radius )
{
Vector vScreen;
if( !WorldToScreen( vOrigin, vScreen ) )
return;
int radius2 = radius<<1;
OutlineRect( vScreen.x - radius + box_width, vScreen.y - radius + box_width, radius2 - box_width, radius2 - box_width, Color::Black() );
OutlineRect( vScreen.x - radius - 1, vScreen.y - radius - 1, radius2 + ( box_width + 2 ), radius2 + ( box_width + 2 ), Color::Black() );
DrawRect( vScreen.x - radius + box_width, vScreen.y - radius, radius2 - box_width, box_width, Color( r, g, b, alpha ));
DrawRect( vScreen.x - radius, vScreen.y + radius, radius2, box_width, Color( r, g, b, alpha ));
DrawRect( vScreen.x - radius, vScreen.y - radius, box_width, radius2, Color( r, g, b, alpha ));
DrawRect( vScreen.x + radius, vScreen.y - radius, box_width, radius2 + box_width, Color( r, g, b, alpha ) );
}
//===================================================================================
bool CDrawManager::WorldToScreen( Vector &vOrigin, Vector &vScreen )
{
const matrix3x4& worldToScreen = gInts.Engine->WorldToScreenMatrix(); //Grab the world to screen matrix from CEngineClient::WorldToScreenMatrix
float w = worldToScreen[3][0] * vOrigin[0] + worldToScreen[3][1] * vOrigin[1] + worldToScreen[3][2] * vOrigin[2] + worldToScreen[3][3]; //Calculate the angle in compareson to the player's camera.
vScreen.z = 0; //Screen doesn't have a 3rd dimension.
if( w > 0.001 ) //If the object is within view.
{
float fl1DBw = 1 / w; //Divide 1 by the angle.
vScreen.x = (gScreenSize.iScreenWidth / 2) + ( 0.5 * ((worldToScreen[0][0] * vOrigin[0] + worldToScreen[0][1] * vOrigin[1] + worldToScreen[0][2] * vOrigin[2] + worldToScreen[0][3]) * fl1DBw) * gScreenSize.iScreenWidth + 0.5); //Get the X dimension and push it in to the Vector.
vScreen.y = (gScreenSize.iScreenHeight / 2) - ( 0.5 * ((worldToScreen[1][0] * vOrigin[0] + worldToScreen[1][1] * vOrigin[1] + worldToScreen[1][2] * vOrigin[2] + worldToScreen[1][3]) * fl1DBw) * gScreenSize.iScreenHeight + 0.5); //Get the Y dimension and push it in to the Vector.
return true;
}
return false;
}