-
Notifications
You must be signed in to change notification settings - Fork 49
/
main.h
415 lines (334 loc) · 9.84 KB
/
main.h
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
//d3d11 w2s for ut4 engine games by n7
//==========================================================================================================================
//globals
DWORD Daimkey = VK_RBUTTON; //aimkey
int aimheight = 46; //aim height value
unsigned int asdelay = 90; //use x-999 (shoot for xx millisecs, looks more legit)
bool IsPressed = false; //
DWORD astime = timeGetTime(); //autoshoot timer
//init only once
bool firstTime = true;
//Enum Mode
enum Mode { Off = 0, Simple = 1, Advanced = 2 };
inline Mode& operator++(Mode& orig)
{
if (orig == Advanced)
orig = Off;
else
orig = static_cast<Mode>(orig + 1);
return orig;
}
inline Mode& operator--(Mode& orig)
{
if (orig == Off)
orig = Advanced;
else
orig = static_cast<Mode>(orig - 1);
return orig;
}
std::wstring GetTextForMode(Mode mode);
//Enum Option
enum Option
{
Chams = 0,
EnemyESP,
ItemESP,
AimbotKey,
HeadshotRange,
FieldOfView
};
inline Option& operator++(Option& orig)
{
if (orig == FieldOfView)
orig = Chams;
else
orig = static_cast<Option>(orig + 1);
return orig;
}
inline Option& operator--(Option& orig)
{
if (orig == Chams)
orig = FieldOfView;
else
orig = static_cast<Option>(orig - 1);
return orig;
}
std::wstring GetTextForOption(Option option);
//Enum AimButton
enum AimButton { Mouse5 = 0, RMouseButton = 1, LeftAlt = 2 };
inline AimButton& operator++(AimButton& orig)
{
if (orig == LeftAlt)
orig = Mouse5;
else
orig = static_cast<AimButton>(orig + 1);
return orig;
}
inline AimButton& operator--(AimButton& orig)
{
if (orig == Mouse5)
orig = LeftAlt;
else
orig = static_cast<AimButton>(orig - 1);
return orig;
}
std::wstring GetTextForAimButton(AimButton AimButton);
int GetAimButton(AimButton AimButton);
//helper Functions
Color GetItemColor(SDK::EFortItemTier tier);
void UpdateMenu();
void DrawMenu();
void ChangeOption(Option option, int direction);
void HandelInput();
void InitializeGlobals();
std::wstring GetStatus(bool status);
void DrawPlayerBox(SDK::AFortPawn* playerPawn);
void DrawDevVisuals();
//viewport
UINT vps = 1;
D3D11_VIEWPORT viewport;
float ScreenCenterX;
float ScreenCenterY;
//vertex
ID3D11Buffer* veBuffer;
UINT Stride = 24;
UINT veBufferOffset = 0;
D3D11_BUFFER_DESC vedesc;
//index
ID3D11Buffer* inBuffer;
DXGI_FORMAT inFormat;
UINT inOffset;
D3D11_BUFFER_DESC indesc;
//rendertarget
ID3D11Texture2D* RenderTargetTexture;
ID3D11RenderTargetView* RenderTargetView = NULL;
//shader
ID3D11PixelShader* psRed = NULL;
ID3D11PixelShader* psGreen = NULL;
//pssetshaderresources
UINT pssrStartSlot;
D3D11_SHADER_RESOURCE_VIEW_DESC Descr;
ID3D11ShaderResourceView* ShaderResourceView;
D3D11_TEXTURE2D_DESC texdesc;
//psgetConstantbuffers
ID3D11Buffer* pcsBuffer;
D3D11_BUFFER_DESC pscdesc;
UINT pscStartSlot;
//vsgetconstantbuffers
ID3D11Buffer* mConstantBuffers;
UINT vsConstant_StartSlot;
UINT psStartSlot;
UINT vsStartSlot;
//used for logging/cycling through values
bool logger = true;
int countnum = 1;
char szString[64];
//nospread
using _GetWeaponStatsRow = SDK::FFortRangedWeaponStats* (__thiscall*)(SDK::FDataTableRowHandle* pDataRow,
SDK::FString* tableName, UINT32 unk1,
UINT32 unk2);
_GetWeaponStatsRow pGetWeaponStatsRow = nullptr;
#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = nullptr; } }
//==========================================================================================================================
//get dir
using namespace std;
#include <fstream>
char dlldir[320];
char* GetDirectoryFile(char* filename)
{
static char path[320];
strcpy_s(path, dlldir);
strcat_s(path, filename);
return path;
}
//log
void Log(const char* fmt, ...)
{
if (!fmt) return;
char text[4096];
va_list ap;
va_start(ap, fmt);
vsprintf_s(text, fmt, ap);
va_end(ap);
ofstream logfile(GetDirectoryFile("log.txt"), ios::app);
if (logfile.is_open() && text) logfile << text << endl;
logfile.close();
}
//==========================================================================================================================
//generate shader func
HRESULT GenerateShader(ID3D11Device* pD3DDevice, ID3D11PixelShader** pShader, float r, float g, float b)
{
char szCast[] = "struct VS_OUT"
"{"
" float4 Position : SV_Position;"
" float4 Color : COLOR0;"
"};"
"float4 main( VS_OUT input ) : SV_Target"
"{"
" float4 fake;"
" fake.a = 0.5f;"
" fake.r = %f;"
" fake.g = %f;"
" fake.b = %f;"
" return fake;"
"}";
ID3D10Blob* pBlob;
char szPixelShader[1000];
sprintf_s(szPixelShader, szCast, r, g, b);
ID3DBlob* d3dErrorMsgBlob;
HRESULT hr = D3DCompile(szPixelShader, sizeof(szPixelShader), "shader", NULL, NULL, "main", "ps_4_0", NULL, NULL,
&pBlob, &d3dErrorMsgBlob);
if (FAILED(hr))
return hr;
hr = pD3DDevice->CreatePixelShader((DWORD*)pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, pShader);
if (FAILED(hr))
return hr;
return S_OK;
}
//==========================================================================================================================
//wh
char* state;
ID3D11RasterizerState* rwState;
ID3D11RasterizerState* rsState;
enum eDepthState
{
ENABLED,
DISABLED,
READ_NO_WRITE,
NO_READ_NO_WRITE,
_DEPTH_COUNT
};
ID3D11DepthStencilState* myDepthStencilStates[static_cast<int>(eDepthState::_DEPTH_COUNT)];
void SetDepthStencilState(eDepthState aState)
{
pContext->OMSetDepthStencilState(myDepthStencilStates[aState], 1);
}
static Vec4 Vec4MulMat4x4(const Vec4& v, float (*mat4x4)[4])
{
Vec4 o;
o.x = v.x * mat4x4[0][0] + v.y * mat4x4[1][0] + v.z * mat4x4[2][0] + v.w * mat4x4[3][0];
o.y = v.x * mat4x4[0][1] + v.y * mat4x4[1][1] + v.z * mat4x4[2][1] + v.w * mat4x4[3][1];
o.z = v.x * mat4x4[0][2] + v.y * mat4x4[1][2] + v.z * mat4x4[2][2] + v.w * mat4x4[3][2];
o.w = v.x * mat4x4[0][3] + v.y * mat4x4[1][3] + v.z * mat4x4[2][3] + v.w * mat4x4[3][3];
return o;
}
static Vec4 Vec3MulMat4x4(const Vec3& v, float (*mat4x4)[4])
{
Vec4 o;
o.x = v.x * mat4x4[0][0] + v.y * mat4x4[1][0] + v.z * mat4x4[2][0] + mat4x4[3][0];
o.y = v.x * mat4x4[0][1] + v.y * mat4x4[1][1] + v.z * mat4x4[2][1] + mat4x4[3][1];
o.z = v.x * mat4x4[0][2] + v.y * mat4x4[1][2] + v.z * mat4x4[2][2] + mat4x4[3][2];
o.w = v.x * mat4x4[0][3] + v.y * mat4x4[1][3] + v.z * mat4x4[2][3] + mat4x4[3][3];
return o;
}
static Vec3 Vec3MulMat4x3(const Vec3& v, float (*mat4x3)[3])
{
Vec3 o;
o.x = v.x * mat4x3[0][0] + v.y * mat4x3[1][0] + v.z * mat4x3[2][0] + mat4x3[3][0];
o.y = v.x * mat4x3[0][1] + v.y * mat4x3[1][1] + v.z * mat4x3[2][1] + mat4x3[3][1];
o.z = v.x * mat4x3[0][2] + v.y * mat4x3[1][2] + v.z * mat4x3[2][2] + mat4x3[3][2];
return o;
}
void MapBuffer(ID3D11Buffer* pStageBuffer, void** ppData, UINT* pByteWidth)
{
D3D11_MAPPED_SUBRESOURCE subRes;
HRESULT res = pContext->Map(pStageBuffer, 0, D3D11_MAP_READ, 0, &subRes);
D3D11_BUFFER_DESC desc;
pStageBuffer->GetDesc(&desc);
if (FAILED(res))
{
Log("Map stage buffer failed {%d} {%d} {%d} {%d} {%d}", (void*)pStageBuffer, desc.ByteWidth, desc.BindFlags,
desc.CPUAccessFlags, desc.Usage);
}
*ppData = subRes.pData;
if (pByteWidth)
*pByteWidth = desc.ByteWidth;
}
void UnmapBuffer(ID3D11Buffer* pStageBuffer)
{
pContext->Unmap(pStageBuffer, 0);
}
ID3D11Buffer* CopyBufferToCpu(ID3D11Buffer* pBuffer)
{
D3D11_BUFFER_DESC CBDesc;
pBuffer->GetDesc(&CBDesc);
ID3D11Buffer* pStageBuffer = NULL;
{
// create shadow buffer.
D3D11_BUFFER_DESC desc;
desc.BindFlags = 0;
desc.ByteWidth = CBDesc.ByteWidth;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.MiscFlags = 0;
desc.StructureByteStride = 0;
desc.Usage = D3D11_USAGE_STAGING;
if (FAILED(pDevice->CreateBuffer(&desc, NULL, &pStageBuffer)))
{
Log("CreateBuffer failed when CopyBufferToCpu {%d}", CBDesc.ByteWidth);
}
}
if (pStageBuffer != NULL)
pContext->CopyResource(pStageBuffer, pBuffer);
return pStageBuffer;
}
//w2s
int WorldViewCBnum = 2;
int ProjCBnum = 1;
int matProjnum = 16;
//Game WorldViewCBnum ProjCBnum matProjnum
//UT4 Alpha 2 1 16
//Fortnite 2 1 16
//Outlast 0 1 0 and 16
//Warframe 0 0 0 or 4
ID3D11Buffer* pWorldViewCB = nullptr;
ID3D11Buffer* pProjCB = nullptr;
ID3D11Buffer* m_pCurWorldViewCB = nullptr;
ID3D11Buffer* m_pCurProjCB = nullptr;
void AddModel(ID3D11DeviceContext* pContext)
{
//Warning, this is NOT optimized:
pContext->VSGetConstantBuffers(WorldViewCBnum, 1, &pWorldViewCB);//WorldViewCBnum
pContext->VSGetConstantBuffers(ProjCBnum, 1, &pProjCB);//ProjCBnum
if (pWorldViewCB == NULL)
{
SAFE_RELEASE(pWorldViewCB)
//return; here only if a game is crashing
}
if (pProjCB == NULL)
{
SAFE_RELEASE(pProjCB)
//return; here only if a game is crashing
}
//WORLDVIEW
if (pWorldViewCB != NULL)
m_pCurWorldViewCB = CopyBufferToCpu(pWorldViewCB);
SAFE_RELEASE(pWorldViewCB);
float matWorldView[4][4];
{
float* WorldViewCB;
MapBuffer(m_pCurWorldViewCB, (void**)&WorldViewCB, NULL);
memcpy(matWorldView, &WorldViewCB[0], sizeof(matWorldView));
matWorldView[3][2] = matWorldView[3][2] + (aimheight * 20); //aimheight can be done here for body parts
UnmapBuffer(m_pCurWorldViewCB);
SAFE_RELEASE(m_pCurWorldViewCB);
}
Vec3 v;
Vec4 vWorldView = Vec3MulMat4x4(v, matWorldView);
//PROJECTION
if (pProjCB != NULL)
m_pCurProjCB = CopyBufferToCpu(pProjCB);
SAFE_RELEASE(pProjCB);
float matProj[4][4];
{
float* pProjCB;
MapBuffer(m_pCurProjCB, (void**)&pProjCB, NULL);
memcpy(matProj, &pProjCB[matProjnum], sizeof(matProj));//matProjnum
UnmapBuffer(m_pCurProjCB);
SAFE_RELEASE(m_pCurProjCB);
}
Vec4 vWorldViewProj = Vec4MulMat4x4(vWorldView, matProj);
Vec2 o;
o.x = ScreenCenterX + ScreenCenterX * vWorldViewProj.x / vWorldViewProj.w;
o.y = ScreenCenterY + ScreenCenterY * -vWorldViewProj.y / vWorldViewProj.w;
}
//==========================================================================================================================