Example #1
0
        async void SearchImpl(SeedSearcher searcher)
        {
            bool[] enabled = { GB_41.Enabled, GB_42.Enabled, GB_43.Enabled, GB_51.Enabled, GB_61.Enabled };
            GB_41.Enabled        = false;
            GB_42.Enabled        = false;
            GB_43.Enabled        = false;
            GB_51.Enabled        = false;
            GB_61.Enabled        = false;
            GB_Left.Enabled      = false;
            BT_newsearch.Enabled = false;
            SeedResult.Text      = "";
            int minRerolls = (int)NUD_IVMin.Value;
            int maxRerolls = (int)NUD_IVMax.Value;

            BT_Search.Enabled = false;
            BT_Search.Text    = "Searching...";
            // 時間計測
            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            stopWatch.Start();

            await Task.Run(() =>
            {
                searcher.Calculate(minRerolls, maxRerolls, LBL_IVDev);
            });

            stopWatch.Stop();
            LBL_Time.Text = $"{stopWatch.ElapsedMilliseconds} ms";

            BT_Search.Enabled = true;
            BT_Search.Text    = "Search";
            // 結果が見つからなかったらエラー
            SystemSounds.Asterisk.Play();
            if (searcher.Result.Count == 0)
            {
                MessageBox.Show("No Seed found. Please increase IV Deviation and run the tool again.");
                //unlock for editing
                GB_41.Enabled = enabled[0];
                GB_42.Enabled = enabled[1];
                GB_43.Enabled = enabled[2];
                GB_51.Enabled = enabled[3];
                GB_61.Enabled = enabled[4];
            }
            else
            {
                for (int i = 0; i < searcher.Result.Count; ++i)
                {
                    SeedResult.Text += $"{searcher.Result[i]:X}\n";
                }
                BT_Table.Enabled = true;
            }
            BT_newsearch.Enabled = true;
        }
