Exemplo n.º 1
0
        //--------------------------------------------------------------------------------------------------
        private void buttonShinyGenerate_Click(object sender, EventArgs e)
        {
            //the main function for the shiny Time finder

            //check to make sure the user hasn't filled the text
            //boxes with exception-throwing garbage
            validateShinyInput();

            if (checkBoxShinyDreamWorld.Checked && checkBoxShinyDittoParent.Checked)
            {
                MessageBox.Show("Unable to have Ditto parent and Dream World ability at the same time.");
                checkBoxShinyDittoParent.Focus();
                return;
            }

            //read the user input from the form
            int year = Convert.ToInt32(maskedTextBoxShinyYear.Text);
            if (year < 2000 || year > 2099)
            {
                MessageBox.Show("Year must be between 2000 and 2099.");
                maskedTextBoxShinyYear.Focus();
                return;
            }

            var months = new List<int>();
            for (int month = 1; month <= 12; month++)
            {
                if (comboBoxShinyMonth.CheckBoxItems[month].Checked)
                    months.Add(month);
            }

            if (months.Count == 0)
            {
                comboBoxShinyMonth.Focus();
                return;
            }

            List<uint> nature = null;
            if (comboBoxShinyNature.SelectedIndex != 0)
                nature = new List<uint> {(uint) ((Nature) comboBoxShinyNature.SelectedItem).Number};

            // Don't proceed without all DS Parameters
            if (!DSParametersInputCheck())
                return;

            if (maskedTextBoxShinyMinFrame.Text == "")
            {
                maskedTextBoxShinyMinFrame.Focus();
                maskedTextBoxShinyMinFrame.SelectAll();
                return;
            }

            if (maskedTextBoxShinyMaxFrame.Text == "")
            {
                maskedTextBoxShinyMaxFrame.Focus();
                maskedTextBoxShinyMaxFrame.SelectAll();
                return;
            }

            var parentA = new uint[6];
            var parentB = new uint[6];

            uint.TryParse(maskedTextBoxShinyHPParentA.Text, out parentA[0]);
            uint.TryParse(maskedTextBoxShinyAtkParentA.Text, out parentA[1]);
            uint.TryParse(maskedTextBoxShinyDefParentA.Text, out parentA[2]);
            uint.TryParse(maskedTextBoxShinySpAParentA.Text, out parentA[3]);
            uint.TryParse(maskedTextBoxShinySpDParentA.Text, out parentA[4]);
            uint.TryParse(maskedTextBoxShinySpeParentA.Text, out parentA[5]);

            uint.TryParse(maskedTextBoxShinyHPParentB.Text, out parentB[0]);
            uint.TryParse(maskedTextBoxShinyAtkParentB.Text, out parentB[1]);
            uint.TryParse(maskedTextBoxShinyDefParentB.Text, out parentB[2]);
            uint.TryParse(maskedTextBoxShinySpAParentB.Text, out parentB[3]);
            uint.TryParse(maskedTextBoxShinySpDParentB.Text, out parentB[4]);
            uint.TryParse(maskedTextBoxShinySpeParentB.Text, out parentB[5]);

            uint minFrame;
            uint maxFrame;

            uint.TryParse(maskedTextBoxShinyMinFrame.Text, out minFrame);
            uint.TryParse(maskedTextBoxShinyMaxFrame.Text, out maxFrame);

            if (minFrame > maxFrame)
            {
                maskedTextBoxShinyMinFrame.Focus();
                maskedTextBoxShinyMinFrame.SelectAll();
                return;
            }

            generator = new FrameGenerator {FrameType = FrameType.Method5Standard, InitialFrame = 8, MaxResults = 1};

            shinygenerator = new FrameGenerator
                {
                    FrameType =
                        !checkBoxIntlParents.Checked ? FrameType.BWBred : FrameType.BWBredInternational,
                    ParentA = parentA,
                    ParentB = parentB,
                    SynchNature = ((Nature) comboBoxShinyEverstoneNature.SelectedItem).Number,
                    InitialFrame = minFrame,
                    MaxResults = maxFrame - minFrame + 1,
                    DittoUsed = checkBoxShinyDittoParent.Checked,
                    MaleOnlySpecies = cbNidoBeat.Checked,
                    ShinyCharm = cbShinyCharm.Visible && cbShinyCharm.Checked
                };

            frameCompare = new FrameCompare(
                null,
                null,
                -1,
                false,
                false,
                false,
                null,
                new NoGenderFilter());

            subFrameCompare = new FrameCompare(
                ivFiltersEggs.IVFilter,
                nature,
                (int) ((ComboBoxItem) comboBoxShinyAbility.SelectedItem).Reference,
                checkBoxShinyShinyOnly.Checked,
                false,
                checkBoxShinyDreamWorld.Checked,
                null,
                (GenderFilter) (comboBoxShinyGender.SelectedItem));

            // Here we check the parent IVs
            // To make sure they even have a chance of producing the desired spread

            int parentPassCount = 0;
            for (int i = 0; i < 6; i++)
            {
                if (subFrameCompare.CompareIV(i, parentA[i]) ||
                    subFrameCompare.CompareIV(i, parentB[i]))
                {
                    parentPassCount++;
                }
            }

            if (parentPassCount < 3)
            {
                MessageBox.Show("The parent IVs you have listed cannot produce your desired search results.");
                return;
            }

            iframesEgg = new List<IFrameCapture>();
            listBindingEgg = new BindingSource {DataSource = iframesEgg};
            dataGridViewShinyResults.DataSource = listBindingEgg;

            var profile = (Profile) comboBoxProfiles.SelectedItem;

            List<List<ButtonComboType>> keypresses = profile.GetKeypresses();

            bool fastSearch = FastEggFilters() && eggSeeds != null && eggSeeds.Count > 0; // && FastEggFrames()

            int dayTotal = months.Sum(month => DateTime.DaysInMonth(year, month));

            progressTotal =
                (ulong)
                (dayTotal*86400*keypresses.Count*(profile.Timer0Max - profile.Timer0Min + 1)*(maxFrame - minFrame + 1));

            float interval = ((float) 24/cpus + (float) 0.05);

            var hourMin = new int[cpus];
            var hourMax = new int[cpus];

            jobs = new Thread[cpus];
            generators = new FrameGenerator[cpus];
            shinygenerators = new FrameGenerator[cpus];
            waitHandle = new EventWaitHandle(true, EventResetMode.ManualReset);

            for (int i = 0; i < jobs.Length; i++)
            {
                hourMin[i] = (int) (interval*i);
                hourMax[i] = (int) (interval*(i + 1) - 1);

                if (hourMax[i] > 23)
                {
                    hourMax[i] = 23;
                }
            }

            for (int i = 0; i < jobs.Length; i++)
            {
                generators[i] = generator.Clone();

                if (shinygenerator != null)
                {
                    shinygenerators[i] = shinygenerator.Clone();
                }

                //copy to prevent issues with i being incremented before the call
                int i1 = i;
                jobs[i] =
                    new Thread(
                        () =>
                        GenerateShinyJob((uint) year, months, hourMin[i1], hourMax[i1], profile, keypresses, fastSearch,
                                         i1));
                jobs[i].Start();
                // for some reason not making the thread sleep causes issues with updating dayMin\Max
                Thread.Sleep(200);
            }

            var progressJob =
                new Thread(
                    () => ManageProgress(listBindingEgg, dataGridViewShinyResults, shinygenerator.FrameType, 2000));
            progressJob.Start();
            progressJob.Priority = ThreadPriority.Lowest;

            buttonCapGenerate.Enabled = false;
            buttonShinyGenerate.Enabled = false;

            dataGridViewShinyResults.Focus();
        }
