Skip to content

Commit 8aebdec

Browse files
committed
Merge commit '3ff7f98cb98922cdab711ff3e0cb6cea5cf0cd40'
2 parents 7ed1a0f + 3ff7f98 commit 8aebdec

File tree

7 files changed

+148
-146
lines changed

7 files changed

+148
-146
lines changed

MainForm.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,14 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
457457
if (form is SessionForm)
458458
sessionForms.Add(form as SessionForm);
459459

460-
while (sessionForms.Count > 0)
460+
int sessions = sessionForms.Count;
461+
bool doSaveQuestioning = true;
462+
if (sessions > 5)
463+
{
464+
doSaveQuestioning = MessageBox.Show("You've got " + sessions + " sessions open. Say 'Yes' if you want to get a question for each session, 'No' if you want to quit MapleShark.", "MapleShark", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes;
465+
}
466+
467+
while (doSaveQuestioning && sessionForms.Count > 0)
461468
{
462469
SessionForm ses = sessionForms[0];
463470
if (!ses.Saved)

MaplePacket.cs

+85-115
Original file line numberDiff line numberDiff line change
@@ -1,205 +1,175 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Text;
45
using System.Windows.Forms;
56

67
namespace MapleShark
78
{
89
public sealed class MaplePacket : ListViewItem
910
{
10-
private DateTime mTimestamp;
11-
private bool mOutbound;
12-
private ushort mBuild = 0;
13-
private ushort mLocale = 0;
14-
private ushort mOpcode = 0;
15-
private byte[] mBuffer = null;
16-
private int mCursor = 0;
11+
public DateTime Timestamp { get; private set; }
12+
public bool Outbound { get; private set; }
13+
public ushort Build { get; private set; }
14+
public ushort Locale { get; private set; }
15+
public ushort Opcode { get; private set; }
16+
public new string Name { set { SubItems[4].Text = value; } }
17+
18+
public byte[] Buffer { get; private set; }
19+
public int Cursor { get; private set; }
20+
public int Length { get { return Buffer.Length; } }
21+
public int Remaining { get { return Length - Cursor; } }
22+
public uint PreDecodeIV { get; private set; }
23+
public uint PostDecodeIV { get; private set; }
1724

18-
internal MaplePacket(DateTime pTimestamp, bool pOutbound, ushort pBuild, ushort pLocale, ushort pOpcode, string pName, byte[] pBuffer)
25+
internal MaplePacket(DateTime pTimestamp, bool pOutbound, ushort pBuild, ushort pLocale, ushort pOpcode, string pName, byte[] pBuffer, uint pPreDecodeIV, uint pPostDecodeIV)
1926
: base(new string[] {
2027
pTimestamp.ToString("yyyy-MM-dd HH:mm:ss.fff"),
2128
pOutbound ? "Outbound" : "Inbound",
2229
pBuffer.Length.ToString(),
2330
"0x" + pOpcode.ToString("X4"),
2431
pName })
2532
{
26-
mTimestamp = pTimestamp;
27-
mOutbound = pOutbound;
28-
mBuild = pBuild;
29-
mOpcode = pOpcode;
30-
mBuffer = pBuffer;
31-
mLocale = pLocale;
33+
Timestamp = pTimestamp;
34+
Outbound = pOutbound;
35+
Build = pBuild;
36+
Opcode = pOpcode;
37+
Buffer = pBuffer;
38+
Locale = pLocale;
39+
PreDecodeIV = pPreDecodeIV;
40+
PostDecodeIV = pPostDecodeIV;
3241
}
3342

34-
public DateTime Timestamp { get { return mTimestamp; } }
35-
public bool Outbound { get { return mOutbound; } }
36-
public ushort Build { get { return mBuild; } }
37-
public ushort Locale { get { return mLocale; } }
38-
public ushort Opcode { get { return mOpcode; } }
39-
public new string Name { set { SubItems[4].Text = value; } }
40-
41-
public byte[] InnerBuffer { get { return mBuffer; } }
42-
public int Cursor { get { return mCursor; } }
43-
public int Length { get { return mBuffer.Length; } }
44-
public int Remaining { get { return mBuffer.Length - mCursor; } }
45-
46-
public void Rewind() { mCursor = 0; }
43+
public void Rewind() { Cursor = 0; }
4744

4845
public bool ReadByte(out byte pValue)
4946
{
5047
pValue = 0;
51-
if (mCursor + 1 > mBuffer.Length) return false;
52-
pValue = mBuffer[mCursor++];
48+
if (Cursor + 1 > Length) return false;
49+
pValue = Buffer[Cursor++];
5350
return true;
5451
}
5552
public bool ReadSByte(out sbyte pValue)
5653
{
5754
pValue = 0;
58-
if (mCursor + 1 > mBuffer.Length) return false;
59-
pValue = (sbyte)mBuffer[mCursor++];
55+
if (Cursor + 1 > Length) return false;
56+
pValue = (sbyte)Buffer[Cursor++];
6057
return true;
6158
}
6259
public bool ReadUShort(out ushort pValue)
6360
{
6461
pValue = 0;
65-
if (mCursor + 2 > mBuffer.Length) return false;
66-
pValue = (ushort)(mBuffer[mCursor++] |
67-
mBuffer[mCursor++] << 8);
62+
if (Cursor + 2 > Length) return false;
63+
pValue = (ushort)(Buffer[Cursor++] |
64+
Buffer[Cursor++] << 8);
6865
return true;
6966
}
7067
public bool ReadShort(out short pValue)
7168
{
7269
pValue = 0;
73-
if (mCursor + 2 > mBuffer.Length) return false;
74-
pValue = (short)(mBuffer[mCursor++] |
75-
mBuffer[mCursor++] << 8);
70+
if (Cursor + 2 > Length) return false;
71+
pValue = (short)(Buffer[Cursor++] |
72+
Buffer[Cursor++] << 8);
7673
return true;
7774
}
7875
public bool ReadUInt(out uint pValue)
7976
{
8077
pValue = 0;
81-
if (mCursor + 4 > mBuffer.Length) return false;
82-
pValue = (uint)(mBuffer[mCursor++] |
83-
mBuffer[mCursor++] << 8 |
84-
mBuffer[mCursor++] << 16 |
85-
mBuffer[mCursor++] << 24);
78+
if (Cursor + 4 > Length) return false;
79+
pValue = (uint)(Buffer[Cursor++] |
80+
Buffer[Cursor++] << 8 |
81+
Buffer[Cursor++] << 16 |
82+
Buffer[Cursor++] << 24);
8683
return true;
8784
}
8885
public bool ReadInt(out int pValue)
8986
{
9087
pValue = 0;
91-
if (mCursor + 4 > mBuffer.Length) return false;
92-
pValue = (int)(mBuffer[mCursor++] |
93-
mBuffer[mCursor++] << 8 |
94-
mBuffer[mCursor++] << 16 |
95-
mBuffer[mCursor++] << 24);
88+
if (Cursor + 4 > Length) return false;
89+
pValue = (int)(Buffer[Cursor++] |
90+
Buffer[Cursor++] << 8 |
91+
Buffer[Cursor++] << 16 |
92+
Buffer[Cursor++] << 24);
9693
return true;
9794
}
9895
public bool ReadFloat(out float pValue)
9996
{
10097
pValue = 0;
101-
if (mCursor + 4 > mBuffer.Length) return false;
102-
pValue = BitConverter.ToSingle(mBuffer, mCursor);
103-
mCursor += 4;
98+
if (Cursor + 4 > Length) return false;
99+
pValue = BitConverter.ToSingle(Buffer, Cursor);
100+
Cursor += 4;
104101
return true;
105102
}
106103
public bool ReadULong(out ulong pValue)
107104
{
108105
pValue = 0;
109-
if (mCursor + 8 > mBuffer.Length) return false;
110-
pValue = (ulong)(mBuffer[mCursor++] |
111-
mBuffer[mCursor++] << 8 |
112-
mBuffer[mCursor++] << 16 |
113-
mBuffer[mCursor++] << 24 |
114-
mBuffer[mCursor++] << 32 |
115-
mBuffer[mCursor++] << 40 |
116-
mBuffer[mCursor++] << 48 |
117-
mBuffer[mCursor++] << 56);
106+
if (Cursor + 8 > Length) return false;
107+
pValue = (ulong)(Buffer[Cursor++] |
108+
Buffer[Cursor++] << 8 |
109+
Buffer[Cursor++] << 16 |
110+
Buffer[Cursor++] << 24 |
111+
Buffer[Cursor++] << 32 |
112+
Buffer[Cursor++] << 40 |
113+
Buffer[Cursor++] << 48 |
114+
Buffer[Cursor++] << 56);
118115
return true;
119116
}
120117
public bool ReadLong(out long pValue)
121118
{
122119
pValue = 0;
123-
if (mCursor + 8 > mBuffer.Length) return false;
124-
pValue = (long)(mBuffer[mCursor++] |
125-
mBuffer[mCursor++] << 8 |
126-
mBuffer[mCursor++] << 16 |
127-
mBuffer[mCursor++] << 24 |
128-
mBuffer[mCursor++] << 32 |
129-
mBuffer[mCursor++] << 40 |
130-
mBuffer[mCursor++] << 48 |
131-
mBuffer[mCursor++] << 56);
120+
if (Cursor + 8 > Length) return false;
121+
pValue = (long)(Buffer[Cursor++] |
122+
Buffer[Cursor++] << 8 |
123+
Buffer[Cursor++] << 16 |
124+
Buffer[Cursor++] << 24 |
125+
Buffer[Cursor++] << 32 |
126+
Buffer[Cursor++] << 40 |
127+
Buffer[Cursor++] << 48 |
128+
Buffer[Cursor++] << 56);
132129
return true;
133130
}
134131
public bool ReadFlippedLong(out long pValue) // 5 6 7 8 1 2 3 4
135132
{
136133
pValue = 0;
137-
if (mCursor + 8 > mBuffer.Length) return false;
134+
if (Cursor + 8 > Length) return false;
138135
pValue = (long)(
139-
mBuffer[mCursor++] << 32 |
140-
mBuffer[mCursor++] << 40 |
141-
mBuffer[mCursor++] << 48 |
142-
mBuffer[mCursor++] << 56 |
143-
mBuffer[mCursor++] |
144-
mBuffer[mCursor++] << 8 |
145-
mBuffer[mCursor++] << 16 |
146-
mBuffer[mCursor++] << 24);
136+
Buffer[Cursor++] << 32 |
137+
Buffer[Cursor++] << 40 |
138+
Buffer[Cursor++] << 48 |
139+
Buffer[Cursor++] << 56 |
140+
Buffer[Cursor++] |
141+
Buffer[Cursor++] << 8 |
142+
Buffer[Cursor++] << 16 |
143+
Buffer[Cursor++] << 24);
147144
return true;
148145
}
149146
public bool ReadDouble(out double pValue)
150147
{
151148
pValue = 0;
152-
if (mCursor + 8 > mBuffer.Length) return false;
153-
pValue = BitConverter.ToDouble(mBuffer, mCursor);
154-
mCursor += 8;
149+
if (Cursor + 8 > Length) return false;
150+
pValue = BitConverter.ToDouble(Buffer, Cursor);
151+
Cursor += 8;
155152
return true;
156153
}
157154
public bool ReadBytes(byte[] pBytes) { return ReadBytes(pBytes, 0, pBytes.Length); }
158155
public bool ReadBytes(byte[] pBytes, int pStart, int pLength)
159156
{
160-
if (mCursor + pLength > mBuffer.Length) return false;
161-
Buffer.BlockCopy(mBuffer, mCursor, pBytes, pStart, pLength);
162-
mCursor += pLength;
157+
if (Cursor + pLength > Length) return false;
158+
159+
System.Buffer.BlockCopy(Buffer, Cursor, pBytes, pStart, pLength);
160+
Cursor += pLength;
163161
return true;
164162
}
165163

166164
public bool ReadPaddedString(out string pValue, int pLength)
167165
{
168166
pValue = "";
169-
if (mCursor + pLength > mBuffer.Length) return false;
167+
if (Cursor + pLength > Length) return false;
170168
int length = 0;
171-
while (length < pLength && mBuffer[mCursor + length] != 0x00) ++length;
172-
if (length > 0) pValue = Encoding.ASCII.GetString(mBuffer, mCursor, length);
173-
mCursor += pLength;
169+
while (length < pLength && Buffer[Cursor + length] != 0x00) ++length;
170+
if (length > 0) pValue = Encoding.ASCII.GetString(Buffer, Cursor, length);
171+
Cursor += pLength;
174172
return true;
175173
}
176-
177-
public byte[] Dump()
178-
{
179-
byte[] buffer = new byte[mBuffer.Length + 13];
180-
ushort size = (ushort)(mBuffer.Length);
181-
182-
long ticks = mTimestamp.Ticks;
183-
buffer[0] = (byte)ticks;
184-
buffer[1] = (byte)(ticks >> 8);
185-
buffer[2] = (byte)(ticks >> 16);
186-
buffer[3] = (byte)(ticks >> 24);
187-
buffer[4] = (byte)(ticks >> 32);
188-
buffer[5] = (byte)(ticks >> 40);
189-
buffer[6] = (byte)(ticks >> 48);
190-
buffer[7] = (byte)(ticks >> 56);
191-
192-
buffer[8] = (byte)size;
193-
buffer[9] = (byte)(size >> 8);
194-
195-
buffer[10] = (byte)mOpcode;
196-
buffer[11] = (byte)(mOpcode >> 8);
197-
198-
buffer[12] = mOutbound ? (byte)1 : (byte)0;
199-
200-
Buffer.BlockCopy(mBuffer, 0, buffer, 13, mBuffer.Length);
201-
202-
return buffer;
203-
}
204174
}
205175
}

MapleStream.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ public MaplePacket Read(DateTime pTransmitted, ushort pBuild, byte pLocale)
9999
byte[] packetBuffer = new byte[packetSize];
100100
Buffer.BlockCopy(mBuffer, 4, packetBuffer, 0, packetSize);
101101

102+
var preDecodeIV = BitConverter.ToUInt32(mAES.mIV, 0);
103+
102104
Decrypt(packetBuffer, pBuild, pLocale, _transformMethod);
103105

106+
var postDecodeIV = BitConverter.ToUInt32(mAES.mIV, 0);
107+
104108
mCursor -= (packetSize + 4);
105109
if (mCursor > 0) Buffer.BlockCopy(mBuffer, packetSize + 4, mBuffer, 0, mCursor);
106110
ushort opcode;
@@ -119,7 +123,7 @@ public MaplePacket Read(DateTime pTransmitted, ushort pBuild, byte pLocale)
119123
}
120124

