コード例 #1
0
        public static string[] GetIVPID(uint nature, int hiddenpower, bool XD = false, IVPIDMethod method = IVPIDMethod.None)
        {
            if (method == IVPIDMethod.BACD_R)
            {
                return(GenerateWishmkr(nature));
            }
            var generator = new FrameGenerator();

            if (XD || method == IVPIDMethod.XD)
            {
                generator = new FrameGenerator {
                    FrameType = FrameType.ColoXD
                }
            }
            ;
            if (method == IVPIDMethod.M2)
            {
                generator = new FrameGenerator {
                    FrameType = FrameType.Method2
                }
            }
            ;
            var frameCompare = new FrameCompare(Hptofilter(hiddenpower), nature);
            var frames       = generator.Generate(frameCompare, 0, 0);

            return(new[] { frames[0].Pid.ToString("X"), frames[0].Hp.ToString(), frames[0].Atk.ToString(), frames[0].Def.ToString(), frames[0].Spa.ToString(), frames[0].Spd.ToString(), frames[0].Spe.ToString() });
        }
    }
コード例 #2
0
        private void Generate(FrameGenerator generator, IEnumerable <DateTime> possibleDates, uint minFrame,
                              uint maxFrame, Profile profile, uint groupSize, uint calibratedDelay)
        {
            const uint incrementFound = 1;
            List <List <ButtonComboType> > keypresses = profile.GetKeypresses();

            foreach (DateTime seedTime in possibleDates)
            {
                waitHandle.WaitOne();
                foreach (var combo in keypresses)
                {
                    for (uint timer0 = profile.Timer0Min; timer0 <= profile.Timer0Max; timer0++)
                    {
                        ulong seed = Functions.EncryptSeed(seedTime, profile, timer0, Functions.buttonMashed(combo));

                        generator.InitialSeed  = seed;
                        generator.InitialFrame = Functions.initialPIDRNG(seed, profile) + minFrame;
                        generator.MaxResults   = maxFrame - minFrame + 1;

                        List <Frame> frames = generator.Generate(frameCompare, 0, 0);

                        IFrameCapture previous        = null;
                        bool          previouslyAdded = false;

                        var frameGroup = new List <IFrameCapture>();
                        // quick check and if it's impossible that this is a match don't waste our time loop
                        // breaks search progress so that needs to get fixed
                        if (frames.Count < groupSize)
                        {
                            continue;
                        }
                        foreach (Frame frame in frames)
                        {
                            var iframe = new IFrameCapture
                            {
                                Offset     = frame.Number,
                                Seed       = seed,
                                Frame      = frame,
                                TimeDate   = seedTime,
                                Timer0     = timer0,
                                Delay      = calibratedDelay,
                                KeyPresses = combo
                            };

                            //  Calibrated delay instead of the real delay for correct CGear Times

                            if (previous != null &&
                                (iframe.Offset == previous.Offset + 1 || iframe.Offset == previous.Offset + 2))
                            {
                                if (!previouslyAdded)
                                {
                                    frameGroup.Add(previous);
                                }

                                frameGroup.Add(iframe);
                                previouslyAdded = true;
                            }
                            else
                            {
                                if (frameGroup.Count >= groupSize)
                                {
                                    lock (threadLock)
                                    {
                                        foreach (IFrameCapture t in frameGroup)
                                        {
                                            t.Frame.Synchable = grey;
                                        }
                                        iframes.AddRange(frameGroup);
                                        grey = !grey;
                                    }
                                    refreshQueue   = true;
                                    progressFound += incrementFound;
                                }

                                frameGroup      = new List <IFrameCapture>();
                                previouslyAdded = false;
                            }
                            previous = iframe;
                        }
                        progressSearched += (uint)frames.Count;

                        if (frameGroup.Count >= groupSize)
                        {
                            lock (threadLock)
                            {
                                for (int i = 0; i < frameGroup.Count; ++i)
                                {
                                    frameGroup[i].Frame.Synchable = grey;
                                }
                                iframes.AddRange(frameGroup);
                                grey = !grey;
                            }
                            refreshQueue   = true;
                            progressFound += incrementFound;
                        }
                    }
                }
            }
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        private void Generate()
        {
            var  profile  = (Profile)comboBoxProfiles.SelectedItem;
            uint minFrame = uint.Parse(maskedTextBoxCapMinOffset.Text);
            uint maxFrame = uint.Parse(maskedTextBoxCapMaxOffset.Text);

            DateTime seedTime = datePicker.Value;

            iframes = new List <IFrameCapture>();

            generator = new FrameGenerator
            {
                FrameType     = (FrameType)((ComboBoxItem)comboBoxMethod.SelectedItem).Reference,
                EncounterType =
                    (EncounterType)((ComboBoxItem)comboBoxEncounterType.SelectedItem).Reference,
                EncounterMod = (EncounterMod)((ComboBoxItem)comboBoxLead.SelectedItem).Reference,
                SynchNature  = -2,
                InitialFrame = minFrame + (profile.IsBW2() ? 2u : 0),
                MaxResults   = maxFrame - minFrame + 1
            };

            // Now that each combo box item is a custom object containing the FrameType reference
            // We can simply retrieve the FrameType from the selected item


            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());

            switch (generator.FrameType)
            {
            case FrameType.Method5Standard:
                CapSeed.DefaultCellStyle.Format = "X16";
                EncounterSlot.Visible           = false;
                PID.Visible     = false;
                Shiny.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;
                f25.Visible     = false;
                f50.Visible     = false;
                f75.Visible     = false;
                f125.Visible    = false;
                break;

            case FrameType.Method5Natures:

                CapSeed.DefaultCellStyle.Format = "X16";
                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;
                Nature.Visible  = true;
                Ability.Visible = true;
                CapHP.Visible   = false;
                CapAtk.Visible  = false;
                CapDef.Visible  = false;
                CapSpA.Visible  = false;
                CapSpD.Visible  = false;
                CapSpe.Visible  = false;
                f25.Visible     = true;
                f50.Visible     = true;
                f75.Visible     = true;
                f125.Visible    = true;
                break;

            case FrameType.BWBred:
                generator.FrameType    = FrameType.Method5Standard;
                generator.InitialFrame = 14;
                generator.MaxResults   = 7;

                CapSeed.DefaultCellStyle.Format = "X16";
                EncounterSlot.Visible           = false;
                PID.Visible     = false;
                Shiny.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;
                f25.Visible     = false;
                f50.Visible     = false;
                f75.Visible     = false;
                f125.Visible    = false;
                break;

            case FrameType.Wondercard5thGen:
            case FrameType.Wondercard5thGenFixed:
                CapSeed.DefaultCellStyle.Format = "X16";
                EncounterSlot.Visible           = false;
                PID.Visible     = false;
                Shiny.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;
                f25.Visible     = false;
                f50.Visible     = false;
                f75.Visible     = false;
                f125.Visible    = false;
                break;
            }

            for (int seconds = (int)numericUpDownSeconds.Value * -1; seconds <= numericUpDownSeconds.Value; seconds++)
            {
                for (uint timer0 = profile.Timer0Min - 1; timer0 <= profile.Timer0Max + 1; timer0++)
                {
                    ulong seed = Functions.EncryptSeed(seedTime.AddSeconds(seconds), profile.MAC_Address,
                                                       profile.Version, profile.Language,
                                                       profile.DSType, profile.SoftReset, profile.VCount, timer0,
                                                       profile.GxStat,
                                                       profile.VFrame, buttonValue());

                    if (seconds == 0 && timer0 == profile.Timer0Min)
                    {
                        seedMatch = seed;
                    }

                    switch (generator.FrameType)
                    {
                    case FrameType.Method5Standard:
                        generator.InitialSeed = seed >> 32;
                        break;

                    case FrameType.Method5Natures:
                    case FrameType.Wondercard5thGen:
                    case FrameType.Wondercard5thGenFixed:
                        generator.InitialSeed  = seed;
                        generator.InitialFrame = Functions.initialPIDRNG(seed, profile) + minFrame;
                        break;
                    }

                    List <Frame> frames = generator.Generate(frameCompare, profile.ID, profile.SID);

                    foreach (Frame frame in frames)
                    {
                        var iframe = new IFrameCapture();

                        frame.DisplayPrep();
                        iframe.Offset = frame.Number;
                        iframe.Seed   = seed;
                        iframe.Frame  = frame;

                        iframe.TimeDate = seedTime.AddSeconds(seconds);
                        iframe.Timer0   = timer0;

                        iframes.Add(iframe);
                    }
                }
            }

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


            foreach (DataGridViewRow row in dataGridViewCapValues.Rows)
            {
                if ((ulong)row.Cells[0].Value == seedMatch)
                {
                    dataGridViewCapValues.CurrentCell = row.Cells[0];
                    dataGridViewCapValues.FirstDisplayedScrollingRowIndex = row.Index;
                    break;
                }
            }

            dataGridViewCapValues.Focus();
        }