From 40e5cd66dac9a164d8be8cb12ebb0b6cce05bcb5 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 19 Jan 2020 22:29:50 -0800 Subject: [PATCH] Add block diff for swsh, add bool type toggle Apparently my copypaste of the class didn't delete all the old unused controls. Ha! Move non-gui logic to core as separate classes, in case ppl wanted to reuse them in their own projects. --- PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs | 94 +++ PKHeX.Core/Saves/MemeCrypto/SCBlockUtil.cs | 101 +++ .../Gen8/SAV_BlockDump8.Designer.cs | 593 +++++------------- .../Save Editors/Gen8/SAV_BlockDump8.cs | 166 +++-- 4 files changed, 436 insertions(+), 518 deletions(-) create mode 100644 PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs create mode 100644 PKHeX.Core/Saves/MemeCrypto/SCBlockUtil.cs diff --git a/PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs b/PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs new file mode 100644 index 000000000..bba337a33 --- /dev/null +++ b/PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs @@ -0,0 +1,94 @@ +using System.Collections.Generic; +using System.Linq; + +namespace PKHeX.Core +{ + public class SCBlockCompare + { + private readonly List AddedKeys = new List(); + private readonly List RemovedKeys = new List(); + private readonly List TypesChanged = new List(); + private readonly List ValueChanged = new List(); + + public SCBlockCompare(SAV8SWSH s1, SAV8SWSH s2) + { + var b1 = s1.Blocks.BlockInfo; + var b2 = s2.Blocks.BlockInfo; + + var hs1 = new HashSet(b1.Select(z => z.Key)); + var hs2 = new HashSet(b2.Select(z => z.Key)); + + var unique = new HashSet(hs1); + unique.SymmetricExceptWith(hs2); + foreach (var k in unique) + { + if (hs1.Contains(k)) + { + var b = s1.Blocks.GetBlock(k); + RemovedKeys.Add($"{b.Key:X8} - {b.Type}"); + } + else + { + var b = s2.Blocks.GetBlock(k); + AddedKeys.Add($"{b.Key:X8} - {b.Type}"); + } + } + + hs1.IntersectWith(hs2); + foreach (var k in hs1) + { + var x1 = s1.Blocks.GetBlock(k); + var x2 = s2.Blocks.GetBlock(k); + if (x1.Type != x2.Type) + { + TypesChanged.Add($"{x1.Key:X8} - {x1.Type} => {x2.Type}"); + continue; + } + if (x1.Data.Length != x2.Data.Length) + { + ValueChanged.Add($"{x1.Key:X8} - Length: {x1.Data.Length} => {x2.Data.Length}"); + continue; + } + + if (x1.Data.Length == 0) + continue; + + if (x1.Type == SCTypeCode.Object || x1.Type == SCTypeCode.Array) + { + if (!x1.Data.SequenceEqual(x2.Data)) + ValueChanged.Add($"{x1.Key:X8} - Bytes Changed"); + continue; + } + + var val1 = x1.GetValue(); + var val2 = x2.GetValue(); + if (Equals(val1, val2)) + continue; + if (val1 is ulong u1 && val2 is ulong u2) + ValueChanged.Add($"{x1.Key:X8} - {u1:X8} => {u2:x8}"); + else + ValueChanged.Add($"{x1.Key:X8} - {val1} => {val2}"); + } + } + + public IReadOnlyList Summary() + { + var result = new List(); + AddIfPresent(result, AddedKeys, "Blocks Added:"); + AddIfPresent(result, RemovedKeys, "Blocks Removed:"); + AddIfPresent(result, TypesChanged, "BlockType Changed:"); + AddIfPresent(result, ValueChanged, "Value Changed:"); + + return result; + + static void AddIfPresent(List result, IList list, string hdr) + { + if (list.Count == 0) + return; + result.Add(hdr); + result.AddRange(list); + result.Add(string.Empty); + } + } + } +} \ No newline at end of file diff --git a/PKHeX.Core/Saves/MemeCrypto/SCBlockUtil.cs b/PKHeX.Core/Saves/MemeCrypto/SCBlockUtil.cs new file mode 100644 index 000000000..d5d9162d4 --- /dev/null +++ b/PKHeX.Core/Saves/MemeCrypto/SCBlockUtil.cs @@ -0,0 +1,101 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace PKHeX.Core +{ + public static class SCBlockUtil + { + public static void ExportAllBlocksAsSingleFile(IReadOnlyList blocks, string path, bool dataOnly = true, bool key = true, bool typeInfo = true, bool fakeHeader = true) + { + using var stream = new MemoryStream(); + using var bw = new BinaryWriter(stream); + + if (fakeHeader) + { + for (int i = 0; i < blocks.Count; i++) + blocks[i].ID = (uint)i; + } + + var iterate = dataOnly ? blocks.Where(z => z.Data.Length != 0) : blocks; + foreach (var b in iterate) + { + if (fakeHeader) + bw.Write($"BLOCK{b.ID:0000} {b.Key:X8}"); + if (key) + bw.Write(b.Key); + if (typeInfo) + { + bw.Write((byte)b.Type); + bw.Write((byte)b.SubType); + } + bw.Write(b.Data); + } + var data = stream.ToArray(); // SwishCrypto.GetDecryptedRawData(blocks); for raw encrypted + File.WriteAllBytes(path, data); + } + + public static string GetBlockFileNameWithoutExtension(SCBlock block) + { + var key = block.Key; + var name = $"{key:X8}"; + if (block.HasValue()) + name += $" {block.GetValue()}"; + return name; + } + + public static string GetBlockSummary(SCBlock b) + { + var sb = new StringBuilder(); + sb.Append("Key: ").AppendFormat("{0:X8}", b.Key).AppendLine(); + sb.Append("Type: ").Append(b.Type).AppendLine(); + if (b.Data.Length != 0) + sb.Append("Length: ").AppendFormat("{0:X8}", b.Data.Length).AppendLine(); + + if (b.SubType != 0) + sb.Append("SubType: ").Append(b.SubType).AppendLine(); + else if (b.HasValue()) + sb.Append("Value: ").Append(b.GetValue()).AppendLine(); + + return sb.ToString(); + } + + public static List ImportBlocksFromFolder(string path, SAV8SWSH sav) + { + var failed = new List(); + var files = Directory.EnumerateFiles(path); + foreach (var f in files) + { + var fn = Path.GetFileNameWithoutExtension(f); + + // Trim off Value summary if present + var space = fn.IndexOf(' '); + if (space >= 0) + fn = fn.Substring(0, space); + + var hex = Util.GetHexValue(fn); + try + { + var block = sav.Blocks.GetBlock(hex); + var len = block.Data.Length; + var fi = new FileInfo(f); + if (fi.Length != len) + { + failed.Add(fn); + continue; + } + + var data = File.ReadAllBytes(f); + data.CopyTo(block.Data, 0); + } + catch + { + failed.Add(fn); + } + } + + return failed; + } + } +} \ No newline at end of file diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.Designer.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.Designer.cs index a9e0ff41a..39eda8bd0 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.Designer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.Designer.cs @@ -28,50 +28,6 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.L_Saying5 = new System.Windows.Forms.Label(); - this.L_Saying4 = new System.Windows.Forms.Label(); - this.L_Saying3 = new System.Windows.Forms.Label(); - this.L_Saying2 = new System.Windows.Forms.Label(); - this.L_Saying1 = new System.Windows.Forms.Label(); - this.TB_Saying5 = new System.Windows.Forms.TextBox(); - this.TB_Saying4 = new System.Windows.Forms.TextBox(); - this.TB_Saying3 = new System.Windows.Forms.TextBox(); - this.TB_Saying2 = new System.Windows.Forms.TextBox(); - this.TB_Saying1 = new System.Windows.Forms.TextBox(); - this.TB_MBMS = new System.Windows.Forms.MaskedTextBox(); - this.TB_MBMN = new System.Windows.Forms.MaskedTextBox(); - this.TB_MBRS = new System.Windows.Forms.MaskedTextBox(); - this.TB_MBRN = new System.Windows.Forms.MaskedTextBox(); - this.TB_MBTS = new System.Windows.Forms.MaskedTextBox(); - this.TB_MBTN = new System.Windows.Forms.MaskedTextBox(); - this.TB_MBDS = new System.Windows.Forms.MaskedTextBox(); - this.TB_MBDN = new System.Windows.Forms.MaskedTextBox(); - this.TB_MBSS = new System.Windows.Forms.MaskedTextBox(); - this.TB_MBSN = new System.Windows.Forms.MaskedTextBox(); - this.L_SuperB = new System.Windows.Forms.Label(); - this.L_NormalB = new System.Windows.Forms.Label(); - this.L_MultiB = new System.Windows.Forms.Label(); - this.L_RotationB = new System.Windows.Forms.Label(); - this.L_TriplesB = new System.Windows.Forms.Label(); - this.L_DoublesB = new System.Windows.Forms.Label(); - this.L_SinglesB = new System.Windows.Forms.Label(); - this.TB_MCMS = new System.Windows.Forms.MaskedTextBox(); - this.TB_MCMN = new System.Windows.Forms.MaskedTextBox(); - this.TB_MCRS = new System.Windows.Forms.MaskedTextBox(); - this.TB_MCRN = new System.Windows.Forms.MaskedTextBox(); - this.TB_MCTS = new System.Windows.Forms.MaskedTextBox(); - this.TB_MCTN = new System.Windows.Forms.MaskedTextBox(); - this.TB_MCDS = new System.Windows.Forms.MaskedTextBox(); - this.TB_MCDN = new System.Windows.Forms.MaskedTextBox(); - this.TB_MCSS = new System.Windows.Forms.MaskedTextBox(); - this.TB_MCSN = new System.Windows.Forms.MaskedTextBox(); - this.L_SuperC = new System.Windows.Forms.Label(); - this.L_NormalC = new System.Windows.Forms.Label(); - this.L_MultiC = new System.Windows.Forms.Label(); - this.L_RotationC = new System.Windows.Forms.Label(); - this.L_TriplesC = new System.Windows.Forms.Label(); - this.L_DoublesC = new System.Windows.Forms.Label(); - this.L_SinglesC = new System.Windows.Forms.Label(); this.CB_Key = new System.Windows.Forms.ComboBox(); this.L_Key = new System.Windows.Forms.Label(); this.L_Detail_L = new System.Windows.Forms.Label(); @@ -85,315 +41,21 @@ private void InitializeComponent() this.CHK_DataOnly = new System.Windows.Forms.CheckBox(); this.CHK_FakeHeader = new System.Windows.Forms.CheckBox(); this.CHK_Key = new System.Windows.Forms.CheckBox(); - this.SuspendLayout(); - // - // L_Saying5 - // - this.L_Saying5.Location = new System.Drawing.Point(0, 0); - this.L_Saying5.Name = "L_Saying5"; - this.L_Saying5.Size = new System.Drawing.Size(100, 23); - this.L_Saying5.TabIndex = 0; - // - // L_Saying4 - // - this.L_Saying4.Location = new System.Drawing.Point(0, 0); - this.L_Saying4.Name = "L_Saying4"; - this.L_Saying4.Size = new System.Drawing.Size(100, 23); - this.L_Saying4.TabIndex = 0; - // - // L_Saying3 - // - this.L_Saying3.Location = new System.Drawing.Point(0, 0); - this.L_Saying3.Name = "L_Saying3"; - this.L_Saying3.Size = new System.Drawing.Size(100, 23); - this.L_Saying3.TabIndex = 0; - // - // L_Saying2 - // - this.L_Saying2.Location = new System.Drawing.Point(0, 0); - this.L_Saying2.Name = "L_Saying2"; - this.L_Saying2.Size = new System.Drawing.Size(100, 23); - this.L_Saying2.TabIndex = 0; - // - // L_Saying1 - // - this.L_Saying1.Location = new System.Drawing.Point(0, 0); - this.L_Saying1.Name = "L_Saying1"; - this.L_Saying1.Size = new System.Drawing.Size(100, 23); - this.L_Saying1.TabIndex = 0; - // - // TB_Saying5 - // - this.TB_Saying5.Location = new System.Drawing.Point(0, 0); - this.TB_Saying5.Name = "TB_Saying5"; - this.TB_Saying5.Size = new System.Drawing.Size(100, 20); - this.TB_Saying5.TabIndex = 0; - // - // TB_Saying4 - // - this.TB_Saying4.Location = new System.Drawing.Point(0, 0); - this.TB_Saying4.Name = "TB_Saying4"; - this.TB_Saying4.Size = new System.Drawing.Size(100, 20); - this.TB_Saying4.TabIndex = 0; - // - // TB_Saying3 - // - this.TB_Saying3.Location = new System.Drawing.Point(0, 0); - this.TB_Saying3.Name = "TB_Saying3"; - this.TB_Saying3.Size = new System.Drawing.Size(100, 20); - this.TB_Saying3.TabIndex = 0; - // - // TB_Saying2 - // - this.TB_Saying2.Location = new System.Drawing.Point(0, 0); - this.TB_Saying2.Name = "TB_Saying2"; - this.TB_Saying2.Size = new System.Drawing.Size(100, 20); - this.TB_Saying2.TabIndex = 0; - // - // TB_Saying1 - // - this.TB_Saying1.Location = new System.Drawing.Point(0, 0); - this.TB_Saying1.Name = "TB_Saying1"; - this.TB_Saying1.Size = new System.Drawing.Size(100, 20); - this.TB_Saying1.TabIndex = 0; - // - // TB_MBMS - // - this.TB_MBMS.Location = new System.Drawing.Point(0, 0); - this.TB_MBMS.Name = "TB_MBMS"; - this.TB_MBMS.Size = new System.Drawing.Size(100, 20); - this.TB_MBMS.TabIndex = 0; - // - // TB_MBMN - // - this.TB_MBMN.Location = new System.Drawing.Point(0, 0); - this.TB_MBMN.Name = "TB_MBMN"; - this.TB_MBMN.Size = new System.Drawing.Size(100, 20); - this.TB_MBMN.TabIndex = 0; - // - // TB_MBRS - // - this.TB_MBRS.Location = new System.Drawing.Point(0, 0); - this.TB_MBRS.Name = "TB_MBRS"; - this.TB_MBRS.Size = new System.Drawing.Size(100, 20); - this.TB_MBRS.TabIndex = 0; - // - // TB_MBRN - // - this.TB_MBRN.Location = new System.Drawing.Point(0, 0); - this.TB_MBRN.Name = "TB_MBRN"; - this.TB_MBRN.Size = new System.Drawing.Size(100, 20); - this.TB_MBRN.TabIndex = 0; - // - // TB_MBTS - // - this.TB_MBTS.Location = new System.Drawing.Point(0, 0); - this.TB_MBTS.Name = "TB_MBTS"; - this.TB_MBTS.Size = new System.Drawing.Size(100, 20); - this.TB_MBTS.TabIndex = 0; - // - // TB_MBTN - // - this.TB_MBTN.Location = new System.Drawing.Point(0, 0); - this.TB_MBTN.Name = "TB_MBTN"; - this.TB_MBTN.Size = new System.Drawing.Size(100, 20); - this.TB_MBTN.TabIndex = 0; - // - // TB_MBDS - // - this.TB_MBDS.Location = new System.Drawing.Point(0, 0); - this.TB_MBDS.Name = "TB_MBDS"; - this.TB_MBDS.Size = new System.Drawing.Size(100, 20); - this.TB_MBDS.TabIndex = 0; - // - // TB_MBDN - // - this.TB_MBDN.Location = new System.Drawing.Point(0, 0); - this.TB_MBDN.Name = "TB_MBDN"; - this.TB_MBDN.Size = new System.Drawing.Size(100, 20); - this.TB_MBDN.TabIndex = 0; - // - // TB_MBSS - // - this.TB_MBSS.Location = new System.Drawing.Point(0, 0); - this.TB_MBSS.Name = "TB_MBSS"; - this.TB_MBSS.Size = new System.Drawing.Size(100, 20); - this.TB_MBSS.TabIndex = 0; - // - // TB_MBSN - // - this.TB_MBSN.Location = new System.Drawing.Point(0, 0); - this.TB_MBSN.Name = "TB_MBSN"; - this.TB_MBSN.Size = new System.Drawing.Size(100, 20); - this.TB_MBSN.TabIndex = 0; - // - // L_SuperB - // - this.L_SuperB.Location = new System.Drawing.Point(0, 0); - this.L_SuperB.Name = "L_SuperB"; - this.L_SuperB.Size = new System.Drawing.Size(100, 23); - this.L_SuperB.TabIndex = 0; - // - // L_NormalB - // - this.L_NormalB.Location = new System.Drawing.Point(0, 0); - this.L_NormalB.Name = "L_NormalB"; - this.L_NormalB.Size = new System.Drawing.Size(100, 23); - this.L_NormalB.TabIndex = 0; - // - // L_MultiB - // - this.L_MultiB.Location = new System.Drawing.Point(0, 0); - this.L_MultiB.Name = "L_MultiB"; - this.L_MultiB.Size = new System.Drawing.Size(100, 23); - this.L_MultiB.TabIndex = 0; - // - // L_RotationB - // - this.L_RotationB.Location = new System.Drawing.Point(0, 0); - this.L_RotationB.Name = "L_RotationB"; - this.L_RotationB.Size = new System.Drawing.Size(100, 23); - this.L_RotationB.TabIndex = 0; - // - // L_TriplesB - // - this.L_TriplesB.Location = new System.Drawing.Point(0, 0); - this.L_TriplesB.Name = "L_TriplesB"; - this.L_TriplesB.Size = new System.Drawing.Size(100, 23); - this.L_TriplesB.TabIndex = 0; - // - // L_DoublesB - // - this.L_DoublesB.Location = new System.Drawing.Point(0, 0); - this.L_DoublesB.Name = "L_DoublesB"; - this.L_DoublesB.Size = new System.Drawing.Size(100, 23); - this.L_DoublesB.TabIndex = 0; - // - // L_SinglesB - // - this.L_SinglesB.Location = new System.Drawing.Point(0, 0); - this.L_SinglesB.Name = "L_SinglesB"; - this.L_SinglesB.Size = new System.Drawing.Size(100, 23); - this.L_SinglesB.TabIndex = 0; - // - // TB_MCMS - // - this.TB_MCMS.Location = new System.Drawing.Point(0, 0); - this.TB_MCMS.Name = "TB_MCMS"; - this.TB_MCMS.Size = new System.Drawing.Size(100, 20); - this.TB_MCMS.TabIndex = 0; - // - // TB_MCMN - // - this.TB_MCMN.Location = new System.Drawing.Point(0, 0); - this.TB_MCMN.Name = "TB_MCMN"; - this.TB_MCMN.Size = new System.Drawing.Size(100, 20); - this.TB_MCMN.TabIndex = 0; - // - // TB_MCRS - // - this.TB_MCRS.Location = new System.Drawing.Point(0, 0); - this.TB_MCRS.Name = "TB_MCRS"; - this.TB_MCRS.Size = new System.Drawing.Size(100, 20); - this.TB_MCRS.TabIndex = 0; - // - // TB_MCRN - // - this.TB_MCRN.Location = new System.Drawing.Point(0, 0); - this.TB_MCRN.Name = "TB_MCRN"; - this.TB_MCRN.Size = new System.Drawing.Size(100, 20); - this.TB_MCRN.TabIndex = 0; - // - // TB_MCTS - // - this.TB_MCTS.Location = new System.Drawing.Point(0, 0); - this.TB_MCTS.Name = "TB_MCTS"; - this.TB_MCTS.Size = new System.Drawing.Size(100, 20); - this.TB_MCTS.TabIndex = 0; - // - // TB_MCTN - // - this.TB_MCTN.Location = new System.Drawing.Point(0, 0); - this.TB_MCTN.Name = "TB_MCTN"; - this.TB_MCTN.Size = new System.Drawing.Size(100, 20); - this.TB_MCTN.TabIndex = 0; - // - // TB_MCDS - // - this.TB_MCDS.Location = new System.Drawing.Point(0, 0); - this.TB_MCDS.Name = "TB_MCDS"; - this.TB_MCDS.Size = new System.Drawing.Size(100, 20); - this.TB_MCDS.TabIndex = 0; - // - // TB_MCDN - // - this.TB_MCDN.Location = new System.Drawing.Point(0, 0); - this.TB_MCDN.Name = "TB_MCDN"; - this.TB_MCDN.Size = new System.Drawing.Size(100, 20); - this.TB_MCDN.TabIndex = 0; - // - // TB_MCSS - // - this.TB_MCSS.Location = new System.Drawing.Point(0, 0); - this.TB_MCSS.Name = "TB_MCSS"; - this.TB_MCSS.Size = new System.Drawing.Size(100, 20); - this.TB_MCSS.TabIndex = 0; - // - // TB_MCSN - // - this.TB_MCSN.Location = new System.Drawing.Point(0, 0); - this.TB_MCSN.Name = "TB_MCSN"; - this.TB_MCSN.Size = new System.Drawing.Size(100, 20); - this.TB_MCSN.TabIndex = 0; - // - // L_SuperC - // - this.L_SuperC.Location = new System.Drawing.Point(0, 0); - this.L_SuperC.Name = "L_SuperC"; - this.L_SuperC.Size = new System.Drawing.Size(100, 23); - this.L_SuperC.TabIndex = 0; - // - // L_NormalC - // - this.L_NormalC.Location = new System.Drawing.Point(0, 0); - this.L_NormalC.Name = "L_NormalC"; - this.L_NormalC.Size = new System.Drawing.Size(100, 23); - this.L_NormalC.TabIndex = 0; - // - // L_MultiC - // - this.L_MultiC.Location = new System.Drawing.Point(0, 0); - this.L_MultiC.Name = "L_MultiC"; - this.L_MultiC.Size = new System.Drawing.Size(100, 23); - this.L_MultiC.TabIndex = 0; - // - // L_RotationC - // - this.L_RotationC.Location = new System.Drawing.Point(0, 0); - this.L_RotationC.Name = "L_RotationC"; - this.L_RotationC.Size = new System.Drawing.Size(100, 23); - this.L_RotationC.TabIndex = 0; - // - // L_TriplesC - // - this.L_TriplesC.Location = new System.Drawing.Point(0, 0); - this.L_TriplesC.Name = "L_TriplesC"; - this.L_TriplesC.Size = new System.Drawing.Size(100, 23); - this.L_TriplesC.TabIndex = 0; - // - // L_DoublesC - // - this.L_DoublesC.Location = new System.Drawing.Point(0, 0); - this.L_DoublesC.Name = "L_DoublesC"; - this.L_DoublesC.Size = new System.Drawing.Size(100, 23); - this.L_DoublesC.TabIndex = 0; - // - // L_SinglesC - // - this.L_SinglesC.Location = new System.Drawing.Point(0, 0); - this.L_SinglesC.Name = "L_SinglesC"; - this.L_SinglesC.Size = new System.Drawing.Size(100, 23); - this.L_SinglesC.TabIndex = 0; + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.Tab_Dump = new System.Windows.Forms.TabPage(); + this.CB_TypeToggle = new System.Windows.Forms.ComboBox(); + this.Tab_Compare = new System.Windows.Forms.TabPage(); + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.GB_Researcher = new System.Windows.Forms.GroupBox(); + this.TB_NewSAV = new System.Windows.Forms.TextBox(); + this.TB_OldSAV = new System.Windows.Forms.TextBox(); + this.B_LoadNew = new System.Windows.Forms.Button(); + this.B_LoadOld = new System.Windows.Forms.Button(); + this.tabControl1.SuspendLayout(); + this.Tab_Dump.SuspendLayout(); + this.Tab_Compare.SuspendLayout(); + this.GB_Researcher.SuspendLayout(); + this.SuspendLayout(); // // CB_Key // @@ -401,7 +63,7 @@ private void InitializeComponent() this.CB_Key.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.CB_Key.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.CB_Key.FormattingEnabled = true; - this.CB_Key.Location = new System.Drawing.Point(89, 12); + this.CB_Key.Location = new System.Drawing.Point(83, 9); this.CB_Key.Name = "CB_Key"; this.CB_Key.Size = new System.Drawing.Size(183, 22); this.CB_Key.TabIndex = 0; @@ -410,7 +72,7 @@ private void InitializeComponent() // L_Key // this.L_Key.AutoSize = true; - this.L_Key.Location = new System.Drawing.Point(12, 15); + this.L_Key.Location = new System.Drawing.Point(6, 12); this.L_Key.Name = "L_Key"; this.L_Key.Size = new System.Drawing.Size(58, 13); this.L_Key.TabIndex = 1; @@ -419,7 +81,7 @@ private void InitializeComponent() // L_Detail_L // this.L_Detail_L.AutoSize = true; - this.L_Detail_L.Location = new System.Drawing.Point(12, 64); + this.L_Detail_L.Location = new System.Drawing.Point(6, 61); this.L_Detail_L.Name = "L_Detail_L"; this.L_Detail_L.Size = new System.Drawing.Size(67, 13); this.L_Detail_L.TabIndex = 2; @@ -428,7 +90,7 @@ private void InitializeComponent() // L_Detail_R // this.L_Detail_R.AutoSize = true; - this.L_Detail_R.Location = new System.Drawing.Point(86, 64); + this.L_Detail_R.Location = new System.Drawing.Point(80, 61); this.L_Detail_R.Name = "L_Detail_R"; this.L_Detail_R.Size = new System.Drawing.Size(69, 13); this.L_Detail_R.TabIndex = 3; @@ -436,7 +98,7 @@ private void InitializeComponent() // // B_ExportAll // - this.B_ExportAll.Location = new System.Drawing.Point(12, 143); + this.B_ExportAll.Location = new System.Drawing.Point(6, 140); this.B_ExportAll.Name = "B_ExportAll"; this.B_ExportAll.Size = new System.Drawing.Size(91, 50); this.B_ExportAll.TabIndex = 4; @@ -446,7 +108,7 @@ private void InitializeComponent() // // B_ExportAllSingle // - this.B_ExportAllSingle.Location = new System.Drawing.Point(12, 255); + this.B_ExportAllSingle.Location = new System.Drawing.Point(6, 252); this.B_ExportAllSingle.Name = "B_ExportAllSingle"; this.B_ExportAllSingle.Size = new System.Drawing.Size(91, 50); this.B_ExportAllSingle.TabIndex = 5; @@ -456,7 +118,7 @@ private void InitializeComponent() // // B_ImportCurrent // - this.B_ImportCurrent.Location = new System.Drawing.Point(109, 199); + this.B_ImportCurrent.Location = new System.Drawing.Point(103, 196); this.B_ImportCurrent.Name = "B_ImportCurrent"; this.B_ImportCurrent.Size = new System.Drawing.Size(91, 50); this.B_ImportCurrent.TabIndex = 7; @@ -466,7 +128,7 @@ private void InitializeComponent() // // B_ExportCurrent // - this.B_ExportCurrent.Location = new System.Drawing.Point(12, 199); + this.B_ExportCurrent.Location = new System.Drawing.Point(6, 196); this.B_ExportCurrent.Name = "B_ExportCurrent"; this.B_ExportCurrent.Size = new System.Drawing.Size(91, 50); this.B_ExportCurrent.TabIndex = 6; @@ -476,7 +138,7 @@ private void InitializeComponent() // // B_ImportFolder // - this.B_ImportFolder.Location = new System.Drawing.Point(109, 143); + this.B_ImportFolder.Location = new System.Drawing.Point(103, 140); this.B_ImportFolder.Name = "B_ImportFolder"; this.B_ImportFolder.Size = new System.Drawing.Size(91, 50); this.B_ImportFolder.TabIndex = 8; @@ -487,7 +149,7 @@ private void InitializeComponent() // CHK_Type // this.CHK_Type.AutoSize = true; - this.CHK_Type.Location = new System.Drawing.Point(109, 279); + this.CHK_Type.Location = new System.Drawing.Point(103, 276); this.CHK_Type.Name = "CHK_Type"; this.CHK_Type.Size = new System.Drawing.Size(109, 17); this.CHK_Type.TabIndex = 9; @@ -499,7 +161,7 @@ private void InitializeComponent() this.CHK_DataOnly.AutoSize = true; this.CHK_DataOnly.Checked = true; this.CHK_DataOnly.CheckState = System.Windows.Forms.CheckState.Checked; - this.CHK_DataOnly.Location = new System.Drawing.Point(109, 251); + this.CHK_DataOnly.Location = new System.Drawing.Point(103, 248); this.CHK_DataOnly.Name = "CHK_DataOnly"; this.CHK_DataOnly.Size = new System.Drawing.Size(108, 17); this.CHK_DataOnly.TabIndex = 9; @@ -511,7 +173,7 @@ private void InitializeComponent() this.CHK_FakeHeader.AutoSize = true; this.CHK_FakeHeader.Checked = true; this.CHK_FakeHeader.CheckState = System.Windows.Forms.CheckState.Checked; - this.CHK_FakeHeader.Location = new System.Drawing.Point(109, 293); + this.CHK_FakeHeader.Location = new System.Drawing.Point(103, 290); this.CHK_FakeHeader.Name = "CHK_FakeHeader"; this.CHK_FakeHeader.Size = new System.Drawing.Size(141, 17); this.CHK_FakeHeader.TabIndex = 10; @@ -521,31 +183,141 @@ private void InitializeComponent() // CHK_Key // this.CHK_Key.AutoSize = true; - this.CHK_Key.Location = new System.Drawing.Point(109, 265); + this.CHK_Key.Location = new System.Drawing.Point(103, 262); this.CHK_Key.Name = "CHK_Key"; this.CHK_Key.Size = new System.Drawing.Size(109, 17); this.CHK_Key.TabIndex = 11; this.CHK_Key.Text = "Include 32Bit Key"; this.CHK_Key.UseVisualStyleBackColor = true; // + // tabControl1 + // + this.tabControl1.Controls.Add(this.Tab_Dump); + this.tabControl1.Controls.Add(this.Tab_Compare); + this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tabControl1.Location = new System.Drawing.Point(0, 0); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(284, 344); + this.tabControl1.TabIndex = 12; + // + // Tab_Dump + // + this.Tab_Dump.Controls.Add(this.CB_TypeToggle); + this.Tab_Dump.Controls.Add(this.L_Key); + this.Tab_Dump.Controls.Add(this.CHK_FakeHeader); + this.Tab_Dump.Controls.Add(this.CB_Key); + this.Tab_Dump.Controls.Add(this.CHK_Type); + this.Tab_Dump.Controls.Add(this.L_Detail_L); + this.Tab_Dump.Controls.Add(this.CHK_Key); + this.Tab_Dump.Controls.Add(this.L_Detail_R); + this.Tab_Dump.Controls.Add(this.CHK_DataOnly); + this.Tab_Dump.Controls.Add(this.B_ExportAll); + this.Tab_Dump.Controls.Add(this.B_ImportFolder); + this.Tab_Dump.Controls.Add(this.B_ExportAllSingle); + this.Tab_Dump.Controls.Add(this.B_ImportCurrent); + this.Tab_Dump.Controls.Add(this.B_ExportCurrent); + this.Tab_Dump.Location = new System.Drawing.Point(4, 22); + this.Tab_Dump.Name = "Tab_Dump"; + this.Tab_Dump.Padding = new System.Windows.Forms.Padding(3); + this.Tab_Dump.Size = new System.Drawing.Size(276, 318); + this.Tab_Dump.TabIndex = 0; + this.Tab_Dump.Text = "Dump"; + this.Tab_Dump.UseVisualStyleBackColor = true; + // + // CB_TypeToggle + // + this.CB_TypeToggle.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.CB_TypeToggle.FormattingEnabled = true; + this.CB_TypeToggle.Location = new System.Drawing.Point(83, 37); + this.CB_TypeToggle.Name = "CB_TypeToggle"; + this.CB_TypeToggle.Size = new System.Drawing.Size(97, 21); + this.CB_TypeToggle.TabIndex = 12; + this.CB_TypeToggle.Visible = false; + this.CB_TypeToggle.SelectedIndexChanged += new System.EventHandler(this.CB_TypeToggle_SelectedIndexChanged); + // + // Tab_Compare + // + this.Tab_Compare.Controls.Add(this.richTextBox1); + this.Tab_Compare.Controls.Add(this.GB_Researcher); + this.Tab_Compare.Location = new System.Drawing.Point(4, 22); + this.Tab_Compare.Name = "Tab_Compare"; + this.Tab_Compare.Size = new System.Drawing.Size(276, 318); + this.Tab_Compare.TabIndex = 1; + this.Tab_Compare.Text = "Compare"; + this.Tab_Compare.UseVisualStyleBackColor = true; + // + // richTextBox1 + // + this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.richTextBox1.Location = new System.Drawing.Point(0, 76); + this.richTextBox1.Margin = new System.Windows.Forms.Padding(0); + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.ReadOnly = true; + this.richTextBox1.Size = new System.Drawing.Size(276, 242); + this.richTextBox1.TabIndex = 15; + this.richTextBox1.Text = ""; + // + // GB_Researcher + // + this.GB_Researcher.Controls.Add(this.TB_NewSAV); + this.GB_Researcher.Controls.Add(this.TB_OldSAV); + this.GB_Researcher.Controls.Add(this.B_LoadNew); + this.GB_Researcher.Controls.Add(this.B_LoadOld); + this.GB_Researcher.Dock = System.Windows.Forms.DockStyle.Top; + this.GB_Researcher.Location = new System.Drawing.Point(0, 0); + this.GB_Researcher.Name = "GB_Researcher"; + this.GB_Researcher.Size = new System.Drawing.Size(276, 76); + this.GB_Researcher.TabIndex = 14; + this.GB_Researcher.TabStop = false; + this.GB_Researcher.Text = "Load Two Save Files"; + // + // TB_NewSAV + // + this.TB_NewSAV.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.TB_NewSAV.Location = new System.Drawing.Point(93, 47); + this.TB_NewSAV.Name = "TB_NewSAV"; + this.TB_NewSAV.ReadOnly = true; + this.TB_NewSAV.Size = new System.Drawing.Size(177, 20); + this.TB_NewSAV.TabIndex = 5; + // + // TB_OldSAV + // + this.TB_OldSAV.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.TB_OldSAV.Location = new System.Drawing.Point(93, 21); + this.TB_OldSAV.Name = "TB_OldSAV"; + this.TB_OldSAV.ReadOnly = true; + this.TB_OldSAV.Size = new System.Drawing.Size(177, 20); + this.TB_OldSAV.TabIndex = 4; + // + // B_LoadNew + // + this.B_LoadNew.Location = new System.Drawing.Point(12, 45); + this.B_LoadNew.Name = "B_LoadNew"; + this.B_LoadNew.Size = new System.Drawing.Size(75, 23); + this.B_LoadNew.TabIndex = 1; + this.B_LoadNew.Text = "Load New"; + this.B_LoadNew.UseVisualStyleBackColor = true; + this.B_LoadNew.Click += new System.EventHandler(this.B_LoadNew_Click); + // + // B_LoadOld + // + this.B_LoadOld.Location = new System.Drawing.Point(12, 19); + this.B_LoadOld.Name = "B_LoadOld"; + this.B_LoadOld.Size = new System.Drawing.Size(75, 23); + this.B_LoadOld.TabIndex = 0; + this.B_LoadOld.Text = "Load Old"; + this.B_LoadOld.UseVisualStyleBackColor = true; + this.B_LoadOld.Click += new System.EventHandler(this.B_LoadOld_Click); + // // SAV_BlockDump8 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(284, 316); - this.Controls.Add(this.CHK_FakeHeader); - this.Controls.Add(this.CHK_Type); - this.Controls.Add(this.CHK_Key); - this.Controls.Add(this.CHK_DataOnly); - this.Controls.Add(this.B_ImportFolder); - this.Controls.Add(this.B_ImportCurrent); - this.Controls.Add(this.B_ExportCurrent); - this.Controls.Add(this.B_ExportAllSingle); - this.Controls.Add(this.B_ExportAll); - this.Controls.Add(this.L_Detail_R); - this.Controls.Add(this.L_Detail_L); - this.Controls.Add(this.L_Key); - this.Controls.Add(this.CB_Key); + this.ClientSize = new System.Drawing.Size(284, 344); + this.Controls.Add(this.tabControl1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = global::PKHeX.WinForms.Properties.Resources.Icon; this.MaximizeBox = false; @@ -553,56 +325,17 @@ private void InitializeComponent() this.Name = "SAV_BlockDump8"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Savedata Block Dump"; + this.tabControl1.ResumeLayout(false); + this.Tab_Dump.ResumeLayout(false); + this.Tab_Dump.PerformLayout(); + this.Tab_Compare.ResumeLayout(false); + this.GB_Researcher.ResumeLayout(false); + this.GB_Researcher.PerformLayout(); this.ResumeLayout(false); - this.PerformLayout(); } #endregion - private System.Windows.Forms.Label L_Saying5; - private System.Windows.Forms.Label L_Saying4; - private System.Windows.Forms.Label L_Saying3; - private System.Windows.Forms.Label L_Saying2; - private System.Windows.Forms.Label L_Saying1; - private System.Windows.Forms.TextBox TB_Saying5; - private System.Windows.Forms.TextBox TB_Saying4; - private System.Windows.Forms.TextBox TB_Saying3; - private System.Windows.Forms.TextBox TB_Saying2; - private System.Windows.Forms.TextBox TB_Saying1; - private System.Windows.Forms.Label L_SuperB; - private System.Windows.Forms.Label L_NormalB; - private System.Windows.Forms.Label L_MultiB; - private System.Windows.Forms.Label L_RotationB; - private System.Windows.Forms.Label L_TriplesB; - private System.Windows.Forms.Label L_DoublesB; - private System.Windows.Forms.Label L_SinglesB; - private System.Windows.Forms.Label L_SuperC; - private System.Windows.Forms.Label L_NormalC; - private System.Windows.Forms.Label L_MultiC; - private System.Windows.Forms.Label L_RotationC; - private System.Windows.Forms.Label L_TriplesC; - private System.Windows.Forms.Label L_DoublesC; - private System.Windows.Forms.Label L_SinglesC; - private System.Windows.Forms.MaskedTextBox TB_MBMS; - private System.Windows.Forms.MaskedTextBox TB_MBMN; - private System.Windows.Forms.MaskedTextBox TB_MBRS; - private System.Windows.Forms.MaskedTextBox TB_MBRN; - private System.Windows.Forms.MaskedTextBox TB_MBTS; - private System.Windows.Forms.MaskedTextBox TB_MBTN; - private System.Windows.Forms.MaskedTextBox TB_MBDS; - private System.Windows.Forms.MaskedTextBox TB_MBDN; - private System.Windows.Forms.MaskedTextBox TB_MBSS; - private System.Windows.Forms.MaskedTextBox TB_MBSN; - private System.Windows.Forms.MaskedTextBox TB_MCMS; - private System.Windows.Forms.MaskedTextBox TB_MCMN; - private System.Windows.Forms.MaskedTextBox TB_MCRS; - private System.Windows.Forms.MaskedTextBox TB_MCRN; - private System.Windows.Forms.MaskedTextBox TB_MCTS; - private System.Windows.Forms.MaskedTextBox TB_MCTN; - private System.Windows.Forms.MaskedTextBox TB_MCDS; - private System.Windows.Forms.MaskedTextBox TB_MCDN; - private System.Windows.Forms.MaskedTextBox TB_MCSS; - private System.Windows.Forms.MaskedTextBox TB_MCSN; private System.Windows.Forms.ComboBox CB_Key; private System.Windows.Forms.Label L_Key; private System.Windows.Forms.Label L_Detail_L; @@ -616,5 +349,15 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox CHK_DataOnly; private System.Windows.Forms.CheckBox CHK_FakeHeader; private System.Windows.Forms.CheckBox CHK_Key; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.TabPage Tab_Dump; + private System.Windows.Forms.TabPage Tab_Compare; + private System.Windows.Forms.ComboBox CB_TypeToggle; + private System.Windows.Forms.GroupBox GB_Researcher; + private System.Windows.Forms.TextBox TB_NewSAV; + private System.Windows.Forms.TextBox TB_OldSAV; + private System.Windows.Forms.Button B_LoadNew; + private System.Windows.Forms.Button B_LoadOld; + private System.Windows.Forms.RichTextBox richTextBox1; } } \ No newline at end of file diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.cs index ddd35995c..645ecca4e 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using System.Windows.Forms; using PKHeX.Core; +using static PKHeX.Core.SCBlockUtil; namespace PKHeX.WinForms { @@ -19,9 +19,18 @@ public SAV_BlockDump8(SaveFile sav) WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage); SAV = (SAV8SWSH)sav; - var blocks = SAV.AllBlocks.Select((z, i) => new ComboItem($"{z.Key:X8} - {i:0000} {z.Type}", (int)z.Key)); + var blocks = SAV.AllBlocks.Select((z, i) => new ComboItem($"{z.Key:X8} - {i:0000} {(z.Type.IsBoolean() ? "Bool" : z.Type.ToString())}", (int)z.Key)); CB_Key.InitializeBinding(); CB_Key.DataSource = blocks.ToArray(); + + var boolToggle = new[] + { + new ComboItem(nameof(SCTypeCode.Bool1), (int)SCTypeCode.Bool1), + new ComboItem(nameof(SCTypeCode.Bool2), (int)SCTypeCode.Bool2), + new ComboItem(nameof(SCTypeCode.Bool3), (int)SCTypeCode.Bool3), + }; + CB_TypeToggle.InitializeBinding(); + CB_TypeToggle.DataSource = boolToggle; } private void CB_Key_SelectedIndexChanged(object sender, EventArgs e) @@ -29,6 +38,25 @@ private void CB_Key_SelectedIndexChanged(object sender, EventArgs e) var key = (uint)WinFormsUtil.GetIndex(CB_Key); CurrentBlock = SAV.Blocks.GetBlock(key); L_Detail_R.Text = GetBlockSummary(CurrentBlock); + if (CurrentBlock.Type.IsBoolean()) + { + CB_TypeToggle.SelectedValue = (int)CurrentBlock.Type; + CB_TypeToggle.Visible = true; + } + else + { + CB_TypeToggle.Visible = false; + } + } + + private void CB_TypeToggle_SelectedIndexChanged(object sender, EventArgs e) + { + var cType = CurrentBlock.Type; + var cValue = (SCTypeCode)WinFormsUtil.GetIndex(CB_TypeToggle); + if (cType == cValue) + return; + CurrentBlock.Type = cValue; + L_Detail_R.Text = GetBlockSummary(CurrentBlock); } private void B_ExportAll_Click(object sender, EventArgs e) @@ -73,6 +101,49 @@ private void B_ExportAllSingle_Click(object sender, EventArgs e) ExportAllBlocksAsSingleFile(blocks, sfd.FileName, CHK_DataOnly.Checked, CHK_Key.Checked, CHK_Type.Checked, CHK_FakeHeader.Checked); } + private void B_LoadOld_Click(object sender, EventArgs e) + { + using var ofd = new OpenFileDialog { FileName = "main" }; + if (ofd.ShowDialog() != DialogResult.OK) + return; + TB_OldSAV.Text = ofd.FileName; + if (!string.IsNullOrWhiteSpace(TB_NewSAV.Text)) + CompareSaves(); + } + + private void B_LoadNew_Click(object sender, EventArgs e) + { + using var ofd = new OpenFileDialog { FileName = "main" }; + if (ofd.ShowDialog() != DialogResult.OK) + return; + TB_NewSAV.Text = ofd.FileName; + if (!string.IsNullOrWhiteSpace(TB_OldSAV.Text)) + CompareSaves(); + } + + private void CompareSaves() + { + var p1 = TB_OldSAV.Text; + var p2 = TB_NewSAV.Text; + + var f1 = new FileInfo(p1); + if (!SaveUtil.IsSizeValid((int)f1.Length)) + return; + var f2 = new FileInfo(p1); + if (!SaveUtil.IsSizeValid((int)f2.Length)) + return; + + var s1 = SaveUtil.GetVariantSAV(p1); + if (!(s1 is SAV8SWSH w1)) + return; + var s2 = SaveUtil.GetVariantSAV(p2); + if (!(s2 is SAV8SWSH w2)) + return; + + var compare = new SCBlockCompare(w1, w2); + richTextBox1.Lines = compare.Summary().ToArray(); + } + private static void ExportSelectBlock(SCBlock block) { var name = GetBlockFileNameWithoutExtension(block); @@ -101,96 +172,5 @@ private static void ImportSelectBlock(SCBlock blockTarget) var bytes = File.ReadAllBytes(path); bytes.CopyTo(data, 0); } - - private static void ExportAllBlocksAsSingleFile(IReadOnlyList blocks, string path, bool dataOnly = true, bool key = true, bool typeInfo = true, bool fakeHeader = true) - { - using var stream = new MemoryStream(); - using var bw = new BinaryWriter(stream); - - if (fakeHeader) - { - for (int i = 0; i < blocks.Count; i++) - blocks[i].ID = (uint)i; - } - - var iterate = dataOnly ? blocks.Where(z => z.Data.Length != 0) : blocks; - foreach (var b in iterate) - { - if (fakeHeader) - bw.Write($"BLOCK{b.ID:0000} {b.Key:X8}"); - if (key) - bw.Write(b.Key); - if (typeInfo) - { - bw.Write((byte)b.Type); - bw.Write((byte)b.SubType); - } - bw.Write(b.Data); - } - var data = stream.ToArray(); // SwishCrypto.GetDecryptedRawData(blocks); for raw encrypted - File.WriteAllBytes(path, data); - } - - private static string GetBlockFileNameWithoutExtension(SCBlock block) - { - var key = block.Key; - var name = $"{key:X8}"; - if (block.HasValue()) - name += $" {block.GetValue()}"; - return name; - } - - private static string GetBlockSummary(SCBlock b) - { - var sb = new StringBuilder(); - sb.Append("Key: ").AppendFormat("{0:X8}", b.Key).AppendLine(); - sb.Append("Type: ").Append(b.Type).AppendLine(); - if (b.Data.Length != 0) - sb.Append("Length: ").AppendFormat("{0:X8}", b.Data.Length).AppendLine(); - - if (b.SubType != 0) - sb.Append("SubType: ").Append(b.SubType).AppendLine(); - else if (b.HasValue()) - sb.Append("Value: ").Append(b.GetValue()).AppendLine(); - - return sb.ToString(); - } - - private static List ImportBlocksFromFolder(string path, SAV8SWSH sav) - { - var failed = new List(); - var files = Directory.EnumerateFiles(path); - foreach (var f in files) - { - var fn = Path.GetFileNameWithoutExtension(f); - - // Trim off Value summary if present - var space = fn.IndexOf(' '); - if (space >= 0) - fn = fn.Substring(0, space); - - var hex = Util.GetHexValue(fn); - try - { - var block = sav.Blocks.GetBlock(hex); - var len = block.Data.Length; - var fi = new FileInfo(f); - if (fi.Length != len) - { - failed.Add(fn); - continue; - } - - var data = File.ReadAllBytes(f); - data.CopyTo(block.Data, 0); - } - catch - { - failed.Add(fn); - } - } - - return failed; - } } }