Example #1
0
        public static FCXCompressedData Pack(BinaryStream stream)
        {
            var compressedData = new FCXCompressedData();

            using (var bs = new BinaryStream(1024))
            {
                uint virtualOffset = 0;
                uint realOffset    = 4;

                while (stream.Position < stream.Length)
                {
                    var length = (int)Math.Min(0x40000, (stream.Length - stream.Position));

                    using (var block = new BinaryStream(16))
                    {
                        var zlib   = new DeflaterOutputStream(block);
                        var buffer = stream.ReadBytes(length);

                        zlib.Write(buffer, 0, length);
                        zlib.Finish();

                        compressedData.Blocks.Add(new Block()
                        {
                            VirtualOffset = virtualOffset,
                            FileOffset    = realOffset,
                            IsCompressed  = true,
                        });

                        block.Position = 0;
                        block.CopyTo(bs);

                        realOffset += (uint)block.Length;
                    }

                    virtualOffset += (uint)length;
                }

                compressedData.Data = bs.ToArray();

                compressedData.Blocks.Add(new Block()
                {
                    VirtualOffset = virtualOffset,
                    FileOffset    = realOffset,
                    IsCompressed  = true,
                });
            }

            return(compressedData);
        }
Example #2
0
        public void Deserialize(BinaryStream stream)
        {
            var baseOffset = stream.Position;

            var magic = stream.ReadInt32();

            if (magic != Signature)
            {
                throw new FormatException();
            }

            Version = stream.ReadInt32();

            if (Version != 1)
            {
                throw new FormatException();
            }

            uint offsetData       = stream.ReadUInt32();
            uint offsetHeader     = stream.ReadUInt32();
            uint offsetDescriptor = stream.ReadUInt32();

            if (offsetData != 20)
            {
                throw new FormatException();
            }

            Data = new FCXCompressedData();
            Data.Deserialize(stream);

            if (baseOffset + offsetHeader != stream.Position)
            {
                throw new FormatException();
            }

            Header = new FCXCompressedData();
            Header.Deserialize(stream);

            if (baseOffset + offsetDescriptor != stream.Position)
            {
                throw new FormatException();
            }

            Descriptor = new FCXCompressedData();
            Descriptor.Deserialize(stream);
        }