forked from ReClassNET/ReClass.NET-FrostbitePlugin
-
Notifications
You must be signed in to change notification settings - Fork 12
/
UnrealPluginExt.cs
191 lines (147 loc) · 5.9 KB
/
UnrealPluginExt.cs
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
using System;
using System.Text;
using ReClassNET;
using ReClassNET.Memory;
using ReClassNET.MemoryScanner;
using ReClassNET.Nodes;
using ReClassNET.Plugins;
using ReClassNET.Util;
using static System.IO.Path;
namespace UnrealPlugin
{
public class UnrealPluginExt : Plugin, INodeInfoReader
{
private IPluginHost host;
internal static Settings Settings;
private IntPtr gNames;
private IntPtr gObjects;
public override bool Initialize(IPluginHost host)
{
//System.Diagnostics.Debugger.Launch();
if (this.host != null)
{
Terminate();
}
this.host = host ?? throw new ArgumentNullException(nameof(host));
Settings = host.Settings;
// Register the InfoReader
host.RegisterNodeInfoReader(this);
// Register ProcessAttached handler
host.Process.ProcessAttached += OnProcessAttached;
return true;
}
private static IntPtr FindPattern(RemoteProcess process, Module module, string pattern)
{
// Read Module Bytes
var moduleBytes = process.ReadRemoteMemory(module.Start, module.Size.ToInt32());
// Parse Bytepattern
var bytePattern = BytePattern.Parse(pattern);
// Find Bytepattern in our copy
var limit = moduleBytes.Length - bytePattern.Length;
for (var i = 0; i < limit; ++i)
{
if (bytePattern.Equals(moduleBytes, i))
{
return module.Start + i;
}
}
return IntPtr.Zero;
}
private void OnProcessAttached(RemoteProcess process)
{
process.UpdateProcessInformations();
gNames = IntPtr.Zero;
gObjects = IntPtr.Zero;
var processName = GetFileName(process.UnderlayingProcess.Path).ToLower();
switch (processName)
{
// TODO: Add more games
case "tslgame.exe": // Playerunknown's Battlegrounds
case "fortniteclient-win64-shipping.exe": // Fortnite
{
var pattern = "48 89 1D ?? ?? ?? ?? 48 8B 5C 24 ?? 48 83 C4 28 C3 48 8B 5C 24 ?? 48 89 05 ?? ?? ?? ?? 48 83 C4 28 C3";
var address = FindPattern(process, process.GetModuleByName(processName), pattern);
if (!address.IsNull())
{
var offset = process.ReadRemoteInt32(address + 0x3);
gNames = process.ReadRemoteIntPtr(address + offset + 7);
}
pattern = "48 8D 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 8B D6 48 89 B5";
address = FindPattern(process, process.GetModuleByName(processName), pattern);
if (!address.IsNull())
{
var offset = process.ReadRemoteInt32(address + 0x3);
gObjects = address + offset + 7;
}
break;
}
}
}
public override void Terminate()
{
host.DeregisterNodeInfoReader(this);
}
public string ReadNodeInfo(BaseNode node, IntPtr nodeAddress, IntPtr nodeValue, MemoryBuffer memory)
{
if (IsUObject(nodeValue, memory))
{
return GetUObjectName(nodeValue, memory);
}
return null;
}
private bool IsUObject(IntPtr objectPtr, MemoryBuffer memory)
{
if (gObjects.IsNull())
{
return false;
}
var internalIndex = memory.Process.ReadRemoteInt32(objectPtr + IntPtr.Size + 0x4);
var numElements = memory.Process.ReadRemoteInt32(gObjects + 0x10 + IntPtr.Size + 0x4);
if (internalIndex < 0 || internalIndex >= numElements) return false;
var objects = memory.Process.ReadRemoteIntPtr(gObjects + 0x10);
#if RECLASSNET64
var objectPtrCheck = memory.Process.ReadRemoteIntPtr(objects + internalIndex * 0x18);
#else
var objectPtrCheck = memory.Process.ReadRemoteIntPtr(objects + internalIndex * 0x10);
#endif
bool result = objectPtr == objectPtrCheck;
return result;
}
private string GetUObjectName(IntPtr objectPtr, MemoryBuffer memory)
{
if (gNames.IsNull())
{
return null;
}
#if RECLASSNET64
var nameIndex = memory.Process.ReadRemoteInt32(objectPtr + 0x18);
#else
var nameIndex = memory.Process.ReadRemoteInt32(objectPtr + 0x10);
#endif
if (nameIndex < 1)
{
return null;
}
var numElements = memory.Process.ReadRemoteInt32(gNames + 0x80 * IntPtr.Size);
var numChunks = memory.Process.ReadRemoteInt32(gNames + 0x80 * IntPtr.Size + 0x4);
var indexChunk = nameIndex / 16384;
var indexName = nameIndex % 16384;
if (nameIndex < numElements && indexChunk < numChunks)
{
var chunkPtr = memory.Process.ReadRemoteIntPtr(gNames + indexChunk * IntPtr.Size);
if (chunkPtr.MayBeValid())
{
var namePtr = memory.Process.ReadRemoteIntPtr(chunkPtr + indexName * IntPtr.Size);
var nameEntryIndex = memory.Process.ReadRemoteInt32(namePtr);
if (nameEntryIndex >> 1 == nameIndex)
{
var wideChar = (nameEntryIndex & 1) != 0;
var name = memory.Process.ReadRemoteString(wideChar ? Encoding.Unicode : Encoding.ASCII, namePtr + 0x8 + IntPtr.Size, 1024);
return name;
}
}
}
return null;
}
}
}