mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-13 05:35:28 -05:00
Add bounds check for API purposes
chris doing things funkily, might as well range check ourselves before blindly accessing the array Use a const value for vivillon max wild form value
This commit is contained in:
@@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Compares the Vivillon pattern against its console region to determine if the pattern is legal.
|
||||
/// </summary>
|
||||
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)
|
||||
/// <returns>True if valid</returns>
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user