public uint CompressPacket(byte[] data, ServerOpcodes opcode) { byte[] uncompressedData = BitConverter.GetBytes((ushort)opcode).Combine(data); uint bufferSize = ZLib.deflateBound(_compressionStream, (uint)uncompressedData.Length); byte[] outPrt = new byte[bufferSize]; _compressionStream.next_out = 0; _compressionStream.avail_out = bufferSize; _compressionStream.out_buf = outPrt; _compressionStream.next_in = 0; _compressionStream.avail_in = (uint)uncompressedData.Length; _compressionStream.in_buf = uncompressedData; int z_res = ZLib.deflate(_compressionStream, 2); if (z_res != 0) { Log.outError(LogFilter.Network, "Can't compress packet data (zlib: deflate) Error code: {0} msg: {1}", z_res, _compressionStream.msg); return(0); } uint compressedSize = bufferSize - _compressionStream.avail_out; Buffer.BlockCopy(outPrt, 0, data, 0, (int)compressedSize); return(compressedSize); }