internal Record(string name, uint Size, BinaryReader br, bool Oblivion) { bool compressedRecord = false; SubRecords = new AdvancedList <SubRecord>(1); SubRecords.AllowSorting = false; Name = name; Flags1 = br.ReadUInt32(); FormID = br.ReadUInt32(); Flags2 = br.ReadUInt32(); if (!Oblivion) { Flags3 = br.ReadUInt32(); } if ((Flags1 & 0x00040000) > 0) { //Flags1 ^= 0x00040000; uint newSize = br.ReadUInt32(); br = Decompressor.Decompress(br, (int)(Size - 4), (int)newSize); Size = newSize; compressedRecord = true; } uint AmountRead = 0; while (AmountRead < Size) { string s = ReadRecName(br); uint i = 0; if (s == "XXXX") { ushort xsize = br.ReadUInt16(); if (xsize != 4) { throw new TESParserException( String.Format("Unexpected Subrecord block XXXX size! Expected 4 but found {0:D}!", xsize)); } i = br.ReadUInt32(); s = ReadRecName(br); } var r = new SubRecord(this, s, br, i); AmountRead += (uint)(r.Size2); SubRecords.Add(r); } descNameOverride = DefaultDescriptiveName; UpdateShortDescription(); //br.BaseStream.Position+=Size; if (AmountRead != Size) { System.Windows.Forms.Application.Exit(); // throw new TESParserException( // String.Format("Subrecord block did not match the size specified in the record header. Name={3} Header size={0:D} Subrecord Size={1:D} CompressedRecord={2:G}", Size, AmountRead, compressedRecord, name)); } }
internal Record(string name, uint Size, BinaryReader br, bool Oblivion) { SubRecords = new AdvancedList <SubRecord>(1); SubRecords.AllowSorting = false; Name = name; Flags1 = br.ReadUInt32(); FormID = br.ReadUInt32(); Flags2 = br.ReadUInt32(); if (!Oblivion) { Flags3 = br.ReadUInt32(); } if ((Flags1 & 0x00040000) > 0) { //Flags1 ^= 0x00040000; uint newSize = br.ReadUInt32(); br = Decompressor.Decompress(br, (int)(Size - 4), (int)newSize); Size = newSize; } uint AmountRead = 0; while (AmountRead < Size) { string s = ReadRecName(br); uint i = 0; if (s == "XXXX") { br.ReadUInt16(); i = br.ReadUInt32(); s = ReadRecName(br); } var r = new SubRecord(this, s, br, i); AmountRead += (uint)(r.Size2); SubRecords.Add(r); } if (AmountRead > Size) { throw new TESParserException("Subrecord block did not match the size specified in the record header"); } descNameOverride = DefaultDescriptiveName; UpdateShortDescription(); //br.BaseStream.Position+=Size; }
private void LoadPluginData(BinaryReader br, bool headerOnly, string[] recFilter) { bool oldHoldUpdates = HoldUpdates; try { string s; uint recsize; bool IsOblivion = false; Filtered = (recFilter != null && recFilter.Length > 0); HoldUpdates = true; Decompressor.Init(); s = ReadRecName(br); if (s != "TES4") { throw new Exception("File is not a valid TES4 plugin (Missing TES4 record)"); } // Check for file version by checking the position of the HEDR field in the file. (ie. how big are the record header.) br.BaseStream.Position = 20; s = ReadRecName(br); if (s == "HEDR") { // Record Header is 20 bytes IsOblivion = true; } else { s = ReadRecName(br); if (s != "HEDR") { throw new Exception( "File is not a valid TES4 plugin (Missing HEDR subrecord in the TES4 record)"); } // Record Header is 24 bytes. Or the file is illegal } br.BaseStream.Position = 4; recsize = br.ReadUInt32(); try { AddRecord(new Record("TES4", recsize, br, IsOblivion)); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } if (!headerOnly) { while (br.PeekChar() != -1) { s = ReadRecName(br); recsize = br.ReadUInt32(); if (s == "GRUP") { try { AddRecord(new GroupRecord(recsize, br, IsOblivion, recFilter, false)); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } } else { bool skip = recFilter != null && Array.IndexOf(recFilter, s) >= 0; if (skip) { long size = (recsize + (IsOblivion ? 8 : 12)); if ((br.ReadUInt32() & 0x00040000) > 0) { size += 4; // Add 4 bytes for compressed record since the decompressed size is not included in the record size. } br.BaseStream.Position += size; // just position past the data } else { try { AddRecord(new Record(s, recsize, br, IsOblivion)); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } } } } } } finally { HoldUpdates = oldHoldUpdates; FireRecordListUpdate(this, this); Decompressor.Close(); } }
private void LoadPluginData(BinaryReader br, bool headerOnly, string[] recFilter) { bool oldHoldUpdates = HoldUpdates; try { string s; uint recsize; bool IsOblivion = false; Filtered = (recFilter != null && recFilter.Length > 0); HoldUpdates = true; Decompressor.Init(); s = ReadRecName(br); if (s != "TES4") throw new Exception("File is not a valid TES4 plugin (Missing TES4 record)"); br.BaseStream.Position = 20; s = ReadRecName(br); if (s == "HEDR") { IsOblivion = true; } else { s = ReadRecName(br); if (s != "HEDR") throw new Exception( "File is not a valid TES4 plugin (Missing HEDR subrecord in the TES4 record)"); } br.BaseStream.Position = 4; recsize = br.ReadUInt32(); AddRecord(new Record("TES4", recsize, br, IsOblivion)); if (!headerOnly) { while (br.PeekChar() != -1) { s = ReadRecName(br); recsize = br.ReadUInt32(); if (s == "GRUP") { AddRecord(new GroupRecord(recsize, br, IsOblivion, recFilter, false)); } else { bool skip = recFilter != null && Array.IndexOf(recFilter, s) >= 0; if (skip) { long size = (recsize + (IsOblivion ? 8 : 12)); if ((br.ReadUInt32() & 0x00040000) > 0) size += 4; br.BaseStream.Position += size; // just read past the data } else AddRecord(new Record(s, recsize, br, IsOblivion)); } } } } finally { HoldUpdates = oldHoldUpdates; FireRecordListUpdate(this, this); Decompressor.Close(); } }