mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 06:20:25 +00:00
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:
parent
c4ce22412a
commit
a885f6b48f
4 changed files with 15 additions and 16 deletions
|
@ -28,12 +28,12 @@ namespace PKHeX.WinForms.Controls
|
|||
if (!(Entity is PK6 pk6))
|
||||
throw new FormatException(nameof(Entity));
|
||||
|
||||
CheckTransferPIDValid();
|
||||
SaveMisc1(pk6);
|
||||
SaveMisc2(pk6);
|
||||
SaveMisc3(pk6);
|
||||
SaveMisc4(pk6);
|
||||
SaveMisc6(pk6);
|
||||
CheckTransferPIDValid(pk6);
|
||||
|
||||
pk6.EncounterType = WinFormsUtil.GetIndex(CB_EncounterType);
|
||||
|
||||
|
|
|
@ -25,12 +25,12 @@ namespace PKHeX.WinForms.Controls
|
|||
if (!(Entity is PK7 pk7))
|
||||
throw new FormatException(nameof(Entity));
|
||||
|
||||
CheckTransferPIDValid();
|
||||
SaveMisc1(pk7);
|
||||
SaveMisc2(pk7);
|
||||
SaveMisc3(pk7);
|
||||
SaveMisc4(pk7);
|
||||
SaveMisc6(pk7);
|
||||
CheckTransferPIDValid(pk7);
|
||||
|
||||
// Toss in Party Stats
|
||||
SavePartyStats(pk7);
|
||||
|
@ -71,7 +71,6 @@ namespace PKHeX.WinForms.Controls
|
|||
if (!(Entity is PB7 pk7))
|
||||
throw new FormatException(nameof(Entity));
|
||||
|
||||
CheckTransferPIDValid();
|
||||
SaveMisc1(pk7);
|
||||
SaveMisc2(pk7);
|
||||
SaveMisc3(pk7);
|
||||
|
|
|
@ -27,13 +27,13 @@ namespace PKHeX.WinForms.Controls
|
|||
if (!(Entity is PK8 pk8))
|
||||
throw new FormatException(nameof(Entity));
|
||||
|
||||
CheckTransferPIDValid();
|
||||
SaveMisc1(pk8);
|
||||
SaveMisc2(pk8);
|
||||
SaveMisc3(pk8);
|
||||
SaveMisc4(pk8);
|
||||
SaveMisc6(pk8);
|
||||
SaveMisc8(pk8);
|
||||
CheckTransferPIDValid(pk8);
|
||||
|
||||
// Toss in Party Stats
|
||||
SavePartyStats(pk8);
|
||||
|
|
|
@ -345,32 +345,32 @@ namespace PKHeX.WinForms.Controls
|
|||
}
|
||||
|
||||
// Misc
|
||||
private void CheckTransferPIDValid()
|
||||
private static void CheckTransferPIDValid(PKM pk)
|
||||
{
|
||||
if (Entity.Version >= 24)
|
||||
if (pk.Version >= 24 && pk.Version != 0)
|
||||
return;
|
||||
|
||||
uint EC = Util.GetHexValue(TB_EC.Text);
|
||||
uint PID = Util.GetHexValue(TB_PID.Text);
|
||||
uint EC = pk.EncryptionConstant;
|
||||
uint PID = pk.PID;
|
||||
uint LID = PID & 0xFFFF;
|
||||
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.
|
||||
if (XOR >> 3 == 1) // Illegal, fix. (not 16<XOR>=8)
|
||||
{
|
||||
// Keep as shiny, so we have to mod the PID
|
||||
PID ^= XOR;
|
||||
TB_PID.Text = PID.ToString("X8");
|
||||
TB_EC.Text = PID.ToString("X8");
|
||||
// Keep as shiny, so we have to mod the EC
|
||||
pk.EncryptionConstant = PID ^ 0x80000000;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue