-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSessionForm.cs
662 lines (597 loc) · 28.9 KB
/
SessionForm.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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
using ScriptNET;
using PacketDotNet;
using PacketDotNet.Utils;
using PacketDotNet.LLDP;
using SharpPcap;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using MapleLib.PacketLib;
namespace MapleShark
{
public partial class SessionForm : DockContent
{
public enum Results
{
Continue,
Terminated,
CloseMe
}
private string mFilename = null;
private bool mTerminated = false;
//private bool mSavedAfterTermination = false;
private ushort mLocalPort = 0;
private ushort mRemotePort = 0;
private uint mOutboundSequence = 0;
private uint mInboundSequence = 0;
private ushort mBuild = 0;
private byte mLocale = 0;
private string mPatchLocation = "";
private bool isFirstPacket = true;
private byte[] inboundBuffer = {};
private byte[] outboundBuffer = {};
private byte[] curInboundIV = {};
private byte[] curOutboundIV = {};
private Dictionary<uint, byte[]> mOutboundBuffer = new Dictionary<uint, byte[]>();
private Dictionary<uint, byte[]> mInboundBuffer = new Dictionary<uint, byte[]>();
private MapleStream mOutboundStream = null;
private MapleStream mInboundStream = null;
private List<MaplePacket> mPackets = new List<MaplePacket>();
private List<Pair<bool, ushort>> mOpcodes = new List<Pair<bool, ushort>>();
private string mRemoteEndpoint = "???";
private string mLocalEndpoint = "???";
internal SessionForm()
{
InitializeComponent();
}
public MainForm MainForm { get { return ParentForm as MainForm; } }
public ListView ListView { get { return mPacketList; } }
public ushort Build { get { return mBuild; } }
public ushort Locale { get { return mLocale; } }
public List<Pair<bool, ushort>> Opcodes { get { return mOpcodes; } }
private DateTime startTime;
public void UpdateOpcodeList()
{
mOpcodes = mOpcodes.OrderBy(a => a.Second).ToList();
}
internal bool MatchTCPPacket(TcpPacket pTCPPacket)
{
if (mTerminated) return false;
if (pTCPPacket.SourcePort == mLocalPort && pTCPPacket.DestinationPort == mRemotePort) return true;
if (pTCPPacket.SourcePort == mRemotePort && pTCPPacket.DestinationPort == mLocalPort) return true;
return false;
}
internal bool CloseMe(DateTime pTime)
{
if (mPackets.Count == 0 && (pTime - startTime).TotalSeconds >= 5)
{
return true;
}
return false;
}
internal Results BufferTCPPacket(TcpPacket pTCPPacket, DateTime pArrivalTime)
{
if (pTCPPacket.Fin || pTCPPacket.Rst)
{
mTerminated = true;
Text += " (Terminated)";
if (mPackets.Count == 0)
{
// fuck
return Results.CloseMe;
}
else
{
return Results.Terminated;
}
}
if (pTCPPacket.Syn && !pTCPPacket.Ack)
{
mLocalPort = (ushort)pTCPPacket.SourcePort;
mRemotePort = (ushort)pTCPPacket.DestinationPort;
mOutboundSequence = (uint)(pTCPPacket.SequenceNumber + 1);
Text = "Port " + mLocalPort.ToString();
startTime = DateTime.Now;
mRemoteEndpoint = ((PacketDotNet.IPv4Packet)pTCPPacket.ParentPacket).SourceAddress.ToString() + ":" + pTCPPacket.SourcePort.ToString();
mLocalEndpoint = ((PacketDotNet.IPv4Packet)pTCPPacket.ParentPacket).DestinationAddress.ToString() + ":" + pTCPPacket.DestinationPort.ToString();
Console.WriteLine("[CONNECTION] From {0} to {1}", mLocalEndpoint, mRemoteEndpoint);
return Results.Continue;
}
if (pTCPPacket.Syn && pTCPPacket.Ack) { mInboundSequence = (uint)(pTCPPacket.SequenceNumber + 1); return Results.Continue; }
if (pTCPPacket.PayloadData.Length == 0) return Results.Continue;
if (mBuild == 0)
{
//if (pTCPPacket.PayloadData.Length < 13) return Results.CloseMe;
byte[] tcpData = pTCPPacket.PayloadData;
//mBuild = (ushort)(tcpData[2] | (tcpData[3] << 8));
bool mIsKMS = false;
PacketReader pr = new PacketReader(tcpData);
//pr.ReadShort();
//ushort version = pr.ReadUShort();
/*
var pos = pr.Position;
{
var shrt = pr.ReadShort();
//if (shrt < 0 || shrt > 0x0020)
//{
// return Results.CloseMe;
//}
}
pr.Reset(pos);
string patchLocation = pr.ReadMapleString();
byte[] localIV = pr.ReadBytes(4);
byte[] remoteIV = pr.ReadBytes(4);
byte serverLocale = pr.ReadByte();
*/
/*
if (serverLocale == 0x07 && pr.Remaining > 0)
{
ushort unk = pr.ReadUShort();
}
if (pr.Remaining > 0 || serverLocale > 0x12)
{
//MessageBox.Show("Connection closing. pr.remaining > 0 | ServerLocale > 0x12: " + (pr.Remaining > 0) + " - " + (serverLocale > 0x12));
//MessageBox.Show(string.Format("Version {0} patch location {1} serverlocale {4}", version, patchLocation, localIV, remoteIV, serverLocale));
return Results.CloseMe;
}
*/
//if (serverLocale == 0x02 || (serverLocale == 0x01 && version > 255)) mIsKMS = true;
//else mIsKMS = false;
/*
if (mIsKMS)
{
int test = int.Parse(patchLocation);
ushort t1 = (ushort)(test & 0x7FFF);
int t2 = (test >> 15) & 1;
int t3 = (test >> 16) & 0xFF;
Console.WriteLine("Logging KMS connection. Version {0} | {1} | {2}", t1, t2, t3);
mBuild = t1;
}
else
{
mBuild = version;
}
*/
//mLocale = serverLocale;
//mPatchLocation = patchLocation;
mOutboundStream = new MapleStream(true, mBuild, mLocale, null);
mInboundStream = new MapleStream(false, (ushort)(0xFFFF - mBuild), mLocale, null);
mInboundSequence += (uint)tcpData.Length;
/*
// Generate HandShake packet
Definition definition = Config.Instance.GetDefinition(mBuild, mLocale, false, 0xFFFF);
if (definition == null)
{
definition = new Definition();
definition.Outbound = false;
definition.Locale = mLocale;
definition.Opcode = 0xFFFF;
definition.Name = "Maple Handshake";
definition.Build = mBuild;
Config.Instance.Definitions.Add(definition);
}
{
string filename = "Scripts" +
Path.DirectorySeparatorChar + mLocale.ToString() +
Path.DirectorySeparatorChar + mBuild.ToString() +
Path.DirectorySeparatorChar + "Inbound" +
Path.DirectorySeparatorChar + "0xFFFF.txt";
if (!Directory.Exists(Path.GetDirectoryName(filename))) Directory.CreateDirectory(Path.GetDirectoryName(filename));
if (!File.Exists(filename))
{
string contents = "";
contents += "using (ScriptAPI) {\r\n";
contents += "\tAddShort(\"Packet Size\");\r\n";
contents += "\tAddUShort(\"MapleStory Version\");\r\n";
contents += "\tAddString(\"MapleStory Patch Location\");\r\n";
contents += "\tAddField(\"Local Initializing Vector (IV)\", 4);\r\n";
contents += "\tAddField(\"Remote Initializing Vector (IV)\", 4);\r\n";
contents += "\tAddByte(\"MapleStory Locale\");\r\n";
contents += "}";
File.WriteAllText(filename, contents);
}
}
MaplePacket packet = new MaplePacket(pArrivalTime, false, mBuild, mLocale, 0xFFFF, definition == null ? "" : definition.Name, tcpData);
if (!mOpcodes.Exists(kv => kv.First == packet.Outbound && kv.Second == packet.Opcode))
{ // Should be false, but w/e
mOpcodes.Add(new Pair<bool, ushort>(packet.Outbound, packet.Opcode));
}
mPacketList.Items.Add(packet);
mPackets.Add(packet);
MainForm.SearchForm.RefreshOpcodes(true);
Console.WriteLine("[CONNECTION] MapleStory V{2}.{3} Locale {4}", mLocalEndpoint, mRemoteEndpoint, mBuild, patchLocation, serverLocale);
*/
}
if (pTCPPacket.SourcePort == mLocalPort) ProcessTCPPacket(pTCPPacket, ref mOutboundSequence, mOutboundBuffer, mOutboundStream, pArrivalTime, false);
else ProcessTCPPacket(pTCPPacket, ref mInboundSequence, mInboundBuffer, mInboundStream, pArrivalTime, true);
return Results.Continue;
}
private void ProcessTCPPacket(TcpPacket pTCPPacket, ref uint pSequence, Dictionary<uint, byte[]> pBuffer, MapleStream pStream, DateTime pArrivalDate, bool isInbound)
{
/*
if (pTCPPacket.SequenceNumber > pSequence)
{
byte[] data;
while ((data = pBuffer.GetOrDefault(pSequence, null)) != null)
{
pBuffer.Remove(pSequence);
pStream.Append(data);
pSequence += (uint)data.Length;
}
if (pTCPPacket.SequenceNumber > pSequence) pBuffer[(uint)pTCPPacket.SequenceNumber] = pTCPPacket.PayloadData;
}
if (pTCPPacket.SequenceNumber < pSequence)
{
int difference = (int)(pSequence - pTCPPacket.SequenceNumber);
if (difference > 0)
{
byte[] data = pTCPPacket.PayloadData;
if (data.Length > difference)
{
pStream.Append(data, difference, data.Length - difference);
pSequence += (uint)(data.Length - difference);
}
}
}
else if (pTCPPacket.SequenceNumber == pSequence)
{*/
byte[] data = pTCPPacket.PayloadData;
if (isInbound)
{
pStream.Append(data, ref inboundBuffer);
}
else
{
pStream.Append(data, ref outboundBuffer);
}
//pSequence += (uint)data.Length;
// }
MaplePacket packet;
bool refreshOpcodes = false;
try
{
while ((isInbound ? (packet = pStream.Read(pArrivalDate, mBuild, mLocale, ref isFirstPacket, ref inboundBuffer, ref curInboundIV)) : (packet = pStream.Read(pArrivalDate, mBuild, mLocale, ref isFirstPacket, ref outboundBuffer, ref curOutboundIV))) != null)
{
Console.WriteLine("OK");
Console.WriteLine(" ");
mPackets.Add(packet);
Definition definition = Config.Instance.GetDefinition(mBuild, mLocale, packet.Outbound, packet.Opcode);
if (!mOpcodes.Exists(kv => kv.First == packet.Outbound && kv.Second == packet.Opcode))
{
mOpcodes.Add(new Pair<bool, ushort>(packet.Outbound, packet.Opcode));
refreshOpcodes = true;
}
//if (definition != null && !mViewIgnoredMenu.Checked && definition.Ignore) continue;
mPacketList.Items.Add(packet);
if (mPacketList.SelectedItems.Count == 0) packet.EnsureVisible();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
mTerminated = true;
Text += " (Terminated)";
//MainForm.CloseSession(this);
return;
}
if (DockPanel.ActiveDocument == this && refreshOpcodes) MainForm.SearchForm.RefreshOpcodes(true);
}
public void OpenReadOnly(string pFilename)
{
// mFileSaveMenu.Enabled = false;
mTerminated = true;
using (FileStream stream = new FileStream(pFilename, FileMode.Open, FileAccess.Read))
{
BinaryReader reader = new BinaryReader(stream);
mBuild = reader.ReadUInt16();
ushort version = mBuild;
if (mBuild == 0x2012)
{
mLocale = (byte)reader.ReadUInt16();
mBuild = reader.ReadUInt16();
mLocalPort = reader.ReadUInt16();
}
else if (mBuild == 0x2014)
{
mLocalEndpoint = reader.ReadString();
mLocalPort = reader.ReadUInt16();
mRemoteEndpoint = reader.ReadString();
mRemotePort = reader.ReadUInt16();
mLocale = (byte)reader.ReadUInt16();
mBuild = reader.ReadUInt16();
}
else if (mBuild == 0x2015 || mBuild == 0x2020)
{
mLocalEndpoint = reader.ReadString();
mLocalPort = reader.ReadUInt16();
mRemoteEndpoint = reader.ReadString();
mRemotePort = reader.ReadUInt16();
mLocale = reader.ReadByte();
mBuild = reader.ReadUInt16();
}
else
{
mLocalPort = reader.ReadUInt16();
// Old version
frmLocale loc = new frmLocale();
var res = loc.ShowDialog();
if (res == System.Windows.Forms.DialogResult.OK)
{
mLocale = loc.ChosenLocale;
}
}
mPacketList.BeginUpdate();
while (stream.Position < stream.Length)
{
long timestamp = reader.ReadInt64();
ushort size = reader.ReadUInt16();
ushort opcode = reader.ReadUInt16();
bool outbound;
if (version >= 0x2020) {
outbound = reader.ReadBoolean();
}
else {
outbound = (size & 0x8000) != 0;
size = (ushort)(size & 0x7FFF);
}
byte[] buffer = reader.ReadBytes(size);
Definition definition = Config.Instance.GetDefinition(mBuild, mLocale, outbound, opcode);
MaplePacket packet = new MaplePacket(new DateTime(timestamp), outbound, mBuild, mLocale, opcode, definition == null ? "" : definition.Name, buffer);
mPackets.Add(packet);
if (!mOpcodes.Exists(kv => kv.First == packet.Outbound && kv.Second == packet.Opcode)) mOpcodes.Add(new Pair<bool, ushort>(packet.Outbound, packet.Opcode));
if (definition != null && definition.Ignore) continue;
mPacketList.Items.Add(packet);
}
mPacketList.EndUpdate();
if (mPacketList.Items.Count > 0) mPacketList.EnsureVisible(0);
}
Text = string.Format("{0} (ReadOnly)", Path.GetFileName(pFilename));
Console.WriteLine("Loaded file: {0}", pFilename);
}
public void RefreshPackets()
{
Pair<bool, ushort> search = (MainForm.SearchForm.ComboBox.SelectedIndex >= 0 ? mOpcodes[MainForm.SearchForm.ComboBox.SelectedIndex] : null);
MaplePacket previous = mPacketList.SelectedItems.Count > 0 ? mPacketList.SelectedItems[0] as MaplePacket : null;
mOpcodes.Clear();
mPacketList.Items.Clear();
MainForm.DataForm.HexBox.ByteProvider = null;
MainForm.StructureForm.Tree.Nodes.Clear();
MainForm.PropertyForm.Properties.SelectedObject = null;
if (!mViewOutboundMenu.Checked && !mViewInboundMenu.Checked) return;
mPacketList.BeginUpdate();
for (int index = 0; index < mPackets.Count; ++index)
{
MaplePacket packet = mPackets[index];
if (packet.Outbound && !mViewOutboundMenu.Checked) continue;
if (!packet.Outbound && !mViewInboundMenu.Checked) continue;
Definition definition = Config.Instance.GetDefinition(mBuild, mLocale, packet.Outbound, packet.Opcode);
packet.Name = definition == null ? "" : definition.Name;
if (!mOpcodes.Exists(kv => kv.First == packet.Outbound && kv.Second == packet.Opcode)) mOpcodes.Add(new Pair<bool, ushort>(packet.Outbound, packet.Opcode));
if (definition != null && !mViewIgnoredMenu.Checked && definition.Ignore) continue;
mPacketList.Items.Add(packet);
if (packet == previous) packet.Selected = true;
}
mPacketList.EndUpdate();
MainForm.SearchForm.RefreshOpcodes(true);
}
public void RunSaveCMD()
{
mFileSaveMenu.PerformClick();
}
private void mFileSaveMenu_Click(object pSender, EventArgs pArgs)
{
if (!mTerminated) {
MessageBox.Show("Cannot save this session when it's still open.");
}
if (mFilename == null)
{
mSaveDialog.FileName = string.Format("Port {0}", mLocalPort);
if (mSaveDialog.ShowDialog(this) == DialogResult.OK) mFilename = mSaveDialog.FileName;
else return;
}
using (FileStream stream = new FileStream(mFilename, FileMode.Create, FileAccess.Write))
{
BinaryWriter writer = new BinaryWriter(stream);
writer.Write((ushort)0x2020);
writer.Write(mLocalEndpoint);
writer.Write(mLocalPort);
writer.Write(mRemoteEndpoint);
writer.Write(mRemotePort);
writer.Write(mLocale);
writer.Write(mBuild);
foreach (MaplePacket packet in mPackets) {
writer.Write(packet.Dump());
}
stream.Flush();
}
if (mTerminated)
{
mFileSaveMenu.Enabled = false;
Text = string.Format("Port {0} (ReadOnly)", mLocalPort);
}
}
private void mFileExportMenu_Click(object pSender, EventArgs pArgs)
{
mExportDialog.FileName = string.Format("Port {0}", mLocalPort);
if (mExportDialog.ShowDialog(this) != DialogResult.OK) return;
string tmp = "";
tmp += string.Format("=== MapleStory Version: {0}; Locale: {1} ===\r\n", mBuild, mLocale);
tmp += string.Format("Endpoint From: {0}\r\n", mLocalEndpoint);
tmp += string.Format("Endpoint To: {0}\r\n", mRemoteEndpoint);
tmp += string.Format("- Packets: {0}\r\n", mPackets.Count);
long dataSize = 0;
foreach (var packet in mPackets)
dataSize += 2 + packet.InnerBuffer.Length;
tmp += string.Format("- Data: {0:N0} bytes\r\n", dataSize);
tmp += string.Format("================================================\r\n");
File.WriteAllText(mExportDialog.FileName, tmp);
tmp = "";
int outboundCount = 0;
int inboundCount = 0;
int i = 0;
foreach (var packet in mPackets)
{
if (packet.Outbound) ++outboundCount;
else ++inboundCount;
tmp += string.Format("[{0}][{2}] [{3:X4}] {4}\r\n", packet.Timestamp.ToString("yyyy-MM-dd HH:mm:ss.fff"), (packet.Outbound ? outboundCount : inboundCount), (packet.Outbound ? "Outbound" : "Inbound "), packet.Opcode, BitConverter.ToString(packet.InnerBuffer).Replace('-', ' '));
i++;
if (i % 1000 == 0)
{
File.AppendAllText(mExportDialog.FileName, tmp);
tmp = "";
}
}
File.AppendAllText(mExportDialog.FileName, tmp);
}
private void mViewCommonScriptMenu_Click(object pSender, EventArgs pArgs)
{
string scriptPath = "Scripts" + Path.DirectorySeparatorChar + mLocale.ToString() + Path.DirectorySeparatorChar + mBuild.ToString() + Path.DirectorySeparatorChar + "Common.txt";
if (!Directory.Exists(Path.GetDirectoryName(scriptPath))) Directory.CreateDirectory(Path.GetDirectoryName(scriptPath));
ScriptForm script = new ScriptForm(scriptPath, null);
script.FormClosed += CommonScript_FormClosed;
script.Show(DockPanel, new Rectangle(MainForm.Location, new Size(600, 300)));
}
private void CommonScript_FormClosed(object pSender, FormClosedEventArgs pArgs)
{
if (mPacketList.SelectedIndices.Count == 0) return;
MaplePacket packet = mPacketList.SelectedItems[0] as MaplePacket;
MainForm.StructureForm.ParseMaplePacket(packet);
Activate();
}
private void mViewRefreshMenu_Click(object pSender, EventArgs pArgs) { RefreshPackets(); }
private void mViewOutboundMenu_CheckedChanged(object pSender, EventArgs pArgs) { RefreshPackets(); }
private void mViewInboundMenu_CheckedChanged(object pSender, EventArgs pArgs) { RefreshPackets(); }
private void mViewIgnoredMenu_CheckedChanged(object pSender, EventArgs pArgs) { RefreshPackets(); }
private void mPacketList_SelectedIndexChanged(object pSender, EventArgs pArgs)
{
if (mPacketList.SelectedItems.Count == 0) { MainForm.DataForm.HexBox.ByteProvider = null; MainForm.StructureForm.Tree.Nodes.Clear(); MainForm.PropertyForm.Properties.SelectedObject = null; return; }
MainForm.DataForm.HexBox.ByteProvider = new DynamicByteProvider((mPacketList.SelectedItems[0] as MaplePacket).InnerBuffer);
MainForm.StructureForm.ParseMaplePacket(mPacketList.SelectedItems[0] as MaplePacket);
}
private void mPacketList_ItemActivate(object pSender, EventArgs pArgs)
{
if (mPacketList.SelectedIndices.Count == 0) return;
MaplePacket packet = mPacketList.SelectedItems[0] as MaplePacket;
string scriptPath = "Scripts" + Path.DirectorySeparatorChar + mLocale.ToString() + Path.DirectorySeparatorChar + mBuild.ToString() + Path.DirectorySeparatorChar + (packet.Outbound ? "Outbound" : "Inbound") + Path.DirectorySeparatorChar + "0x" + packet.Opcode.ToString("X4") + ".txt";
if (!Directory.Exists(Path.GetDirectoryName(scriptPath))) Directory.CreateDirectory(Path.GetDirectoryName(scriptPath));
ScriptForm script = new ScriptForm(scriptPath, packet);
script.FormClosed += Script_FormClosed;
script.Show(DockPanel, new Rectangle(MainForm.Location, new Size(600, 300)));
}
private void Script_FormClosed(object pSender, FormClosedEventArgs pArgs)
{
ScriptForm script = pSender as ScriptForm;
script.Packet.Selected = true;
MainForm.StructureForm.ParseMaplePacket(script.Packet);
Activate();
}
private void mPacketContextMenu_Opening(object pSender, CancelEventArgs pArgs)
{
mPacketContextNameBox.Text = "";
mPacketContextIgnoreMenu.Checked = false;
if (mPacketList.SelectedItems.Count == 0) pArgs.Cancel = true;
else
{
MaplePacket packet = mPacketList.SelectedItems[0] as MaplePacket;
Definition definition = Config.Instance.GetDefinition(mBuild, mLocale, packet.Outbound, packet.Opcode);
if (definition != null)
{
mPacketContextNameBox.Text = definition.Name;
mPacketContextIgnoreMenu.Checked = definition.Ignore;
}
}
}
private void mPacketContextMenu_Opened(object pSender, EventArgs pArgs)
{
mPacketContextNameBox.Focus();
mPacketContextNameBox.SelectAll();
}
private void mPacketContextNameBox_KeyDown(object pSender, KeyEventArgs pArgs)
{
if (pArgs.Modifiers == Keys.None && pArgs.KeyCode == Keys.Enter)
{
MaplePacket packet = mPacketList.SelectedItems[0] as MaplePacket;
Definition definition = Config.Instance.GetDefinition(mBuild, mLocale, packet.Outbound, packet.Opcode);
if (definition == null)
{
definition = new Definition();
definition.Build = mBuild;
definition.Outbound = packet.Outbound;
definition.Opcode = packet.Opcode;
definition.Locale = mLocale;
Config.Instance.Definitions.Add(definition);
}
definition.Name = mPacketContextNameBox.Text;
Config.Instance.Save();
pArgs.SuppressKeyPress = true;
mPacketContextMenu.Close();
RefreshPackets();
}
}
private void mPacketContextIgnoreMenu_CheckedChanged(object pSender, EventArgs pArgs)
{
MaplePacket packet = mPacketList.SelectedItems[0] as MaplePacket;
Definition definition = Config.Instance.GetDefinition(mBuild, mLocale, packet.Outbound, packet.Opcode);
if (definition == null)
{
definition = new Definition();
definition.Locale = mLocale;
definition.Build = mBuild;
definition.Outbound = packet.Outbound;
definition.Opcode = packet.Opcode;
definition.Locale = mLocale;
Config.Instance.Definitions.Add(definition);
}
definition.Ignore = mPacketContextIgnoreMenu.Checked;
Config.Instance.Save();
RefreshPackets();
}
private void SessionForm_Load(object sender, EventArgs e)
{
}
private void mMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) {
}
private void sessionInformationToolStripMenuItem_Click(object sender, EventArgs e) {
SessionInformation si = new SessionInformation();
si.txtVersion.Text = mBuild.ToString();
si.txtPatchLocation.Text = mPatchLocation;
si.txtLocale.Text = mLocale.ToString();
si.txtAdditionalInfo.Text = "Connection info:\r\n" + mLocalEndpoint + " to " + mRemoteEndpoint;
if ((mLocale == 1 && mBuild != 255) || mLocale == 2) {
si.txtAdditionalInfo.Text += "\r\nRecording session of a MapleStory Korea" + (mLocale == 1 ? " Test" : "") + " server.\r\nAdditional KMS info:\r\n";
int test = int.Parse(mPatchLocation);
ushort maplerVersion = (ushort)(test & 0x7FFF);
int subVersion = (test >> 15) & 1;
int extraOption = (test >> 16) & 0xFF;
si.txtAdditionalInfo.Text += "Real Version: " + maplerVersion + "\r\nSubversion: " + subVersion + "\r\nRemove cookie: " + extraOption;
}
si.Show();
}
private void sendpropertiesToolStripMenuItem_Click(object sender, EventArgs e)
{
Config.Instance.SaveProperties();
string tmp = Config.GetPropertiesFile(true, (byte)mLocale, mBuild);
System.Diagnostics.Process.Start(tmp);
}
private void recvpropertiesToolStripMenuItem_Click(object sender, EventArgs e)
{
Config.Instance.SaveProperties();
string tmp = Config.GetPropertiesFile(false, (byte)mLocale, mBuild);
System.Diagnostics.Process.Start(tmp);
}
private void removeLoggedPacketsToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to delete all logged packets?", "!!", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) return;
mPackets.Clear();
ListView.Items.Clear();
mOpcodes.Clear();
}
}
}