-
Notifications
You must be signed in to change notification settings - Fork 13
/
newtest.cpp
437 lines (347 loc) · 13 KB
/
newtest.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
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
#include <windows.h>
#include <stdio.h>
#pragma comment(lib,"winmm.lib")
//glew
#define GLEW_STATIC
#if defined _M_X64
#include "glew\glew.h"
#pragma comment(lib, "glew/x64//glew32s.lib")
#elif defined _M_IX86
#include "glew\glew.h"
#pragma comment(lib, "glew/x86/glew32s.lib")
#endif
#include <gl/GL.h>
#pragma comment(lib, "OpenGL32.lib")
//detours
#include "detours.h"
#if defined _M_X64
#pragma comment(lib, "detours.X64/detours.lib")
#elif defined _M_IX86
#pragma comment(lib, "detours.X86/detours.lib")
#endif
//imgui
#include "ImGui/imgui.h"
#include "ImGui/imgui_impl_opengl3.h"
#include "ImGui/imgui_impl_win32.h"
#include "ImGui/imgui_stdlib.h"
extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
typedef LRESULT(CALLBACK* WNDPROC)(HWND, UINT, WPARAM, LPARAM);
#ifdef _WIN64
#define GWL_WNDPROC GWLP_WNDPROC
#endif
WNDPROC oWndProc;
static HWND hwndWindow = NULL;
typedef BOOL(__stdcall* tSwapBuffers) (HDC unnamedParam1); //GDI swapbuffers
tSwapBuffers orig_SwapBuffers;
typedef BOOL(__stdcall* twglSwapBuffers) (HDC hDc); //opengl swapbuffers
twglSwapBuffers orig_wglSwapBuffers = NULL;
static void (WINAPI* orig_glBindMultiTextureEXT) (GLenum texunit, GLenum target, GLuint texture) = NULL; //called by doom4 2016
static void (WINAPI* orig_glDrawElementsBaseVertex) (GLenum mode, GLsizei count, GLenum type, const void* indices, GLint baseVertex) = NULL;//doom4 2016
static void (WINAPI* orig_glBindTexture) (GLenum target, GLuint texture) = glBindTexture; //called by quake3, enemy territory ect.
static void (WINAPI* orig_glDrawElements) (GLenum mode, GLsizei count, GLenum type, const void * indices) = glDrawElements; //q3, et
static void (WINAPI* orig_glVertexPointer) (GLint size, GLenum type, GLsizei stride, const void* pointer) = glVertexPointer; //q3, et
static void (WINAPI* orig_glTexCoordPointer) (GLint size, GLenum type, GLsizei stride, const void* pointer) = glTexCoordPointer; //q3, et, cod1
//Globals
bool InitOnce1 = false;
bool InitOnce2 = false;
bool InitOnce3 = false;
bool InitOnce4 = false;
bool InitOnce5 = false;
bool InitOnce6 = false;
bool InitOnce7 = false;
bool InitOnce8 = false;
bool showmenu = false;
GLuint texture2d;
unsigned int cubemap;
//item states
bool wallhack = 1;
bool chams = 0;
int countnum = -1;
DWORD gameWidth; //game window width
DWORD gameHeight; //game window height
unsigned int asdelay = 100; //wait ms before MOUSEEVENTF_LEFTUP
DWORD dwLastAction = timeGetTime(); //as timer
bool IsPressed = false; //is left mouse down, are we shooting
//other
#include "main.h"
LRESULT __stdcall WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
if (ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam))
return true;
if (showmenu)
return 1;
return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam);
}
BOOL __stdcall hooked_SwapBuffers(HDC hDC) // GDI32
{
if (InitOnce1 == FALSE)
{
InitOnce1 = TRUE;
Log("GDI SwapBuffers hooked");
hwndWindow = GetProcessWindow();
}
//get gamewindow size
//gameWidth = GetSystemMetrics(SM_CXSCREEN);
//gameHeight = GetSystemMetrics(SM_CYSCREEN);
//readPixelsAndShoot();
return orig_SwapBuffers(hDC);
}
BOOL __stdcall hooked_wglSwapBuffers(HDC hDc)
{
if (InitOnce2 == FALSE)
{
InitOnce2 = TRUE;
Log("wglSwapBuffers hooked");
hwndWindow = GetProcessWindow();
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK)
{
Log("Failed to initialize GLEW");
}
if (glewInit() == GLEW_OK)
{
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags = ImGuiConfigFlags_NoMouseCursorChange;
ImGui_ImplWin32_Init(hwndWindow);
ImGui_ImplOpenGL3_Init();
}
}
//get gamewindow size
gameWidth = GetSystemMetrics(SM_CXSCREEN);
gameHeight = GetSystemMetrics(SM_CYSCREEN);
if ((GetAsyncKeyState(VK_INSERT) & 1) && (hwndWindow == GetFocus()))
showmenu = !showmenu;
//if (GetAsyncKeyState(VK_END) & 1) // Unload
//{
// MH_DisableHook(MH_ALL_HOOKS);
// SetWindowLongPtr(Window, GWL_WNDPROC, (LONG_PTR)oWndProc); // Reset WndProc
//}
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
// HACK MENU
if (showmenu)
{
//ImGui::SetNextWindowPos(ImVec2(50.0f, 400.0f)); //pos
ImGui::SetNextWindowSize(ImVec2(510.0f, 400.0f)); //size
ImVec4 Bgcol = ImColor(0.0f, 0.4f, 0.28f, 0.8f); //bg color
ImGui::PushStyleColor(ImGuiCol_WindowBg, Bgcol);
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.2f, 0.2f, 0.2f, 0.8f)); //frame color
ImGui::Begin("OpenGL Imgui");
ImGui::Text("countnum == %d", countnum);
ImGui::Text("gameWidth == %d", gameWidth);
ImGui::Text("gameHeight == %d", gameHeight);
//ImGui::Text("Project under development.");
ImGui::Separator();
//if (ImGui::CollapsingHeader("Stats")) {
// ImGui::Text("Health: %d/%d", health, healthmax);
//ImGui::Text("Mana: %d/%d", mana, manamax);
//}
ImGui::Separator();
if (ImGui::CollapsingHeader("Wallhack")) {
ImGui::Checkbox("Wallhack", &wallhack);
//ImGui::Checkbox("Enabled##Healing", &enabled_auto_heal);
}
ImGui::Separator();
if (ImGui::CollapsingHeader("Chams")) {
ImGui::Checkbox("Chams", &chams);
ImGui::Text("Use arrows to navigate.");
}
ImGui::End();
}
ImGui::EndFrame();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
readPixelsAndShoot();
//drawAimbotSquare();
//drawAimAtDisplay();
return orig_wglSwapBuffers(hDc);
}
void WINAPI hooked_glBindMultiTextureEXT(GLenum texunit, GLenum target, GLuint texture)
{
if (InitOnce3 == FALSE)
{
InitOnce3 = TRUE;
Log("glBindMultiTextureEXT hooked");
glGenTextures(1, &texture2d);
glGenTextures(1, &cubemap);
}
return orig_glBindMultiTextureEXT(texunit, target, texture);
}
void WINAPI hooked_glDrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type, const void * indices, GLint baseVertex)
{
if (InitOnce4 == FALSE)
{
InitOnce4 = TRUE;
Log("glDrawElementsBaseVertex hooked");
}
glColorMask(1, 1, 1, 1); //let all colors through
//uac skin
if(count == 11982||
//demonic skin
count == 12558|| count == 12702||
//utilitarian skin
count == 11670||
//templar skin
count == 11028||count == 11958||count == 11706||
//bounty hunter skin
count == 11502||count == 11265||
//robotic skin
count == 12042||
//cyberdemonic skn
count == 13086||count == 13236||count == 13452||count == 13302||
//evil cultist skin
count == 11922||count == 11634)
{
glColorMask(1, 0, 0, 1); //red
// save OpenGL state
glPushMatrix();
glPushAttrib(GL_ALL_ATTRIB_BITS);
//required?
glEnable(GL_COLOR_MATERIAL);
glDisableClientState(GL_COLOR_ARRAY);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_ALWAYS);
glEnable(GL_TEXTURE_GEN_S); //enable texture coordinate generation, to draw to any texture
glEnable(GL_TEXTURE_GEN_T);
/*
glBindTexture(GL_TEXTURE_2D, texture2d);
//green, works in many games but not in doom 2016+
uint8_t textureColor[16] = {
0, 255, 0, 0, // Red
0, 255, 0, 0, // Green
0, 255, 0, 0, // Blue
0, 255, 0, 0
};
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureColor);
*/
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap);
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 2, 2, 0, GL_RGB, GL_FLOAT, nullptr);
glColorMask(1, 0, 0, 1); //red
//draw point
//glEnable(GL_POINT_SMOOTH);
//glPointSize((float)20.0f);
//glBegin(GL_POINTS);
//glVertex2f(0, 0);
//glEnd();
//drawBox(-20.0, -20.0, -20.0, 20.0, 20.0, 20.0, 60, 2.0);
//drawBox(20.0, 20.0, 20.0, -20.0, -20.0, -20.0, 60, 2.0);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
// restore OpenGL state
glPopAttrib();
glPopMatrix();
}
//Hold down P key until the current texture disappears, press I to log values of those textures
if (GetAsyncKeyState('O') & 1) //-
countnum--;
if (GetAsyncKeyState('P') & 1) //+
countnum++;
if (GetAsyncKeyState(VK_MENU) && GetAsyncKeyState('9') & 1) //reset, set to -1
countnum = -1;
//Log
if (countnum == count / 1000)
if (GetAsyncKeyState('I') & 1)
Log("count == %d", count);
//delete texture
if (countnum == count / 1000)
return;
return orig_glDrawElementsBaseVertex(mode, count, type, indices, baseVertex);
}
void WINAPI hooked_glBindTexture(GLenum target, GLuint texture)
{
if (InitOnce5 == FALSE)
{
InitOnce5 = TRUE;
Log("glBindTexture hooked");
}
return orig_glBindTexture(target, texture);
}
void WINAPI hooked_glDrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
{
if (InitOnce6 == FALSE)
{
InitOnce6 = TRUE;
Log("glDrawElements hooked");
}
return orig_glDrawElements(mode, count, type, indices);
}
void WINAPI hooked_glVertexPointer(GLint size, GLenum type, GLsizei stride, const void* pointer)
{
if (InitOnce7 == FALSE)
{
InitOnce7 = TRUE;
Log("glVertexPointer hooked");
}
return orig_glVertexPointer(size, type, stride, pointer);
}
void WINAPI hooked_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const void* pointer)
{
if (InitOnce8 == FALSE)
{
InitOnce8 = TRUE;
Log("glTexCoordpointer hooked");
}
return orig_glTexCoordPointer(size, type, stride, pointer);
}
DWORD WINAPI InitSwapbuffers(LPVOID lpParameter)
{
while (GetModuleHandle(L"opengl32.dll") == NULL) { Sleep(100); }
Sleep(100);
HMODULE hMod = GetModuleHandle(L"opengl32.dll");
if (hMod)
{
orig_wglSwapBuffers = (twglSwapBuffers)(PVOID)GetProcAddress(hMod, "wglSwapBuffers"); //gl
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)orig_wglSwapBuffers, hooked_wglSwapBuffers);
DetourTransactionCommit();
do
hwndWindow = GetProcessWindow(); //GetForegroundWindow();
while (hwndWindow == NULL);
oWndProc = (WNDPROC)SetWindowLongPtr(hwndWindow, GWL_WNDPROC, (LONG_PTR)WndProc);
}
HMODULE gMod = GetModuleHandle(L"gdi32.dll");
if (gMod)
{
orig_SwapBuffers = (tSwapBuffers)(PVOID)GetProcAddress(gMod, "SwapBuffers"); //gdi
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)orig_SwapBuffers, hooked_SwapBuffers);
DetourTransactionCommit();
}
return true;
}
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
if (dwReason == DLL_PROCESS_ATTACH) {
DisableThreadLibraryCalls(hinst);
CreateThread(0, 0, InitSwapbuffers, 0, 0, 0);
orig_glDrawElementsBaseVertex = (void (WINAPI*)(GLenum, GLsizei, GLenum, const void*, GLint))wglGetProcAddress("glDrawElementsBaseVertex");
orig_glBindMultiTextureEXT = (void (WINAPI*)(GLenum, GLenum, GLuint))wglGetProcAddress("glBindMultiTextureEXT");
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)orig_glBindMultiTextureEXT, hooked_glBindMultiTextureEXT);
DetourAttach(&(PVOID&)orig_glDrawElementsBaseVertex, hooked_glDrawElementsBaseVertex);
DetourAttach(&(PVOID&)orig_glBindTexture, hooked_glBindTexture);
DetourAttach(&(PVOID&)orig_glDrawElements, hooked_glDrawElements);
DetourAttach(&(PVOID&)orig_glVertexPointer, hooked_glVertexPointer);
DetourAttach(&(PVOID&)orig_glTexCoordPointer, hooked_glTexCoordPointer);
DetourTransactionCommit();
}
else if (dwReason == DLL_PROCESS_DETACH) {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)orig_glBindMultiTextureEXT, hooked_glBindMultiTextureEXT);
DetourDetach(&(PVOID&)orig_glDrawElementsBaseVertex, hooked_glDrawElementsBaseVertex);
DetourDetach(&(PVOID&)orig_glBindTexture, hooked_glBindTexture);
DetourDetach(&(PVOID&)orig_glDrawElements, hooked_glDrawElements);
DetourDetach(&(PVOID&)orig_glVertexPointer, hooked_glVertexPointer);
DetourDetach(&(PVOID&)orig_glTexCoordPointer, hooked_glTexCoordPointer);
DetourTransactionCommit();
}
return TRUE;
}