public void Read(object root)
{
using (this.InputReader = new BinaryReader(InputStream))
{
Magic = ReadMagic();
if (Magic.format != Magic.Format.LittleEndian32 && Magic.format != Magic.Format.LittleEndian64)
throw new ParsingException("Only little-endian GR2 files are supported");
Header = ReadHeader();
for (int i = 0; i < Header.numSections; i++)
{
var section = new Section();
section.Header = ReadSectionHeader();
Sections.Add(section);
}
Debug.Assert(InputStream.Position == Magic.headersSize);
UncompressStream();
foreach (var section in Sections)
{
ReadSectionRelocations(section);
}
if (Magic.IsLittleEndian != BitConverter.IsLittleEndian)
{
// TODO: This should be done before applying relocations?
foreach (var section in Sections)
{
ReadSectionMixedMarshallingRelocations(section);
}
}
var rootStruct = new StructReference();
rootStruct.Offset = Sections[(int)Header.rootType.Section].Header.offsetInFile + Header.rootType.Offset;
Seek(Header.rootNode);
ReadStruct(rootStruct.Resolve(this), MemberType.Inline, root, null);
}
}