Example #2
0
        private void BT_Search_Click(object sender, EventArgs e)
        {
            int[]        iv1       = { -1, -1, -1, -1, -1, -1 }; // 1 low IV
            int[]        iv2       = { -1, -1, -1, -1, -1, -1 }; // 1 mid IV
            int[]        iv3       = { -1, -1, -1, -1, -1, -1 }; // 1 high IV
            int[]        iv4       = { -1, -1, -1, -1, -1, -1 }; // 2
            int[]        iv5       = { -1, -1, -1, -1, -1, -1 }; // 3
            int          flawless1 = 0;
            int          flawless2 = 0;
            int          flawless3 = 0;
            int          flawless4 = 0;
            int          flawless5 = 0;
            RaidTemplate pkmn1     = null;
            RaidTemplate pkmn2     = null;
            RaidTemplate pkmn3     = null;
            RaidTemplate pkmn4     = null;
            RaidTemplate pkmn5     = null;

            int ability1 = -1;
            int ability2 = -1;
            int ability3 = -1;
            int ability4 = -1;
            int ability5 = -1;

            int nature1 = -1;
            int nature2 = -1;
            int nature3 = -1;
            int nature4 = -1;
            int nature5 = -1;

            int characteristics1 = -1;
            int characteristics2 = -1;
            int characteristics3 = -1;
            int characteristics4 = -1;
            int characteristics5 = -1;

            int fixedIV1 = -1;
            int fixedIV2 = -1;
            int fixedIV3 = -1;
            int fixedIV4 = -1;
            int fixedIV5 = -1;

            bool noGender1 = false;
            bool noGender2 = false;
            bool noGender3 = false;
            bool noGender4 = false;
            bool noGender5 = false;

            bool HA1 = false;
            bool HA2 = false;
            bool HA3 = false;
            bool HA4 = false;
            bool HA5 = false;

            if (GB_41.Enabled)
            {
                pkmn1            = (RaidTemplate)((ComboboxItem)CB_Species[0].SelectedItem).Value;
                ability1         = CB_Ability1.SelectedIndex - 1;
                characteristics1 = CB_Characteristic1.SelectedIndex - 1;
                fixedIV1         = pkmn1.FlawlessIVs;
                nature1          = CB_Nature1.SelectedIndex;
                int Gender = PersonalTable.SWSH[pkmn1.Species].Gender;
                noGender1 = Gender == 0 || Gender > 253;
                HA1       = pkmn1.Ability == 4;
            }

            if (GB_42.Enabled)
            {
                pkmn2            = (RaidTemplate)((ComboboxItem)CB_Species[1].SelectedItem).Value;
                ability2         = CB_Ability2.SelectedIndex - 1;
                characteristics2 = CB_Characteristic2.SelectedIndex - 1;
                fixedIV2         = pkmn2.FlawlessIVs;
                nature2          = CB_Nature2.SelectedIndex;
                int Gender = PersonalTable.SWSH[pkmn2.Species].Gender;
                noGender2 = Gender == 0 || Gender > 253;
                HA2       = pkmn2.Ability == 4;
            }

            if (GB_43.Enabled)
            {
                pkmn3            = (RaidTemplate)((ComboboxItem)CB_Species[2].SelectedItem).Value;
                ability3         = CB_Ability3.SelectedIndex - 1;
                characteristics3 = CB_Characteristic3.SelectedIndex - 1;
                fixedIV3         = pkmn3.FlawlessIVs;
                nature3          = CB_Nature3.SelectedIndex;
                int Gender = PersonalTable.SWSH[pkmn3.Species].Gender;
                noGender3 = Gender == 0 || Gender > 253;
                HA3       = pkmn3.Ability == 4;
            }

            if (GB_51.Enabled)
            {
                pkmn4            = (RaidTemplate)((ComboboxItem)CB_Species[3].SelectedItem).Value;
                ability4         = CB_Ability4.SelectedIndex - 1;
                characteristics4 = CB_Characteristic4.SelectedIndex - 1;
                fixedIV4         = pkmn4.FlawlessIVs;
                nature4          = CB_Nature4.SelectedIndex;
                int Gender = PersonalTable.SWSH[pkmn4.Species].Gender;
                noGender4 = Gender == 0 || Gender > 253;
                HA4       = pkmn4.Ability == 4;
            }

            if (GB_61.Enabled)
            {
                pkmn5            = (RaidTemplate)((ComboboxItem)CB_Species[4].SelectedItem).Value;
                ability5         = CB_Ability5.SelectedIndex - 1;
                characteristics5 = CB_Characteristic5.SelectedIndex - 1;
                fixedIV5         = pkmn5.FlawlessIVs;
                nature5          = CB_Nature5.SelectedIndex;
                int Gender = PersonalTable.SWSH[pkmn5.Species].Gender;
                noGender5 = Gender == 0 || Gender > 253;
                HA5       = pkmn5.Ability == 4;
            }

            for (int i = 0; i < 6; i++)
            {
                iv1[i] = (int)NUD_Stats[i].Value;
                iv2[i] = (int)NUD_Stats[i + 6 * 1].Value;
                iv3[i] = (int)NUD_Stats[i + 6 * 2].Value;
                iv4[i] = (int)NUD_Stats[i + 6 * 3].Value;
                iv5[i] = (int)NUD_Stats[i + 6 * 4].Value;
                if (iv1[i] == 31)
                {
                    flawless1++;
                }
                if (iv2[i] == 31)
                {
                    flawless2++;
                }
                if (iv3[i] == 31)
                {
                    flawless3++;
                }
                if (iv4[i] == 31)
                {
                    flawless4++;
                }
                if (iv5[i] == 31)
                {
                    flawless5++;
                }
            }
            if (GB_41.Enabled && flawless1 < fixedIV1)
            {
                MessageBox.Show("Invalid IV for Pokémon 1.");
                return;
            }
            if (GB_42.Enabled && flawless2 < fixedIV2)
            {
                MessageBox.Show("Invalid IV for Pokémon 2.");
                return;
            }
            if (GB_43.Enabled && flawless3 < fixedIV3)
            {
                MessageBox.Show("Invalid IV for Pokémon 3.");
                return;
            }
            if (GB_51.Enabled && flawless4 < fixedIV4)
            {
                MessageBox.Show("Invalid IV for Pokémon 4.");
                return;
            }
            if (GB_51.Enabled && flawless5 < fixedIV5)
            {
                MessageBox.Show("Invalid IV for Pokémon 5.");
                return;
            }

            // sanity check characteristics
            if (characteristics1 >= 0 && iv1[iv_order[characteristics1]] != 31)
            {
                MessageBox.Show("Invalid Characteristic for Pokémon 1.");
                return;
            }
            if (characteristics2 >= 0 && iv2[iv_order[characteristics2]] != 31)
            {
                MessageBox.Show("Invalid Characteristic for Pokémon 2.");
                return;
            }
            if (characteristics3 >= 0 && iv3[iv_order[characteristics3]] != 31)
            {
                MessageBox.Show("Invalid Characteristic for Pokémon 3.");
                return;
            }
            if (characteristics4 >= 0 && iv4[iv_order[characteristics4]] != 31)
            {
                MessageBox.Show("Invalid Characteristic for Pokémon 4.");
                return;
            }
            if (characteristics5 >= 0 && iv5[iv_order[characteristics5]] != 31)
            {
                MessageBox.Show("Invalid Characteristic for Pokémon 5.");
                return;
            }
            int[] fixedIV        = { -1, -1, -1, -1, -1 };
            int[] consecutiveIVs = CheckIVs(ref fixedIV);

            if (pkmn1.FlawlessIVs == 1)
            {
                if (fixedIV[0] == -1)
                {
                    MessageBox.Show("Invalid IV for Pokémon 1.");
                    return;
                }
                SearchOneIV(fixedIV[0]);
                return;
            }

            if (consecutiveIVs[4] == -1)
            {
                MessageBox.Show("Invalid IVs for first Pokémon. Use \"Check IVs\" option to check your IVs.");
                return;
            }
            // 2+ search
            // calculate seed LSB
            int LSB        = -1;
            var candidates = new List <int>();

            candidates.AddRange(new int[] { 0, 1, 2, 3, 4, 5 });
            if (characteristics1 >= 0 && flawless1 > 1)
            {
                removeCandidates(characteristics1, iv1, ref candidates);
            }
            else
            {
                characteristics1 = -1; // ensure its -1
            }
            if (GB_42.Enabled && characteristics2 >= 0 && flawless2 > 1)
            {
                removeCandidates(characteristics2, iv2, ref candidates);
            }
            else
            {
                characteristics2 = -1; // ensure its -1
            }
            if (GB_43.Enabled && characteristics3 >= 0 && flawless3 > 1)
            {
                removeCandidates(characteristics3, iv3, ref candidates);
            }
            else
            {
                characteristics3 = -1; // ensure its -1
            }
            shiftCandidates(ref candidates);
            if (characteristics4 >= 0 && flawless4 > 1)
            {
                removeCandidates(characteristics4, iv4, ref candidates);
            }
            else
            {
                characteristics4 = -1; // ensure its -1
            }
            shiftCandidates(ref candidates);
            if (characteristics5 >= 0 && flawless5 > 1)
            {
                removeCandidates(characteristics5, iv5, ref candidates);
            }
            else
            {
                characteristics5 = -1; // ensure its -1
            }
            if (candidates.Count == 1)
            {
                LSB = 1 - candidates[0] & 1;
                characteristics1 = (candidates[0] + 4) % 6;
            }
            else
            {
                if (candidates.Count == 0)
                {
                    var result = Util.Prompt(MessageBoxButtons.YesNo, "Entered characteristics seem to be wrong. This might increase the search time. Do you want to start the search anyway?");
                    if (result == DialogResult.No)
                    {
                        return;
                    }
                }
                characteristics1 = -1;
            }

            SeedSearcher searcher = new SeedSearcher(consecutiveIVs[5] == -1 ? SeedSearcher.Mode.Star35_5 : SeedSearcher.Mode.Star35_6);

            SeedSearcher.SetSixFirstCondition(iv1[0], iv1[1], iv1[2], iv1[3], iv1[4], iv1[5], pkmn1.FlawlessIVs, ability1, nature1, characteristics1, noGender1, HA1);
            if (GB_42.Enabled)
            {
                SeedSearcher.SetSixSecondCondition(iv2[0], iv2[1], iv2[2], iv2[3], iv2[4], iv2[5], pkmn2.FlawlessIVs, ability2, nature2, characteristics2, noGender2, HA2);
            }
            else
            {
                SeedSearcher.SetSixSecondCondition(iv3[0], iv3[1], iv3[2], iv3[3], iv3[4], iv3[5], pkmn3.FlawlessIVs, ability3, nature3, characteristics3, noGender3, HA3);
            }

            SeedSearcher.SetSixThirdCondition(iv4[0], iv4[1], iv4[2], iv4[3], iv4[4], iv4[5], pkmn4.FlawlessIVs, ability4, nature4, characteristics4, noGender4, HA4);
            SeedSearcher.SetSixFourthCondition(iv5[0], iv5[1], iv5[2], iv5[3], iv5[4], iv5[5], pkmn5.FlawlessIVs, ability5, nature5, characteristics5, noGender5, HA5);
            SeedSearcher.SetSixLSB(LSB);

            if (consecutiveIVs[5] == -1)
            {
                SeedSearcher.SetTargetCondition5(consecutiveIVs[0], consecutiveIVs[1], consecutiveIVs[2], consecutiveIVs[3], consecutiveIVs[4]);
            }
            else
            {
                SeedSearcher.SetTargetCondition6(consecutiveIVs[0], consecutiveIVs[1], consecutiveIVs[2], consecutiveIVs[3], consecutiveIVs[4], consecutiveIVs[5]);
            }

            SearchImpl(searcher);
        }
