diff --git a/PKHeX.Core/Legality/Restrictions/Vivillon3DS.cs b/PKHeX.Core/Legality/Restrictions/Vivillon3DS.cs index b3ddc2fc6..8f155e7f9 100644 --- a/PKHeX.Core/Legality/Restrictions/Vivillon3DS.cs +++ b/PKHeX.Core/Legality/Restrictions/Vivillon3DS.cs @@ -204,11 +204,15 @@ internal FormSubregionTable(byte form, byte[] regions) new FormSubregionTable(17, new byte[] {12})), }; + public const int MaxWildFormID = 17; // 0-17 valid form indexes + /// /// Compares the Vivillon pattern against its console region to determine if the pattern is legal. /// public static bool IsPatternValid(int form, int consoleRegion) { + if ((uint)form > MaxWildFormID) + return false; var permit = GetConsoleRegionFlag(consoleRegion); return VivillonRegionTable[form].HasFlag(permit); } @@ -222,11 +226,13 @@ public static bool IsPatternValid(int form, int consoleRegion) /// True if valid public static bool IsPatternNative(int form, byte country, byte region) { + if ((uint)form > MaxWildFormID) + return false; if (!VivillonCountryTable[form].Contains(country)) return false; // Country mismatch var ct = Array.Find(RegionFormTable, t => t.CountryID == country); - if (ct == default(CountryTable)) // empty = one form for country + if (ct == null) // empty = one form for country return true; // No subregion table, already checked if Country can have this form if (ct.BaseForm == form) @@ -243,7 +249,7 @@ public static bool IsPatternNative(int form, byte country, byte region) public static int GetPattern(byte country, byte region) { var ct = Array.Find(RegionFormTable, t => t.CountryID == country); - if (ct == default(CountryTable)) // empty = no forms referenced + if (ct == null) // empty = no forms referenced return GetPattern(country); foreach (var sub in ct.SubRegionForms) diff --git a/PKHeX.Core/Legality/Tables/FormInfo.cs b/PKHeX.Core/Legality/Tables/FormInfo.cs index b34120f27..6777c9e14 100644 --- a/PKHeX.Core/Legality/Tables/FormInfo.cs +++ b/PKHeX.Core/Legality/Tables/FormInfo.cs @@ -251,8 +251,8 @@ public static int GetTotemBaseForm(int species, int form) Unown => form < (format == 2 ? 26 : 28), // A-Z : A-Z?! Mothim => form < 3, // Burmy base form is kept - Scatterbug => form < 18, // Vivillon Pre-evolutions - Spewpa => form < 18, // Vivillon Pre-evolutions + Scatterbug => form <= Vivillon3DS.MaxWildFormID, // Vivillon Pre-evolutions + Spewpa => form <= Vivillon3DS.MaxWildFormID, // Vivillon Pre-evolutions _ => false }; diff --git a/PKHeX.Core/Legality/Verifiers/FormVerifier.cs b/PKHeX.Core/Legality/Verifiers/FormVerifier.cs index 9980e789b..5a3c6e4af 100644 --- a/PKHeX.Core/Legality/Verifiers/FormVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/FormVerifier.cs @@ -98,7 +98,7 @@ private CheckResult VerifyForm(LegalityAnalysis data) break; case Scatterbug or Spewpa: - if (form > 17) // Fancy & Pokéball + if (form > Vivillon3DS.MaxWildFormID) // Fancy & Pokéball return GetInvalid(LFormVivillonEventPre); if (pkm is not IRegionOrigin tr) break; @@ -108,7 +108,7 @@ private CheckResult VerifyForm(LegalityAnalysis data) data.AddLine(Get(LFormVivillonNonNative, Severity.Fishy)); break; case Vivillon: - if (form > 17) // Fancy & Pokéball + if (form > Vivillon3DS.MaxWildFormID) // Fancy & Pokéball { if (enc is not MysteryGift) return GetInvalid(LFormVivillonInvalid);