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.
This commit is contained in:
Kurt 2020-01-25 12:16:45 -08:00
parent 63ee520e75
commit 527442bb49

View file

@ -75,16 +75,19 @@ namespace PKHeX.Core
private static IReadOnlyList<string> GetSaveFileErrata(this SaveFile sav, PKM pkm, IBasicStrings strings) private static IReadOnlyList<string> GetSaveFileErrata(this SaveFile sav, PKM pkm, IBasicStrings strings)
{ {
var errata = new List<string>(); var errata = new List<string>();
if (sav.Generation > 1) ushort held = (ushort)pkm.HeldItem;
if (sav.Generation > 1 && held != 0)
{ {
ushort held = (ushort)pkm.HeldItem; string? msg = null;
var itemstr = GameInfo.Strings.GetItemStrings(pkm.Format, (GameVersion) pkm.Version); if (held > sav.MaxItemID)
if (held > itemstr.Count) msg = MsgIndexItemGame;
errata.Add($"{MsgIndexItemRange} {held}");
else if (held > sav.MaxItemID)
errata.Add($"{MsgIndexItemGame} {itemstr[held]}");
else if (!pkm.CanHoldItem(sav.HeldItems)) 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) if (pkm.Species > strings.Species.Count)