-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLabtool.cs
More file actions
223 lines (198 loc) · 7.55 KB
/
Labtool.cs
File metadata and controls
223 lines (198 loc) · 7.55 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using System;
using System.Runtime.InteropServices;
class Labtool
{
public Controller _controller = new Controller();
public KeyboardInput _keyboard = new KeyboardInput();
public Player _player1 = new Player();
public Player _player2 = new Player();
public class Framedata
{
public bool blockstring = false;
public int frameAdvantage;
public bool updateFA;
}
public class Gapdata
{
public bool updateGap = false;
public int idleCount = 0;
public int rememberGap;
}
#region Framedata
public Framedata f = new Framedata();
public Gapdata g1 = new Gapdata();
public Gapdata g2 = new Gapdata();
private void frameAdvantage(Framedata f, ref Player p1, ref Player p2)
{
bool p1idle = p1.IsCompletelyIdle();
bool p2idle = p2.IsCompletelyIdle();
if (!p1idle && !p2idle)
{
f.frameAdvantage = 0;
f.blockstring = true;
}
if ((p1idle || p2idle) && f.blockstring)
{
if (p1idle && p2idle)
{
f.blockstring = false;
f.updateFA = true;
}
if (!p1idle)
{
--f.frameAdvantage;
}
if (!p2idle)
{
++f.frameAdvantage;
}
}
}
private void gap(Gapdata g, ref Player opponent)
{
if (opponent.IsUnderAttack())
{
if (g.idleCount != -1)
{
if (g.idleCount <= 30)
{
g.rememberGap = g.idleCount + 1;
g.updateGap = true;
g.idleCount = 0;
}
g.idleCount = -1;
}
}
else
{
++g.idleCount;
}
}
#endregion
#region DataRefreshing
private int prevFrame = 0;
private int currFrame = 0;
public void updateFrameInfo()
{
do
{
timeBeginPeriod(1);
System.Threading.Thread.Sleep(1);
timeEndPeriod(1);
currFrame = MemoryAccessor.FrameCount();
}
while (currFrame == prevFrame);
IntPtr aswEngPtr = MemoryAccessor.GetAswEnginePtr();
if ((int)aswEngPtr == 0)
{
// match not currently running
System.Threading.Thread.Sleep(1000);
return;
}
_player1.assignPlayerPtr(aswEngPtr + MemoryAccessor._p1Offset);
_player2.assignPlayerPtr(aswEngPtr + MemoryAccessor._p2Offset);
_player1.characterIndex = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._charIndexOffset);
_player2.characterIndex = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._charIndexOffset);
_player1._isBlocking = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._BlockstunOffset) != 0;
_player2._isBlocking = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._BlockstunOffset) != 0;
_player1._isHit = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._HitstunOffset) != 0;
_player2._isHit = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._HitstunOffset) != 0;
_player1._currentAnim = MemoryAccessor.ReadAnimationString(ref _player1);
_player2._currentAnim = MemoryAccessor.ReadAnimationString(ref _player2);
_player1._hitstop = MemoryAccessor.ReadHitstop(ref _player1);
_player2._hitstop = MemoryAccessor.ReadHitstop(ref _player2);
_player1._flags0x4d3c = MemoryAccessor.ReadFlags0x4d3c(ref _player1);
_player2._flags0x4d3c = MemoryAccessor.ReadFlags0x4d3c(ref _player2);
_player1._flags0x4d48 = MemoryAccessor.ReadFlags0x4d48(ref _player1);
_player2._flags0x4d48 = MemoryAccessor.ReadFlags0x4d48(ref _player2);
_player1._forceDisableFlags = MemoryAccessor.ReadForceDisableFlags(ref _player1);
_player2._forceDisableFlags = MemoryAccessor.ReadForceDisableFlags(ref _player2);
frameAdvantage(f, ref _player1, ref _player2);
gap(g1, ref _player2);
gap(g2, ref _player1);
_player1._HP = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._HPOffset);
_player2._HP = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._HPOffset);
_player1._defenseModifier = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._DefenseModifierOffset);
_player2._defenseModifier = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._DefenseModifierOffset);
_player1._meter = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._MeterOffset);
_player2._meter = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._MeterOffset);
_player1._RISC = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._RISCOffset);
_player2._RISC = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._RISCOffset);
_player1._stun = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._StunOffset);
_player2._stun = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._StunOffset);
_player1._stunThreshold = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._StunThresholdOffset);
_player2._stunThreshold = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._StunThresholdOffset);
_player1._pos.x = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._PositionXOffset);
_player1._pos.y = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._PositionYOffset);
_player2._pos.x = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._PositionXOffset);
_player2._pos.y = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._PositionYOffset);
if (MemoryAccessor.FrameCount() - currFrame != 0)
{
Console.WriteLine("frame skipped");
}
prevFrame = currFrame;
}
#endregion
#region InputProcessing
Position savedPosP1 = new Position(-252000,0); //P1 roundstart position
Position savedPosP2 = new Position(252000, 0); //P2 roundstart position
public static bool processKeys = false;
public void macroButtons()
{
_keyboard.readKeys();
if (processKeys)
{
if (_keyboard._save)
{
savedPosP1.x = _player1._pos.x;
savedPosP1.y = _player1._pos.y;
savedPosP2.x = _player2._pos.x;
savedPosP2.y = _player2._pos.y;
}
else if (_keyboard._reset)
{
MemoryAccessor.WriteInfoInt(ref _player1, MemoryAccessor._PositionXOffset, savedPosP1.x);
MemoryAccessor.WriteInfoInt(ref _player1, MemoryAccessor._PositionYOffset, savedPosP1.y);
MemoryAccessor.WriteInfoInt(ref _player2, MemoryAccessor._PositionXOffset, savedPosP2.x);
MemoryAccessor.WriteInfoInt(ref _player2, MemoryAccessor._PositionYOffset, savedPosP2.y);
}
else if (_controller._isStickEnabled == true)
{
_controller.GetState();
/*
if (_controller._pressedButtons[6])
{
MemoryAccessor.WriteInfoInt(ref _player1, MemoryAccessor._PositionXOffset, savedPosP1.x);
MemoryAccessor.WriteInfoInt(ref _player1, MemoryAccessor._PositionYOffset, savedPosP1.y);
MemoryAccessor.WriteInfoInt(ref _player2, MemoryAccessor._PositionXOffset, savedPosP2.x);
MemoryAccessor.WriteInfoInt(ref _player2, MemoryAccessor._PositionYOffset, savedPosP2.y);
}
*/
}
}
}
#endregion
#region DLL Imports
[DllImport("winmm.dll")]
private static extern int timeBeginPeriod(uint uPeriod);
[DllImport("winmm.dll")]
private static extern int timeEndPeriod(uint uPeriod);
#endregion
}
/*
* TODO
* - Find Camera center
* - Fix display when playing as p2 (most probably, find real positions and/or which side they are facing at first)
* - Find dizzy thresholds and guts in memory
*
* DONE
* Positions are displayed (divided by 1000 for lisibility's sake)
* keyboard key "1" or joystick button 6 (select) do reset the positions you saved by using keyboard key "2". Custom buttons and keys implementation is planned.
* Consistency of framedata readings improved (the tool may be wrong once every twenty times now, and only by a frame)
* Using actual blockstun and hitstun values to compute gaps
* Dizzy renamed to Stun to avoid confusions with the playable character
* Stun values corrected: Johnny 7000, I-no 5500
*
* NOTES
* If stuck falling on the ground indefinitely because of the position reset, you can jump to go back to normal
*/