private TransferBuffer FormatPacket(Packet packet) { var bytes = packet.GetBytes(); if (packet.Opcode == 0x00) { return(new TransferBuffer(bytes, 0, bytes.Length, false)); } using (var pWriter = new PacketIO.PacketWriter()) { pWriter.Write((ushort)(count | 2)); pWriter.Write((byte)0x00); pWriter.Write((ushort)(bytes.Length)); pWriter.Write(packet.Opcode1); pWriter.Write(packet.Opcode2); pWriter.Write((ushort)(bytes.Length + 7)); pWriter.Write((byte)0x00); //USUALLY 0, UNKNOWN CURRENTLY pWriter.Write(bytes); var pbytes = pWriter.GetBytes().Skip(3).ToArray(); var data = Crypto.UDPCrypto.Encrypt(pbytes); pWriter.Seek(0x03, System.IO.SeekOrigin.Begin); pWriter.Write(data); data = pWriter.GetBytes(); data[2] = (byte)((data.Length + 0x78) - (data.Sum(x => x) & 0xFF)); count += 8; return(new TransferBuffer(data, 0, data.Length, false)); } }
private TransferBuffer FormatPacket(Packet packet) { var pWriter = new PacketIO.PacketWriter(); var raw_bytes = packet.GetBytes(); pWriter.Write((ushort)(raw_bytes.Length + 0x07)); pWriter.Write((byte)0x00); pWriter.Write((ushort)(raw_bytes.Length + 0x04)); pWriter.Write(packet.Opcode1); pWriter.Write(packet.Opcode2); pWriter.Write(raw_bytes); raw_bytes = Crypto.CustomXTEA.Encrypt(pWriter.GetBytes().Skip(3).ToArray()); pWriter.Seek(0x03, System.IO.SeekOrigin.Begin); pWriter.Write(raw_bytes); return(new TransferBuffer(pWriter.GetBytes(), 0, raw_bytes.Length + 0x03, false)); }