-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.cpp
449 lines (377 loc) · 15.4 KB
/
main.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
438
439
440
441
442
443
444
445
446
447
448
449
#include <d3d9.h>
#pragma comment (lib, "d3dx9.lib")
#pragma comment (lib, "d3d9.lib")
#include <thread>
#include "ImGui/imgui_impl_win32.h"
#include "ImGui/imgui_impl_dx9.h"
#include "ImGui/imgui_internal.h"
#include "ImGui/imgui.h"
#include "ProcessManager.hpp"
#include "Game.h"
#include "Entity.h"
#define RGBA_TO_FLOAT(r,g,b,a) (float)r/255.0f, (float)g/255.0f, (float)b/255.0f, (float)a/255.0f
// Data
static IDirect3D9* g_pD3D = NULL;
static IDirect3DDevice9* g_pd3dDevice = NULL;
static D3DPRESENT_PARAMETERS g_d3dpp = {};
// Forward declarations of helper functions
bool CreateDeviceD3D(HWND hWnd);
void CleanupDeviceD3D();
void ResetDevice();
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
HWND hwnd;
int WIDTH = 300;
int HEIGHT = 155;
POINTS position = { };
int prelogs_count = 0;
float on = 86400.f;
float off = 0.f;
bool SpottedStatusTrue = true;
bool SpottedStatusFalse = false;
bool EnableGlow = false;
bool EnableRadar = false;
bool EnableTrigger = false;
int TriggerHotKey = 0;
int TD = 15;
namespace TriggerBot
{
inline DWORD TriggerDelay = 40; // ms
inline int HotKey = VK_LMENU;
inline std::vector<int> HotKeyList{ VK_LMENU, VK_RBUTTON, VK_XBUTTON1, VK_XBUTTON2, VK_CAPITAL, VK_LSHIFT, VK_LCONTROL };
inline void SetHotKey(int Index)
{
HotKey = HotKeyList.at(Index);
}
// Triggerbot
void Trigger(const CEntity& LocalEntity);
}
void TriggerBot::Trigger(const CEntity& LocalEntity)
{
DWORD uHandle = 0;
if (!ProcessMgr.ReadMemory<DWORD>(LocalEntity.Pawn.Address + Offset::Pawn.iIDEntIndex, uHandle))
return;
if (uHandle == -1)
return;
DWORD64 ListEntry = 0;
ListEntry = ProcessMgr.TraceAddress(gGame.GetEntityListAddress(), { 0x8 * (uHandle >> 9) + 0x10,0x0 });
if (ListEntry == 0)
return;
DWORD64 PawnAddress = 0;
if (!ProcessMgr.ReadMemory<DWORD64>(ListEntry + 0x78 * (uHandle & 0x1FF), PawnAddress))
return;
CEntity Entity;
if (!Entity.UpdatePawn(PawnAddress))
return;
bool AllowShoot = false;
AllowShoot = LocalEntity.Pawn.TeamID != Entity.Pawn.TeamID && Entity.Pawn.Health > 0;
if (!AllowShoot)
return;
static std::chrono::time_point LastTimePoint = std::chrono::steady_clock::now();
auto CurTimePoint = std::chrono::steady_clock::now();
if (CurTimePoint - LastTimePoint >= std::chrono::milliseconds(TriggerDelay))
{
const bool isAlreadyShooting = GetAsyncKeyState(VK_LBUTTON) < 0;
if (!isAlreadyShooting)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
LastTimePoint = CurTimePoint;
}
}
void Cheat() {
while (true) {
// Update EntityList Entry
gGame.UpdateEntityListEntry();
DWORD64 LocalControllerAddress = 0;
DWORD64 LocalPawnAddress = 0;
while (LocalControllerAddress == 0) {
ProcessMgr.ReadMemory(gGame.GetLocalControllerAddress(), LocalControllerAddress);
if (LocalControllerAddress == 0) Sleep(100);
}
ProcessMgr.ReadMemory(gGame.GetLocalPawnAddress(), LocalPawnAddress);
// LocalEntity
CEntity LocalEntity;
static int LocalPlayerControllerIndex = 1;
LocalEntity.UpdateController(LocalControllerAddress);
LocalEntity.UpdatePawn(LocalPawnAddress);
for (int i = 0; i < 64; i++)
{
CEntity Entity;
DWORD64 EntityAddress = 0;
ProcessMgr.ReadMemory<DWORD64>(gGame.GetEntityListEntry() + (i + 1) * 0x78, EntityAddress);
Entity.UpdateController(EntityAddress);
Entity.UpdatePawn(Entity.Pawn.Address);
if (EnableTrigger && GetAsyncKeyState(TriggerBot::HotKey) && LocalEntity.Pawn.WeaponName != "knife")
TriggerBot::Trigger(LocalEntity);
if (!EnableGlow)
{
ProcessMgr.WriteMemory(Entity.Pawn.Address + Offset::Entity.EnemySensor, off);
}
else {
ProcessMgr.WriteMemory(Entity.Pawn.Address + Offset::Entity.EnemySensor, on);
}
if (EnableRadar) {
ProcessMgr.WriteMemory(Entity.Pawn.Address + Offset::Pawn.bSpottedByMask, SpottedStatusTrue);
}
else {
ProcessMgr.WriteMemory(Entity.Pawn.Address + Offset::Pawn.bSpottedByMask, SpottedStatusFalse);
}
}
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}
int main(HINSTANCE hinst, DWORD fdwReason, LPVOID lpvReserved)
{
FreeConsole();
DisableThreadLibraryCalls(hinst);
auto ProcessStatus = ProcessMgr.Attach("cs2.exe");
if (ProcessStatus != StatusCode::SUCCEED)
{
MessageBox(NULL, L"Failed to attach \"cs2.exe\" process.", L"Error", MB_ICONERROR);
return 0;
}
if (!Offset::UpdateOffsets())
{
MessageBox(NULL, L"Failed to update offsets.", L"Error", MB_ICONERROR);
return 0;
}
if (!gGame.InitAddress())
{
MessageBox(NULL, L"Failed to call InitAddress().", L"Error", MB_ICONERROR);
return 0;
}
std::thread run(Cheat);
RECT desktop;
GetWindowRect(GetDesktopWindow(), &desktop);
// Create application window
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, L" ", NULL };
::RegisterClassEx(&wc);
hwnd = ::CreateWindow(wc.lpszClassName, L" ", WS_POPUP, desktop.right / 2 - WIDTH / 2, desktop.bottom / 2 - HEIGHT / 2, WIDTH, HEIGHT, NULL, NULL, wc.hInstance, NULL);
// Show the window
::ShowWindow(hwnd, SW_SHOWDEFAULT);
::UpdateWindow(hwnd);
// Initialize Direct3D
if (!CreateDeviceD3D(hwnd))
{
CleanupDeviceD3D();
::UnregisterClass(wc.lpszClassName, wc.hInstance);
exit(0);
}
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
ImGui::StyleColorsDark();
// Setup Platform/Renderer backends
ImGui_ImplWin32_Init(hwnd);
ImGui_ImplDX9_Init(g_pd3dDevice);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
ImGuiStyle& Style = ImGui::GetStyle();
ImGui::GetStyle().WindowPadding = ImVec2(10.000f, 8.000f);
Style.WindowTitleAlign = ImVec2(0.500f, 0.500f);
Style.Colors[ImGuiCol_FrameBg] = ImVec4(0.141f, 0.141f, 0.141f, 0.667f);
Style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.141f, 0.141f, 0.141f, 0.667f);
Style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.141f, 0.141f, 0.141f, 0.667f);
Style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.039f, 0.039f, 0.037f, 1.000f);
Style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.141f, 0.141f, 0.141f, 0.667f);
Style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.580f, 0.294f, 0.282f, 1.000f);
Style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.643f, 0.329f, 0.318f, 1.000f);
Style.Colors[ImGuiCol_CheckMark] = ImVec4(0.769f, 0.349f, 0.333f, 1.000f);
Style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.580f, 0.294f, 0.282f, 1.000f);
Style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.769f, 0.349f, 0.333f, 1.000f);
Style.Colors[ImGuiCol_Button] = ImVec4(0.137f, 0.137f, 0.141f, 0.549f);
Style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.580f, 0.294f, 0.282f, 1.000f);
Style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.769f, 0.349f, 0.333f, 1.000f);
Style.Colors[ImGuiCol_Header] = ImVec4(0.141f, 0.141f, 0.141f, 0.667f);
Style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.580f, 0.294f, 0.282f, 1.000f);
Style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.769f, 0.349f, 0.333f, 1.000f);
Style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.580f, 0.294f, 0.282f, 0.549f);
Style.Colors[ImGuiCol_Separator] = ImVec4(0.780f, 0.349f, 0.333f, 1.000f);
Style.Colors[ImGuiCol_Tab] = ImVec4(0.137f, 0.137f, 0.141f, 0.549f);
Style.Colors[ImGuiCol_TabHovered] = ImVec4(0.580f, 0.294f, 0.282f, 1.000f);
Style.Colors[ImGuiCol_TabActive] = ImVec4(0.769f, 0.349f, 0.333f, 1.000f);
Style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.137f, 0.137f, 0.141f, 0.549f);
Style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.580f, 0.294f, 0.282f, 0.549f);
// Main loop
bool done = false;
int cwr = 0;
while (!done)
{
// Poll and handle messages (inputs, window resize, etc.)
MSG msg;
while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
if (msg.message == WM_QUIT)
done = true;
}
if (done)
break;
cwr++;
// Start the Dear ImGui frame
ImGui_ImplDX9_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
ImGui::SetNextWindowPos(ImVec2(0, 0));
ImGui::SetNextWindowSize(ImVec2(WIDTH, HEIGHT), ImGuiCond_Once);
{
ImGui::Begin("xvisual - CS 2 by xvorost", NULL, 18470);
ImGui::PushItemWidth(80);
{
ImGui::Spacing();
ImGui::Text(" ");
ImGui::SameLine();
ImGui::BulletText("Enable Glow:"); ImGui::SameLine();
ImGui::Checkbox("##EnableGlow", &EnableGlow);
ImGui::SameLine();
ImGui::Text(" ");
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.769f, 0.349f, 0.333f, 1.000f));
if (ImGui::Button("_")) ::ShowWindow(hwnd, SW_MINIMIZE);
ImGui::PopStyleColor(1);
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.769f, 0.349f, 0.333f, 1.000f));
if (ImGui::Button("X")) {
ShellExecute(NULL, L"open", L"https://github.com/xvorost/", NULL, NULL, SW_SHOWNORMAL);
exit(0);
}
ImGui::PopStyleColor(1);
ImGui::Text(" ");
ImGui::SameLine();
ImGui::BulletText("Enable Radar:"); ImGui::SameLine();
ImGui::Checkbox("##EnableRadar", &EnableRadar);
ImGui::Text(" ");
ImGui::SameLine();
ImGui::BulletText("Enable TriggerBot:"); ImGui::SameLine();
ImGui::Checkbox("##EnableTrigger", &EnableTrigger);
ImGui::Text(" ");
ImGui::SameLine();
ImGui::Text("Trigger Key:"); ImGui::SameLine();
if (ImGui::Combo("##TriggerKey", &TriggerHotKey, "MENU\0RBUTTON\0XBUTTON1\0XBUTTON2\0CAPITAL\0SHIFT\0CONTROL\0"))
{
TriggerBot::SetHotKey(TriggerHotKey);
}
ImGui::Text(" ");
ImGui::SameLine();
ImGui::Text("Delay:");
ImGui::SameLine(); ImGui::InputInt("##TriggerDelay", &TD, 0, 0);
if (TD < 0) TD = 0; else if (TD > 200) TD = 200;
TriggerBot::TriggerDelay = (DWORD)TD;
}
ImGui::End();
}
// Rendering
if (cwr >= 1000) { ::UpdateWindow(hwnd); cwr = 0; }
ImGui::EndFrame();
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_color.x * clear_color.w * 255.0f), (int)(clear_color.y * clear_color.w * 255.0f), (int)(clear_color.z * clear_color.w * 255.0f), (int)(clear_color.w * 255.0f));
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, clear_col_dx, 1.0f, 0);
if (g_pd3dDevice->BeginScene() >= 0)
{
ImGui::Render();
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
g_pd3dDevice->EndScene();
}
HRESULT result = g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
// Handle loss of D3D9 device
if (result == D3DERR_DEVICELOST && g_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
ResetDevice();
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
// Cleanup
ImGui_ImplDX9_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
CleanupDeviceD3D();
::DestroyWindow(hwnd);
::UnregisterClass(wc.lpszClassName, wc.hInstance);
//}
return 0;
}
bool CreateDeviceD3D(HWND hWnd)
{
if ((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
return false;
// Create the D3DDevice
g_d3dpp.Windowed = true;
g_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
g_d3dpp.hDeviceWindow = hWnd;
HRESULT dummyDeviceCreated = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_d3dpp.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice);
if (dummyDeviceCreated != S_OK)
{
g_pD3D->Release();
Sleep(5000);
return false;
}
return true;
}
void CleanupDeviceD3D()
{
if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
if (g_pD3D) { g_pD3D->Release(); g_pD3D = NULL; }
}
void ResetDevice()
{
ImGui_ImplDX9_InvalidateDeviceObjects();
HRESULT hr = g_pd3dDevice->Reset(&g_d3dpp);
if (hr == D3DERR_INVALIDCALL)
IM_ASSERT(0);
ImGui_ImplDX9_CreateDeviceObjects();
}
// Forward declare message handler from imgui_impl_win32.cpp
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
// Win32 message handler
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
return true;
switch (msg)
{
case WM_SIZE:
if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
{
g_d3dpp.BackBufferWidth = LOWORD(lParam);
g_d3dpp.BackBufferHeight = HIWORD(lParam);
ResetDevice();
}
return 0;
break;
case WM_SYSCOMMAND:
if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
return 0;
break;
case WM_DESTROY:
//ShellExecute(NULL, L"open", L"https://github.com/xvorost/", NULL, NULL, SW_SHOWNORMAL);
::PostQuitMessage(0);
return 0;
case WM_LBUTTONDOWN:
position = MAKEPOINTS(lParam); // set click points
return 0;
case WM_MOUSEMOVE:
if (wParam == MK_LBUTTON)
{
const auto points = MAKEPOINTS(lParam);
auto rect = ::RECT{ };
GetWindowRect(hwnd, &rect);
rect.left += points.x - position.x;
rect.top += points.y - position.y;
if (position.x >= 0 &&
position.x <= WIDTH &&
position.y >= 0 && position.y <= 19)
SetWindowPos(
hwnd,
HWND_TOPMOST,
rect.left,
rect.top,
0, 0,
SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOZORDER
);
}
return 0;
}
return ::DefWindowProc(hWnd, msg, wParam, lParam);
}