public void OpenFile(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog {Filter = "*.hex|*.hex"}; if (openFileDialog.ShowDialog() == false) return; Session = new Session(); State = -1; ServerBuffer = new byte[0]; ClientBuffer = new byte[0]; Packets = new List<Packet>(); PacketsList.Items.Clear(); using (FileStream fileStream = File.OpenRead(openFileDialog.FileName)) { using (TextReader stream = new StreamReader(fileStream)) { while (true) { string line = stream.ReadLine(); if (line == null) break; if (line.Length == 0) continue; if (State == -1) { State = 0; continue; } bool isServer = line[0] == ' '; string hex = line.Substring(isServer ? 14 : 10, 49).Replace(" ", ""); byte[] data = hex.ToBytes(); if (isServer) { AppendServerData(data); // ReSharper disable CSharpWarnings::CS0642 while (ProcessServerData()) ; // ReSharper restore CSharpWarnings::CS0642 } else { AppendClientData(data); // ReSharper disable CSharpWarnings::CS0642 while (ProcessClientData()) ; // ReSharper restore CSharpWarnings::CS0642 } } } } SetText("Loaded " + Packets.Count + " packets..."); }
private static Session CreateSession(byte[] clientKey1, byte[] clientKey2, byte[] serverKey1, byte[] serverKey2) { var session = new Session(); session.ClientKey1 = clientKey1; session.ClientKey2 = clientKey2; session.ServerKey1 = serverKey1; session.ServerKey2 = serverKey2; session.Init(); return session; }
private void Reset() { State = -1; ClientPort = 0; Session = new Session(); ServerBuffer = new byte[0]; ClientBuffer = new byte[0]; ServerSeqNum = 0; ClientSeqNum = 0; TcpBuffer = new PriorityQueue<PacketDotNet.TcpPacket>(); }
public GameProtocol(Session session) { Session = session; }
private void TryInitialize() { if (Initialized) throw new InvalidOperationException("Already initalized"); if (_client.Length < 256 || _server.Length < 256 + 4) return; _server.Position = 0; _client.Position = 0; var magicBytes = _server.ReadBytes(4); if (!magicBytes.SequenceEqual(new byte[] { 1, 0, 0, 0 })) throw new FormatException("Not a Tera connection"); var clientKey1 = _client.ReadBytes(128); var clientKey2 = _client.ReadBytes(128); var serverKey1 = _server.ReadBytes(128); var serverKey2 = _server.ReadBytes(128); _session = CreateSession(clientKey1, clientKey2, serverKey1, serverKey2); ClientToServer(_client.ReadBytes((int)(_client.Length - _client.Position))); ServerToClient(_server.ReadBytes((int)(_server.Length - _server.Position))); _client = null; _server = null; }