public void MoveAndSwap(IffChunk chunk, ushort targID) { if (chunk.ChunkID == targID) { return; } var type = chunk.GetType(); object targ = null; if (ByChunkId.ContainsKey(type)) { ByChunkId[type].TryGetValue(targID, out targ); } var tChunk = (IffChunk)targ; if (tChunk != null) { RemoveChunk(tChunk); } var oldID = chunk.ChunkID; RemoveChunk(chunk); chunk.ChunkID = targID; AddChunk(chunk); if (tChunk != null) { tChunk.ChunkID = oldID; AddChunk(tChunk); } }
public void WriteChunk(IoWriter io,IffChunk c) { var typeString = CHUNK_TYPES.FirstOrDefault(x => x.Value == c.GetType()).Key; io.WriteCString((typeString == null) ? c.ChunkType : typeString,4); byte[] data; using (var cstr = new MemoryStream()) { if (c.Write(this,cstr)) { data = cstr.ToArray(); } else { data = c.OriginalData; } } //todo: exporting PIFF as IFF SHOULD NOT DO THIS c.OriginalData = data; //if we revert, it is to the last save. c.RuntimeInfo = ChunkRuntimeState.Normal; io.WriteUInt32((uint)data.Length + 76); io.WriteUInt16(c.ChunkID); io.WriteUInt16(c.ChunkFlags); io.WriteCString(c.ChunkLabel,64); io.WriteBytes(data); }
public void RemoveChunk(IffChunk chunk) { var type = chunk.GetType(); ByChunkId[type].Remove(chunk.ChunkID); ByChunkType[type].Remove(chunk); }
public void AddChunk(IffChunk chunk) { var type = chunk.GetType(); chunk.ChunkParent = this; if (!ByChunkType.ContainsKey(type)) { ByChunkType.Add(type, new List <object>()); } if (!ByChunkId.ContainsKey(type)) { ByChunkId.Add(type, new Dictionary <ushort, object>()); } ByChunkId[type].Add(chunk.ChunkID, chunk); ByChunkType[type].Add(chunk); }
public void GotoResource(IffChunk chunk) { GotoResource(chunk.GetType(), chunk.ChunkID); }