LSLib.Granny.GR2.GR2Reader.ReadSectionHeader C# (CSharp) Method

ReadSectionHeader() private method

private ReadSectionHeader ( ) : SectionHeader
return SectionHeader
        private SectionHeader ReadSectionHeader()
        {
            var header = new SectionHeader();
            header.compression = InputReader.ReadUInt32();
            header.offsetInFile = InputReader.ReadUInt32();
            header.compressedSize = InputReader.ReadUInt32();
            header.uncompressedSize = InputReader.ReadUInt32();
            header.alignment = InputReader.ReadUInt32();
            header.first16bit = InputReader.ReadUInt32();
            header.first8bit = InputReader.ReadUInt32();
            header.relocationsOffset = InputReader.ReadUInt32();
            header.numRelocations = InputReader.ReadUInt32();
            header.mixedMarshallingDataOffset = InputReader.ReadUInt32();
            header.numMixedMarshallingData = InputReader.ReadUInt32();

            Debug.Assert(header.offsetInFile <= Header.fileSize);

            if (header.compression != 0)
            {
                Debug.Assert(header.offsetInFile + header.compressedSize <= Header.fileSize);
            }
            else
            {
                Debug.Assert(header.compressedSize == header.uncompressedSize);
                Debug.Assert(header.offsetInFile + header.uncompressedSize <= Header.fileSize);
            }

            // TODO: check alignment, secondaryDataOffset[2]
            Debug.Assert(header.relocationsOffset <= Header.fileSize);
            Debug.Assert(header.relocationsOffset + header.numRelocations * 12 <= Header.fileSize);
            Debug.Assert(header.mixedMarshallingDataOffset <= Header.fileSize);
            Debug.Assert(header.mixedMarshallingDataOffset + header.numMixedMarshallingData * 16 <= Header.fileSize);

#if DEBUG_GR2_SERIALIZATION
            System.Console.WriteLine(" ===== Section Header ===== ");
            System.Console.WriteLine(String.Format("Compression: {0}", header.compression));
            System.Console.WriteLine(String.Format("Offset {0:X8} Comp/UncompSize {1:X8}/{2:X8}", header.offsetInFile, header.compressedSize, header.uncompressedSize));
            System.Console.WriteLine(String.Format("Alignment {0}", header.alignment));
            System.Console.WriteLine(String.Format("First 16/8bit: {0:X8}/{1:X8}", header.first16bit, header.first8bit));
            System.Console.WriteLine(String.Format("Relocations: {0:X8} count {1}", header.relocationsOffset, header.numRelocations));
            System.Console.WriteLine(String.Format("Marshalling data: {0:X8} count {1}", header.mixedMarshallingDataOffset, header.numMixedMarshallingData));
#endif
            return header;
        }