Exemplo n.º 1
0
        public byte[] CompressBytes(byte[] input)
        {
            MemoryStream stream = new MemoryStream();
            stream.WriteByte(0x78);
            stream.WriteByte(0x01);
            int checksum;
            using (var compressStream = new ZLibStream(stream, CompressionLevel.Optimal, true))
            {
                NbtBinaryWriter writer = new NbtBinaryWriter(compressStream, true);
                writer.Write(input);

                writer.Flush();

                checksum = compressStream.Checksum;
                writer.Close();
            }

            byte[] checksumBytes = BitConverter.GetBytes(checksum);
            if (BitConverter.IsLittleEndian)
            {
                // Adler32 checksum is big-endian
                Array.Reverse(checksumBytes);
            }
            stream.Write(checksumBytes, 0, checksumBytes.Length);

            var bytes = stream.ToArray();
            stream.Close();

            return bytes;
        }
Exemplo n.º 2
0
 public override long ReadInt64()
 {
     if (BitConverter.IsLittleEndian == bigEndian)
     {
         return(NbtBinaryWriter.Swap(base.ReadInt64()));
     }
     else
     {
         return(base.ReadInt64());
     }
 }
Exemplo n.º 3
0
 public byte[] Export()
 {
     using (MemoryStream stream = new MemoryStream())
     {
         NbtBinaryWriter writer = new NbtBinaryWriter(stream, false);
         writer.Write(X);
         writer.Write(Y);
         writer.Write(Z);
         writer.Write(Yaw);
         writer.Write(Pitch);
         writer.Write(HeadYaw);
         writer.Flush();
         return stream.GetBuffer();
     }
 }
Exemplo n.º 4
0
 public byte[] Export()
 {
     using (MemoryStream stream = new MemoryStream())
     {
         NbtBinaryWriter writer = new NbtBinaryWriter(stream, false);
         writer.Write(X);
         writer.Write(Y);
         writer.Write(Z);
         writer.Write(Yaw);
         writer.Write(Pitch);
         writer.Write(HeadYaw);
         writer.Flush();
         return(stream.GetBuffer());
     }
 }
Exemplo n.º 5
0
        public byte[] Export()
        {
            byte[] buffer;
            using (MemoryStream stream = new MemoryStream())
            {
                NbtBinaryWriter writer = new NbtBinaryWriter(stream, false);

                Armor.WriteTo(writer);

                Slots.WriteTo(writer);

                ItemHotbar.WriteTo(writer);

                writer.Flush();
                buffer = stream.GetBuffer();
            }
            return buffer;
        }
Exemplo n.º 6
0
 public static void Write(this NbtBinaryWriter writer, byte[] data)
 {
     writer.Write(data, 0, data.Length);
 }