Пример #1
0
        public static byte[] WriteZLIBFile(CompoundTag tag, ByteOrder order = ByteOrder.Little)
        {
            using (NBTStream stream = new NBTStream(order))
            {
                tag.Write(stream);

                int sum = 0;
                using (MemoryStream ms = new MemoryStream())
                {
                    ms.WriteByte(0x78);
                    ms.WriteByte(0x01);
                    using (ZlibStream zlib = new ZlibStream(ms, CompressionMode.Compress, true))
                    {
                        zlib.Write(stream.ToArray(), 0, (int)stream.Length);
                        sum = zlib.Checksum;
                    }

                    byte[] sumBytes = BitConverter.GetBytes(sum);
                    if (BitConverter.IsLittleEndian)
                    {
                        Array.Reverse(sumBytes);
                    }
                    ms.Write(sumBytes, 0, sumBytes.Length);

                    return(ms.ToArray());
                }
            }
        }
Пример #2
0
 public static byte[] WriteTag(CompoundTag tag, ByteOrder order = ByteOrder.Little, bool isNetwork = false)
 {
     using (NBTStream stream = new NBTStream(order, isNetwork))
     {
         tag.WriteTag(stream);
         return(stream.ToArray());
     }
 }
Пример #3
0
 public static void WriteRawFile(string fileName, CompoundTag tag, ByteOrder order = ByteOrder.Little)
 {
     using (NBTStream stream = new NBTStream(order))
     {
         tag.Write(stream);
         File.WriteAllBytes(fileName, stream.ToArray());
     }
 }
Пример #4
0
        public static void WriteGZIPFile(string fileName, CompoundTag tag, ByteOrder order = ByteOrder.Little)
        {
            using (NBTStream stream = new NBTStream(order))
            {
                tag.Write(stream);

                using (MemoryStream ms = new MemoryStream())
                {
                    using (GZipStream gs = new GZipStream(ms, CompressionMode.Compress, true))
                    {
                        gs.Write(stream.ToArray(), 0, (int)stream.Length);
                    }

                    File.WriteAllBytes(fileName, ms.ToArray());
                }
            }
        }