public void ReadBinary(ESPReader reader) { Tag = reader.ReadTag(); Size = reader.ReadUInt32(); Flags = (RecordFlag)reader.ReadUInt32(); FormID = reader.Read <FormID>(); LastModified = new DateStamp(); LastModified.ReadBinary(reader); reader.ReadBytes(2); FormVersion = reader.ReadUInt16(); reader.ReadBytes(2); if (Flags.HasFlag(RecordFlag.Compressed)) { byte[] outBytes; compressionCorrupted = !TryDecompressData(reader, out outBytes); if (compressionCorrupted) { corruptedBytes = outBytes; } else { using (MemoryStream stream = new MemoryStream(outBytes)) using (ESPReader subReader = new ESPReader(stream, reader.Plugin)) ReadData(subReader, stream.Length); } } else { ReadData(reader, reader.BaseStream.Position + Size); } }
public RecordView(ESPReader reader, MemoryMappedFile file) { master = reader.Plugin; Source = DataSource.Binary; this.file = file; Offset = reader.BaseStream.Position; Tag = reader.ReadTag(); Size = reader.ReadUInt32() + 24; Flags = (RecordFlag)reader.ReadUInt32(); FormID = reader.Read <FormID>(); VersionControlInfo1 = reader.ReadUInt32(); FormVersion = reader.ReadUInt16(); VersionControlInfo2 = reader.ReadUInt16(); reader.BaseStream.Seek(Offset + Size, SeekOrigin.Begin); }
public static Group CreateGroup(ESPReader reader) { reader.BaseStream.Seek(12, SeekOrigin.Current); Group outGroup = Group.CreateGroup((GroupType)reader.ReadUInt32()); reader.BaseStream.Seek(-16, SeekOrigin.Current); return(outGroup); }
bool TryDecompressData(ESPReader reader, out byte[] outBytes) { uint origSize = reader.ReadUInt32(); byte[] compressedBytes = reader.ReadBytes((int)Size - 4); try { using (MemoryStream stream = new MemoryStream(compressedBytes)) outBytes = Zlib.Decompress(stream, origSize - 4); return(true); } catch { List <byte> temp = BitConverter.GetBytes(origSize).ToList(); temp.AddRange(compressedBytes); outBytes = temp.ToArray(); return(false); } }
public void ReadBinary(ESPReader reader, MemoryMappedFile source) { Tag = reader.ReadTag(); Size = reader.ReadUInt32() - 24; ReadTypeData(reader); GroupType thisType = (GroupType)reader.ReadUInt32(); Debug.Assert(thisType == type); LastModified = new DateStamp(); LastModified.ReadBinary(reader); Unknown = reader.ReadBytes(6); long offset = reader.BaseStream.Position; while (reader.BaseStream.Position < offset + Size) { if (reader.PeekTag() == "GRUP") { Group newGroup = Group.CreateGroup(reader); if (GroupAdded != null) { GroupAdded(newGroup); } newGroup.GroupAdded += (g) => { AllSubgroups.Add(g); if (GroupAdded != null) { GroupAdded(g); } }; newGroup.RecordViewAdded += (r) => { AllRecordViews.Add(r); if (RecordViewAdded != null) { RecordViewAdded(r); } }; Children.Add(newGroup); AllSubgroups.Add(newGroup); newGroup.ReadBinary(reader, source); } else { RecordView newView = new RecordView(reader, source); ChildRecordViews.Add(newView); AllRecordViews.Add(newView); if (RecordViewAdded != null) { RecordViewAdded(newView); } } } }