-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFVector.h
267 lines (224 loc) · 5.01 KB
/
FVector.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
typedef struct {
float X, Y, Z;
} FVector;
typedef struct {
float X, Y;
} FVector2D;
typedef struct {
float Pitch;
float Yaw;
float Roll;
} FRotator;
typedef struct {
FVector Location;
FRotator Rotation;
float FOV;
float OrthoWidth;
float OrthoNearClipPlane;
float OrthoFarClipPlane;
float AspectRatio;
} FMinimalViewInfo;
typedef struct {
float M[4][4];
} FMatrix;
typedef struct {
FVector ViewOrigin;
char _padding_0[4];
FMatrix ViewRotationMatrix;
FMatrix ProjectionMatrix;
} FSceneViewProjectionData;
class UClass {
public:
BYTE _padding_0[0x40];
UClass* SuperClass;
};
class UObject {
public:
PVOID VTableObject;
DWORD ObjectFlags;
DWORD InternalIndex;
UClass* Class;
BYTE _padding_0[0x8];
UObject* Outer;
inline BOOLEAN IsA(PVOID parentClass) {
for (auto super = this->Class; super; super = super->SuperClass) {
if (super == parentClass) {
return TRUE;
}
}
return FALSE;
}
};
class FUObjectItem {
public:
UObject* Object;
DWORD Flags;
DWORD ClusterIndex;
DWORD SerialNumber;
DWORD SerialNumber2;
};
class TUObjectArray {
public:
FUObjectItem* Objects[9];
};
class GObjects {
public:
TUObjectArray* ObjectArray;
BYTE _padding_0[0xC];
DWORD ObjectCount;
};
template<class T>
struct TArray {
friend struct FString;
public:
inline TArray() {
Data = nullptr;
Count = Max = 0;
};
inline INT Num() const {
return Count;
};
inline T& operator[](INT i) {
return Data[i];
};
inline BOOLEAN IsValidIndex(INT i) {
return i < Num();
}
private:
T* Data;
INT Count;
INT Max;
};
struct FString : private TArray<WCHAR> {
FString() {
Data = nullptr;
Max = Count = 0;
}
FString(LPCWSTR other) {
Max = Count = static_cast<INT>(wcslen(other));
if (Count) {
Data = const_cast<PWCHAR>(other);
}
};
inline BOOLEAN IsValid() {
return Data != nullptr;
}
inline PWCHAR c_str() {
return Data;
}
};
VOID(*FreeInternal)(PVOID) = nullptr;
VOID Free(PVOID buffer) {
FreeInternal(buffer);
}
#pragma once
namespace detail
{
extern "C" void* _spoofer_stub();
template <typename Ret, typename... Args>
static inline auto shellcode_stub_helper(
const void* shell,
Args... args
) -> Ret
{
auto fn = (Ret(*)(Args...))(shell);
return fn(args...);
}
template <std::size_t Argc, typename>
struct argument_remapper
{
template<
typename Ret,
typename First,
typename Second,
typename Third,
typename Fourth,
typename... Pack
>
static auto do_call(const void* shell, void* shell_param, First first, Second second,
Third third, Fourth fourth, Pack... pack) -> Ret
{
return shellcode_stub_helper< Ret, First, Second, Third, Fourth, void*, void*, Pack... >(shell, first, second, third, fourth, shell_param, nullptr, pack...);
}
};
template <std::size_t Argc>
struct argument_remapper<Argc, std::enable_if_t<Argc <= 4>>
{
template<
typename Ret,
typename First = void*,
typename Second = void*,
typename Third = void*,
typename Fourth = void*
>
static auto do_call(
const void* shell,
void* shell_param,
First first = First{},
Second second = Second{},
Third third = Third{},
Fourth fourth = Fourth{}
) -> Ret
{
return shellcode_stub_helper<
Ret,
First,
Second,
Third,
Fourth,
void*,
void*
>(
shell,
first,
second,
third,
fourth,
shell_param,
nullptr
);
}
};
}
template <typename Ret, typename... Args>
static inline auto SpoofCall(Ret(*fn)(Args...), Args... args) -> Ret
{
static const void* jmprbx = nullptr;
if (!jmprbx) {
const auto ntdll = reinterpret_cast<const unsigned char*>(::GetModuleHandleW(NULL));
const auto dos = reinterpret_cast<const IMAGE_DOS_HEADER*>(ntdll);
const auto nt = reinterpret_cast<const IMAGE_NT_HEADERS*>(ntdll + dos->e_lfanew);
const auto sections = IMAGE_FIRST_SECTION(nt);
const auto num_sections = nt->FileHeader.NumberOfSections;
constexpr char section_name[5]{ '.', 't', 'e', 'x', 't' };
const auto section = std::find_if(sections, sections + num_sections, [&](const auto& s) {
return std::equal(s.Name, s.Name + 5, section_name);
});
constexpr unsigned char instr_bytes[2]{ 0xFF, 0x26 };
const auto va = ntdll + section->VirtualAddress;
jmprbx = std::search(va, va + section->Misc.VirtualSize, instr_bytes, instr_bytes + 2);
}
struct shell_params
{
const void* trampoline;
void* function;
void* rdx;
};
shell_params p
{
jmprbx,
reinterpret_cast<void*>(fn)
};
using mapper = detail::argument_remapper<sizeof...(Args), void>;
return mapper::template do_call<Ret, Args...>((const void*)&detail::_spoofer_stub, &p, args...);
}
namespace SpoofRuntime {
inline float acosf_(float x)
{
return SpoofCall(acosf, x);
}
inline float atan2f_(float x, float y)
{
return SpoofCall(atan2f, x, y);
}
}