-
Notifications
You must be signed in to change notification settings - Fork 1
/
Finder.cpp
197 lines (157 loc) · 5.89 KB
/
Finder.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
#include "pch.h"
#include "Finder.h"
GameObject* ObjectFinder::InternalFindChildInObject(GameObject* inObject, std::wstring_view childName)
{
GameObject* propertyObject = nullptr;
GameObject* next = inObject->GetNext();
if (next == nullptr) return nullptr;
auto firstPropertyName = UE4::GetFirstName(reinterpret_cast<FField*>(inObject));
//printf("\n firstPropertyName: %ls \n", firstPropertyName.c_str());
if (firstPropertyName == childName)
{
return inObject;
}
while (next)
{
std::wstring nextName = UE4::GetFirstName(reinterpret_cast<FField*>(next));
//printf("\n nextName: %ls \n", nextName.c_str());
if (childName == nextName)
{
propertyObject = next;
break;
}
else
{
next = next->GetNext();
}
}
return propertyObject;
}
GameObject*& ObjectFinder::resolveValuePointer(GameObject* bastePtr, GameObject* prop) const
{
//printf("\nObject: %ls, Offset: %x\n", GetObjectFirstName(reinterpret_cast<UObject*>(m_object)).c_str(), prop->GetOffsetInternal());
return *reinterpret_cast<GameObject**>(reinterpret_cast<uintptr_t>(m_object) + prop->GetOffsetInternal());
}
GameObject*& ObjectFinder::resolveArrayValuePointer(GameObject* bastePtr, GameObject* prop) const
{
return *reinterpret_cast<GameObject**>(*reinterpret_cast<GameObject**>(reinterpret_cast<uintptr_t>(m_object) + prop->GetOffsetInternal()));
}
ObjectFinder::ObjectFinder(const std::wstring& currentObject, const std::wstring objectType, GameObject* object, GameObject*& objectRef) :
m_currentObject(currentObject), m_objectType(objectType), m_object(object), m_objectRef(objectRef)
{
};
InternalUObject*& ObjectFinder::GetObj() const
{
return reinterpret_cast<InternalUObject*&>(m_objectRef);
}
ObjectFinder ObjectFinder::EntryPoint(uintptr_t EntryPointAddress)
{
return ObjectFinder{ L"EntryPoint", L"None", reinterpret_cast<GameObject*>(EntryPointAddress), reinterpret_cast<GameObject*&>(EntryPointAddress) };
}
ObjectFinder ObjectFinder::Find(const std::wstring& objectToFind) const
{
return FindChildObject(objectToFind);
}
int32_t ObjectFinder::FindOffset(const std::wstring& classToFind, const std::wstring& objectToFind)
{
auto Class = UE4::FindObject<InternalUClass*>(classToFind.c_str(), true);
if (Class)
{
GameObject* property = InternalFindChildInObject(reinterpret_cast<GameObject*>(Class->ChildProperties), objectToFind);
if (property)
{
//printf("[ObjectFinder] Found %ls at 0x%x", objectToFind.c_str(), property->GetOffsetInternal());
return property->GetOffsetInternal();
}
}
return 0;
}
ObjectFinder ObjectFinder::FindChildObject(const std::wstring& objectToFind) const
{
GameClass* classPrivate = m_object->GetClass();
GameObject* childProperties = classPrivate->GetChildProperties();
GameObject* propertyFound = nullptr;
if (childProperties)
{
propertyFound = InternalFindChildInObject(childProperties, objectToFind);
}
GameClass* superStruct = classPrivate->GetSuperStruct();
while (superStruct && !propertyFound)
{
childProperties = superStruct->GetChildProperties();
if (childProperties)
{
propertyFound = InternalFindChildInObject(childProperties, objectToFind);
if (propertyFound) break;
}
superStruct = superStruct->GetSuperStruct();
}
GameObject* valuePtr = resolveValuePointer(m_object, propertyFound);
const std::wstring type = UE4::GetFieldClassName(reinterpret_cast<FField*>(propertyFound));
if (type == XOR(L"ArrayProperty"))
{
//this will return the first element in the array
//TODO: recode this part
valuePtr = *reinterpret_cast<GameObject**>(valuePtr);
GameObject*& valuePtrRef = resolveArrayValuePointer(m_object, propertyFound);
return ObjectFinder(objectToFind, type, valuePtr, valuePtrRef);
}
else
{
GameObject*& valuePtrRef = resolveValuePointer(m_object, propertyFound);
return ObjectFinder(objectToFind, type, valuePtr, valuePtrRef);
}
}
InternalUObject* ObjectFinder::FindActor(std::wstring name, int toSkip)
{
ObjectFinder EngineFinder = EntryPoint(uintptr_t(GEngine));
ObjectFinder GameViewPortClientFinder = EngineFinder.Find(XOR(L"GameViewport"));
ObjectFinder WorldFinder = GameViewPortClientFinder.Find(XOR(L"World"));
ObjectFinder PersistentLevelFinder = WorldFinder.Find(XOR(L"PersistentLevel"));
const DWORD AActors = 0x98;
for (auto i = 0x00; i < READ_DWORD(PersistentLevelFinder.GetObj(), AActors + sizeof(void*)); i++)
{
auto Actors = READ_POINTER(PersistentLevelFinder.GetObj(), AActors);
auto pActor = static_cast<InternalUObject*>(READ_POINTER(Actors, i * sizeof(void*)));
if (pActor != nullptr)
{
//printf("\n[Actor %i] %ls, Class : %ls\n", i, GetObjectFullName(pActor).c_str(), GetObjectFullName(pActor->Class).c_str());
if (UE4::GetObjectFullName(pActor).starts_with(name))
{
if (toSkip > 0)
{
toSkip--;
}
else
{
printf("\n[NeoRoyale] %ls was found!.\n", name.c_str());
return pActor;
}
}
}
}
return nullptr;
}
void ObjectFinder::DestroyActor(std::wstring name)
{
ObjectFinder EngineFinder = EntryPoint(uintptr_t(GEngine));
ObjectFinder GameViewPortClientFinder = EngineFinder.Find(XOR(L"GameViewport"));
ObjectFinder WorldFinder = GameViewPortClientFinder.Find(XOR(L"World"));
ObjectFinder PersistentLevelFinder = WorldFinder.Find(XOR(L"PersistentLevel"));
const DWORD AActors = 0x98;
for (auto i = 0x00; i < READ_DWORD(PersistentLevelFinder.GetObj(), AActors + sizeof(void*)); i++)
{
auto Actors = READ_POINTER(PersistentLevelFinder.GetObj(), AActors);
auto pActor = static_cast<UObject*>(READ_POINTER(Actors, i * sizeof(void*)));
if (pActor != nullptr)
{
//printf("\n[Actor %i] %ls, Class : %ls\n", i, GetObjectFullName(pActor).c_str(), GetObjectFullName(pActor->Class).c_str());
/*if (UE4::GetObjectFullName(pActor).starts_with(name))
{
auto fn = UE4::FindObject<UFunction*>(XOR(L"Function /Script/Engine.Actor:K2_DestroyActor"));
ProcessEvent(pActor, fn, nullptr);
printf("\n[NeoRoyale] %ls was destroyed!.\n", name.c_str());
}*/
}
}
}