public void OpenReadOnly(string pFilename) { // mFileSaveMenu.Enabled = false; Saved = true; mTerminated = true; using (FileStream stream = new FileStream(pFilename, FileMode.Open, FileAccess.Read)) { BinaryReader reader = new BinaryReader(stream); ushort MapleSharkVersion = reader.ReadUInt16(); mBuild = MapleSharkVersion; if (MapleSharkVersion < 0x2000) { mLocalPort = reader.ReadUInt16(); // Old version frmLocale loc = new frmLocale(); var res = loc.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { mLocale = loc.ChosenLocale; } } else { byte v1 = (byte)((MapleSharkVersion >> 12) & 0xF), v2 = (byte)((MapleSharkVersion >> 8) & 0xF), v3 = (byte)((MapleSharkVersion >> 4) & 0xF), v4 = (byte)((MapleSharkVersion >> 0) & 0xF); Console.WriteLine("Loading MSB file, saved by MapleShark V{0}.{1}.{2}.{3}", v1, v2, v3, v4); if (MapleSharkVersion == 0x2012) { mLocale = (byte)reader.ReadUInt16(); mBuild = reader.ReadUInt16(); mLocalPort = reader.ReadUInt16(); } else if (MapleSharkVersion == 0x2014) { mLocalEndpoint = reader.ReadString(); mLocalPort = reader.ReadUInt16(); mRemoteEndpoint = reader.ReadString(); mRemotePort = reader.ReadUInt16(); mLocale = (byte)reader.ReadUInt16(); mBuild = reader.ReadUInt16(); } else if (MapleSharkVersion == 0x2015 || MapleSharkVersion >= 0x2020) { mLocalEndpoint = reader.ReadString(); mLocalPort = reader.ReadUInt16(); mRemoteEndpoint = reader.ReadString(); mRemotePort = reader.ReadUInt16(); mLocale = reader.ReadByte(); mBuild = reader.ReadUInt32(); if (MapleSharkVersion >= 0x2021 && !Config.Instance.Maple2) { mPatchLocation = reader.ReadString(); } } else { MessageBox.Show("I have no idea how to open this MSB file. It looks to me as a version " + string.Format("{0}.{1}.{2}.{3}", v1, v2, v3, v4) + " MapleShark MSB file... O.o?!"); return; } } mPacketList.BeginUpdate(); while (stream.Position < stream.Length) { long timestamp = reader.ReadInt64(); int size = MapleSharkVersion < 0x2027 ? reader.ReadUInt16() : reader.ReadInt32(); ushort opcode = reader.ReadUInt16(); bool outbound; if (MapleSharkVersion >= 0x2020) { outbound = reader.ReadBoolean(); } else { outbound = (size & 0x8000) != 0; size = (ushort)(size & 0x7FFF); } byte[] buffer = reader.ReadBytes(size); uint preDecodeIV = 0, postDecodeIV = 0; if (MapleSharkVersion >= 0x2025) { preDecodeIV = reader.ReadUInt32(); postDecodeIV = reader.ReadUInt32(); } 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, preDecodeIV, postDecodeIV); AddPacket(packet); if (!mOpcodes.Exists(op => op.Outbound == packet.Outbound && op.Header == packet.Opcode)) { mOpcodes.Add(new Opcode(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 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 OpenReadOnly(string pFilename) { // mFileSaveMenu.Enabled = false; Saved = true; mTerminated = true; using (FileStream stream = new FileStream(pFilename, FileMode.Open, FileAccess.Read)) { BinaryReader reader = new BinaryReader(stream); ushort MapleSharkVersion = reader.ReadUInt16(); mBuild = MapleSharkVersion; if (MapleSharkVersion < 0x2000) { mLocalPort = reader.ReadUInt16(); // Old version frmLocale loc = new frmLocale(); var res = loc.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { mLocale = loc.ChosenLocale; } } else { byte v1 = (byte)((MapleSharkVersion >> 12) & 0xF), v2 = (byte)((MapleSharkVersion >> 8) & 0xF), v3 = (byte)((MapleSharkVersion >> 4) & 0xF), v4 = (byte)((MapleSharkVersion >> 0) & 0xF); Console.WriteLine("Loading MSB file, saved by MapleShark V{0}.{1}.{2}.{3}", v1, v2, v3, v4); if (MapleSharkVersion == 0x2012) { mLocale = (byte)reader.ReadUInt16(); mBuild = reader.ReadUInt16(); mLocalPort = reader.ReadUInt16(); } else if (MapleSharkVersion == 0x2014) { mLocalEndpoint = reader.ReadString(); mLocalPort = reader.ReadUInt16(); mRemoteEndpoint = reader.ReadString(); mRemotePort = reader.ReadUInt16(); mLocale = (byte)reader.ReadUInt16(); mBuild = reader.ReadUInt16(); } else if (MapleSharkVersion == 0x2015 || MapleSharkVersion >= 0x2020) { mLocalEndpoint = reader.ReadString(); mLocalPort = reader.ReadUInt16(); mRemoteEndpoint = reader.ReadString(); mRemotePort = reader.ReadUInt16(); mLocale = reader.ReadByte(); mBuild = reader.ReadUInt16(); if (MapleSharkVersion >= 0x2021) { mPatchLocation = reader.ReadString(); } } else { MessageBox.Show("I have no idea how to open this MSB file. It looks to me as a version " + string.Format("{0}.{1}.{2}.{3}", v1, v2, v3, v4) + " MapleShark MSB file... O.o?!"); return; } } mPacketList.BeginUpdate(); while (stream.Position < stream.Length) { long timestamp = reader.ReadInt64(); ushort size = reader.ReadUInt16(); ushort opcode = reader.ReadUInt16(); bool outbound; if (MapleSharkVersion >= 0x2020) { outbound = reader.ReadBoolean(); } else { outbound = (size & 0x8000) != 0; size = (ushort)(size & 0x7FFF); } byte[] buffer = reader.ReadBytes(size); uint preDecodeIV = 0, postDecodeIV = 0; if (MapleSharkVersion >= 0x2025) { preDecodeIV = reader.ReadUInt32(); postDecodeIV = reader.ReadUInt32(); } 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, preDecodeIV, postDecodeIV); 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 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(); 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) { 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 = (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); }