internal static byte[] Decode(byte[] arr, AesDecryptor aesDecryptor, ref int recvIdx) { byte flag = arr[0]; bool ziped = ((flag & 0x80) == 0x80); bool aesed = ((flag & 0x40) == 0x40); bool crced = ((flag & 0x20) == 0x20); int idx = flag & 0x1F; if (recvIdx == idx) { recvIdx++; if (recvIdx > 0x1F) { recvIdx = 0; } Byte[] bcrc = new Byte[4]; Buffer.BlockCopy(arr, 1, bcrc, 0, 4); int crc32 = BitConverter.ToInt32(bcrc, 0); Byte[] data = new Byte[arr.Length - 1 - 4]; Buffer.BlockCopy(arr, 1 + 4, data, 0, data.Length); int ncrc32 = 0; if (crced) { ncrc32 = Crc.Crc32(data); } if (ncrc32 == crc32) { if (aesed) { data = aesDecryptor.Decrypt(data); } if (ziped) { data = ZLib.UnZip(data); } if (data != null) { return(data); } else { TcpLogger.LogError("Recv Decode data null"); } } else { TcpLogger.LogError("Recv error crc32 " + crc32 + " ncrc32" + ncrc32); } } else { TcpLogger.LogError("Recv error idx " + idx + " lidx" + recvIdx); } return(null); }