Example #3
0
        private void SearchOneIV(int flawlessIdx)
        {
            int[]        iv1       = { -1, -1, -1, -1, -1, -1 };
            int[]        iv2       = { -1, -1, -1, -1, -1, -1 };
            int[]        iv3       = { -1, -1, -1, -1, -1, -1 };
            int          flawless1 = 0;
            int          flawless2 = 0;
            int          flawless3 = 0;
            RaidTemplate pkmn1     = (RaidTemplate)((ComboboxItem)CB_Species[0].SelectedItem).Value;
            RaidTemplate pkmn2     = (RaidTemplate)((ComboboxItem)CB_Species[3].SelectedItem).Value;
            RaidTemplate pkmn3     = (RaidTemplate)((ComboboxItem)CB_Species[4].SelectedItem).Value;

            for (int i = 0; i < 6; i++)
            {
                iv1[i] = (int)NUD_Stats[i].Value;
                iv2[i] = (int)NUD_Stats[i + 6 * 3].Value;
                iv3[i] = (int)NUD_Stats[i + 6 * 4].Value;
            }

            int ability1 = CB_Ability1.SelectedIndex - 1;
            int ability2 = CB_Ability4.SelectedIndex - 1;
            int ability3 = CB_Ability5.SelectedIndex - 1;

            int characteristics1 = CB_Characteristic1.SelectedIndex - 1;
            int characteristics2 = CB_Characteristic4.SelectedIndex - 1;
            int characteristics3 = CB_Characteristic5.SelectedIndex - 1;

            // calculate seed LSB
            int LSB        = -1;
            var candidates = new List <int>();

            candidates.AddRange(new int[] { 0, 1, 2, 3, 4, 5 });
            if (characteristics1 >= 0 && flawless1 > 1)
            {
                removeCandidates(characteristics1, iv1, ref candidates);
            }
            else
            {
                characteristics1 = -1; // ensure its -1
            }
            shiftCandidates(ref candidates);
            if (characteristics2 >= 0 && flawless2 > 1)
            {
                removeCandidates(characteristics2, iv2, ref candidates);
            }
            else
            {
                characteristics2 = -1; // ensure its -1
            }
            shiftCandidates(ref candidates);
            if (characteristics3 >= 0 && flawless3 > 1)
            {
                removeCandidates(characteristics3, iv3, ref candidates);
            }
            else
            {
                characteristics3 = -1; // ensure its -1
            }
            if (candidates.Count == 1)
            {
                LSB = 1 - (candidates[0] & 1);
                characteristics1 = candidates[0];
            }
            else
            {
                if (candidates.Count == 0)
                {
                    var result = Util.Prompt(MessageBoxButtons.YesNo, "Entered characteristics seem to be wrong. This might increase the search time. Do you want to start the search anyway?");
                    if (result == DialogResult.No)
                    {
                        return;
                    }
                }
                characteristics1 = -1;
            }
            int nature1 = CB_Nature1.SelectedIndex;
            int nature2 = CB_Nature4.SelectedIndex;
            int nature3 = CB_Nature5.SelectedIndex;

            int Gender1 = PersonalTable.SWSH[pkmn1.Species].Gender;
            int Gender2 = PersonalTable.SWSH[pkmn2.Species].Gender;
            int Gender3 = PersonalTable.SWSH[pkmn3.Species].Gender;

            bool noGender1 = Gender1 == 0 || Gender1 > 253;
            bool noGender2 = Gender2 == 0 || Gender2 > 253;
            bool noGender3 = Gender3 == 0 || Gender3 > 253;

            bool HA1 = pkmn1.Ability == 4;
            bool HA2 = pkmn2.Ability == 4;
            bool HA3 = pkmn3.Ability == 4;

            SeedSearcher searcher = new SeedSearcher(SeedSearcher.Mode.Star12);

            SeedSearcher.SetFirstCondition(iv1[0], iv1[1], iv1[2], iv1[3], iv1[4], iv1[5], pkmn1.FlawlessIVs, flawlessIdx, ability1, nature1, characteristics1, noGender1, HA1);
            SeedSearcher.SetNextCondition(iv2[0], iv2[1], iv2[2], iv2[3], iv2[4], iv2[5], pkmn2.FlawlessIVs, ability2, nature2, characteristics2, noGender2, HA2);
            SeedSearcher.SetThirdCondition(iv3[0], iv3[1], iv3[2], iv3[3], iv3[4], iv3[5], pkmn3.FlawlessIVs, ability3, nature3, characteristics3, noGender3, HA3);
            SeedSearcher.SetLSB(LSB);
            SearchImpl(searcher);
        }