121125
Definition definition = Config.Instance.GetDefinition(pBuild, pLocale, mOutbound, opcode);
122-
return new MaplePacket(pTransmitted, mOutbound, pBuild, pLocale, opcode, definition == null ? "" : definition.Name, packetBuffer);
126+
return new MaplePacket(pTransmitted, mOutbound, pBuild, pLocale, opcode, definition == null ? "" : definition.Name, packetBuffer, preDecodeIV, postDecodeIV);
123127
}
124128

125129
private void Decrypt(byte[] pBuffer, ushort pBuild, byte pLocale, TransformMethod pTransformLocale)

Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.0.2.4")]
36-
[assembly: AssemblyFileVersion("2.0.2.4")]
35+
[assembly: AssemblyVersion("2.0.2.5")]
36+
[assembly: AssemblyFileVersion("2.0.2.5")]

SearchForm.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ private void NextSequence()
9898
MaplePacket packet = session.ListView.Items[index] as MaplePacket;
9999
long searchIndex = startIndex + 1;
100100
bool found = false;
101-
while (searchIndex <= packet.InnerBuffer.Length - pattern.Length)
101+
while (searchIndex <= packet.Buffer.Length - pattern.Length)
102102
{
103103
found = true;
104-
for (int patternIndex = 0; found && patternIndex < pattern.Length; ++patternIndex) found = packet.InnerBuffer[searchIndex + patternIndex] == pattern[patternIndex];
104+
for (int patternIndex = 0; found && patternIndex < pattern.Length; ++patternIndex) found = packet.Buffer[searchIndex + patternIndex] == pattern[patternIndex];
105105
if (found) break;
106106
++searchIndex;
107107
}

0 commit comments

Comments
 (0)