Exemplo n.º 2
0
        //  Capture code begins here -- This is all of the good stuff for
        //  captured Pokemon.
        private void buttonCapGenerate_Click(object sender, EventArgs e)
        {
            var profile = (Profile) comboBoxProfiles.SelectedItem;
            iframes = new List<IFrameCapture>();
            listBindingCap = new BindingSource {DataSource = iframes};
            dataGridViewCapValues.DataSource = listBindingCap;

            jobs = new Thread[cpus];
            generators = new FrameGenerator[cpus];
            shinygenerators = new FrameGenerator[cpus];
            waitHandle = new EventWaitHandle(true, EventResetMode.ManualReset);

            var year = (uint) DateTime.Now.Year;
            if (maskedTextBoxCapYear.Text != "")
            {
                year = uint.Parse(maskedTextBoxCapYear.Text);

                //  Need to validate the year here
                if (year < 2000)
                {
                    MessageBox.Show("You must enter a year greater than 1999.", "Please Enter a Valid Year",
                                    MessageBoxButtons.OK);
                    return;
                }
            }

            uint maxOffset = 1000;
            if (maskedTextBoxCapMaxOffset.Text != "")
            {
                maxOffset = uint.Parse(maskedTextBoxCapMaxOffset.Text);
            }
            else
            {
                maskedTextBoxCapMaxOffset.Text = "1000";
            }

            uint minOffset = 1;
            if (maskedTextBoxCapMinOffset.Text != "")
            {
                minOffset = uint.Parse(maskedTextBoxCapMinOffset.Text);
            }
            else
            {
                maskedTextBoxCapMinOffset.Text = "1";
            }

            if (minOffset > maxOffset)
            {
                maskedTextBoxCapMinOffset.Focus();
                maskedTextBoxCapMinOffset.SelectAll();
                return;
            }

            generator = new FrameGenerator
                {
                    // Now that each combo box item is a custom object containing the FrameType reference
                    // We can simply retrieve the FrameType from the selected item
                    FrameType = (FrameType) ((ComboBoxItem) comboBoxMethod.SelectedItem).Reference,
                    EncounterType =
                        (EncounterType) ((ComboBoxItem) comboBoxEncounterType.SelectedItem).Reference,
                    EncounterMod = Objects.EncounterMod.Search,
                    InitialFrame = minOffset,
                    MaxResults = maxOffset - minOffset + 1
                };
            if (generator.FrameType == FrameType.BWBred && profile.IsBW2()) generator.FrameType = FrameType.BW2Bred;
            if (generator.FrameType == FrameType.BWBredInternational && profile.IsBW2())
                generator.FrameType = FrameType.BW2BredInternational;
            generator.isBW2 = profile.IsBW2();

            // set up the hashtables containing precomputed MTRNG values
            // this saves time by reducing the search to a hashtable lookup
            // of MTRNG seeds that corresponds to common spreads
            //list = new Hashtable[6];
            list = new Dictionary<uint, uint>[6];

            bool fastSearch = FastCapFilters() && FastCapFrames();

            //  Build up a FrameComparer

            //  Map the information from the IV box.  Anything
            //  that is blank is considered a zero.

            List<int> encounterSlots = null;
            if (comboBoxEncounterSlot.Text != "Any" && comboBoxEncounterSlot.CheckBoxItems.Count > 0)
            {
                encounterSlots = new List<int>();
                for (int i = 0; i < comboBoxEncounterSlot.CheckBoxItems.Count; i++)
                {
                    if (comboBoxEncounterSlot.CheckBoxItems[i].Checked)
                        // We have to subtract 1 because this custom control contains a hidden item for text display
                        encounterSlots.Add(i - 1);
                }
            }

            List<uint> natures = null;
            if (comboBoxNature.Text != "Any" && comboBoxNature.CheckBoxItems.Count > 0)
            {
                natures =
                    (from t in comboBoxNature.CheckBoxItems
                     where t.Checked
                     select (uint) ((Nature) t.ComboBoxItem).Number).ToList();
            }

            uint shinyOffset = 0;
            if (checkBoxShinyOnly.Checked)
            {
                uint.TryParse(maskedTextBoxMaxShiny.Text, out shinyOffset);
            }

            if (generator.FrameType == FrameType.Method5CGear || generator.FrameType == FrameType.Method5Standard)
            {
                EncounterSlot.Visible = false;
                EncounterMod.Visible = false;
                PID.Visible = false;
                Shiny.Visible = false;
                NearestShiny.Visible = false;
                Nature.Visible = false;
                Ability.Visible = false;
                CapHP.Visible = true;
                CapAtk.Visible = true;
                CapDef.Visible = true;
                CapSpA.Visible = true;
                CapSpD.Visible = true;
                CapSpe.Visible = true;
                HiddenPower.Visible = true;
                HiddenPowerPower.Visible = true;
                f25.Visible = false;
                f50.Visible = false;
                f75.Visible = false;
                f125.Visible = false;

                if (generator.FrameType == FrameType.Method5Standard)
                {
                    CapSeed.DefaultCellStyle.Format = "X16";
                    CapSeed.Width = seedColumnLong(true);
                    CapDateTime.Visible = true;
                    CapKeypress.Visible = true;
                    CapTimer0.Visible = true;

                    if (shinyOffset > 0)
                    {
                        shinygenerator = new FrameGenerator
                            {
                                FrameType = FrameType.Method5Natures,
                                EncounterType =
                                    (EncounterType)
                                    ((ComboBoxItem) comboBoxEncounterType.SelectedItem).Reference,
                                EncounterMod = Objects.EncounterMod.Search,
                                InitialFrame = 1,
                                MaxResults = shinyOffset,
                                //ShinyCharm = cbCapShinyCharm.Checked
                            };

                        subFrameCompare = new FrameCompare(
                            ivFiltersCapture.IVFilter,
                            natures,
                            (int) ((ComboBoxItem) comboBoxAbility.SelectedItem).Reference,
                            true,
                            checkBoxSynchOnly.Checked,
                            false,
                            encounterSlots,
                            constructGenderFilter());

                        NearestShiny.Visible = true;
                        PID.Visible = false;

                        if (shinygenerator.EncounterType != EncounterType.Gift &&
                            shinygenerator.EncounterType != EncounterType.Roamer &&
                            shinygenerator.EncounterType != EncounterType.LarvestaEgg &&
                            shinygenerator.EncounterType != EncounterType.AllEncounterShiny)
                            EncounterMod.Visible = true;
                        else
                            EncounterMod.Visible = false;
                        if (shinygenerator.EncounterType != EncounterType.Stationary &&
                            shinygenerator.EncounterType != EncounterType.Gift &&
                            shinygenerator.EncounterType != EncounterType.Roamer &&
                            shinygenerator.EncounterType != EncounterType.LarvestaEgg &&
                            shinygenerator.EncounterType != EncounterType.AllEncounterShiny)
                            EncounterSlot.Visible = true;
                        else
                            EncounterSlot.Visible = false;

                        Nature.Visible = true;
                        Ability.Visible = true;
                        DisplayGenderColumns();
                    }
                    if (profile.IsBW2())
                        generator.InitialFrame += 2;
                }
                else
                {
                    CapSeed.DefaultCellStyle.Format = "X8";
                    CapSeed.Width = seedColumnLong(false);
                    CapDateTime.Visible = false;
                    CapKeypress.Visible = false;
                    CapTimer0.Visible = false;
                }

                frameCompare = new FrameCompare(
                    ivFiltersCapture.IVFilter,
                    null,
                    -1,
                    false,
                    false,
                    false,
                    null,
                    new NoGenderFilter());
            }

            if (generator.FrameType == FrameType.Wondercard5thGen ||
                generator.FrameType == FrameType.Wondercard5thGenFixed)
            {
                CapSeed.DefaultCellStyle.Format = "X16";
                CapSeed.Width = seedColumnLong(true);
                EncounterMod.Visible = false;
                EncounterSlot.Visible = false;
                PID.Visible = true;
                Shiny.Visible = true;
                NearestShiny.Visible = false;
                Nature.Visible = true;
                Ability.Visible = false;
                CapHP.Visible = true;
                CapAtk.Visible = true;
                CapDef.Visible = true;
                CapSpA.Visible = true;
                CapSpD.Visible = true;
                CapSpe.Visible = true;
                HiddenPower.Visible = true;
                HiddenPowerPower.Visible = true;
                f25.Visible = false;
                f50.Visible = false;
                f75.Visible = false;
                f125.Visible = false;
                CapDateTime.Visible = true;
                CapKeypress.Visible = true;
                CapTimer0.Visible = true;

                // genders are unsupported for now, fix this later
                frameCompare = new FrameCompare(
                    ivFiltersCapture.IVFilter,
                    natures,
                    -1,
                    checkBoxShinyOnly.Checked,
                    false,
                    false,
                    null,
                    new NoGenderFilter());
            }

            if (generator.FrameType == FrameType.Method5Natures)
            {
                CapSeed.DefaultCellStyle.Format = "X16";
                CapSeed.Width = seedColumnLong(true);
                if (generator.EncounterType != EncounterType.Gift && generator.EncounterType != EncounterType.Roamer &&
                    generator.EncounterType != EncounterType.LarvestaEgg &&
                    generator.EncounterType != EncounterType.AllEncounterShiny)
                    EncounterMod.Visible = true;
                else
                    EncounterMod.Visible = false;
                if (generator.EncounterType != EncounterType.Stationary && generator.EncounterType != EncounterType.Gift &&
                    generator.EncounterType != EncounterType.Roamer &&
                    generator.EncounterType != EncounterType.LarvestaEgg)
                    EncounterSlot.Visible = true;
                else
                    EncounterSlot.Visible = false;
                PID.Visible = true;
                Shiny.Visible = true;
                NearestShiny.Visible = false;
                Nature.Visible = true;
                Ability.Visible = true;
                CapHP.Visible = false;
                CapAtk.Visible = false;
                CapDef.Visible = false;
                CapSpA.Visible = false;
                CapSpD.Visible = false;
                CapSpe.Visible = false;
                HiddenPower.Visible = false;
                HiddenPowerPower.Visible = false;
                DisplayGenderColumns();
                CapDateTime.Visible = true;
                CapKeypress.Visible = true;
                CapTimer0.Visible = true;

                //generator.ShinyCharm = cbCapShinyCharm.Checked;

                frameCompare = new FrameCompare(
                    ivFiltersCapture.IVFilter,
                    natures,
                    (int) ((ComboBoxItem) comboBoxAbility.SelectedItem).Reference,
                    checkBoxShinyOnly.Checked,
                    checkBoxSynchOnly.Checked,
                    false,
                    encounterSlots,
                    constructGenderFilter());
            }

            if (generator.FrameType != FrameType.Method5CGear)
            {
                if (fastSearch)
                {
                    Assembly thisExe = Assembly.GetExecutingAssembly();
                    Stream file;

                    if (generator.EncounterType == EncounterType.Roamer)
                    {
                        file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame1D-Roamer.txt");
                        list[0] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                        file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame2D-Roamer.txt");
                        list[1] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                        file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame3D-Roamer.txt");
                        list[2] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                        file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame4D-Roamer.txt");
                        list[3] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                        file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame5D-Roamer.txt");
                        list[4] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                        file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame6D-Roamer.txt");
                        list[5] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);

                        foreach (var partialList in list)
                        {
                            if (partialList == null)
                                MessageBox.Show("error in loading roamer tables");
                        }
                    }
                    else
                    {
                        if (profile.IsBW2())
                        {
                            // entralink
                            if (minOffset > 21)
                            {
                                file =
                                    thisExe.GetManifestResourceStream(
                                        "RNGReporter.Resources.MTRNG-Frame25-Entralink.txt");
                                list[0] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                                file =
                                    thisExe.GetManifestResourceStream(
                                        "RNGReporter.Resources.MTRNG-Frame26-Entralink.txt");
                                list[1] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                                file =
                                    thisExe.GetManifestResourceStream(
                                        "RNGReporter.Resources.MTRNG-Frame27-Entralink.txt");
                                list[2] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                                file =
                                    thisExe.GetManifestResourceStream(
                                        "RNGReporter.Resources.MTRNG-Frame28-Entralink.txt");
                                list[3] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                                file =
                                    thisExe.GetManifestResourceStream(
                                        "RNGReporter.Resources.MTRNG-Frame29-Entralink.txt");
                                list[4] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                                file =
                                    thisExe.GetManifestResourceStream(
                                        "RNGReporter.Resources.MTRNG-Frame30-Entralink.txt");
                                list[5] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                            }
                            else
                            {
                                file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame3D.txt");
                                list[0] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                                file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame4D.txt");
                                list[1] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                                file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame5D.txt");
                                list[2] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                                file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame6D.txt");
                                list[3] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                                file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame7D.txt");
                                list[4] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                                file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame8D.txt");
                                list[5] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                            }
                        }
                        else
                        {
                            file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame1D.txt");
                            list[0] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                            file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame2D.txt");
                            list[1] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                            file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame3D.txt");
                            list[2] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                            file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame4D.txt");
                            list[3] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                            file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame5D.txt");
                            list[4] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                            file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame6D.txt");
                            list[5] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                        }

                        foreach (var partialList in list)
                        {
                            if (partialList == null)
                                MessageBox.Show("error in loading hashtables");
                        }
                    }
                }

                generateTimesToolStripMenuItem.Visible = false;
                generateEntralinkNatureSeedsToolStripMenuItem.Visible = false;
                generateAdjacentSeedsToolStripMenuItem.Visible = true;

                var months = new List<int>();
                for (int month = 1; month <= 12; month++)
                {
                    if (comboBoxCapMonth.CheckBoxItems[month].Checked)
                        months.Add(month);
                }

                if (months.Count == 0)
                {
                    comboBoxCapMonth.Focus();
                    return;
                }

                if (!DSParametersInputCheck())
                    return;

                List<List<ButtonComboType>> keypresses = profile.GetKeypresses();

                progressSearched = 0;
                progressFound = 0;

                int dayTotal = months.Sum(month => DateTime.DaysInMonth((int) year, month));
                progressTotal =
                    (ulong)
                    (dayTotal*86400*(maxOffset - minOffset + 1)*keypresses.Count*
                     (profile.Timer0Max - profile.Timer0Min + 1));

                for (int i = 0; i < jobs.Length; i++)
                {
                    generators[i] = generator.Clone();

                    if (shinygenerator != null)
                    {
                        shinygenerators[i] = shinygenerator.Clone();
                    }

                    //copy to prevent issues with it being incremented before the actual thread really starts
                    int i1 = i;
                    //passing in a profile instead of the params would probably be more efficent
                    if (generator.FrameType == FrameType.Wondercard5thGen ||
                        generator.FrameType == FrameType.Wondercard5thGenFixed)
                    {
                        int shiny = comboBoxShiny.SelectedIndex;
                        jobs[i] =
                            new Thread(
                                () =>
                                GenerateWonderCardJob(year, months, 0, 23, profile, shinyOffset, fastSearch, i1,
                                                      shiny));
                    }
                    else
                    {
                        jobs[i] =
                            new Thread(
                                () =>
                                GenerateJob(year, months, 0, 23, profile, shinyOffset, fastSearch, i1));
                    }
                    jobs[i].Start();
                    // for some reason not making the thread sleep causes issues with updating dayMin\Max
                    Thread.Sleep(200);
                }
                var progressJob =
                    new Thread(() => ManageProgress(listBindingCap, dataGridViewCapValues, generator.FrameType, 2000));
                progressJob.Start();
                progressJob.Priority = ThreadPriority.Lowest;

                buttonCapGenerate.Enabled = false;
                buttonShinyGenerate.Enabled = false;
            }
            else
            {
                //  We want to get our year and offset ranges here so
                //  that we can have some values for our looping.
                //  Default these to this value, but save to
                //  the registry so we can not have to redo.
                uint maxDelay = 610;
                if (maskedTextBoxCapMaxDelay.Text != "")
                    maxDelay = uint.Parse(maskedTextBoxCapMaxDelay.Text);

                uint minDelay = 600;
                if (maskedTextBoxCapMinDelay.Text != "")
                    minDelay = uint.Parse(maskedTextBoxCapMinDelay.Text);

                uint minEfgh = (year - 2000) + minDelay;
                uint maxEfgh = (year - 2000) + maxDelay;

                if (fastSearch)
                {
                    Assembly thisExe = Assembly.GetExecutingAssembly();

                    Stream file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame21-Entralink.txt");
                    list[0] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                    file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame22-Entralink.txt");
                    list[1] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                    file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame23-Entralink.txt");
                    list[2] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                    file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame24-Entralink.txt");
                    list[3] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                    file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame25-Entralink.txt");
                    list[4] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);
                    file = thisExe.GetManifestResourceStream("RNGReporter.Resources.MTRNG-Frame26-Entralink.txt");
                    list[5] = (Dictionary<uint, uint>) new BinaryFormatter().Deserialize(file);

                    foreach (var partialList in list)
                    {
                        if (partialList == null)
                            MessageBox.Show("error in loading hashtables");
                    }
                }

                generateTimesToolStripMenuItem.Visible = true;
                generateEntralinkNatureSeedsToolStripMenuItem.Visible = true;
                generateAdjacentSeedsToolStripMenuItem.Visible = false;

                jobs = new Thread[1];

                //todo: split this into multiple threads
                //jobs[0] = new Thread(() => GenerateCGearCapJob(profile, minEfgh, maxEfgh, fastSearch));
                jobs[0] =
                    new Thread(
                        () =>
                        GenerateCGearCapJob(profile.MAC_Address, minEfgh, maxEfgh, fastSearch, profile.ID, profile.SID));
                jobs[0].Start();

                progressTotal = (255*24*(maxEfgh - minEfgh + 1)*generator.MaxResults);
                var progressJob =
                    new Thread(() => ManageProgress(listBindingCap, dataGridViewCapValues, generator.FrameType, 0));
                progressJob.Start();
                progressJob.Priority = ThreadPriority.Lowest;

                buttonCapGenerate.Enabled = false;
            }

            dataGridViewCapValues.Focus();
        }
        private void buttonSeedGenerate_Click(object sender, EventArgs e)
        {
            if (!ParametersInputCheck())
                return;

            #region Initialize

            if (comboBoxNature.Text == "Any")
            {
                MessageBox.Show("Please select a specific list of natures.");
                return;
            }
            List<uint> natures =
                (from t in comboBoxNature.CheckBoxItems where t.Checked select (uint) ((Nature) t.ComboBoxItem).Number).
                    ToList();

            var profile = (Profile) comboBoxProfiles.SelectedItem;
            uint mac_partial = (uint) profile.MAC_Address & 0xFFFFFF;

            uint minFrame = uint.Parse(maskedTextBoxCapMinOffset.Text);
            uint maxFrame = uint.Parse(maskedTextBoxCapMaxOffset.Text);

            uint groupSize = uint.Parse(maskedTextBoxGroupSize.Text);

            uint seedCGear = uint.Parse(textBoxSeed.Text, NumberStyles.HexNumber);

            int generateYear = int.Parse(maskedTextBoxYear.Text);

            if (generateYear < 2000 || generateYear > 2099)
            {
                MessageBox.Show("Year must be a value between 2000 and 2099, inclusive.");
                return;
            }

            uint frameCGear = uint.Parse(maskedTextBoxCGearFrame.Text);
            //generate the CGear Seed Times
            uint ab = seedCGear - mac_partial >> 24;
            uint cd = (seedCGear - mac_partial & 0x00FF0000) >> 16;
            uint efgh = seedCGear - mac_partial & 0x0000FFFF;

            //  Get Delay
            uint delay = efgh + (uint) (2000 - generateYear);

            //  Get Calibration
            uint calibration = uint.Parse(maskedTextBoxDelayCalibration.Text);

            //  Store the Calibrated Delay and offset
            uint calibratedDelay = delay + calibration;

            long offset = -calibratedDelay/60;

            //  Get Hour
            var hour = (int) cd;

            //  We need to check here, as a user could have entered a seed
            //  that is not possible (invalid hour) to lets warn and exit
            //  on it.
            if (hour > 23)
            {
                MessageBox.Show("This seed is invalid, please verify that you have entered it correctly and try again.",
                                "Invalid Seed", MessageBoxButtons.OK);

                return;
            }

            maskedTextBoxDelay.Text = delay.ToString(CultureInfo.InvariantCulture);

            List<List<ButtonComboType>> keypresses = GetKeypresses();

            iframes = new List<IFrameCapture>();
            var generator = new FrameGenerator
                {
                    InitialSeed = seedCGear,
                    FrameType = FrameType.Method5CGear,
                    InitialFrame = frameCGear,
                    MaxResults = 1
                };

            GenderFilter genderFilter = checkBoxGenderless.Checked
                                            ? new GenderFilter("Genderless", 0xFF, GenderCriteria.DontCareGenderless)
                                            : new GenderFilter("Gendered", 0, GenderCriteria.DontCareGenderless);

            var possibleDates = new List<DateTime>();
            //  Loop through all months
            for (int month = 1; month <= 12; month++)
            {
                int daysInMonth = DateTime.DaysInMonth(generateYear, month);

                //  Loop through all days
                for (int day = 1; day <= daysInMonth; day++)
                {
                    //  Loop through all minutes
                    for (int minute = 0; minute <= 59; minute++)
                    {
                        //  Loop through all seconds
                        for (int second = 0; second <= 59; second++)
                        {
                            if (ab != ((month*day + minute + second)%0x100)) continue;
                            var dateTime = new DateTime(generateYear, month, day, hour, minute, second);

                            // Standard seed time will be the C-Gear seed time, minus the delay
                            // We'll skip seeds that cross over into the next day and cause unwanted advances
                            // Added calibration to the delay to account for the fact that people aren't perfectly fast
                            DateTime possibleDate = dateTime.AddSeconds(offset);
                            if (dateTime.Day == possibleDate.Day)
                                possibleDates.Add(possibleDate);
                        }
                    }
                }
            }

            // Generate the IVs for the corresponding C-Gear seed first

            var rngIVs = new uint[6];

            frameCompare = new FrameCompare(
                0, CompareType.None,
                0, CompareType.None,
                0, CompareType.None,
                0, CompareType.None,
                0, CompareType.None,
                0, CompareType.None,
                null,
                -1,
                false,
                false,
                false,
                null,
                new NoGenderFilter());

            List<Frame> IVs = generator.Generate(frameCompare, 0, 0);
            if (IVs.Count > 0)
            {
                rngIVs[0] = IVs[0].Hp;
                rngIVs[1] = IVs[0].Atk;
                rngIVs[2] = IVs[0].Def;
                rngIVs[3] = IVs[0].Spa;
                rngIVs[4] = IVs[0].Spd;
                rngIVs[5] = IVs[0].Spe;
            }

            // Now that each combo box item is a custom object containing the FrameType reference
            // We can simply retrieve the FrameType from the selected item
            generator.FrameType = FrameType.Method5Natures;
            generator.EncounterType = EncounterType.Entralink;
            generator.RNGIVs = rngIVs;

            generator.InitialFrame = minFrame;
            generator.MaxResults = maxFrame - minFrame + 1;

            frameCompare = new FrameCompare(
                0, CompareType.None,
                0, CompareType.None,
                0, CompareType.None,
                0, CompareType.None,
                0, CompareType.None,
                0, CompareType.None,
                null,
                -1,
                false,
                false,
                false,
                null,
                new NoGenderFilter());

            frameCompare = new FrameCompare(
                0, CompareType.None,
                0, CompareType.None,
                0, CompareType.None,
                0, CompareType.None,
                0, CompareType.None,
                0, CompareType.None,
                natures,
                -1,
                false,
                false,
                false,
                null,
                genderFilter);

            #endregion

            waitHandle = new EventWaitHandle(true, EventResetMode.ManualReset);

            jobs = new Thread[cpus];
            //divide the possible times into even groups
            int split = possibleDates.Count/cpus;
            for (int i = 0; i < cpus; ++i)
            {
                List<DateTime> dates = i < cpus - 1
                                           ? possibleDates.GetRange(i*split, split)
                                           : possibleDates.GetRange(i*split, split + possibleDates.Count%cpus);
                //if the last i make sure we add the remainder as well
                // technically supposed to copy profile and send in a copy because now the threads are
                // using a reference to the same profile but that's fine because the profile isn't getting
                // mutated anyway
                jobs[i] =
                    new Thread(
                        () =>
                        Generate(generator.Clone(), dates, minFrame, maxFrame,
                                 profile, groupSize, calibratedDelay));
                jobs[i].Start();
            }

            listBindingCap = new BindingSource {DataSource = iframes};
            dataGridViewCapValues.DataSource = listBindingCap;

            progressTotal =
                (ulong)
                (maxFrame - minFrame + 1)*(profile.Timer0Max - profile.Timer0Min + 1)*(ulong) keypresses.Count*
                (ulong) possibleDates.Count;
            var progressJob =
                new Thread(() => ManageProgress(listBindingCap, dataGridViewCapValues, generator.FrameType, 0));
            progressJob.Start();
            progressJob.Priority = ThreadPriority.Lowest;

            buttonSeedGenerate.Enabled = false;
        }