-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFreezerManager.cs
More file actions
64 lines (54 loc) · 1.7 KB
/
FreezerManager.cs
File metadata and controls
64 lines (54 loc) · 1.7 KB
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
namespace MemTools
{
public class FreezerManager
{
private readonly Dictionary<IntPtr, (object value, Type type)> Values = new();
private readonly Memory Mem;
private Thread FreezeThread;
private bool Running;
public FreezerManager(Memory mem)
{
Mem = mem;
}
public void Add<T>(IntPtr address, T value) where T : unmanaged
{
if(Values.ContainsKey(address))
return;
Values[address] = (value, typeof(T));
}
public void Remove(IntPtr address)
{
Values.Remove(address);
}
public void Start(int intervalMs = 50)
{
if(Running) return;
Running = true;
FreezeThread = new Thread(() =>
{
while(Running)
{
foreach(KeyValuePair<IntPtr, (object value, Type type)> kvp in Values)
{
IntPtr addr = kvp.Key;
(object value, Type type) = kvp.Value;
if(type == typeof(int))
Mem.Write(addr, (int)value);
else if(type == typeof(float))
Mem.Write(addr, (float)value);
else if(type == typeof(double))
Mem.Write(addr, (double)value);
}
Thread.Sleep(intervalMs);
}
})
{ IsBackground = true };
FreezeThread.Start();
}
public void Stop()
{
Running = false;
FreezeThread?.Join();
}
}
}