forked from boowampp/ApexDmaCheatUpdated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRender.cpp
352 lines (307 loc) · 13 KB
/
Render.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
#include "Render.hpp"
#include "LocalPlayer.hpp"
#include "Player.hpp"
#include "Camera.hpp"
#include "Spectator.hpp"
#include "Aimbot.hpp"
#include "Glow.hpp"
#include "Config.hpp"
#include "imgui.h"
#include "imgui_impl_win32.h"
#include "imgui_impl_dx11.h"
#include <d3d11.h>
#include <tchar.h>
#include <utility>
// Data
static ID3D11Device* g_pd3dDevice = nullptr;
static ID3D11DeviceContext* g_pd3dDeviceContext = nullptr;
static IDXGISwapChain* g_pSwapChain = nullptr;
static UINT g_ResizeWidth = 0, g_ResizeHeight = 0;
static ID3D11RenderTargetView* g_mainRenderTargetView = nullptr;
// Forward declarations of helper functions
bool CreateDeviceD3D(HWND hWnd);
void CleanupDeviceD3D();
void CreateRenderTarget();
void CleanupRenderTarget();
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
ImFont* regular_font;
ImFont* bold_font;
ImFont* italic_font;
ImFont* huge_font;
// Define the display names and corresponding values separately
const char* keyNames[] = {
"Left Mouse Button",
"Right Mouse Button",
"Middle Mouse Button",
"Side1 Mouse Button",
"Side2 Mouse Button",
"Left SHIFT Button",
"Left ALT Button",
"OFF",
};
int keyValues[] = {
0x01, // Left Mouse Button
0x02, // Right Mouse Button
0x04, // Middle Mouse Button
0x05, // Side1 Mouse Button
0x06, // Side2 Mouse Button
0xA0, // Left SHIFT Button
0xA4, // Left ALT Button
0x2A, // A button that is rarely used instead off
};
constexpr int keyCount = sizeof(keyNames) / sizeof(keyNames[0]);
const char* glowNames[] = {
"Blue",
"Purple",
"Gold",
};
int glowValues[] = {
35, // Blue
36, // Purple
37, // Gold
};
constexpr int glowCount = sizeof(glowNames) / sizeof(glowNames[0]);
int FindCurrentSelectionIndex(const int value, const int* keyValues, const int keyCount) {
for (int i = 0; i < keyCount; ++i) {
if (value == keyValues[i]) {
return i;
}
}
return 0; // Default to the first item if not found
}
// Main code
void Render(LocalPlayer* Myself, std::vector<Player*>* Players, Camera* GameCamera, Spectator* Spectators, Aimbot* AimAssist, Sense* ESP)
{
int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);
// Create application window
WNDCLASSEXW wc = { sizeof(wc), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, L"ApexDMA", nullptr };
::RegisterClassExW(&wc);
HWND hwnd = ::CreateWindowEx(WS_EX_LAYERED, wc.lpszClassName, L"ApexDMA", WS_POPUP, 0, 0, width, height, nullptr, nullptr, wc.hInstance, nullptr);
// Set Transparency, WS_EX_LAYERED is required for transparency
SetLayeredWindowAttributes(hwnd, 0, 255, LWA_ALPHA);
SetLayeredWindowAttributes(hwnd, 0, RGB(0, 0, 0), LWA_COLORKEY);
// Initialize Direct3D
if (!CreateDeviceD3D(hwnd))
{
CleanupDeviceD3D();
::UnregisterClassW(wc.lpszClassName, wc.hInstance);
return;
}
// Show the window
::ShowWindow(hwnd, SW_SHOWDEFAULT);
::UpdateWindow(hwnd);
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
// Setup fonts
regular_font = io.Fonts->AddFontFromFileTTF("regular.otf", 12.0f);
bold_font = io.Fonts->AddFontFromFileTTF("bold.otf", 12.0f);
italic_font = io.Fonts->AddFontFromFileTTF("italic.otf", 12.0f);
huge_font = io.Fonts->AddFontFromFileTTF("bold.otf", 20.0f);
io.FontDefault = bold_font;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
// Setup Platform/Renderer backends
ImGui_ImplWin32_Init(hwnd);
ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext);
ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
// Main loop
while (true)
{
// Poll and handle messages (inputs, window resize, etc.)
// See the WndProc() function below for our to dispatch events to the Win32 backend.
MSG msg;
while (::PeekMessage(&msg, nullptr, 0U, 0U, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
if (msg.message == WM_QUIT)
break;
}
// Handle window resize (we don't resize directly in the WM_SIZE handler)
if (g_ResizeWidth != 0 && g_ResizeHeight != 0)
{
CleanupRenderTarget();
g_pSwapChain->ResizeBuffers(0, g_ResizeWidth, g_ResizeHeight, DXGI_FORMAT_UNKNOWN, 0);
g_ResizeWidth = g_ResizeHeight = 0;
CreateRenderTarget();
}
// Start the Dear ImGui frame
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
// Foreground Drawlist
ImDrawList* fg_draw = ImGui::GetForegroundDrawList();
// Performance
std::string PerformanceString = "Render FPS: " + std::to_string(static_cast<int>(ImGui::GetIO().Framerate));
fg_draw->AddText(ImVec2(10, 50), IM_COL32(255, 255, 255, 255), PerformanceString.c_str());
// Settings Window, Fixed Width
ImGui::SetNextWindowSize(ImVec2(400, 430), ImGuiCond_FirstUseEver); // ImGuiCond_FirstUseEver 仅当窗口第一次被使用时才应用这个设置
ImGui::SetNextWindowPos(ImVec2(width - 410, 10), ImGuiCond_FirstUseEver);
ImGui::Begin("Settings");
// AimAssist Settings
ImGui::PushFont(huge_font); // 通过将字体推入堆栈,可以暂时改变当前的字体,直到它从堆栈中弹出为止
ImGui::Text("AimAssist Settings");
ImGui::PopFont();
ImGui::Text("Sticky Aim:");
ImGui::SameLine(); // 得接下来的文本或控件与前面的文本处于同一行
if (ImGui::Checkbox("##Sticky Aim:", &AimAssist->Sticky)) { // 标签字符串前面添加了 "##",因此该字符串不会显示在界面上
Config::GetInstance().Save(); // 复选框与布尔变量 AimAssist->Sticky 关联 复选框的状态发生变化,则条件成立
}
ImGui::Text("Aim FOV:");
if (ImGui::SliderFloat("##Aim FOV:", &AimAssist->FOV, 1.0f, 50.0f, "% .1f")) {
Config::GetInstance().Save();
}
ImGui::Text("Smoothing:");
if (ImGui::SliderFloat("##Smoothing:", &AimAssist->Smooth, 1.0f, 10.0f, "% .1f")) {
Config::GetInstance().Save();
}
ImGui::Text("Max Smoothing Increase:");
if (ImGui::SliderFloat("##Max Smoothing Increase:", &AimAssist->MaxSmoothIncrease, 0.0f, 1.0f, "% .2f")) {
Config::GetInstance().Save();
}
ImGui::Text("Recoil:");
if (ImGui::SliderFloat("##Recoil:", &AimAssist->RecoilCompensation, 1.0f, 5.0f, "% .2f")) {
Config::GetInstance().Save();
}
// For AimBotKey
int aimBotKeyIndex = FindCurrentSelectionIndex(AimAssist->AimBotKey, keyValues, keyCount);
ImGui::Text("AimBot Key:");
if (ImGui::Combo("##AimBotKey", &aimBotKeyIndex, keyNames, keyCount)) {
AimAssist->AimBotKey = keyValues[aimBotKeyIndex];
Config::GetInstance().Save();
}
// For AimBotKey2
int aimBotKey2Index = FindCurrentSelectionIndex(AimAssist->AimBotKey2, keyValues, keyCount);
ImGui::Text("AimBot Key2:");
if (ImGui::Combo("##AimBotKey2", &aimBotKey2Index, keyNames, keyCount)) {
AimAssist->AimBotKey2 = keyValues[aimBotKey2Index];
Config::GetInstance().Save();
}
// For AimTriggerKey
int aimTriggerKeyIndex = FindCurrentSelectionIndex(AimAssist->AimTriggerKey, keyValues, keyCount);
ImGui::Text("AimTrigger Key:");
if (ImGui::Combo("##AimTriggerKey", &aimTriggerKeyIndex, keyNames, keyCount)) {
AimAssist->AimTriggerKey = keyValues[aimTriggerKeyIndex];
Config::GetInstance().Save();
}
// For AimFlickKey
int aimFlickKeyIndex = FindCurrentSelectionIndex(AimAssist->AimFlickKey, keyValues, keyCount);
ImGui::Text("AimFlick Key:");
if (ImGui::Combo("##AimFlickKey", &aimFlickKeyIndex, keyNames, keyCount)) {
AimAssist->AimFlickKey = keyValues[aimFlickKeyIndex];
Config::GetInstance().Save();
}
// Glow Settings
ImGui::PushFont(huge_font);
ImGui::Text("Glow Settings");
ImGui::PopFont();
ImGui::Text("Item Glow:");
ImGui::SameLine();
if (ImGui::Checkbox("##Item Glow:", &ESP->ItemGlow)) {
Config::GetInstance().Save();
}
int itemGlowIndex = FindCurrentSelectionIndex(ESP->MinimumItemRarity, glowValues, glowCount);
ImGui::Text("Minimum Item Rarity:");
if (ImGui::Combo("##Minimum Item Rarity", &itemGlowIndex, glowNames, glowCount)) {
ESP->MinimumItemRarity = glowValues[itemGlowIndex];
Config::GetInstance().Save();
}
ImGui::End();
// Rendering
ImGui::Render();
const float clear_color_with_alpha[4] = { clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w }; // rgba ->x,y,z,w
g_pd3dDeviceContext->OMSetRenderTargets(1, &g_mainRenderTargetView, nullptr);
g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, clear_color_with_alpha);
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
g_pSwapChain->Present(0, 0); // Present without vsync
}
// Cleanup
ImGui_ImplDX11_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
CleanupDeviceD3D();
::DestroyWindow(hwnd);
::UnregisterClassW(wc.lpszClassName, wc.hInstance);
return;
}
// Helper functions
bool CreateDeviceD3D(HWND hWnd)
{
// Setup swap chain
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory(&sd, sizeof(sd));
sd.BufferCount = 2;
sd.BufferDesc.Width = 0;
sd.BufferDesc.Height = 0;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = hWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
UINT createDeviceFlags = 0;
//createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
D3D_FEATURE_LEVEL featureLevel;
const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, };
HRESULT res = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext);
if (res == DXGI_ERROR_UNSUPPORTED) // Try high-performance WARP software driver if hardware is not available.
res = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_WARP, nullptr, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext);
if (res != S_OK)
return false;
CreateRenderTarget();
return true;
}
void CleanupDeviceD3D()
{
CleanupRenderTarget();
if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = nullptr; }
if (g_pd3dDeviceContext) { g_pd3dDeviceContext->Release(); g_pd3dDeviceContext = nullptr; }
if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = nullptr; }
}
void CreateRenderTarget()
{
ID3D11Texture2D* pBackBuffer;
g_pSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
g_pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &g_mainRenderTargetView);
pBackBuffer->Release();
}
void CleanupRenderTarget()
{
if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = nullptr; }
}
// 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
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
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 (wParam == SIZE_MINIMIZED)
return 0;
g_ResizeWidth = (UINT)LOWORD(lParam); // Queue resize
g_ResizeHeight = (UINT)HIWORD(lParam);
return 0;
case WM_SYSCOMMAND:
if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
return 0;
break;
case WM_DESTROY:
::PostQuitMessage(0);
return 0;
}
return ::DefWindowProcW(hWnd, msg, wParam, lParam);
}