mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-24 00:04:24 -05:00
Add indication to which blocks changed
Use reflection to grab all const declarations (private and public), and grab the name of that const. Whenever that block is mentioned in our diff, use the name instead of the key. Helps identify what changed / remove noise if you don't care about that block.
This commit is contained in:
@@ -69,10 +69,10 @@ public SaveBlockAccessorSWSH(SAV8SWSH sav)
|
||||
public const uint KGameLanguage = 0x0BFDEBA1; // U32 Game Language
|
||||
public const uint KRepel = 0x9ec079da; // U16 Repel Steps remaining
|
||||
public const uint KRotoRally = 0x38548020; // U32 Roto Rally Score (99,999 cap)
|
||||
public const int KBattleTowerSinglesVictory = 0x436CAF2B; // U32 Singles victories (9,999,999 cap)
|
||||
public const int KBattleTowerDoublesVictory = 0x0D477836; // U32 Doubles victories (9,999,999 cap)
|
||||
public const int KBattleTowerSinglesStreak = 0x6226F5AD; // U16 Singles Streak (255 cap)
|
||||
public const int KBattleTowerDoublesStreak = 0x5F74FCEE; // U16 Doubles Streak (255 cap)
|
||||
public const uint KBattleTowerSinglesVictory = 0x436CAF2B; // U32 Singles victories (9,999,999 cap)
|
||||
public const uint KBattleTowerDoublesVictory = 0x0D477836; // U32 Doubles victories (9,999,999 cap)
|
||||
public const uint KBattleTowerSinglesStreak = 0x6226F5AD; // U16 Singles Streak (255 cap)
|
||||
public const uint KBattleTowerDoublesStreak = 0x5F74FCEE; // U16 Doubles Streak (255 cap)
|
||||
public object GetBlockValue(uint key) => GetBlock(key).GetValue();
|
||||
public void SetBlockValue(uint key, object value) => GetBlock(key).SetValue(value);
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ public SCBlockCompare(SAV8SWSH s1, SAV8SWSH s2)
|
||||
{
|
||||
var b1 = s1.Blocks.BlockInfo;
|
||||
var b2 = s2.Blocks.BlockInfo;
|
||||
var names = s1.Blocks.GetType().GetAllConstantsOfType<uint>();
|
||||
string GetKeyName(uint key) => names.TryGetValue(key, out var val) ? val : $"{key:X8}";
|
||||
|
||||
var hs1 = new HashSet<uint>(b1.Select(z => z.Key));
|
||||
var hs2 = new HashSet<uint>(b2.Select(z => z.Key));
|
||||
@@ -22,15 +24,16 @@ public SCBlockCompare(SAV8SWSH s1, SAV8SWSH s2)
|
||||
unique.SymmetricExceptWith(hs2);
|
||||
foreach (var k in unique)
|
||||
{
|
||||
var name = GetKeyName(k);
|
||||
if (hs1.Contains(k))
|
||||
{
|
||||
var b = s1.Blocks.GetBlock(k);
|
||||
RemovedKeys.Add($"{b.Key:X8} - {b.Type}");
|
||||
RemovedKeys.Add($"{name} - {b.Type}");
|
||||
}
|
||||
else
|
||||
{
|
||||
var b = s2.Blocks.GetBlock(k);
|
||||
AddedKeys.Add($"{b.Key:X8} - {b.Type}");
|
||||
AddedKeys.Add($"{name} - {b.Type}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,14 +42,15 @@ public SCBlockCompare(SAV8SWSH s1, SAV8SWSH s2)
|
||||
{
|
||||
var x1 = s1.Blocks.GetBlock(k);
|
||||
var x2 = s2.Blocks.GetBlock(k);
|
||||
var name = GetKeyName(x1.Key);
|
||||
if (x1.Type != x2.Type)
|
||||
{
|
||||
TypesChanged.Add($"{x1.Key:X8} - {x1.Type} => {x2.Type}");
|
||||
TypesChanged.Add($"{name} - {x1.Type} => {x2.Type}");
|
||||
continue;
|
||||
}
|
||||
if (x1.Data.Length != x2.Data.Length)
|
||||
{
|
||||
ValueChanged.Add($"{x1.Key:X8} - Length: {x1.Data.Length} => {x2.Data.Length}");
|
||||
ValueChanged.Add($"{name} - Length: {x1.Data.Length} => {x2.Data.Length}");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -56,7 +60,7 @@ public SCBlockCompare(SAV8SWSH s1, SAV8SWSH s2)
|
||||
if (x1.Type == SCTypeCode.Object || x1.Type == SCTypeCode.Array)
|
||||
{
|
||||
if (!x1.Data.SequenceEqual(x2.Data))
|
||||
ValueChanged.Add($"{x1.Key:X8} - Bytes Changed");
|
||||
ValueChanged.Add($"{name} - Bytes Changed");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -65,9 +69,9 @@ public SCBlockCompare(SAV8SWSH s1, SAV8SWSH s2)
|
||||
if (Equals(val1, val2))
|
||||
continue;
|
||||
if (val1 is ulong u1 && val2 is ulong u2)
|
||||
ValueChanged.Add($"{x1.Key:X8} - {u1:X8} => {u2:x8}");
|
||||
ValueChanged.Add($"{name} - {u1:X8} => {u2:x8}");
|
||||
else
|
||||
ValueChanged.Add($"{x1.Key:X8} - {val1} => {val2}");
|
||||
ValueChanged.Add($"{name} - {val1} => {val2}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,5 +124,12 @@ private static IEnumerable<T> GetAll<T>(this TypeInfo typeInfo, Func<TypeInfo, I
|
||||
{
|
||||
return GetAllTypeInfo(typeInfo).SelectMany(_ => accessor(typeInfo));
|
||||
}
|
||||
|
||||
public static Dictionary<T, string> GetAllConstantsOfType<T>(this Type type)
|
||||
{
|
||||
var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||
var consts = fields.Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType == typeof(T));
|
||||
return consts.ToDictionary(x => (T)x.GetRawConstantValue(), z => z.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user