Sanity check pk1/pk2 similar to pk3/4/5/6

Refactors code so that the 'validity' check is done by the object not by
the form evaluating properties. Can be expanded upon to mark pk3's
invalid if species is >386 etc; however, it wasn't necessary to do
before for pk6's out-of-bounds.

Thanks theSLAYER!
This commit is contained in:
Kaphotics 2016-09-14 22:04:22 -07:00
parent e6bf2909a7
commit 00cc249861
5 changed files with 8 additions and 5 deletions

View file

@ -2975,7 +2975,7 @@ namespace PKHeX
// Load the PKX file
PKM pk = 30 <= slot && slot < 36 ? SAV.getPartySlot(offset) : SAV.getStoredSlot(offset);
if (pk.Sanity == 0 && pk.Species != 0)
if (pk.Valid && pk.Species != 0)
{
try { populateFields(pk); }
catch { }
@ -3371,7 +3371,7 @@ namespace PKHeX
return;
}
PKM p = SAV.getStoredSlot(offset);
if (p.Sanity != 0 || !p.ChecksumValid) // Invalid
if (!p.Valid) // Invalid
{
// Bad Egg present in slot.
pb.Image = null;
@ -3419,7 +3419,7 @@ namespace PKHeX
for (int i = 0; i < boxdata.Length; i++)
{
PKM pk = boxdata[i];
if (pk.Species == 0 || pk.Sanity != 0)
if (pk.Species == 0 || !pk.Valid)
continue;
string fileName = Util.CleanFileName(pk.FileName);
string boxfolder = "";

View file

@ -11,6 +11,7 @@ namespace PKHeX
public byte[] OT_Name_Raw => (byte[])otname.Clone();
public byte[] Nickname_Raw => (byte[])nick.Clone();
public override bool Valid => Species <= 151 && (Data[0] == 0 || Species != 0);
public sealed override int SIZE_PARTY => PKX.SIZE_1PARTY;
public override int SIZE_STORED => PKX.SIZE_1STORED;

View file

@ -11,6 +11,7 @@ namespace PKHeX
public byte[] OT_Name_Raw => (byte[])otname.Clone();
public byte[] Nickname_Raw => (byte[])nick.Clone();
public override bool Valid => Species <= 252;
public sealed override int SIZE_PARTY => PKX.SIZE_2PARTY;
public override int SIZE_STORED => PKX.SIZE_2STORED;
@ -307,7 +308,7 @@ public override int Stat_Level
}
}
public override bool IsShiny => IV_DEF == 10 && IV_SPE == 10 && IV_SPC == 10 && (new[] { 2, 3, 6, 7, 10, 11, 14, 15 }).Contains(IV_ATK);
public override bool IsShiny => IV_DEF == 10 && IV_SPE == 10 && IV_SPC == 10 && (IV_ATK & 2) == 2;
public override ushort Sanity { get { return 0; } set { } }
public override bool ChecksumValid => true;
public override ushort Checksum { get { return 0; } set { } }

View file

@ -20,6 +20,7 @@ namespace PKHeX
public virtual byte[] EncryptedBoxData => Encrypt().Take(SIZE_STORED).ToArray();
public virtual byte[] DecryptedPartyData => Write().Take(SIZE_PARTY).ToArray();
public virtual byte[] DecryptedBoxData => Write().Take(SIZE_STORED).ToArray();
public virtual bool Valid => ChecksumValid && Sanity == 0;
protected ushort CalculateChecksum()
{

View file

@ -104,7 +104,7 @@ namespace PKHeX
return;
}
PKM p = SAV.getStoredSlot(offset);
if (p.Sanity != 0 || !p.ChecksumValid) // Invalid
if (!p.Valid) // Invalid
{
// Bad Egg present in slot.
pb.Image = null;