From 569873701b5db9f6abc814e3d71a6d84cad9ee46 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 15 Jul 2017 09:48:08 -0700 Subject: [PATCH] Fix antishiny 3-5=>6+ check uint SID = Util.ToUInt32(TB_TID.Text); uint TID = Util.ToUInt32(TB_TID.Text); first line should have been TB_SID.Text not TID pull out method Thanks wejhvabewjty! https://projectpokemon.org/forums/forums/topic/41110-problem-with-pok%C3%A9mon-caught-w-cute-charm-lead/ --- PKHeX.WinForms/Controls/PKM Editor/EditPK6.cs | 24 +---------------- PKHeX.WinForms/Controls/PKM Editor/EditPK7.cs | 27 ++----------------- .../Controls/PKM Editor/PKMEditor.cs | 26 ++++++++++++++++++ 3 files changed, 29 insertions(+), 48 deletions(-) diff --git a/PKHeX.WinForms/Controls/PKM Editor/EditPK6.cs b/PKHeX.WinForms/Controls/PKM Editor/EditPK6.cs index 9531384d2..04f92e5c4 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/EditPK6.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/EditPK6.cs @@ -150,29 +150,7 @@ namespace PKHeX.WinForms.Controls return null; // Repopulate PK6 with Edited Stuff - if (WinFormsUtil.GetIndex(CB_GameOrigin) < 24) - { - uint EC = Util.GetHexValue(TB_EC.Text); - uint PID = Util.GetHexValue(TB_PID.Text); - uint SID = Util.ToUInt32(TB_TID.Text); - uint TID = Util.ToUInt32(TB_TID.Text); - uint LID = PID & 0xFFFF; - uint HID = PID >> 16; - uint XOR = TID ^ LID ^ SID ^ HID; - - // Ensure we don't have a shiny. - if (XOR >> 3 == 1) // Illegal, fix. (not 16=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"); - } - else if ((XOR ^ 0x8000) >> 3 == 1 && PID != EC) - TB_EC.Text = (PID ^ 0x80000000).ToString("X8"); - else // Not Illegal, no fix. - TB_EC.Text = PID.ToString("X8"); - } + CheckTransferPIDValid(); pk6.EncryptionConstant = Util.GetHexValue(TB_EC.Text); pk6.Checksum = 0; // 0 CHK for now diff --git a/PKHeX.WinForms/Controls/PKM Editor/EditPK7.cs b/PKHeX.WinForms/Controls/PKM Editor/EditPK7.cs index e0e06ab36..e3b798580 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/EditPK7.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/EditPK7.cs @@ -149,30 +149,8 @@ namespace PKHeX.WinForms.Controls if (pk7 == null) return null; - // Repopulate PK6 with Edited Stuff - if (WinFormsUtil.GetIndex(CB_GameOrigin) < 24) - { - uint EC = Util.GetHexValue(TB_EC.Text); - uint PID = Util.GetHexValue(TB_PID.Text); - uint SID = Util.ToUInt32(TB_TID.Text); - uint TID = Util.ToUInt32(TB_TID.Text); - uint LID = PID & 0xFFFF; - uint HID = PID >> 16; - uint XOR = TID ^ LID ^ SID ^ HID; - - // Ensure we don't have a shiny. - if (XOR >> 3 == 1) // Illegal, fix. (not 16=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"); - } - else if ((XOR ^ 0x8000) >> 3 == 1 && PID != EC) - TB_EC.Text = (PID ^ 0x80000000).ToString("X8"); - else // Not Illegal, no fix. - TB_EC.Text = PID.ToString("X8"); - } + // Repopulate PK7 with Edited Stuff + CheckTransferPIDValid(); pk7.EncryptionConstant = Util.GetHexValue(TB_EC.Text); pk7.Checksum = 0; // 0 CHK for now @@ -190,7 +168,6 @@ namespace PKHeX.WinForms.Controls pk7.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text); // Number } - // pkx[0x16], pkx[0x17] are handled by the Medals UI (Hits & Training Bag) pk7.PID = Util.GetHexValue(TB_PID.Text); pk7.Nature = (byte)WinFormsUtil.GetIndex(CB_Nature); pk7.FatefulEncounter = CHK_Fateful.Checked; diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index 1170c47dc..482fcfd92 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -807,6 +807,32 @@ namespace PKHeX.WinForms.Controls return true; } + private void CheckTransferPIDValid() + { + if (pkm.Version >= 24) + return; + + uint EC = Util.GetHexValue(TB_EC.Text); + uint PID = Util.GetHexValue(TB_PID.Text); + uint SID = Util.ToUInt32(TB_SID.Text); + uint TID = Util.ToUInt32(TB_TID.Text); + uint LID = PID & 0xFFFF; + uint HID = PID >> 16; + uint XOR = TID ^ LID ^ SID ^ HID; + + // Ensure we don't have a shiny. + if (XOR >> 3 == 1) // Illegal, fix. (not 16=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"); + } + else if ((XOR ^ 0x8000) >> 3 == 1 && PID != EC) + TB_EC.Text = (PID ^ 0x80000000).ToString("X8"); + else // Not Illegal, no fix. + TB_EC.Text = PID.ToString("X8"); + } private void UpdateIVs(object sender, EventArgs e) {