From 527442bb4982cdbd5d0f7396bd9b4e9dda05e991 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 25 Jan 2020 12:16:45 -0800 Subject: [PATCH] Only fetch strings when required for compat check if item == 0, don't bother checking. Fetch strings only if there's an issue with the item. --- PKHeX.Core/Saves/Util/SaveExtensions.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/PKHeX.Core/Saves/Util/SaveExtensions.cs b/PKHeX.Core/Saves/Util/SaveExtensions.cs index b9e17bd7b..ab61658fc 100644 --- a/PKHeX.Core/Saves/Util/SaveExtensions.cs +++ b/PKHeX.Core/Saves/Util/SaveExtensions.cs @@ -75,16 +75,19 @@ namespace PKHeX.Core private static IReadOnlyList GetSaveFileErrata(this SaveFile sav, PKM pkm, IBasicStrings strings) { var errata = new List(); - if (sav.Generation > 1) + ushort held = (ushort)pkm.HeldItem; + if (sav.Generation > 1 && held != 0) { - ushort held = (ushort)pkm.HeldItem; - var itemstr = GameInfo.Strings.GetItemStrings(pkm.Format, (GameVersion) pkm.Version); - if (held > itemstr.Count) - errata.Add($"{MsgIndexItemRange} {held}"); - else if (held > sav.MaxItemID) - errata.Add($"{MsgIndexItemGame} {itemstr[held]}"); + string? msg = null; + if (held > sav.MaxItemID) + msg = MsgIndexItemGame; else if (!pkm.CanHoldItem(sav.HeldItems)) - errata.Add($"{MsgIndexItemHeld} {itemstr[held]}"); + msg = MsgIndexItemHeld; + if (msg != null) + { + var itemstr = GameInfo.Strings.GetItemStrings(pkm.Format, (GameVersion)pkm.Version); + errata.Add($"{msg} {(held >= itemstr.Count ? held.ToString() : itemstr[held])}"); + } } if (pkm.Species > strings.Species.Count)