/// <summary> /// Decrypts the packet data /// </summary> public void Decrypt(Span <byte> data) { if (!RecvCipher.Handshaken) { var pr = new BinaryReader(new MemoryStream(MapleCipher.Handshake(data).ToArray(), false), Encoding.ASCII); var version = pr.ReadInt16(); var subVersionLength = pr.ReadInt16(); var subVersion = new string(pr.ReadChars(subVersionLength)); var siv = pr.ReadUInt32(); var riv = pr.ReadUInt32(); var serverType = pr.ReadByte(); SendCipher.SetIv(siv); RecvCipher.SetIv(riv); HandshakeFinished?.Invoke(siv, riv, version, subVersion, serverType); } else { if (!RecvCipher.CheckHeader(data, !ToClient)) { throw new InvalidOperationException($"Packet header mismatch Size:{data.Length}"); } var decrypted = RecvCipher.Decrypt(data); if (decrypted.Length == 0) { return; } PacketFinished?.Invoke(decrypted.ToArray()); } }
public MapleCipherProvider(ushort currentGameVersion, ulong aesKey, bool useAesEncryption = true, bool toClient = true) { RecvCipher = new MapleCipher(currentGameVersion, aesKey, useAesEncryption); SendCipher = new MapleCipher(currentGameVersion, aesKey, useAesEncryption); ToClient = toClient; }
public MapleCipherProvider(ushort currentGameVersion, ulong?aesKey, bool toClient = true) { RecvCipher = new MapleCipher(currentGameVersion, aesKey); SendCipher = new MapleCipher(currentGameVersion, aesKey); ToClient = toClient; }
/// <summary> /// Gets the packet header from the current packet. /// </summary> public int GetHeader(ReadOnlySequence <byte> buffer) => RecvCipher .Handshaken ? 4 + MapleCipher.GetPacketLength(buffer.Slice(0, 4).ToArray()) : 2 + BitConverter.ToUInt16(buffer.Slice(0, 2).ToArray());