-
Notifications
You must be signed in to change notification settings - Fork 7
/
win_utils.h
261 lines (196 loc) · 6.39 KB
/
win_utils.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
#pragma once
#include <windows.h>
#include <winternl.h>
#include <process.h>
#include <tlhelp32.h>
#include <inttypes.h>
#include <iostream>
#include <stdexcept>
#include <vector>
#include <algorithm>
#include <chrono>
#include <sstream>
#include <d3d9.h>
#pragma comment (lib, "d3d9.lib")
#include "Imgui/imgui.h"
#include "Imgui/imgui_impl_dx9.h"
#include "Imgui/imgui_impl_win32.h"
#include "defs.h"
HANDLE DriverHandle;
uint64_t base_address;
HWND hwnd = NULL;
DWORD processID;
std::string SwapHook = "Hook64";
int Width;
int Height;
int Depth;
#define M_PI 3.14159265358979323846264338327950288419716939937510
#define ctl_write CTL_CODE(FILE_DEVICE_UNKNOWN, 0x0569, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
#define ctl_read CTL_CODE(FILE_DEVICE_UNKNOWN, 0x0567, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
#define ctl_base CTL_CODE(FILE_DEVICE_UNKNOWN, 0x0568, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
typedef struct info_t {
int pid = 0;
DWORD_PTR address;
void* value;
SIZE_T size;
void* data;
} info, * p_info;
std::string swapCaller = ".exe";
template <typename Type>
Type read(void* DriverHandle, unsigned long int Process_Identifier, unsigned long long int Address)
{
info_t Input_Output_Data;
Input_Output_Data.pid = Process_Identifier;
Input_Output_Data.address = Address;
Type Return_Value;
Input_Output_Data.value = &Return_Value;
Input_Output_Data.size = sizeof(Type);
unsigned long int Readed_Bytes_Amount;
DeviceIoControl(DriverHandle, ctl_read, &Input_Output_Data, sizeof Input_Output_Data, &Input_Output_Data, sizeof Input_Output_Data, &Readed_Bytes_Amount, nullptr);
return *(Type*)&Return_Value;
}
void writefloat(unsigned long long int Address, float stuff)
{
info_t Input_Output_Data;
Input_Output_Data.pid = processID;
Input_Output_Data.address = Address;
Input_Output_Data.value = &stuff;
Input_Output_Data.size = sizeof(float);
unsigned long int Readed_Bytes_Amount;
DeviceIoControl(DriverHandle, ctl_write, &Input_Output_Data, sizeof Input_Output_Data, &Input_Output_Data, sizeof Input_Output_Data, &Readed_Bytes_Amount, nullptr);
}
void writedouble(unsigned long long int Address, double stuff)
{
info_t Input_Output_Data;
Input_Output_Data.pid = processID;
Input_Output_Data.address = Address;
Input_Output_Data.value = &stuff;
Input_Output_Data.size = sizeof(double);
unsigned long int Readed_Bytes_Amount;
DeviceIoControl(DriverHandle, ctl_write, &Input_Output_Data, sizeof Input_Output_Data, &Input_Output_Data, sizeof Input_Output_Data, &Readed_Bytes_Amount, nullptr);
}
class Vector3
{
public:
Vector3() : x(0.f), y(0.f), z(0.f)
{
}
Vector3(float _x, float _y, float _z) : x(_x), y(_y), z(_z)
{
}
~Vector3()
{
}
float x;
float y;
float z;
inline float Dot(Vector3 v)
{
return x * v.x + y * v.y + z * v.z;
}
inline float Distance(Vector3 v)
{
return float(sqrtf(powf(v.x - x, 2.0) + powf(v.y - y, 2.0) + powf(v.z - z, 2.0)));
}
inline double Length() {
return sqrt(x * x + y * y + z * z);
}
//inline FRotator ToFRotator() {
//}
Vector3 operator+(Vector3 v)
{
return Vector3(x + v.x, y + v.y, z + v.z);
}
Vector3 operator-(Vector3 v)
{
return Vector3(x - v.x, y - v.y, z - v.z);
}
Vector3 operator*(float flNum) { return Vector3(x * flNum, y * flNum, z * flNum); }
};
struct FQuat
{
float x;
float y;
float z;
float w;
};
struct FTransform
{
FQuat rot;
Vector3 translation;
char pad[4];
Vector3 scale;
char pad1[4];
D3DMATRIX ToMatrixWithScale()
{
D3DMATRIX m;
m._41 = translation.x;
m._42 = translation.y;
m._43 = translation.z;
float x2 = rot.x + rot.x;
float y2 = rot.y + rot.y;
float z2 = rot.z + rot.z;
float xx2 = rot.x * x2;
float yy2 = rot.y * y2;
float zz2 = rot.z * z2;
m._11 = (1.0f - (yy2 + zz2)) * scale.x;
m._22 = (1.0f - (xx2 + zz2)) * scale.y;
m._33 = (1.0f - (xx2 + yy2)) * scale.z;
float yz2 = rot.y * z2;
float wx2 = rot.w * x2;
m._32 = (yz2 - wx2) * scale.z;
m._23 = (yz2 + wx2) * scale.y;
float xy2 = rot.x * y2;
float wz2 = rot.w * z2;
m._21 = (xy2 - wz2) * scale.y;
m._12 = (xy2 + wz2) * scale.x;
float xz2 = rot.x * z2;
float wy2 = rot.w * y2;
m._31 = (xz2 + wy2) * scale.z;
m._13 = (xz2 - wy2) * scale.x;
m._14 = 0.0f;
m._24 = 0.0f;
m._34 = 0.0f;
m._44 = 1.0f;
return m;
}
};
D3DMATRIX MatrixMultiplication(D3DMATRIX pM1, D3DMATRIX pM2)
{
D3DMATRIX pOut;
pOut._11 = pM1._11 * pM2._11 + pM1._12 * pM2._21 + pM1._13 * pM2._31 + pM1._14 * pM2._41;
pOut._12 = pM1._11 * pM2._12 + pM1._12 * pM2._22 + pM1._13 * pM2._32 + pM1._14 * pM2._42;
pOut._13 = pM1._11 * pM2._13 + pM1._12 * pM2._23 + pM1._13 * pM2._33 + pM1._14 * pM2._43;
pOut._14 = pM1._11 * pM2._14 + pM1._12 * pM2._24 + pM1._13 * pM2._34 + pM1._14 * pM2._44;
pOut._21 = pM1._21 * pM2._11 + pM1._22 * pM2._21 + pM1._23 * pM2._31 + pM1._24 * pM2._41;
pOut._22 = pM1._21 * pM2._12 + pM1._22 * pM2._22 + pM1._23 * pM2._32 + pM1._24 * pM2._42;
pOut._23 = pM1._21 * pM2._13 + pM1._22 * pM2._23 + pM1._23 * pM2._33 + pM1._24 * pM2._43;
pOut._24 = pM1._21 * pM2._14 + pM1._22 * pM2._24 + pM1._23 * pM2._34 + pM1._24 * pM2._44;
pOut._31 = pM1._31 * pM2._11 + pM1._32 * pM2._21 + pM1._33 * pM2._31 + pM1._34 * pM2._41;
pOut._32 = pM1._31 * pM2._12 + pM1._32 * pM2._22 + pM1._33 * pM2._32 + pM1._34 * pM2._42;
pOut._33 = pM1._31 * pM2._13 + pM1._32 * pM2._23 + pM1._33 * pM2._33 + pM1._34 * pM2._43;
pOut._34 = pM1._31 * pM2._14 + pM1._32 * pM2._24 + pM1._33 * pM2._34 + pM1._34 * pM2._44;
pOut._41 = pM1._41 * pM2._11 + pM1._42 * pM2._21 + pM1._43 * pM2._31 + pM1._44 * pM2._41;
pOut._42 = pM1._41 * pM2._12 + pM1._42 * pM2._22 + pM1._43 * pM2._32 + pM1._44 * pM2._42;
pOut._43 = pM1._41 * pM2._13 + pM1._42 * pM2._23 + pM1._43 * pM2._33 + pM1._44 * pM2._43;
pOut._44 = pM1._41 * pM2._14 + pM1._42 * pM2._24 + pM1._43 * pM2._34 + pM1._44 * pM2._44;
return pOut;
}
LPCWSTR locxof = L"C:\\Windows\\INF\\Hook64.exe";
std::string string_To_UTF8(const std::string& str)
{
int nwLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
wchar_t* pwBuf = new wchar_t[nwLen + 1];
ZeroMemory(pwBuf, nwLen * 2 + 2);
::MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), pwBuf, nwLen);
int nLen = ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL);
char* pBuf = new char[nLen + 1];
ZeroMemory(pBuf, nLen + 1);
::WideCharToMultiByte(CP_UTF8, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL);
std::string retStr(pBuf);
delete[]pwBuf;
delete[]pBuf;
pwBuf = NULL;
pBuf = NULL;
return retStr;
}