diff --git a/PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs b/PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs index f16844ef5..3f6b0013b 100644 --- a/PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs +++ b/PKHeX.Core/Saves/MemeCrypto/SCBlockCompare.cs @@ -10,17 +10,26 @@ namespace PKHeX.Core private readonly List TypesChanged = new List(); private readonly List ValueChanged = new List(); + private readonly Dictionary KeyNames; + private string GetKeyName(uint key) => KeyNames.TryGetValue(key, out var val) ? val : $"{key:X8}"; + public SCBlockCompare(SCBlockAccessor s1, SCBlockAccessor s2) { var b1 = s1.BlockInfo; var b2 = s2.BlockInfo; - var names = GetKeyNames(s1, b1, b2); - - string GetKeyName(uint key) => names.TryGetValue(key, out var val) ? val : $"{key:X8}"; + KeyNames = GetKeyNames(s1, b1, b2); + SCBlockMetadata.AddExtraKeyNames(KeyNames); var hs1 = new HashSet(b1.Select(z => z.Key)); var hs2 = new HashSet(b2.Select(z => z.Key)); + LoadAddRemove(s1, s2, hs1, hs2); + hs1.IntersectWith(hs2); + LoadChanged(s1, s2, hs1); + } + + private void LoadAddRemove(SCBlockAccessor s1, SCBlockAccessor s2, ICollection hs1, IEnumerable hs2) + { var unique = new HashSet(hs1); unique.SymmetricExceptWith(hs2); foreach (var k in unique) @@ -37,9 +46,11 @@ namespace PKHeX.Core AddedKeys.Add($"{name} - {b.Type}"); } } + } - hs1.IntersectWith(hs2); - foreach (var k in hs1) + private void LoadChanged(SCBlockAccessor s1, SCBlockAccessor s2, IEnumerable shared) + { + foreach (var k in shared) { var x1 = s1.GetBlock(k); var x2 = s2.GetBlock(k); @@ -106,7 +117,7 @@ namespace PKHeX.Core return result; - static void AddIfPresent(List result, IList list, string hdr) + static void AddIfPresent(List result, ICollection list, string hdr) { if (list.Count == 0) return; diff --git a/PKHeX.Core/Saves/MemeCrypto/SCBlockMetadata.cs b/PKHeX.Core/Saves/MemeCrypto/SCBlockMetadata.cs index b0d2116cb..91293e062 100644 --- a/PKHeX.Core/Saves/MemeCrypto/SCBlockMetadata.cs +++ b/PKHeX.Core/Saves/MemeCrypto/SCBlockMetadata.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Globalization; +using System.IO; using System.Linq; namespace PKHeX.Core @@ -20,6 +22,7 @@ namespace PKHeX.Core BlockList = aType.GetAllPropertiesOfType(accessor); ValueList = aType.GetAllConstantsOfType(); + AddExtraKeyNames(ValueList); Accessor = accessor; } @@ -32,6 +35,27 @@ namespace PKHeX.Core return list; } + public static void AddExtraKeyNames(IDictionary names, string extra = "SCBlocks.txt") + { + if (!File.Exists(extra)) + return; + + var lines = File.ReadLines(extra); + foreach (var line in lines) + { + var split = line.IndexOf('\t'); + if (split < 0) + continue; + var hex = line.Substring(0, split); + if (!ulong.TryParse(hex, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out var value)) + continue; + + var name = line.Substring(split + 1); + if (!names.ContainsKey((uint)value)) + names[(uint)value] = name; + } + } + private static string GetSortKey(in ComboItem item) { var text = item.Text;