Exemple #1
0
        public void Deserialize(Stream input)
        {
            uint magic = input.ReadValueU32();

            if (magic != 0x41444620 &&
                magic.Swap() != 0x41444620)
            {
                throw new FormatException("not a ADF file");
            }

            var endian = magic == 0x41444620 // ' FDA'
                             ? Endian.Little
                             : Endian.Big;

            this.Version = input.ReadValueU32(endian);

            if (this.Version != 1)
            {
                throw new FormatException("unhandled ADF file version");
            }

            uint dataCount        = input.ReadValueU32(endian);
            uint dataOffset       = input.ReadValueU32(endian);
            uint definitionCount  = input.ReadValueU32(endian);
            uint definitionOffset = input.ReadValueU32(endian);

            this.Definitions.Clear();
            if (definitionCount > 0)
            {
                input.Seek(definitionOffset, SeekOrigin.Begin);
                for (uint i = 0; i < definitionCount; i++)
                {
                    var definition = new DataFormat.Definition();
                    definition.Deserialize(input, endian);
                    this.Definitions.Add(definition);
                }
            }

            this.Entries.Clear();
            if (dataCount > 0)
            {
                input.Seek(dataOffset, SeekOrigin.Begin);
                for (uint i = 0; i < dataCount; i++)
                {
                    var entry = new DataFormat.Entry();
                    entry.Deserialize(input, endian);
                    this.Entries.Add(entry);
                }
            }

            this.Endian = endian;
        }
Exemple #2
0
        public object ParseEntry(DataFormat.Entry entry, Stream input)
        {
            var definition = this.FindDefinition(entry.TypeHash);

            if (definition == null)
            {
                throw new InvalidOperationException("missing definition " + entry.TypeHash.ToString("X8"));
            }

            input.Seek(entry.Offset, SeekOrigin.Begin);
            using (MemoryStream data = input.ReadToMemoryStream(entry.Size))
            {
                return(this.ParseDefinition(0, definition, data));
            }
        }