forked from XIV-Tools/CustomizePlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddressService.cs
101 lines (80 loc) · 3.13 KB
/
AddressService.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
// © Anamnesis.
// Developed by W and A Walsh.
// Licensed under the MIT license.
namespace Anamnesis.Core.Memory
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Anamnesis.Memory;
using Serilog;
public class AddressService
{
// Static offsets
public static IntPtr ActorTable { get; private set; }
public static IntPtr TargetManager { get; private set; }
public static IntPtr GPoseActorTable { get; private set; }
public static IntPtr GPoseTargetManager { get; private set; }
public static IntPtr SkeletonFreezeScale { get; private set; }
public static IntPtr SkeletonFreezeScale2 { get; private set; }
public static IntPtr GposeCheck { get; private set; } // GPoseCheckOffset
public static IntPtr GposeCheck2 { get; private set; } // GPoseCheck2Offset
public static void Scan()
{
if (MemoryService.Process == null)
return;
if (MemoryService.Process.MainModule == null)
throw new Exception("Process has no main module");
Stopwatch sw = new Stopwatch();
sw.Start();
// Scan for all static addresses
// Some signatures taken from Dalamud: https://github.com/goatcorp/Dalamud/blob/master/Dalamud/Game/ClientState/ClientStateAddressResolver.cs
ActorTable = GetAddressFromSignature("48 8D 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 44 0F B6 83", 0);
TargetManager = GetAddressFromSignature("48 8B 05 ?? ?? ?? ?? 48 8D 0D ?? ?? ?? ?? FF 50 ?? 48 85 DB", 3) + 0x80;
SkeletonFreezeScale = GetAddressFromTextSignature("41 0F 29 44 12 20"); // SkeletonAddress4
SkeletonFreezeScale2 = GetAddressFromTextSignature("43 0F 29 44 18 20"); // SkeletonAddress6
// TODO: replace these manual CMTool offsets with signatures
IntPtr baseAddress = MemoryService.Process.MainModule.BaseAddress;
GPoseActorTable = baseAddress + 0x1DB9500; // GPoseEntityOffset
GPoseTargetManager = baseAddress + 0x1DB9500; // GPoseEntityOffset
GposeCheck = baseAddress + 0x1DBBD00;
GposeCheck2 = baseAddress + 0x1DBBCE0;
Log.Information($"Took {sw.ElapsedMilliseconds}ms to scan for addresses");
}
private static IntPtr GetAddressFromSignature(string signature, int offset)
{
if (MemoryService.Scanner == null)
throw new Exception("No memory scanner");
return MemoryService.Scanner.GetStaticAddressFromSig(signature, offset);
}
private static IntPtr GetAddressFromTextSignature(string signature)
{
if (MemoryService.Scanner == null)
throw new Exception("No memory scanner");
return MemoryService.Scanner.ScanText(signature);
}
private static Task GetBaseAddressFromSignature(string signature, int skip, bool moduleBase, Action<IntPtr> callback)
{
if (MemoryService.Scanner == null)
throw new Exception("No memory scanner");
return Task.Run(() =>
{
if (MemoryService.Process?.MainModule == null)
return;
IntPtr ptr = MemoryService.Scanner.ScanText(signature);
ptr += skip;
int offset = MemoryService.Read<int>(ptr);
if (moduleBase)
{
ptr = MemoryService.Process.MainModule.BaseAddress + offset;
}
else
{
ptr += offset + 4;
}
callback.Invoke(ptr);
});
}
}
}