public static void Write(Stream stream, Doct doct) { if (!stream.CanWrite || !stream.CanSeek) { throw new InvalidDataException($"Write or seek must be supported."); } var entry1Data = new MemoryStream(); { entry1Data.WriteList(doct.Entry1List); } var entry2Data = new MemoryStream(); { entry2Data.WriteList(doct.Entry2List); } { var writer = new BinaryWriter(stream); var newHeader = new HeaderDef { MagicCode = MagicCode, Version = doct.Header.Version, Unk2 = doct.Header.Unk2, HeaderOffset = 0, HeaderLength = 0x2C, Entry1FirstOffset = 0x2C, Entry1TotalLength = Convert.ToInt32(entry1Data.Length), Entry2FirstOffset = 0x2C + Convert.ToInt32(entry1Data.Length), Entry2TotalLength = Convert.ToInt32(entry2Data.Length), Entry3FirstOffset = 0x2C + Convert.ToInt32(entry1Data.Length) + Convert.ToInt32(entry2Data.Length), Entry3TotalLength = 0, }; BinaryMapping.WriteObject(writer, newHeader); entry1Data.Position = 0; entry1Data.CopyTo(stream); entry2Data.Position = 0; entry2Data.CopyTo(stream); } }
public Doct(Stream stream) { if (!stream.CanRead || !stream.CanSeek) { throw new InvalidDataException($"Read or seek must be supported."); } if (stream.Length < HeaderSize) { throw new InvalidDataException("Invalid header length"); } Header = BinaryMapping.ReadObject <HeaderDef>(stream); if (Header.MagicCode != MagicCode) { throw new InvalidDataException("Invalid header"); } Entry1List = stream.ReadList <Entry1>(Header.Entry1FirstOffset, Header.Entry1TotalLength / Entry1Size); Entry2List = stream.ReadList <Entry2>(Header.Entry2FirstOffset, Header.Entry2TotalLength / Entry2Size); }