From 32deb3879a32ec014bf840aa97635e3acd9675ea Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 3 Jun 2017 08:58:30 -0700 Subject: [PATCH] Simplify Shiny SID creation calculates a passing SID and applies random bits to not be too predictable no need to bruteforce --- PKHeX.Core/PKM/PKM.cs | 3 ++- PKHeX.Core/Util/RandUtil.cs | 4 ---- PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index 14a9602d6..39cf09dd9 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -772,7 +772,8 @@ public void setShinyPID() public void setShinySID() { if (IsShiny) return; - do SID = Util.rnd16(); while (!IsShiny); + var xor = TID ^ (PID >> 16) ^ (PID & 0xFFFF); + SID = (int)((xor & 0xFFF8) | (Util.rnd32() & 7)); } /// /// Applies a PID to the according to the specified . diff --git a/PKHeX.Core/Util/RandUtil.cs b/PKHeX.Core/Util/RandUtil.cs index 9ca17f4b3..d638b1bc6 100644 --- a/PKHeX.Core/Util/RandUtil.cs +++ b/PKHeX.Core/Util/RandUtil.cs @@ -9,10 +9,6 @@ public static uint rnd32() { return (uint)rand.Next(1 << 30) << 2 | (uint)rand.Next(1 << 2); } - internal static ushort rnd16() - { - return (ushort)rand.Next(ushort.MaxValue); - } public static void Shuffle(T[] array) { int n = array.Length; diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index 8d09b6d14..5c2617f75 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -1487,7 +1487,7 @@ private void updateShiny(bool PID) if (pkm.Format > 2) { - if(PID) + if (PID) { pkm.setShinyPID(); TB_PID.Text = pkm.PID.ToString("X8");