-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.cpp
More file actions
325 lines (286 loc) 路 9.8 KB
/
Copy pathcustom.cpp
File metadata and controls
325 lines (286 loc) 路 9.8 KB
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
/// @file
/// @brief Hand-written helpers: free engine functions and the convenience
/// member methods added onto the generated SDK types (accessors, name lookup, spawn).
#include "Engine.h"
using namespace Engine;
std::string FNameEntry::String()
{
if (bIsWide)
{
return std::string();
}
return {AnsiName, Len};
}
FNameEntry* FNamePool::GetEntry(FNameEntryHandle handle) const
{
return reinterpret_cast<FNameEntry*>(Blocks[handle.Block] + 2 * static_cast<uint64_t>(handle.Offset));
}
std::string FName::GetName()
{
auto entry = GNames->GetEntry(Index);
auto name = entry->String();
if (Number > 0)
{
name += '_' + std::to_string(Number);
}
auto pos = name.rfind('/');
if (pos != std::string::npos)
{
name = name.substr(pos + 1);
}
return name;
}
std::string UObject::GetName()
{
return NamePrivate.GetName();
}
std::string UObject::GetFullName()
{
std::string name;
for (auto outer = OuterPrivate; outer; outer = outer->OuterPrivate)
{
name = outer->GetName() + "." + name;
}
name = ClassPrivate->GetName() + " " + name + this->GetName();
return name;
}
bool UObject::IsA(void* cmp)
{
for (auto super = ClassPrivate; super; super = static_cast<UClass*>(super->SuperStruct))
{
if (super == cmp)
{
return true;
}
}
return false;
}
bool UObject::IsDefaultObject() const
{
return (ObjectFlags & 0x10) == 0x10;
}
UObject* TUObjectArray::GetObjectPtr(uint32_t id) const
{
if (id >= NumElements) return nullptr;
uint64_t chunkIndex = id / 65536;
if (chunkIndex >= NumChunks) return nullptr;
auto chunk = Objects[chunkIndex];
if (!chunk) return nullptr;
uint32_t withinChunkIndex = id % 65536 * 24;
auto item = *reinterpret_cast<UObject**>(chunk + withinChunkIndex);
return item;
}
UObject* TUObjectArray::FindObject(const char* name) const
{
for (auto i = 0u; i < NumElements; i++)
{
auto object = GetObjectPtr(i);
if (object && object->GetFullName() == name)
{
return object;
}
}
return nullptr;
}
void UObject::ProcessEvent(void* UFunction, void* Params)
{
auto vtable = *reinterpret_cast<void***>(this);
reinterpret_cast<void (*)(void*, void*, void*)>(vtable[68])(this, UFunction, Params);
}
UPortalWarsSaveGame* UPortalWarsLocalPlayer::GetUserSaveGame()
{
struct
{
UPortalWarsSaveGame* ReturnValue;
} Parameters;
static auto Function = GObjects->FindObject("Function PortalWars.PortalWarsLocalPlayer.GetUserSaveGame");
ProcessEvent(Function, &Parameters);
return Parameters.ReturnValue;
};
struct UEngine* UEngine::GetEngine()
{
static UEngine* GEngine = nullptr;
static UClass* EngineClass = Engine::StaticClass<UEngine>();
if (!GEngine)
{
for (auto i = 0u; i < GObjects->NumElements; i++)
{
auto object = GObjects->GetObjectPtr(i);
if (!object)
continue;
if (object->IsA(EngineClass) && !object->IsDefaultObject())
{
GEngine = static_cast<UEngine*>(object);
break;
}
}
}
return GEngine;
}
struct UWorld* UWorld::GetWorld()
{
UWorld* World = *(UWorld**)(GWorld);
return World;
}
struct APortalWarsPlayerController* UWorld::GetLocalPlayerController()
{
UGameInstance* gameInstance = OwningGameInstance;
if (!gameInstance) return nullptr;
TArray<ULocalPlayer*> localPlayers = gameInstance->LocalPlayers;
if (localPlayers.Num() <= 0) return nullptr;
auto* localPlayer = (UPortalWarsLocalPlayer*)localPlayers[0];
if (!localPlayer) return nullptr;
APlayerController* controller = localPlayer->PlayerController;
if (!controller) return nullptr;
return (APortalWarsPlayerController*)controller;
}
struct UInputSettings* UInputSettings::GetInputSettings()
{
auto Func = GObjects->FindObject("Function Engine.InputSettings.GetInputSettings");
struct
{
struct UInputSettings* ReturnValue;
} Parms;
UObject::ProcessEvent(Func, &Parms);
return Parms.ReturnValue;
};
USkeletalMeshComponent* ACharacterSkin::GetMesh3P()
{
static UObject* Function = nullptr;
if (!Function) Function = GObjects->FindObject("Function PortalWars.BaseCharacterSkin.GetMesh3P");
if (!Function) Function = GObjects->FindObject("Function PortalWars.CharacterSkin.GetMesh3P");
if (!Function) return nullptr;
struct
{
USkeletalMeshComponent* ReturnValue;
} Parameters{};
ProcessEvent(Function, &Parameters);
return Parameters.ReturnValue;
}
AActor* UGameplayStatics::BeginDeferredActorSpawnFromClass(UObject* WorldContextObject, UClass* ActorClass, FTransform SpawnTransform, ESpawnActorCollisionHandlingMethod CollisionHandlingOverride, AActor* Owner)
{
static auto Function = GObjects->FindObject("Function Engine.GameplayStatics.BeginDeferredActorSpawnFromClass");
if (!Function) return nullptr;
// Layout matches UE's param struct: FTransform (16-aligned) lands at 0x10 after the two
// pointers, the collision byte at 0x40, Owner at 0x48, ReturnValue at 0x50.
struct
{
UObject* WorldContextObject; // 0x00
UClass* ActorClass; // 0x08
FTransform SpawnTransform; // 0x10
ESpawnActorCollisionHandlingMethod CollisionHandling; // 0x40
AActor* Owner; // 0x48
AActor* ReturnValue; // 0x50
} Parameters;
Parameters.WorldContextObject = WorldContextObject;
Parameters.ActorClass = ActorClass;
Parameters.SpawnTransform = SpawnTransform;
Parameters.CollisionHandling = CollisionHandlingOverride;
Parameters.Owner = Owner;
ProcessEvent(Function, &Parameters);
return Parameters.ReturnValue;
}
AActor* UGameplayStatics::FinishSpawningActor(AActor* Actor, FTransform SpawnTransform)
{
static auto Function = GObjects->FindObject("Function Engine.GameplayStatics.FinishSpawningActor");
if (!Function) return nullptr;
// UE 16-aligns FTransform, so SpawnTransform sits at 0x10 (pad after Actor), ReturnValue at 0x40.
struct
{
AActor* Actor; // 0x00
char pad_08[0x8]; // 0x08
FTransform SpawnTransform; // 0x10
AActor* ReturnValue; // 0x40
} Parameters;
Parameters.Actor = Actor;
Parameters.SpawnTransform = SpawnTransform;
ProcessEvent(Function, &Parameters);
return Parameters.ReturnValue;
}
AActor* SpawnActor(UObject* worldContextObject, UClass* actorClass, FVector location, ESpawnActorCollisionHandlingMethod collision, AActor* owner)
{
auto* gameplayStatics = reinterpret_cast<UGameplayStatics*>(Engine::StaticClass<UGameplayStatics>());
if (!gameplayStatics || !actorClass) return nullptr;
FTransform transform{};
transform.Rotation = FQuat{0.f, 0.f, 0.f, 1.f};
transform.Translation = location;
transform.Scale3D = FVector{1.f, 1.f, 1.f};
AActor* deferred = gameplayStatics->BeginDeferredActorSpawnFromClass(worldContextObject, actorClass, transform, collision, owner);
if (!deferred) return nullptr;
return gameplayStatics->FinishSpawningActor(deferred, transform);
}
bool IsPostGameController(UObject* controller)
{
if (!controller) return false;
static UObject* postClass = nullptr;
if (!postClass) postClass = GObjects->FindObject("Class PortalWars.PortalWarsPostPlayerController");
return postClass && controller->IsA(postClass);
}
bool LineTraceVisible(UObject* worldContext, const FVector& start, const FVector& end, AActor* ignoreActor)
{
static auto Function = GObjects->FindObject("Function Engine.KismetSystemLibrary.LineTraceSingle");
static auto* library = reinterpret_cast<UObject*>(GObjects->FindObject("Class Engine.KismetSystemLibrary"));
if (!Function || !library || !worldContext) return true; // fail-open: never block callers if the probe can't run
// ActorsToIgnore is a real TArray<AActor*>; back it with a stack slot the trace only reads.
AActor* ignoreArr[1] = {ignoreActor};
// UKismetSystemLibrary::LineTraceSingle parameter block. The offsets are the engine's (verified
// by the static_asserts below); every member already lands on its natural alignment, so no
// packing pragma is needed. FHitResult (0x88) sits 8-aligned at 0x40.
struct Params
{
UObject* WorldContextObject; // 0x00
FVector Start; // 0x08
FVector End; // 0x14
uint8_t TraceChannel; // 0x20 ETraceTypeQuery (0 = Visibility)
bool bTraceComplex; // 0x21
char pad_22[6]; // 0x22
struct
{
void* Data;
int32_t Num;
int32_t Max;
} ActorsToIgnore; // 0x28 TArray<AActor*>
uint8_t DrawDebugType; // 0x38 EDrawDebugTrace (0 = None)
char pad_39[7]; // 0x39
FHitResult OutHit; // 0x40
bool bIgnoreSelf; // 0xC8
char pad_C9[3]; // 0xC9
FLinearColor TraceColor; // 0xCC
FLinearColor TraceHitColor; // 0xDC
float DrawTime; // 0xEC
bool ReturnValue; // 0xF0
} p{};
static_assert(offsetof(Params, ActorsToIgnore) == 0x28, "ActorsToIgnore offset");
static_assert(offsetof(Params, DrawDebugType) == 0x38, "DrawDebugType offset");
static_assert(offsetof(Params, OutHit) == 0x40, "OutHit offset");
static_assert(offsetof(Params, bIgnoreSelf) == 0xC8, "bIgnoreSelf offset");
static_assert(offsetof(Params, ReturnValue) == 0xF0, "ReturnValue offset");
p.WorldContextObject = worldContext;
p.Start = start;
p.End = end;
p.TraceChannel = 0; // Visibility
p.bTraceComplex = false;
p.ActorsToIgnore.Data = ignoreActor ? ignoreArr : nullptr;
p.ActorsToIgnore.Num = ignoreActor ? 1 : 0;
p.ActorsToIgnore.Max = ignoreActor ? 1 : 0;
p.DrawDebugType = 0; // None
p.bIgnoreSelf = true;
library->ProcessEvent(Function, &p);
// ReturnValue is bBlockingHit: with the target ignored, a blocking hit means something (a wall)
// stands between start and end, i.e. the point is occluded.
return !p.ReturnValue;
}
FVector USkeletalMeshComponent::GetBoneMatrix(int index)
{
auto GetBoneMatrix = reinterpret_cast<FMatrix* (*)(USkeletalMeshComponent*, FMatrix*, int)>(GetBoneMatrixFn);
FMatrix matrix;
GetBoneMatrix(this, &matrix, index);
return FVector({matrix.M[3][0], matrix.M[3][1], matrix.M[3][2]});
}
FVector2D USkeletalMeshComponent::GetBone(int index, APlayerController* PlayerController)
{
FVector WorldLocation = this->GetBoneMatrix(index);
FVector2D ScreenLocation;
if (PlayerController->ProjectWorldLocationToScreen(WorldLocation, ScreenLocation, false)) return ScreenLocation;
return {0, 0};
}