Esempio n. 1
0
        public static MapFormatHelper FromMap(AowMap map)
        {
            MapFormatHelper helper = new MapFormatHelper();

            helper.ModID      = map.ModID;
            helper.MapClassID = map.ClassID;

            helper.HeaderStream = new MemoryStream();
            _headerSerializer.Serialize(helper.HeaderStream, map.PreviewHeader);

            helper._dataStream = new Lazy <Stream>(() => new MemoryStream());
            _mapSerializer.Serialize(helper.DataStream, map);

            return(helper);
        }
Esempio n. 2
0
        public static MapFormatHelper FromStream(Stream inputStream)
        {
            MapFormatHelper helper = new MapFormatHelper();
            BinaryReader    reader = new BinaryReader(inputStream);

            //	Signature1
            int signature1 = reader.ReadInt32();

            ValidateSignature(_signature1, signature1, inputStream.Position - sizeof(int));

            //	Signature 2
            int signature2 = reader.ReadInt32();

            //	Header length, IDs
            inputStream.Position += 4;             //	always 0
            int headerLength = reader.ReadInt32();

            helper.ModID      = reader.ReadInt32();
            helper.MapClassID = reader.ReadInt32();

            //	Header stream
            helper.HeaderStream = new MemoryStream();
            inputStream.CopyBytesTo(helper.HeaderStream, headerLength);

            //	CFS signature
            ValidateSignature(reader, _signatureCFS);

            //	Data stream
            helper._dataStream = new Lazy <Stream>(
                () =>
            {
                MemoryStream dataStream = new MemoryStream();
                using (ZlibStream zlib = new ZlibStream(inputStream, CompressionMode.Decompress))
                {
                    zlib.CopyTo(dataStream);
                }
                return(dataStream);
            });

            return(helper);
        }