-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodex.cpp
More file actions
349 lines (283 loc) · 11.4 KB
/
codex.cpp
File metadata and controls
349 lines (283 loc) · 11.4 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
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
#include <Windows.h>
#include <iostream>
#include <cstdio>
#include <gl/GL.h>
#include "minhook/include/MinHook.h"
#include "imgui/imgui.h"
#include "imgui/imgui_impl_win32.h"
#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM
#include "imgui/imgui_impl_opengl3.h"
#include "config.hpp"
#include "features.hpp"
//globals for hook
typedef BOOL(__stdcall* wglSwapBuffers_t)(HDC hdc);
wglSwapBuffers_t oSwapBuffers = nullptr;
WNDPROC oWndProc = nullptr;
bool init = false;
HWND game_hwnd = nullptr;
bool show_menu = true;
// Forward declare ImGui's handler
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
// eventually I will probably want to move hooks and other stuff to a seperate file as the project gets larger
//hook to unlock mouse
typedef int (__cdecl* SDL_SetRelativeMouseMode_t)(int enabled);
static SDL_SetRelativeMouseMode_t SDL_SetRelativeMouseMode_fn = nullptr;
//WndProc hook to handle input for the menu
LRESULT __stdcall WndProc(const HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (msg == WM_KEYDOWN && wParam == VK_INSERT)
{
show_menu = !show_menu;
ImGui::GetIO().MouseDrawCursor = show_menu; // show mouse cursor when menu is active
}
if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
{
return true; // blocks input from the game when menu is active
}
if (show_menu)
{
switch (msg)
{
case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_LBUTTONDBLCLK:
case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_RBUTTONDBLCLK:
case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_MBUTTONDBLCLK:
case WM_MOUSEMOVE:
case WM_MOUSEWHEEL:
case WM_KEYDOWN: // Optional: Stop character from moving with WASD while menu open
case WM_KEYUP:
return true; // "Swallow" the message so the game never sees it
}
}
return CallWindowProc(oWndProc, hWnd, msg, wParam, lParam);
}
const char* get_map_name()
{
uintptr_t module_base = (uintptr_t)GetModuleHandle(nullptr);
uintptr_t map_name_offset = module_base + features::offsets::map_name;
const char* map_name = (const char*)map_name_offset;
return map_name;
}
void RenderCustomWatermark() {
char combined_str[256];
snprintf(combined_str, sizeof(combined_str),
"Codex | github.com/oword | %d fps | %s",
(int)ImGui::GetIO().Framerate, get_map_name());
// Dimensions
ImVec2 text_size = ImGui::CalcTextSize(combined_str);
ImVec2 padding(8.0f, 4.0f);
float header_h = 2.0f;
float box_w = text_size.x + (padding.x * 2);
float box_h = text_size.y + (padding.y * 2) + header_h;
// 3. Setup Window
ImGui::SetNextWindowPos(ImVec2(10, 10), ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(box_w, box_h));
ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoSavedSettings;
if (ImGui::Begin("##Watermark", nullptr, flags)) {
ImDrawList* draw_list = ImGui::GetWindowDrawList();
ImVec2 p = ImGui::GetWindowPos();
// Background
draw_list->AddRectFilled(p, ImVec2(p.x + box_w, p.y + box_h), ImColor(18, 18, 18, 230));
// Bright Rainbow Header
ImColor col_a(177, 96, 249, 255);
ImColor col_b(255, 215, 0, 255);
draw_list->AddRectFilledMultiColor(p, ImVec2(p.x + box_w, p.y + header_h), col_a, col_b, col_b, col_a);
// Text
draw_list->AddText(ImVec2(p.x + padding.x, p.y + padding.y + header_h), ImColor(255, 255, 255, 255), combined_str);
// --- Inner Shadow Logic ---
draw_list->AddRect(p, ImVec2(p.x + box_w, p.y + box_h), ImColor(0, 0, 0, 255)); // Dark Outer Border
ImVec2 p_in(p.x + 1.0f, p.y + 1.0f);
ImVec2 p_br(p.x + box_w - 1.0f, p.y + box_h - 1.0f);
ImColor highlight_color(50, 50, 50, 255);
draw_list->AddLine(ImVec2(p_in.x, p_in.y + header_h), ImVec2(p_br.x - 1, p_in.y + header_h), highlight_color);
draw_list->AddLine(ImVec2(p_in.x, p_in.y + header_h), ImVec2(p_in.x, p_br.y - 1), highlight_color);
ImGui::Dummy(ImVec2(0, 0));
}
ImGui::End();
}
void ApplyCustomTheme() {
auto& style = ImGui::GetStyle();
auto& colors = style.Colors;
ImColor main_purple = ImColor(177, 96, 249, 255);
// A darker version for unclicked checkboxes/backgrounds
ImColor darker_purple = ImColor(45, 30, 60, 255);
// A bright version for hover states
ImColor hover_purple = ImColor(190, 120, 255, 255);
style.WindowRounding = 0.0f;
style.FrameRounding = 0.0f;
style.ChildRounding = 0.0f;
// Checkboxes
colors[ImGuiCol_FrameBg] = darker_purple;
colors[ImGuiCol_FrameBgHovered] = ImColor(60, 40, 80, 255);
colors[ImGuiCol_FrameBgActive] = main_purple;
colors[ImGuiCol_CheckMark] = main_purple;
// Tabs (Match the new purple)
colors[ImGuiCol_Tab] = ImColor(25, 25, 25, 255);
colors[ImGuiCol_TabHovered] = main_purple;
colors[ImGuiCol_TabActive] = main_purple;
colors[ImGuiCol_TabUnfocused] = ImColor(20, 20, 20, 255);
colors[ImGuiCol_TabUnfocusedActive] = main_purple;
// Line & Separators (The line under the tabs)
colors[ImGuiCol_Header] = main_purple;
colors[ImGuiCol_HeaderHovered] = main_purple;
colors[ImGuiCol_HeaderActive] = main_purple;
colors[ImGuiCol_Separator] = main_purple;
colors[ImGuiCol_SeparatorActive] = main_purple;
// Sliders & Buttons
colors[ImGuiCol_SliderGrab] = main_purple;
colors[ImGuiCol_SliderGrabActive] = hover_purple;
colors[ImGuiCol_Button] = darker_purple;
colors[ImGuiCol_ButtonHovered] = main_purple;
colors[ImGuiCol_ButtonActive] = hover_purple;
// Backgrounds
colors[ImGuiCol_WindowBg] = ImColor(12, 12, 12, 255);
colors[ImGuiCol_TitleBgActive] = ImColor(18, 18, 18, 255);
}
BOOL __stdcall hkwglSwapBuffers(HDC hdc)
{
if(!init)
{
game_hwnd = WindowFromDC(hdc);
oWndProc = (WNDPROC)SetWindowLongPtr(game_hwnd, GWLP_WNDPROC, (LONG_PTR)WndProc);
//find SDL mode once during init
HMODULE sdlModule = GetModuleHandleA("SDL2.dll");
if (sdlModule) {
SDL_SetRelativeMouseMode_fn = (SDL_SetRelativeMouseMode_t)GetProcAddress(sdlModule, "SDL_SetRelativeMouseMode");
}
ImGui::CreateContext();
ApplyCustomTheme();
ImGui_ImplWin32_Init(game_hwnd);
ImGui_ImplOpenGL3_Init();
init = true;
}
// Static variable to track state changes
static bool last_menu_state = false;
if (show_menu != last_menu_state) {
if (SDL_SetRelativeMouseMode_fn) {
// 0 = Free Mouse, 1 = Locked to Game
SDL_SetRelativeMouseMode_fn(show_menu ? 0 : 1);
}
last_menu_state = show_menu;
}
//this is where we will draw our menu and implement all the menu stuff
ClipCursor(NULL); // release cursor when menu is active
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
if (config.b_watermark) {
RenderCustomWatermark();
}
if (show_menu)
{
ImGui::SetNextWindowSize(ImVec2(400, 300), ImGuiCond_Always);
if (ImGui::Begin("Codex Ac Hack", &show_menu, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse))
{
if (ImGui::BeginTabBar("Tabs"))
{
if (ImGui::BeginTabItem("Aimbot"))
{
ImGui::Checkbox("Aimbot", &config.b_aimbot);
if (config.b_aimbot)
{
// ImGui::SliderInt("Field Of View", &config.aimbot_fov, 0, 180);
ImGui::Checkbox("target teammates", &config.b_target_teammates);
}
ImGui::Checkbox("No Recoil", &config.b_norecoil);
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Misc"))
{
ImGui::Checkbox("Watermark", &config.b_watermark);
ImGui::Checkbox("God Mode", &config.b_god_mode);
if (config.b_god_mode)
{
ImGui::SliderInt("God Mode Health", &config.god_mode_health, 1337, 10000);
}
ImGui::Checkbox("Infinite Ammo", &config.b_inf_ammo);
if (config.b_inf_ammo)
{
ImGui::SliderInt("Infinite Ammo Amount", &config.inf_ammo_amount, 1337, 10000);
}
ImGui::Checkbox("Infinite Grenades", &config.b_inf_grenades);
ImGui::Checkbox("Rapid Grenades", &config.b_rapid_grenades);
ImGui::Checkbox("Rapid knife", &config.b_rapid_knife);
ImGui::Checkbox("Rapid Fire", &config.b_rapid_fire);
ImGui::Checkbox("speed Hack", &config.b_speed_hack);
if (config.b_speed_hack)
{
ImGui::SliderFloat("speed difference", &config.speed_difference, 1.0f, 1.1f);
}
ImGui::EndTabItem();
}
ImGui::EndTabBar(); // closes tab bar
}
ImGui::End();
}
}
ImGui::EndFrame();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
return oSwapBuffers(hdc);
}
FILE* create_console()
{
//create console window
AllocConsole();
//redirect stdout to the new console
FILE* f;
freopen_s(&f, "CONOUT$", "w", stdout);
freopen_s(&f, "CONOUT$", "w", stderr);
freopen_s(&f, "CONIN$", "r", stdin);
SetConsoleTitleA("Codex Console - debugging");
std::cout << "[+] Console initialized!\n";
return f;
}
DWORD WINAPI hack_thread(HMODULE handle)
{
Beep(200, 200);
// Initialize MinHook
if (MH_Initialize() != MH_OK) return 0;
// create the hook
// we use MH_CreateHookApi to let minhook find wglSwapBuffers for us
if (MH_CreateHookApi(L"opengl32.dll", "wglSwapBuffers", &hkwglSwapBuffers, reinterpret_cast<LPVOID*>(&oSwapBuffers)) != MH_OK) return 0;
// Enables all hooks
MH_EnableHook(MH_ALL_HOOKS);
FILE* f = create_console();
while(true)
{
//exits hack
if(GetAsyncKeyState(VK_END) & 0x8000) break;
//executes hack logic
features::execute();
Sleep(10);
}
// cleanup
MH_DisableHook(MH_ALL_HOOKS);
MH_Uninitialize();
//restore the WndProc before leaving
if (oWndProc)
{
SetWindowLongPtr(game_hwnd, GWLP_WNDPROC, (LONG_PTR)oWndProc);
}
//properly shutdown ImGui
if (init)
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
}
Beep(200, 200);
if (f) fclose(f);
FreeConsole();
FreeLibraryAndExitThread(handle, 0);
return 0;
}
BOOL WINAPI DllMain(HINSTANCE handle, DWORD reason, LPVOID)
{
if(reason == DLL_PROCESS_ATTACH)
{
HANDLE thread = CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)hack_thread, handle, 0, nullptr);
if (thread)
CloseHandle(thread);
}
return true;
}