using FSO.Files.Utils; using System; using System.IO; using System.Linq; namespace FSO.Files.Formats.IFF.Chunks { public class PIFF : IffChunk { public static ushort CURRENT_VERSION = 2; public ushort Version = CURRENT_VERSION; public string SourceIff; public string Comment = ""; public PIFFEntry[] Entries; public PIFF() { ChunkType = "PIFF"; } public void AppendAddedChunks(IffFile file) { foreach (var chunk in file.SilentListAll()) { if (chunk == this) continue; var entries = Entries.ToList(); entries.Add(new PIFFEntry() { ChunkID = chunk.ChunkID, ChunkLabel = chunk.ChunkLabel, ChunkFlags = chunk.ChunkFlags, EntryType = PIFFEntryType.Add, NewDataSize = (uint)(chunk.ChunkData?.Length ?? 0), Type = chunk.ChunkType }); Entries = entries.ToArray(); } } public override void Read(IffFile iff, Stream stream) { using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN)) { Version = io.ReadUInt16(); SourceIff = io.ReadVariableLengthPascalString(); if (Version > 1) Comment = io.ReadVariableLengthPascalString(); Entries = new PIFFEntry[io.ReadUInt16()]; for (int i=0; i 1) e.Comment = io.ReadVariableLengthPascalString(); e.EntryType = (PIFFEntryType)io.ReadByte(); if (e.EntryType == PIFFEntryType.Patch) { e.ChunkLabel = io.ReadVariableLengthPascalString(); e.ChunkFlags = io.ReadUInt16(); if (Version > 0) e.NewChunkID = io.ReadUInt16(); else e.NewChunkID = e.ChunkID; e.NewDataSize = io.ReadUInt32(); var size = io.ReadUInt32(); e.Patches = new PIFFPatch[size]; uint lastOff = 0; for (int j=0; j