-
Notifications
You must be signed in to change notification settings - Fork 8
/
Pointera.cs
80 lines (66 loc) · 2.43 KB
/
Pointera.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
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using MemoryLibrary;
namespace SekiroSpeedrunUtil.tracking {
internal class Pointera {
private IntPtr _basePtr;
private int[] _offsets;
private ObjectWrapper _object;
private Thread _listener;
private EThreadPriority _threadPriority;
public Pointera(ObjectWrapper obj, IntPtr basePtr, int[] offsets, EThreadPriority threadPriority = EThreadPriority.Normal) {
_object = obj;
_basePtr = basePtr;
_offsets = offsets;
_threadPriority = threadPriority;
_listener = new Thread(ListenerThread) {
IsBackground = true
};
_listener.Start();
}
public void ResetAddress(IntPtr basePtr, int[] offsets) {
_basePtr = basePtr;
_offsets = offsets;
}
private bool _paused = false;
private bool _stopped = false;
private void ListenerThread() {
while (!_stopped) {
if (_paused) {
Thread.Sleep((int)EThreadPriority.Normal);
continue;
}
Thread.Sleep((int)_threadPriority);
try {
var remoteProc = new RemoteProcess(Process.GetProcessesByName("Sekiro")[0]);
var addr = _basePtr;
if (_offsets.Length > 0) {
addr = _offsets.Aggregate(addr, (current, offset) => remoteProc.Read<IntPtr>(current) + offset);
}
object val = null;
if (_object.ObjType == typeof(byte)) {
val = remoteProc.Read<byte>(addr);
} else if (_object.ObjType == typeof(float)) {
val = remoteProc.Read<float>(addr);
}
_object.SetValue(val);
} catch (Exception e) {
//Debug.WriteLine("Thread exception");
}
}
Debug.WriteLine("Pointerthread stopped");
}
public void Pause() => _paused = true;
public void Stop() => _stopped = true;
public bool Alive() => _listener.IsAlive;
public enum EThreadPriority {
Low = 2000,
Normal = 1000,
High = 100,
Ultra = 10,
Stupid = 1
}
}
}