public void SetActiveResource(IffChunk chunk, GameIffResource res) { GraphicChunk = (SPR2)chunk; ActiveIff = res; FrameList.Items.Clear(); for (int i = 0; i < GraphicChunk.Frames.Length / 3; i++) { FrameList.Items.Add("Rotation " + i); } bool hasFrames = (FrameList.Items.Count > 0); Graphics = null; if (hasFrames) { FrameList.SelectedIndex = 0; } else { SPRBox1.Image = null; SPRBox2.Image = null; SPRBox3.Image = null; } DeleteButton.Enabled = hasFrames; ImportButton.Enabled = hasFrames; ExportButton.Enabled = hasFrames; ImportAll.Enabled = hasFrames; ExportAll.Enabled = hasFrames; }
public void SetActiveResource(IffChunk chunk, GameIffResource res) { OTFFile tuning = null; if (res is GameObjectResource) { tuning = ((GameObjectResource)res).Tuning; } else if (res is GameGlobalResource) { tuning = ((GameGlobalResource)res).Tuning; } if (tuning == null) { XMLDisplay.Text = "No OTF is present for this iff."; } else { using (var stream = new StringWriter()) { var writer = new XmlTextWriter(stream); writer.Formatting = Formatting.Indented; writer.Indentation = 2; tuning.Document.Save(writer); XMLDisplay.Text = stream.ToString(); } } }
public ResAction(UIResActionDelegate action, IffChunk chunk, bool causesChange, AutoResetEvent signal) { Action = action; Chunk = chunk; Signal = signal; CausesChange = causesChange; }
public void DeletePatch(IffChunk chunk) { lock (this) { chunk.ChunkData = chunk.OriginalData; DiscardChange(chunk); } }
private static string FindComment(IffChunk chunk, PIFF oldPIFF) { var oldEntry = oldPIFF?.Entries?.FirstOrDefault(entry => entry.Type == chunk.ChunkType && ((chunk.AddedByPatch) ? chunk.ChunkID : chunk.OriginalID) == entry.ChunkID); return(oldEntry?.Comment ?? ""); }
public void DiscardChange(IffChunk chunk) { lock (this) { UnregisterObjects(chunk.ChunkParent); chunk.ChunkParent.Revert(chunk); if (chunk.ChunkParent.ListAll().Count(x => x.RuntimeInfo == ChunkRuntimeState.Modified || x.RuntimeInfo == ChunkRuntimeState.Delete) == 0) { ChangedFiles.Remove(chunk.ChunkParent); } RegisterObjects(chunk.ChunkParent); } }
public IffNameDialog(IffChunk chunk, bool newChunk) { InitializeComponent(); Chunk = chunk; ChunkLabelEntry.Text = chunk.ChunkLabel; NewChunk = newChunk; if (chunk is BHAV && chunk.ChunkParent.RuntimeInfo.UseCase == IffUseCase.Object) { ChunkIDEntry.Minimum = 4096; } ChunkIDEntry.Value = Math.Max(ChunkIDEntry.Minimum, Math.Min(ChunkIDEntry.Maximum, chunk.ChunkID)); }
public void SetSelectors(OBJD objd, IffChunk active, OBJDSelector[] selectors) { Active = active; Definition = objd; SelectButton.Dock = DockStyle.Fill; SelectCombo.Dock = DockStyle.Fill; SelectButton.Visible = selectors.Length == 1; SelectCombo.Visible = selectors.Length > 1; Selectors = selectors; if (selectors.Length > 1) { SelectCombo.Items.Clear(); SelectCombo.Items.Add("-- Not Selected --"); int i = 1; OwnChange = true; SelectCombo.SelectedIndex = 0; foreach (var sel in selectors) { SelectCombo.Items.Add(sel); if (sel.FieldName != null && objd.GetPropertyByName <ushort>(sel.FieldName) == active.ChunkID) { SelectCombo.SelectedIndex = i; } i++; } OwnChange = false; } else if (selectors.Length > 0) { var sel = selectors[0]; if (sel.FieldName != null && objd.GetPropertyByName <ushort>(sel.FieldName) == active.ChunkID) { SelectButton.Text = "Selected as " + sel.Name; SelectButton.Enabled = false; } else { SelectButton.Text = "Select as " + sel.Name; SelectButton.Enabled = true; } } else { Enabled = false; Visible = false; } }
public void SetActiveResource(IffChunk chunk, GameIffResource res) { Resource = res; Strings = res.Get <TTAs>(chunk.ChunkID); ActiveTTAB = (TTAB)chunk; if (Strings == null) { //we have a problem... make us some strings! Strings = new TTAs(); Strings.ChunkLabel = chunk.ChunkLabel; Strings.ChunkID = chunk.ChunkID; Strings.ChunkProcessed = true; res.MainIff.AddChunk(Strings); } UpdateListing(); UpdateSelection(-1); }
private string GetEntrySummary() { var to = ActiveItem.Replaced; if (to == null || to.OriginalData == null || IgnoreChunks.Contains(to.ChunkType)) { return("Change summary not available."); } Type chunkClass = IffFile.CHUNK_TYPES[to.ChunkType]; IffChunk newChunk = (IffChunk)Activator.CreateInstance(chunkClass); newChunk.ChunkLabel = to.OriginalLabel; newChunk.ChunkID = to.OriginalID; newChunk.OriginalID = to.OriginalID; newChunk.OriginalData = to.OriginalData; newChunk.OriginalLabel = to.OriginalLabel; using (var str = new MemoryStream(to.OriginalData)) { newChunk.Read(to.ChunkParent, str); } var from = newChunk; //instruction mode - load original and new as Routine before we compare fields. (to get operands) //default mode - load original and use reflection to compare fields. var builder = new StringBuilder(); if (from is BHAV) { var froutine = SimAntics.Engine.VMTranslator.INSTANCE.Assemble(from as BHAV, null); var troutine = SimAntics.Engine.VMTranslator.INSTANCE.Assemble(to as BHAV, null); CompareObject("", froutine, troutine, builder); } else { CompareObject("", from, to, builder); } return(builder.ToString()); }
private void PasteRes_Click(object sender,EventArgs e) { //try to paste this into the iff file. DataObject retrievedData = null; IffChunk chunk = null; StaExecute(() => { retrievedData = Clipboard.GetDataObject() as DataObject; if (retrievedData == null || !retrievedData.GetDataPresent("rawbinary")) { return; } MemoryStream memStream = retrievedData.GetData("rawbinary") as MemoryStream; if (memStream == null) { return; } memStream.Seek(0,SeekOrigin.Begin); try { using (var io = IoBuffer.FromStream(memStream,ByteOrder.BIG_ENDIAN)) chunk = ActiveIff.MainIff.AddChunk(memStream,io,false); } catch (Exception) { } }); if (chunk != null) { chunk.ChunkParent = ActiveIff.MainIff; var dialog = new IffNameDialog(chunk,true); dialog.ShowDialog(); } RefreshResList(); }
public PIFFListItem(PIFFEntry entry, IffFile target) { Entry = entry; if (entry.ChunkLabel != "") { Name = entry.ChunkLabel; } else { //try find the original to get name var chunks = target.SilentListAll(); Replaced = chunks.FirstOrDefault(chunk => chunk.ChunkType == entry.Type && chunk.OriginalID == entry.ChunkID); if (Replaced == null) { Name = "UNKNOWN"; } else { Name = Replaced.OriginalLabel; } } }
public ResAction(UIResActionDelegate action, IffChunk chunk, bool causesChange) : this(action, chunk, causesChange, null) { }
public ResAction(UIResActionDelegate action, IffChunk chunk) : this(action, chunk, true, null) { }
public void ChunkChanged(IffChunk chunk) { chunk.RuntimeInfo = ChunkRuntimeState.Modified; chunk.ChunkParent.RuntimeInfo.Dirty = true; IffChanged(chunk.ChunkParent); }
public void SetActiveResource(IffChunk chunk, GameIffResource res) { ActiveConst = (BCON)chunk; ActiveConstLabel = res.Get <TRCN>(chunk.ChunkID); UpdateStrings(); }
public void SetActiveResource(IffChunk chunk,GameIffResource res) { ActiveSLOT = (SLOT)chunk; ActiveSLOTLabel = res.Get <STR>(257); UpdateStrings(); }
public void SetActiveResource(IffChunk chunk, GameIffResource res) { ActiveString = (STR)chunk; UpdateStrings(); }
public void SetActiveResource(IffChunk chunk, GameIffResource res) { ActiveChunk = (BHAV)chunk; ActiveMeta = res.Get <TPRP>(chunk.ChunkID); RefreshDisplay(); }
public void SetActiveResource(IffChunk chunk, GameIffResource res) { }
public void GotoResource(IffChunk chunk) { GotoResource(chunk.GetType(), chunk.ChunkID); }
public static PIFFEntry MakeChunkDiff(IffChunk chk) { var e = new PIFFEntry { Type = chk.ChunkType, ChunkID = chk.OriginalID, NewChunkID = chk.ChunkID }; if (chk == null) { e.Delete = true; return(e); } byte[] newData = null; using (var stream = new MemoryStream()) { if (!chk.Write(chk.ChunkParent, stream)) { return(null); //use original } newData = stream.ToArray(); } e.ChunkLabel = (chk.OriginalLabel == chk.ChunkLabel)?"":chk.ChunkLabel; e.ChunkFlags = chk.ChunkFlags; e.NewDataSize = (uint)newData.Length; //encode difference as sequence of changes var oldData = chk.OriginalData; var patches = new List <PIFFPatch>(); int i; for (i = 0; i < newData.Length; i += 1000) { if (i >= oldData.Length) { //no more comparisons, just add the remainder var remain = new byte[newData.Length - i]; Array.Copy(newData, i, remain, 0, remain.Length); patches.Add(new PIFFPatch { Mode = PIFFPatchMode.Add, Data = remain, Offset = (uint)i, Size = (uint)remain.Length }); break; } //dynamic programming matrix. int m = Math.Min(1000, Math.Max(0, newData.Length - i)) + 1; int n = Math.Min(1000, Math.Max(0, oldData.Length - i)) + 1; ushort[,] comp = new ushort[m, n]; for (int x = 1; x < m; x++) { for (int y = 1; y < n; y++) { if (newData[i + x - 1] == oldData[i + y - 1]) { comp[x, y] = (ushort)(comp[x - 1, y - 1] + 1); } else { comp[x, y] = Math.Max(comp[x, y - 1], comp[x - 1, y]); } } } var changes = new Stack <byte>(); //backtrack through compare { int x = m - 1, y = n - 1; while (true) { if (x > 0 && y > 0 && newData[i + x - 1] == oldData[i + y - 1]) { x--; y--; changes.Push(0); //no change } else if (y > 0 && (x == 0 || comp[x, y - 1] >= comp[x - 1, y])) { y--; changes.Push(2); //remove } else if (x > 0 && (y == 0 || comp[x, y - 1] < comp[x - 1, y])) { x--; changes.Push(1); //add } else { break; } } } byte lastC = 0; PIFFPatch curr = null; List <byte> addArray = null; int ptr = 0; foreach (var c in changes) { if (c != lastC && curr != null) { if (lastC == 1) { curr.Data = addArray.ToArray(); } patches.Add(curr); curr = null; } if (c == 0) { ptr++; } else if (c == 1) { if (lastC != 1) { curr = new PIFFPatch { Mode = PIFFPatchMode.Add, Offset = (uint)(i + ptr), Size = 1 }; addArray = new List <byte>(); addArray.Add(newData[i + ptr]); } else { curr.Size++; addArray.Add(newData[i + ptr]); } ptr++; } else { if (lastC != 2) { curr = new PIFFPatch { Mode = PIFFPatchMode.Remove, Offset = (uint)(i + ptr), Size = 1 } } ; else { curr.Size++; } } lastC = c; } if (curr != null) { if (lastC == 1) { curr.Data = addArray.ToArray(); } patches.Add(curr); } if (m < n) { //remainder on src to be removed patches.Add(new PIFFPatch { Mode = PIFFPatchMode.Remove, Offset = (uint)(i + ptr), Size = (uint)(n - m) }); } /*else if (m != n) * { * //remainder on dest to be added * var remain = new byte[m-n]; * Array.Copy(newData, i+ptr, remain, 0, remain.Length); * patches.Add(new PIFFPatch * { * Mode = PIFFPatchMode.Add, * Data = remain, * Offset = (uint)(i+ ptr), * Size = (uint)remain.Length * }); * }*/ } if (oldData.Length > i) { //ran out of new data, but old is still going. Remove the remainder. patches.Add(new PIFFPatch { Mode = PIFFPatchMode.Remove, Offset = (uint)newData.Length, Size = (uint)(oldData.Length - i) }); } e.Patches = patches.ToArray(); return(e); }