-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMemoryAccessor.cs
More file actions
187 lines (163 loc) · 5.5 KB
/
MemoryAccessor.cs
File metadata and controls
187 lines (163 loc) · 5.5 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
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
using Binarysharp.MemoryManagement;
using System;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
class MemoryAccessor
{
private static readonly string _ggprocname = ConfigurationManager.AppSettings.Get("GGProcessName");
private static MemorySharp _memorySharp;
public static Process process;
#region Pointers
public static readonly IntPtr _aswEnginePtr = new IntPtr(Convert.ToInt32(ConfigurationManager.AppSettings.Get("AswEnginePtr"), 16));
#endregion
#region Offsets
public static readonly int _p1Offset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Player1Offset"), 16);
public static readonly int _p2Offset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Player2Offset"), 16);
public static readonly int[] _pOffset = new int[2] { _p1Offset, _p2Offset };
public static readonly int _frameCountOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("FrameCountOffset"), 16);
public static readonly int _charIndexOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("CharIndexOffset"), 16);
public static readonly int _HPOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("HPOffset"), 16);
public static readonly int _DefenseModifierOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("DefenseModifierOffset"), 16);
public static readonly int _MeterOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("MeterOffset"), 16);
public static readonly int _RISCOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("RISCOffset"), 16);
public static readonly int _PositionXOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("PositionXOffset"), 16);
public static readonly int _PositionYOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("PositionYOffset"), 16);
public static readonly int _AnimStringOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("AnimStringOffset"), 16);
public static readonly int _StunOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("StunOffset"), 16);
public static readonly int _StunThresholdOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("StunThresholdOffset"), 16);
public static readonly int _BlockstunOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("BlockstunOffset"), 16);
public static readonly int _HitstunOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("HitstunOffset"), 16);
public static readonly int _HitstopOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("HitstopOffset"), 16);
public static readonly int _Flags0x4d3cOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Flags0x4d3cOffset"), 16);
public static readonly int _Flags0x4d48Offset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Flags0x4d48Offset"), 16);
public static readonly int _ForceDisableFlagsOffset = Convert.ToInt32(ConfigurationManager.AppSettings.Get("ForceDisableFlagsOffset"), 16);
#endregion
public static void AttachToProcess()
{
process = Process.GetProcessesByName(_ggprocname).FirstOrDefault();
if (process == null)
{
throw new Exception("GGxrd is not open.");
}
_memorySharp = new MemorySharp(process);
Player.setHashSets();
//Controller.getSticks();
}
public static IntPtr GetAswEnginePtr()
{
return _memorySharp[_aswEnginePtr].Read<IntPtr>();
}
public static int ReadInfoInt(ref Player player, int offset)
{
try
{
int integer;
try
{
integer = _memorySharp.Read<int>(player._playerPtr + offset, false);
}
catch (Win32Exception)
{
integer = 0;
}
return integer;
}
catch (ArgumentException)
{
Dispose();
}
return -1;
}
public static float ReadInfoFloat(ref Player player, int offset)
{
try
{
float floatnumber;
try
{
floatnumber = _memorySharp.Read<float>(player._playerPtr + offset, false);
}
catch (Win32Exception)
{
floatnumber = 0;
}
return floatnumber;
}
catch (ArgumentException)
{
Dispose();
}
return -1;
}
public static string ReadAnimationString(ref Player player)
{
try
{
string str;
try
{
str = _memorySharp.ReadString(player._playerPtr + _AnimStringOffset, false, 32);
}
catch (Win32Exception)
{
str = string.Empty;
}
return str;
}
catch (ArgumentException)
{
Dispose();
}
return string.Empty;
}
public static void WriteInfoInt(ref Player player, int offset, int value)
{
_memorySharp.Write<int>(player._playerPtr + offset, value, false);
}
public static int FrameCount()
{
try
{
IntPtr aswEngPtr = GetAswEnginePtr();
if ((int)aswEngPtr == 0)
{
return 0;
}
try
{
return _memorySharp.Read<int>(aswEngPtr + _frameCountOffset, false);
}
catch (Win32Exception)
{
return 0;
}
}
catch (System.ArgumentException)
{
Dispose();
return 0;
}
}
public static int ReadHitstop(ref Player player)
{
return ReadInfoInt(ref player, _HitstopOffset);
}
public static int ReadFlags0x4d3c(ref Player player)
{
return ReadInfoInt(ref player, _Flags0x4d3cOffset);
}
public static int ReadFlags0x4d48(ref Player player)
{
return ReadInfoInt(ref player, _Flags0x4d48Offset);
}
public static int ReadForceDisableFlags(ref Player player)
{
return ReadInfoInt(ref player, _ForceDisableFlagsOffset);
}
public static void Dispose()
{
_memorySharp?.Dispose();
}
}