mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-10 12:16:27 -05:00
Double check some bounds checks
still have some issues with gen4 mystery gifts and some groundtile flagging (to be resolved later)
This commit is contained in:
@@ -9,7 +9,7 @@ public static class GameLanguage
|
||||
{
|
||||
public const string DefaultLanguage = "en"; // English
|
||||
public static int DefaultLanguageIndex => Array.IndexOf(LanguageCodes, DefaultLanguage);
|
||||
public static string Language2Char(int lang) => lang > LanguageCodes.Length ? DefaultLanguage : LanguageCodes[lang];
|
||||
public static string Language2Char(int lang) => (uint)lang >= LanguageCodes.Length ? DefaultLanguage : LanguageCodes[lang];
|
||||
|
||||
public static int LanguageCount => LanguageCodes.Length;
|
||||
|
||||
|
||||
@@ -140,14 +140,14 @@ public override byte[] GetDataForFormatStored(PKM pk)
|
||||
|
||||
private int GetTeamOffsetJ(int team)
|
||||
{
|
||||
if ((uint) team > TeamCount)
|
||||
if ((uint) team >= TeamCount)
|
||||
throw new ArgumentOutOfRangeException(nameof(team));
|
||||
return GetTeamTypeOffsetJ(team / TeamCountJ) + (TeamSizeJ * (team % TeamCountJ));
|
||||
}
|
||||
|
||||
private int GetTeamOffsetU(int team)
|
||||
{
|
||||
if ((uint)team > TeamCount)
|
||||
if ((uint)team >= TeamCount)
|
||||
throw new ArgumentOutOfRangeException(nameof(team));
|
||||
return GetTeamTypeOffsetU(team / TeamCountU) + (TeamSizeU * (team % TeamCountU));
|
||||
}
|
||||
|
||||
@@ -462,7 +462,7 @@ public sealed override int CurrentBox
|
||||
|
||||
public int GetBoxWallpaper(int box)
|
||||
{
|
||||
if (box > COUNT_BOX)
|
||||
if (box >= COUNT_BOX)
|
||||
return box;
|
||||
int offset = GetBoxWallpaperOffset(box);
|
||||
return Storage[offset];
|
||||
@@ -472,7 +472,7 @@ public int GetBoxWallpaper(int box)
|
||||
|
||||
public void SetBoxWallpaper(int box, int value)
|
||||
{
|
||||
if (box > COUNT_BOX)
|
||||
if (box >= COUNT_BOX)
|
||||
return;
|
||||
int offset = GetBoxWallpaperOffset(box);
|
||||
Storage[offset] = (byte)value;
|
||||
|
||||
@@ -678,7 +678,7 @@ private int GetGiftOffsetPCD(int index)
|
||||
}
|
||||
|
||||
private Span<byte> GetCardSpanPGT(int index) => Data.Slice(GetGiftOffsetPGT(index), PGT.Size);
|
||||
private Span<byte> GetCardSpanPCD(int index) => Data.Slice(GetGiftOffsetPCD(index), PGT.Size);
|
||||
private Span<byte> GetCardSpanPCD(int index) => Data.Slice(GetGiftOffsetPCD(index), PCD.Size);
|
||||
public PGT GetMysteryGiftPGT(int index) => new(GetCardSpanPGT(index).ToArray());
|
||||
public PCD GetMysteryGiftPCD(int index) => new(GetCardSpanPCD(index).ToArray());
|
||||
|
||||
|
||||
@@ -24,14 +24,14 @@ public sealed class BoxLayout7(SAV7 sav, Memory<byte> raw) : SaveBlock<SAV7>(sav
|
||||
|
||||
public int GetBoxWallpaper(int box)
|
||||
{
|
||||
if ((uint)box > SAV.BoxCount)
|
||||
if ((uint)box >= SAV.BoxCount)
|
||||
return 0;
|
||||
return Data[GetBoxWallpaperOffset(box)];
|
||||
}
|
||||
|
||||
public void SetBoxWallpaper(int box, int value)
|
||||
{
|
||||
if ((uint)box > SAV.BoxCount)
|
||||
if ((uint)box >= SAV.BoxCount)
|
||||
return;
|
||||
Data[GetBoxWallpaperOffset(box)] = (byte)value;
|
||||
}
|
||||
|
||||
@@ -137,14 +137,14 @@ public byte CurrentBox
|
||||
|
||||
public int GetBoxWallpaper(int box)
|
||||
{
|
||||
if ((uint)box > BoxCount)
|
||||
if ((uint)box >= BoxCount)
|
||||
return 0;
|
||||
return Data[GetBoxWallpaperOffset(box)] - 1;
|
||||
}
|
||||
|
||||
public void SetBoxWallpaper(int box, int value)
|
||||
{
|
||||
if ((uint)box > BoxCount)
|
||||
if ((uint)box >= BoxCount)
|
||||
return;
|
||||
Data[GetBoxWallpaperOffset(box)] = (byte)(value + 1);
|
||||
}
|
||||
|
||||
@@ -122,9 +122,9 @@ public void SetTrainers(ReadOnlySpan<byte> data)
|
||||
|
||||
public void FillNPC(byte value, int start = 0, int count = COUNT_TRAINERS)
|
||||
{
|
||||
if ((uint)start + (uint)count > COUNT_TRAINERS)
|
||||
if ((uint)start + (uint)count >= COUNT_TRAINERS)
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
if ((uint)start > COUNT_TRAINERS)
|
||||
if ((uint)start >= COUNT_TRAINERS)
|
||||
throw new ArgumentOutOfRangeException(nameof(start));
|
||||
|
||||
var ofs = OFS_NPC + start;
|
||||
|
||||
@@ -56,7 +56,7 @@ private static List<string> GetSaveFileErrata(this SaveFile sav, PKM pk, IBasicS
|
||||
}
|
||||
}
|
||||
|
||||
if (pk.Species > strings.Species.Count)
|
||||
if (pk.Species >= strings.Species.Count)
|
||||
errata.Add($"{MsgIndexSpeciesRange} {pk.Species}");
|
||||
else if (sav.MaxSpeciesID < pk.Species)
|
||||
errata.Add($"{MsgIndexSpeciesGame} {strings.Species[pk.Species]}");
|
||||
@@ -68,7 +68,7 @@ private static List<string> GetSaveFileErrata(this SaveFile sav, PKM pk, IBasicS
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
var move = pk.GetMove(i);
|
||||
if ((uint)move > movestr.Count)
|
||||
if ((uint)move >= movestr.Count)
|
||||
errata.Add($"{MsgIndexMoveRange} {move}");
|
||||
else if (move > sav.MaxMoveID)
|
||||
errata.Add($"{MsgIndexMoveGame} {movestr[move]}");
|
||||
|
||||
@@ -82,7 +82,7 @@ private void PopulateGender(PKM pk)
|
||||
}
|
||||
|
||||
var gender = pk.Gender;
|
||||
if (gender > GenderImages.Length)
|
||||
if (gender >= GenderImages.Length)
|
||||
gender = 2;
|
||||
PB_Gender.Image = GenderImages[gender];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user