-
Notifications
You must be signed in to change notification settings - Fork 0
/
dllmain.cpp
315 lines (260 loc) · 8.75 KB
/
dllmain.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
#include <includes.h>
#include <no_renderer/FW1FontWrapper/FW1FontWrapper.h>
#include <no_renderer/no_menu/no_menu.h>
#include <no_renderer/no_gui/no_gui.h>
#include <no_define.h>
#include <fstream>
#include <no_cheat/no_spoofcall.h>
#include <no_cheat/framework.h>
#include <no_cheat/Esp.h>
#include <no_cheat/Aimbot.h>
#include <no_cheat/Exploits.h>
#include <no_cheat/PawnsLoop.h>
// It's generally a good idea to use "using" statements to make your code more readable
using std::ifstream;
using std::ofstream;
using std::ios;
using std::string;
// Use the HRESULT type rather than defining your own function pointer types
typedef HRESULT(*PresentFn)(IDXGISwapChain*, UINT, UINT);
inline PresentFn original_present{ };
typedef HRESULT(*ResizeFn)(IDXGISwapChain*, UINT, UINT, UINT, DXGI_FORMAT, UINT);
inline ResizeFn original_resize{ };
// Declare variables as close to their point of use as possible to improve readability
HRESULT(*present_original)(IDXGISwapChain* swapchain, UINT sync, UINT flags) = nullptr;
ID3D11Texture2D* RenderTargetTexture;
ID3D11RenderTargetView* RenderTargetView = NULL;
UINT vps = 1;
ID3D11RasterizerState* rwState;
ID3D11RasterizerState* rsState;
float ScreenCenterX;
float ScreenCenterY;
// Use bool rather than int for boolean variables
bool firstTime = true;
unsigned long RGBAtoHEX(int r, int g, int b)
{
// Use bit shifting instead of multiplying and adding
return ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
}
// Use the no_menu::color type rather than defining your own
void functions_line(int x, int y, int x2, int y2, no_menu::color c) noexcept
{
color cool_col(c.a, c.r, c.g, c.b);
gui.draw_line(x, y, x2, y2, cool_col);
}
void functions_rect(int x, int y, int x2, int y2, no_menu::color c) noexcept
{
color cool_col(c.a, c.r, c.g, c.b);
gui.draw_rect(x, y, x2, y2, cool_col);
}
void functions_filled_rect(int x, int y, int x2, int y2, no_menu::color c) noexcept
{
color cool_col(c.a, c.r, c.g, c.b);
gui.fill_rect(x, y, x2, y2, cool_col);
}
// Use a reference to the string type rather than a pointer to char
const wchar_t* CharToWchar(const string& ch)
{
// Use the size() function rather than strlen()
const size_t len = ch.size() + 1;
wchar_t* wch = new wchar_t[len];
mbstowcs(wch, ch.c_str(), len);
return wch;
}
UINT32 ColorToUint32(const no_menu::color color)
{
UINT32 result =
(BYTE(color.a) << 24) +
(BYTE(color.r) << 16) +
(BYTE(color.g) << 8) +
BYTE(color.b);
return result;
}
void functions_text(int x, int y, no_menu::color color, bool center, const string& text) noexcept
{
if (pFontWrapper) {
// Use the string type rather than a pointer to char
const size_t cSize = text.size() + 1;
wchar_t* wc = new wchar_t[cSize];
size_t tmp = 0;
mbstowcs_s(&tmp, wc, cSize, text.c_str(), cSize);
pFontWrapper->DrawString(pContext, wc, 14, x, y, ColorToUint32(color), FW1_RESTORESTATE);
delete[] wc;
}
}
// Use a reference to the string type rather than a pointer to char
void functions_text(int x, int y, no_menu::color color, bool center, const string& text) noexcept
{
if (pFontWrapper) {
const size_t cSize = text.size() + 1;
wchar_t* wc = new wchar_t[cSize];
size_t tmp = 0;
mbstowcs_s(&tmp, wc, cSize, text.c_str(), cSize);
if (center) {
// Use a helper function to get the text size rather than calling the same code multiple times
FW1_RECTF textSize = GetTextSize(pFontWrapper, wc, 14);
pFontWrapper->DrawString(pContext, wc, 14, x - textSize.Right / 2, y, ColorToUint32(color), FW1_RESTORESTATE);
}
else {
pFontWrapper->DrawString(pContext, wc, 14, x, y, ColorToUint32(color), FW1_RESTORESTATE);
}
delete[] wc;
}
}
FW1_RECTF GetTextSize(IFW1Factory* pFontFactory, const wchar_t* text, float fontSize)
{
IFW1FontWrapper* pFontWrapper;
pFontFactory->CreateFontWrapper(pDevice, L"Arial", &pFontWrapper);
FW1_RECTF textRect = { 0 };
pFontWrapper->MeasureString(pContext, text, fontSize, &textRect, FW1_RESTORESTATE);
pFontWrapper->Release();
return textRect;
}
HRESULT PresentHook(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags)
{
if (firstTime) {
pSwapChain->GetDevice(__uuidof(pDevice), (void**)&pDevice);
pDevice->GetImmediateContext(&pContext);
D3D11_RASTERIZER_DESC rwDesc = {};
rwDesc.FillMode = D3D11_FILL_SOLID;
rwDesc.CullMode = D3D11_CULL_NONE;
pDevice->CreateRasterizerState(&rwDesc, &rwState);
D3D11_RASTERIZER_DESC rsDesc = {};
rsDesc.FillMode = D3D11_FILL_SOLID;
rsDesc.CullMode = D3D11_CULL_BACK;
pDevice->CreateRasterizerState(&rsDesc, &rsState);
pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&RenderTargetTexture);
pDevice->CreateRenderTargetView(RenderTargetTexture, NULL, &RenderTargetView);
pContext->OMSetRenderTargets(1, &RenderTargetView, NULL);
D3D11_VIEWPORT viewport;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = 1920;
viewport.Height = 1080;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
pContext->RSSetViewports(1, &viewport);
ScreenCenterX = viewport.Width / 2.0f;
ScreenCenterY = viewport.Height / 2.0f;
// Initialize the font wrapper
FW1CreateFactory(FW1_VERSION, &pFontFactory);
pFontFactory->CreateFontWrapper(pDevice, L"Tahoma", &pFontWrapper);
firstTime = false;
}
if (GetAsyncKeyState(VK_INSERT))
menu.show();
else
menu.hide();
if (GetAsyncKeyState(VK_F1))
pawns.menu_loop();
else
pawns.hide_menu();
// Use a helper function to check if the menu is open
if (IsMenuOpen()) {
// Set the rasterizer state to draw the menu
pContext->RSSetState(rwState);
// Clear the render target to a solid color
pContext->ClearRenderTargetView(RenderTargetView, ClearColor);
// Draw the menu
menu.draw();
// Present the swap chain
return present_original(pSwapChain, SyncInterval, Flags);
}
else {
// Set the rasterizer state to draw the game
pContext->RSSetState(rsState);
// Clear the render target to a solid color
pContext->ClearRenderTargetView(RenderTargetView, ClearColor);
// Draw the game
game.draw();
// Present the swap chain
return present_original(pSwapChain, SyncInterval, Flags);
}
HRESULT ResizeHook(IDXGISwapChain* pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags)
{
// Update the render target size and viewport
RenderTargetTexture->Release();
RenderTargetView->Release();
pSwapChain->ResizeBuffers(BufferCount, Width, Height, NewFormat, SwapChainFlags);
pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&RenderTargetTexture);
pDevice->CreateRenderTargetView(RenderTargetTexture, NULL, &RenderTargetView);
pContext->OMSetRenderTargets(1, &RenderTargetView, NULL);
D3D11_VIEWPORT viewport;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = Width;
viewport.Height = Height;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
pContext->RSSetViewports(1, &viewport);
ScreenCenterX = viewport.Width / 2.0f;
ScreenCenterY = viewport.Height / 2.0f;
// Call the original resize function
return original_resize(pSwapChain, BufferCount, Width, Height, NewFormat, SwapChainFlags);
}
bool IsMenuOpen()
{
return menu.is_open();
}
// Other functions
void no_cheat::pawns_loop::add_pawn(const char* pwn, bool(*func)(), bool(*func2)())
{
const size_t len = strlen(pwn) + 1;
wchar_t* wc = new wchar_t[len];
size_t tmp = 0;
mbstowcs_s(&tmp, wc, len, pwn, len);
menu.add(wc, func, func2);
delete[] wc;
}
void no_cheat::pawns_loop::add_pawn(const char* pwn, bool(*func)(), bool(*func2)(), no_menu::color c)
{
const size_t len = strlen(pwn) + 1;
wchar_t* wc = new wchar_t[len];
size_t tmp = 0;
mbstowcs_s(&tmp, wc, len, pwn, len);
menu.add(wc, func, func2, c);
delete[] wc;
}
void no_cheat::pawns_loop::add_pawn(const char* pwn, bool(*func)(), bool(*func2)(), no_menu::color c, no_menu::color c2)
{
const size_t len = strlen(pwn) + 1;
wchar_t* wc = new wchar_t[len];
size_t tmp = 0;
mbstowcs_s(&tmp, wc, len, pwn, len);
menu.add(wc, func, func2, c, c2);
delete[] wc;
}
void no_cheat::pawns_loop::add_pawn(const char* pwn, bool(*func)(), bool(*func2)(), no_menu::color c, no_menu::color c2, no_menu::color c3)
{
const size_t len = strlen(pwn) + 1;
wchar_t* wc = new wchar_t[len];
size_t tmp = 0;
mbstowcs_s(&tmp, wc, len, pwn, len);
menu.add(wc, func, func2, c, c2, c3);
delete[] wc;
}
void no_cheat::pawns_loop::add_pawn(const char* pwn, bool(*func)(), bool(*func2)(), no_menu::color c, no_menu::color c2, no_menu::color c3, bool(*func3)())
{
const size_t len = strlen(pwn) + 1;
wchar_t* wc = new wchar_t[len];
size_t tmp = 0;
mbstowcs_s(&tmp, wc, len, pwn, len);
menu.add(wc, func, func2, c, c2, c3, func3);
delete[] wc;
}
void no_cheat::pawns_loop::add_separator()
{
menu.add_separator();
}
void no_cheat::pawns_loop::menu_loop()
{
menu.show();
}
void no_cheat::pawns_loop::hide_menu()
{
menu.hide();
}
bool no_cheat::pawns_loop::is_menu_open()
{
return menu.is_open();
}