Clean up PID/EC auto-update

Now loads & saves version-less data fine

Co-Authored-By: lusamine <lusamine@users.noreply.github.com>
This commit is contained in:
Kurt 2020-03-13 19:56:53 -07:00
parent c4ce22412a
commit a885f6b48f
4 changed files with 15 additions and 16 deletions

View file

@ -28,12 +28,12 @@ namespace PKHeX.WinForms.Controls
if (!(Entity is PK6 pk6)) if (!(Entity is PK6 pk6))
throw new FormatException(nameof(Entity)); throw new FormatException(nameof(Entity));
CheckTransferPIDValid();
SaveMisc1(pk6); SaveMisc1(pk6);
SaveMisc2(pk6); SaveMisc2(pk6);
SaveMisc3(pk6); SaveMisc3(pk6);
SaveMisc4(pk6); SaveMisc4(pk6);
SaveMisc6(pk6); SaveMisc6(pk6);
CheckTransferPIDValid(pk6);
pk6.EncounterType = WinFormsUtil.GetIndex(CB_EncounterType); pk6.EncounterType = WinFormsUtil.GetIndex(CB_EncounterType);

View file

@ -25,12 +25,12 @@ namespace PKHeX.WinForms.Controls
if (!(Entity is PK7 pk7)) if (!(Entity is PK7 pk7))
throw new FormatException(nameof(Entity)); throw new FormatException(nameof(Entity));
CheckTransferPIDValid();
SaveMisc1(pk7); SaveMisc1(pk7);
SaveMisc2(pk7); SaveMisc2(pk7);
SaveMisc3(pk7); SaveMisc3(pk7);
SaveMisc4(pk7); SaveMisc4(pk7);
SaveMisc6(pk7); SaveMisc6(pk7);
CheckTransferPIDValid(pk7);
// Toss in Party Stats // Toss in Party Stats
SavePartyStats(pk7); SavePartyStats(pk7);
@ -71,7 +71,6 @@ namespace PKHeX.WinForms.Controls
if (!(Entity is PB7 pk7)) if (!(Entity is PB7 pk7))
throw new FormatException(nameof(Entity)); throw new FormatException(nameof(Entity));
CheckTransferPIDValid();
SaveMisc1(pk7); SaveMisc1(pk7);
SaveMisc2(pk7); SaveMisc2(pk7);
SaveMisc3(pk7); SaveMisc3(pk7);

View file

@ -27,13 +27,13 @@ namespace PKHeX.WinForms.Controls
if (!(Entity is PK8 pk8)) if (!(Entity is PK8 pk8))
throw new FormatException(nameof(Entity)); throw new FormatException(nameof(Entity));
CheckTransferPIDValid();
SaveMisc1(pk8); SaveMisc1(pk8);
SaveMisc2(pk8); SaveMisc2(pk8);
SaveMisc3(pk8); SaveMisc3(pk8);
SaveMisc4(pk8); SaveMisc4(pk8);
SaveMisc6(pk8); SaveMisc6(pk8);
SaveMisc8(pk8); SaveMisc8(pk8);
CheckTransferPIDValid(pk8);
// Toss in Party Stats // Toss in Party Stats
SavePartyStats(pk8); SavePartyStats(pk8);

View file

@ -345,32 +345,32 @@ namespace PKHeX.WinForms.Controls
} }
// Misc // Misc
private void CheckTransferPIDValid() private static void CheckTransferPIDValid(PKM pk)
{ {
if (Entity.Version >= 24) if (pk.Version >= 24 && pk.Version != 0)
return; return;
uint EC = Util.GetHexValue(TB_EC.Text); uint EC = pk.EncryptionConstant;
uint PID = Util.GetHexValue(TB_PID.Text); uint PID = pk.PID;
uint LID = PID & 0xFFFF; uint LID = PID & 0xFFFF;
uint HID = PID >> 16; uint HID = PID >> 16;
uint XOR = (uint)(Entity.TID ^ LID ^ Entity.SID ^ HID); uint XOR = (uint)(pk.TID ^ LID ^ pk.SID ^ HID);
// Ensure we don't have a shiny. // Ensure we don't have a shiny.
if (XOR >> 3 == 1) // Illegal, fix. (not 16<XOR>=8) if (XOR >> 3 == 1) // Illegal, fix. (not 16<XOR>=8)
{ {
// Keep as shiny, so we have to mod the PID // Keep as shiny, so we have to mod the EC
PID ^= XOR; pk.EncryptionConstant = PID ^ 0x80000000;
TB_PID.Text = PID.ToString("X8");
TB_EC.Text = PID.ToString("X8");
} }
else if ((XOR ^ 0x8000) >> 3 == 1 && PID != EC) else if ((XOR ^ 0x8000) >> 3 == 1 && PID != EC)
{ {
TB_EC.Text = (PID ^ 0x80000000).ToString("X8"); // Already anti-shiny, ensure the anti-shiny relationship is present.
pk.EncryptionConstant = PID ^ 0x80000000;
} }
else // Not illegal, no fix. else
{ {
TB_EC.Text = PID.ToString("X8"); // Ensure the copy correlation is present.
pk.EncryptionConstant = PID;
} }
} }