ME3LibWV.PCCPackage.ReadHeader C# (CSharp) Method

ReadHeader() private method

private ReadHeader ( Stream s ) : void
s Stream
return void
        private void ReadHeader(Stream s)
        {
            try
            {
                s.Seek(0, 0);
                DebugLog.PrintLn("Reading Package Summary...");
                HeaderInfo h = new HeaderInfo();
                h.magic = ReadUInt(s);
                if (h.magic != 0x9E2A83C1)
                    throw new Exception("Not a valid PCC Package, wrong magic!");
                h.ver1 = ReadUInt16(s);
                h.ver2 = ReadUInt16(s);
                h.HeaderLength = ReadUInt(s);
                h.Group = ReadUString(s);
                h._offsetFlag = (uint)s.Position;
                h.Flags = ReadUInt(s);
                GeneralInfo.compressed = (h.Flags & 0x02000000) != 0;
                DebugLog.PrintLn("Is Compressed : " + GeneralInfo.compressed);
                h.unk1 = ReadUInt(s);
                if(h.unk1 > 1)
                    throw new Exception("Not a valid PCC Package, Unknown 1 (offset 30) > 0");
                h.NameCount = ReadUInt(s);
                h.NameOffset = ReadUInt(s);
                h.ExportCount = ReadUInt(s);
                h.ExportOffset = ReadUInt(s);
                h.ImportCount = ReadUInt(s);
                h.ImportOffset = ReadUInt(s);
                h.FreeZoneStart = ReadUInt(s);
                h.FreeZoneEnd = ReadUInt(s);
                h.unk2 = ReadUInt(s);
                h.unk3 = ReadUInt(s);
                h.unk4 = ReadUInt(s);
                h.GUID = new byte[16];
                s.Read(h.GUID, 0, 16);
                int count = ReadInt(s);
                DebugLog.PrintLn("Reading Generations...");
                h.Generations = new List<Generation>();
                for (int i = 0; i < count; i++)
                {
                    Generation g = new Generation();
                    g.ExportCount = ReadUInt(s);
                    g.ImportCount = ReadUInt(s);
                    g.NetObjCount = ReadUInt(s);
                    h.Generations.Add(g);
                }
                DebugLog.PrintLn("Done.");
                h.EngineVersion = ReadUInt(s);
                h.CookerVersion = ReadUInt(s);
                h.unk5 = ReadUInt(s);
                h.unk6 = ReadUInt(s);
                h.CompressionFlag = ReadUInt(s);
                h._offsetCompFlagEnd = (uint)s.Position;
                count = ReadInt(s);
                h.Chunks = new List<CompressedChunk>();
                if (GeneralInfo.compressed)
                {
                    DebugLog.PrintLn("Reading Chunktable...");
                    for (int i = 0; i < count; i++)
                    {
                        CompressedChunk c = new CompressedChunk();
                        c.UnCompOffset = ReadUInt(s);
                        c.UnCompSize = ReadUInt(s);
                        c.CompOffset = ReadUInt(s);
                        c.CompSize = ReadUInt(s);
                        h.Chunks.Add(c);
                    }
                    h.DeCompBuffer = new MemoryStream();
                    DebugLog.PrintLn("Done.");
                }
                h.unk7 = ReadUInt(s);
                h.unk8 = ReadUInt(s);
                Header = h;
                if (GeneralInfo.compressed)
                    ReadChunks(s);
                DebugLog.PrintLn("Done.");
            }
            catch (Exception ex)
            {
                DebugLog.PrintLn("PCCPACKAGE::READHEADER ERROR:\n" + ex.Message);
            }
        }
        private void ReadChunks(Stream s)