forked from ReClassNET/ReClass.NET-FrostbitePlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrostBiteNodeInfoReader.cs
82 lines (76 loc) · 2.04 KB
/
FrostBiteNodeInfoReader.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
using System;
using System.Text;
using ReClassNET.Extensions;
using ReClassNET.Memory;
using ReClassNET.Nodes;
namespace FrostbitePlugin
{
/// <summary>A custom node info reader which outputs Frostbite type infos.</summary>
public class FrostBiteNodeInfoReader : INodeInfoReader
{
public string ReadNodeInfo(BaseHexCommentNode node, IRemoteMemoryReader reader, MemoryBuffer memory, IntPtr nodeAddress, IntPtr nodeValue)
{
// 1. try the direct value
var info = ReadPtrInfo(nodeValue, reader);
if (!string.IsNullOrEmpty(info))
{
return info;
}
// 2. try indirect pointer
var indirectPtr = reader.ReadRemoteIntPtr(nodeValue);
if (indirectPtr.MayBeValid())
{
info = ReadPtrInfo(indirectPtr, reader);
if (!string.IsNullOrEmpty(info))
{
return $"Ptr -> {info}";
}
// 3. try weak pointer
var weakTempPtr = indirectPtr - IntPtr.Size;
if (weakTempPtr.MayBeValid())
{
var weakPtr = reader.ReadRemoteIntPtr(weakTempPtr);
if (weakPtr.MayBeValid())
{
info = ReadPtrInfo(weakPtr, reader);
if (!string.IsNullOrEmpty(info))
{
return $"WeakPtr -> {info}";
}
}
}
}
return null;
}
private static string ReadPtrInfo(IntPtr value, IRemoteMemoryReader process)
{
var getTypeFnPtr = process.ReadRemoteIntPtr(value);
if (getTypeFnPtr.MayBeValid())
{
#if RECLASSNET64
var offset = process.ReadRemoteInt32(getTypeFnPtr + 3);
var typeInfoPtr = getTypeFnPtr + offset + 7;
#else
var typeInfoPtr = process.ReadRemoteIntPtr(getTypeFnPtr + 1);
#endif
if (typeInfoPtr.MayBeValid())
{
var typeInfoDataPtr = process.ReadRemoteIntPtr(typeInfoPtr);
if (typeInfoDataPtr.MayBeValid())
{
var namePtr = process.ReadRemoteIntPtr(typeInfoDataPtr);
if (namePtr.MayBeValid())
{
var info = process.ReadRemoteStringUntilFirstNullCharacter(namePtr, Encoding.UTF8, 64);
if (info.Length > 0 && info[0].IsPrintable())
{
return info;
}
}
}
}
}
return null;
}
}
}