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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
#include "debugoverlay.h"
#include "dedicated/dedicated.h"
#include "core/convar/cvar.h"
#include "core/math/vector.h"
#include "server/ai_helper.h"
AUTOHOOK_INIT()
enum OverlayType_t
{
OVERLAY_BOX = 0,
OVERLAY_SPHERE,
OVERLAY_LINE,
OVERLAY_SMARTAMMO,
OVERLAY_TRIANGLE,
OVERLAY_SWEPT_BOX,
// [Fifty]: the 2 bellow i did not confirm, rest are good
OVERLAY_BOX2,
OVERLAY_CAPSULE
};
struct OverlayBase_t
{
OverlayBase_t()
{
m_Type = OVERLAY_BOX;
m_nServerCount = -1;
m_nCreationTick = -1;
m_flEndTime = 0.0f;
m_pNextOverlay = NULL;
}
OverlayType_t m_Type; // What type of overlay is it?
int m_nCreationTick; // Duration -1 means go away after this frame #
int m_nServerCount; // Latch server count, too
float m_flEndTime; // When does this box go away
OverlayBase_t* m_pNextOverlay;
__int64 m_pUnk;
};
struct OverlayLine_t : public OverlayBase_t
{
OverlayLine_t()
{
m_Type = OVERLAY_LINE;
}
Vector3 origin;
Vector3 dest;
int r;
int g;
int b;
int a;
bool noDepthTest;
};
struct OverlayBox_t : public OverlayBase_t
{
OverlayBox_t()
{
m_Type = OVERLAY_BOX;
}
Vector3 origin;
Vector3 mins;
Vector3 maxs;
QAngle angles;
int r;
int g;
int b;
int a;
};
struct OverlayTriangle_t : public OverlayBase_t
{
OverlayTriangle_t()
{
m_Type = OVERLAY_TRIANGLE;
}
Vector3 p1;
Vector3 p2;
Vector3 p3;
int r;
int g;
int b;
int a;
bool noDepthTest;
};
struct OverlaySweptBox_t : public OverlayBase_t
{
OverlaySweptBox_t()
{
m_Type = OVERLAY_SWEPT_BOX;
}
Vector3 start;
Vector3 end;
Vector3 mins;
Vector3 maxs;
QAngle angles;
int r;
int g;
int b;
int a;
};
struct OverlaySphere_t : public OverlayBase_t
{
OverlaySphere_t()
{
m_Type = OVERLAY_SPHERE;
}
Vector3 vOrigin;
float flRadius;
int nTheta;
int nPhi;
int r;
int g;
int b;
int a;
bool m_bWireframe;
};
static bool (*OverlayBase_t__IsDead)(OverlayBase_t* a1);
static void (*OverlayBase_t__DestroyOverlay)(OverlayBase_t* a1);
static ConVar* Cvar_enable_debug_overlays;
LPCRITICAL_SECTION s_OverlayMutex;
OverlayBase_t** s_pOverlays;
int* g_nRenderTickCount;
int* g_nOverlayTickCount;
// clang-format off
AUTOHOOK(DrawOverlay, engine.dll + 0xABCB0,
void, __fastcall, (OverlayBase_t * pOverlay))
// clang-format on
{
EnterCriticalSection(s_OverlayMutex);
switch (pOverlay->m_Type)
{
case OVERLAY_SMARTAMMO:
case OVERLAY_LINE:
{
OverlayLine_t* pLine = static_cast<OverlayLine_t*>(pOverlay);
RenderLine(pLine->origin, pLine->dest, Color(pLine->r, pLine->g, pLine->b, pLine->a), pLine->noDepthTest);
}
break;
case OVERLAY_BOX:
{
OverlayBox_t* pCurrBox = static_cast<OverlayBox_t*>(pOverlay);
if (pCurrBox->a > 0)
{
RenderBox(
pCurrBox->origin,
pCurrBox->angles,
pCurrBox->mins,
pCurrBox->maxs,
Color(pCurrBox->r, pCurrBox->g, pCurrBox->b, pCurrBox->a),
false,
false);
}
if (pCurrBox->a < 255)
{
RenderWireframeBox(
pCurrBox->origin,
pCurrBox->angles,
pCurrBox->mins,
pCurrBox->maxs,
Color(pCurrBox->r, pCurrBox->g, pCurrBox->b, 255),
false,
false);
}
}
break;
case OVERLAY_TRIANGLE:
{
OverlayTriangle_t* pTriangle = static_cast<OverlayTriangle_t*>(pOverlay);
RenderTriangle(
pTriangle->p1,
pTriangle->p2,
pTriangle->p3,
Color(pTriangle->r, pTriangle->g, pTriangle->b, pTriangle->a),
pTriangle->noDepthTest);
}
break;
case OVERLAY_SWEPT_BOX:
{
OverlaySweptBox_t* pBox = static_cast<OverlaySweptBox_t*>(pOverlay);
RenderWireframeSweptBox(
pBox->start, pBox->end, pBox->angles, pBox->mins, pBox->maxs, Color(pBox->r, pBox->g, pBox->b, pBox->a), false);
}
break;
case OVERLAY_SPHERE:
{
OverlaySphere_t* pSphere = static_cast<OverlaySphere_t*>(pOverlay);
RenderSphere(
pSphere->vOrigin,
pSphere->flRadius,
pSphere->nTheta,
pSphere->nPhi,
Color(pSphere->r, pSphere->g, pSphere->b, pSphere->a),
false);
}
break;
default:
{
spdlog::warn("Unimplemented overlay type {}", pOverlay->m_Type);
}
break;
}
LeaveCriticalSection(s_OverlayMutex);
}
// clang-format off
AUTOHOOK(DrawAllOverlays, engine.dll + 0xAB780,
void, __fastcall, (bool bRender))
// clang-format on
{
EnterCriticalSection(s_OverlayMutex);
OverlayBase_t* pCurrOverlay = *s_pOverlays; // rbx
OverlayBase_t* pPrevOverlay = nullptr; // rsi
OverlayBase_t* pNextOverlay = nullptr; // rdi
int m_nCreationTick; // eax
bool bShouldDraw; // zf
int m_pUnk; // eax
while (pCurrOverlay)
{
if (OverlayBase_t__IsDead(pCurrOverlay))
{
if (pPrevOverlay)
{
pPrevOverlay->m_pNextOverlay = pCurrOverlay->m_pNextOverlay;
}
else
{
*s_pOverlays = pCurrOverlay->m_pNextOverlay;
}
pNextOverlay = pCurrOverlay->m_pNextOverlay;
OverlayBase_t__DestroyOverlay(pCurrOverlay);
pCurrOverlay = pNextOverlay;
}
else
{
if (pCurrOverlay->m_nCreationTick == -1)
{
m_pUnk = pCurrOverlay->m_pUnk;
if (m_pUnk == -1)
{
bShouldDraw = true;
}
else
{
bShouldDraw = m_pUnk == *g_nOverlayTickCount;
}
}
else
{
bShouldDraw = pCurrOverlay->m_nCreationTick == *g_nRenderTickCount;
}
if (bShouldDraw && bRender && (Cvar_enable_debug_overlays->GetBool() || pCurrOverlay->m_Type == OVERLAY_SMARTAMMO))
{
// call the new function, not the original
// note: if there is a beter way to call the hooked version of an
// autohook func then that would be better than this
__autohookfuncDrawOverlay(pCurrOverlay);
}
pPrevOverlay = pCurrOverlay;
pCurrOverlay = pCurrOverlay->m_pNextOverlay;
}
}
if (bRender && Cvar_enable_debug_overlays->GetBool())
{
g_pAIHelper->DrawNavmeshPolys();
}
LeaveCriticalSection(s_OverlayMutex);
}
ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", DebugOverlay, ConVar, (CModule module))
{
AUTOHOOK_DISPATCH()
OverlayBase_t__IsDead = module.Offset(0xACAC0).RCast<decltype(OverlayBase_t__IsDead)>();
OverlayBase_t__DestroyOverlay = module.Offset(0xAB680).RCast<decltype(OverlayBase_t__DestroyOverlay)>();
RenderLine = module.Offset(0x192A70).RCast<decltype(RenderLine)>();
RenderBox = module.Offset(0x192520).RCast<decltype(RenderBox)>();
RenderWireframeBox = module.Offset(0x193DA0).RCast<decltype(RenderWireframeBox)>();
RenderWireframeSweptBox = module.Offset(0x1945A0).RCast<decltype(RenderWireframeSweptBox)>();
RenderTriangle = module.Offset(0x193940).RCast<decltype(RenderTriangle)>();
RenderAxis = module.Offset(0x1924D0).RCast<decltype(RenderAxis)>();
RenderSphere = module.Offset(0x194170).RCast<decltype(RenderSphere)>();
RenderUnknown = module.Offset(0x1924E0).RCast<decltype(RenderUnknown)>();
s_OverlayMutex = module.Offset(0x10DB0A38).RCast<LPCRITICAL_SECTION>();
s_pOverlays = module.Offset(0x10DB0968).RCast<OverlayBase_t**>();
g_nRenderTickCount = module.Offset(0x10DB0984).RCast<int*>();
g_nOverlayTickCount = module.Offset(0x10DB0980).RCast<int*>();
// not in g_pCVar->FindVar by this point for whatever reason, so have to get from memory
Cvar_enable_debug_overlays = module.Offset(0x10DB0990).RCast<ConVar*>();
Cvar_enable_debug_overlays->SetValue(false);
Cvar_enable_debug_overlays->m_pszDefaultValue = (char*)"0";
Cvar_enable_debug_overlays->AddFlags(FCVAR_CHEAT);
}
|