public override void LoadSection(BinaryReaderEx reader) { base.LoadSection(reader); reader.BaseStream.Position += 16; this.NumSections = reader.ReadInt32(); sectionOffsets = new int[this.NumSections]; for (var i = 0; i < this.NumSections; i++) { sectionOffsets[i] = reader.ReadInt32(); } this.NumSectionNames = reader.ReadInt32(); this.sectionNameOffsets = new int[this.NumSectionNames]; for (var i = 0; i < this.NumSectionNames; i++) { sectionNameOffsets[i] = reader.ReadInt32(); } this.NumChunkNames = reader.ReadInt32(); this.chunkNameOffsets = new int[this.NumChunkNames]; for (var i = 0; i < this.NumChunkNames; i++) { chunkNameOffsets[i] = reader.ReadInt32(); } this.SectionNames = new List <string>(); this.ChunkNames = new List <string>(); LoadStrings(reader, sectionNameOffsets, this.SectionNames); LoadStrings(reader, chunkNameOffsets, this.ChunkNames); // Read Sections -------------------------------------- this.Sections = new List <MtbSubSection>(); this.Children = new List <INavigable>(); for (var i = 0; i < this.NumSections; i++) { reader.BaseStream.Position = this.SectionStart + this.sectionOffsets[i]; int nameIdx = reader.ReadInt32(); reader.BaseStream.Seek(-4, System.IO.SeekOrigin.Current); if (nameIdx >= this.NumSectionNames) { throw new InvalidOperationException("Unexpectedly large section name index"); } string sectionName = this.SectionNames[nameIdx]; MtbSubSection section = null; switch (sectionName) { case "Header": section = new MtbHeader(); break; case "SpuBinary": section = new SpuBinary(); break; default: section = new MtbGenericSection(); break; } if (section != null) { section.Parent = this; this.Children.Add(section); this.Sections.Add(section); section.Load(reader); section.SectionName = sectionName; } } this.Header = (MtbHeader)FindSection("Header", 0); }
public override void LoadSection(BinaryReaderEx reader) { base.LoadSection(reader); reader.BaseStream.Position += 16; this.NumSections = reader.ReadInt32(); sectionOffsets = new int[this.NumSections]; for (var i = 0; i < this.NumSections; i++) { sectionOffsets[i] = reader.ReadInt32(); } this.NumSectionNames = reader.ReadInt32(); this.sectionNameOffsets = new int[this.NumSectionNames]; for (var i = 0; i < this.NumSectionNames; i++) { sectionNameOffsets[i] = reader.ReadInt32(); } this.NumChunkNames = reader.ReadInt32(); this.chunkNameOffsets = new int[this.NumChunkNames]; for (var i = 0; i < this.NumChunkNames; i++) { chunkNameOffsets[i] = reader.ReadInt32(); } this.SectionNames = new List<string>(); this.ChunkNames = new List<string>(); LoadStrings(reader, sectionNameOffsets, this.SectionNames); LoadStrings(reader, chunkNameOffsets, this.ChunkNames); // Read Sections -------------------------------------- this.Sections = new List<MtbSubSection>(); this.Children = new List<INavigable>(); for (var i = 0; i < this.NumSections; i++) { reader.BaseStream.Position = this.SectionStart + this.sectionOffsets[i]; int nameIdx = reader.ReadInt32(); reader.BaseStream.Seek(-4, System.IO.SeekOrigin.Current); if (nameIdx >= this.NumSectionNames) { throw new InvalidOperationException("Unexpectedly large section name index"); } string sectionName = this.SectionNames[nameIdx]; MtbSubSection section = null; switch (sectionName) { case "Header": section = new MtbHeader(); break; case "SpuBinary": section = new SpuBinary(); break; default: section = new MtbGenericSection(); break; } if (section != null) { section.Parent = this; this.Children.Add(section); this.Sections.Add(section); section.Load(reader); section.SectionName = sectionName; } } this.Header = (MtbHeader)FindSection("Header", 0); }