From efc17a1271171296cc3ff4ec35ffa6dfd9ca41e2 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 25 Sep 2020 23:41:20 -0700 Subject: [PATCH] Add interface for revised savefile types (patches) SWSH is the first common savefile type that has different revisions after official patches. We want to indicate in the Program Title which revision we're currently editing, because people still are not editing latest-format saves and complaining y no urshifu. Use short descriptions to indicate revision (Base, IoA, CT), rather than magic numbers (v0/v1) or 1.X or 1.X.Y+, because GameFreak can't follow semver rules. go away ranch platinum update, i might handle you another time --- PKHeX.Core/Saves/SAV8SWSH.cs | 16 ++++++++++++++-- .../Substructures/Misc/ISaveFileRevision.cs | 8 ++++++++ PKHeX.WinForms/MainWindow/Main.cs | 2 ++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 PKHeX.Core/Saves/Substructures/Misc/ISaveFileRevision.cs diff --git a/PKHeX.Core/Saves/SAV8SWSH.cs b/PKHeX.Core/Saves/SAV8SWSH.cs index 4decb853b..209156fff 100644 --- a/PKHeX.Core/Saves/SAV8SWSH.cs +++ b/PKHeX.Core/Saves/SAV8SWSH.cs @@ -7,7 +7,7 @@ namespace PKHeX.Core /// /// Generation 8 object for games. /// - public sealed class SAV8SWSH : SAV8, ISaveBlock8SWSH, ITrainerStatRecord + public sealed class SAV8SWSH : SAV8, ISaveBlock8SWSH, ITrainerStatRecord, ISaveFileRevision { public SAV8SWSH(byte[] data) : this(data, SwishCrypto.Decrypt(data)) { @@ -18,6 +18,7 @@ private SAV8SWSH(byte[] data, IReadOnlyList blocks) : base(data) Data = Array.Empty(); AllBlocks = blocks; Blocks = new SaveBlockAccessor8SWSH(this); + SaveRevision = Zukan.GetRevision(); Initialize(); } @@ -25,6 +26,7 @@ public SAV8SWSH() { AllBlocks = Meta8.GetBlankDataSWSH(); Blocks = new SaveBlockAccessor8SWSH(this); + SaveRevision = Zukan.GetRevision(); Initialize(); ClearBoxes(); } @@ -40,6 +42,16 @@ public override void CopyChangesFrom(SaveFile sav) Edited = true; } + public int SaveRevision { get; } + + public string SaveRevisionString => SaveRevision switch + { + 0 => "-Base", // Vanilla + 1 => "-IoA", // DLC 1: Isle of Armor + 2 => "-CT", // DLC 2: Crown Tundra + _ => throw new ArgumentOutOfRangeException(nameof(SaveRevision)), + }; + public IReadOnlyList AllBlocks { get; } public override bool ChecksumsValid => true; public override string ChecksumInfo => string.Empty; @@ -103,7 +115,7 @@ private void Initialize() PokeDex = 0; TeamIndexes.LoadBattleTeams(); - int rev = Zukan.GetRevision(); + int rev = SaveRevision; if (rev == 0) { m_move = Legal.MaxMoveID_8_O0; diff --git a/PKHeX.Core/Saves/Substructures/Misc/ISaveFileRevision.cs b/PKHeX.Core/Saves/Substructures/Misc/ISaveFileRevision.cs new file mode 100644 index 000000000..864a07231 --- /dev/null +++ b/PKHeX.Core/Saves/Substructures/Misc/ISaveFileRevision.cs @@ -0,0 +1,8 @@ +namespace PKHeX.Core +{ + public interface ISaveFileRevision + { + public int SaveRevision { get; } + string SaveRevisionString { get; } + } +} diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index 192cfac7a..a4196474b 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -819,6 +819,8 @@ private static string GetProgramTitle() private static string GetProgramTitle(SaveFile sav) { string title = GetProgramTitle() + $" - {sav.GetType().Name}: "; + if (sav is ISaveFileRevision rev) + title = title.Insert(title.Length - 2, rev.SaveRevisionString); var ver = GameInfo.GetVersionName(sav.Version); if (Settings.Default.HideSAVDetails) return title + $"[{ver}]";