Ejemplo n.º 1
0
        private uint GeneratePID(BWRng rng)
        {
            uint pid = rng.GetNext32BitNumber();

            if (Genderless)
            {
                return(pid);
            }
            // clear out the lower byte
            pid &= 0xFFFFFF00;
            switch (GenderThreashold)
            {
            // all male
            case 0:
                pid += rng.GetNext32BitNumber(0xF6) + 8;
                break;

            // all female
            case 254:
                pid += rng.GetNext32BitNumber(0x8) + 1;
                break;

            default:
                if (Male)
                {
                    pid += rng.GetNext32BitNumber(0xFE - GenderThreashold) + GenderThreashold;
                }
                else
                {
                    pid += rng.GetNext32BitNumber(GenderThreashold - 1) + 1;
                }
                break;
            }
            return(pid);
        }
Ejemplo n.º 2
0
 private void Advance(BWRng pidrng, MersenneTwister ivrng, List <DreamRadarFrame.Spin> spins)
 {
     // first PIDRNG advance = spin
     spins.Add((DreamRadarFrame.Spin)pidrng.GetNext32BitNumber(8));
     pidrng.GetNext64BitNumber();
     ivrng.Next();
     ivrng.Next();
 }
Ejemplo n.º 3
0
        public List <DreamRadarFrame> Generate(ulong seed, Profile profile)
        {
            var frames = new List <DreamRadarFrame>();
            // Build the PIDRNG
            uint initialFrame = Functions.initialPIDRNG(seed, profile);
            var  pidrng       = new BWRng(seed);

            pidrng.Advance(initialFrame);

            // Build the MTRNG
            // todo: use fast MTRNG when available
            var ivrng = new MersenneTwister((uint)(seed >> 32));

            // advance 8 frames for BW2
            for (uint i = 0; i < 10; ++i)
            {
                ivrng.Next();
            }

            // one single advancement for entering the menu
            pidrng.GetNext64BitNumber();

            var spins = new List <DreamRadarFrame.Spin>();

            // initial advances
            for (uint i = 0; i < initialFrame; ++i)
            {
                Advance(pidrng, ivrng, spins);
            }

            // slot advances
            // we're always doing the slot 1 advance here
            pidrng.GetNext64BitNumber();

            for (uint i = 1; i < TargetSlot; ++i)
            {
                SlotAdvances(pidrng, ivrng);
            }

            for (uint i = initialFrame; i <= MaxFrame; ++i)
            {
                DreamRadarFrame frame = GeneratePokemon(pidrng, ivrng);

                var arrSpins = new DreamRadarFrame.Spin[spins.Count];
                spins.CopyTo(arrSpins);
                frame.Spins = arrSpins;

                // add checks/comparisons on the frame here
                // nature/IVs
                frames.Add(frame);
                Advance(pidrng, ivrng, spins);
            }

            return(frames);
        }
        private uint[] FillRNGArray(uint startingFrame, ulong seed)
        {
            var rng = new BWRng(seed);

            for (uint i = 1; i < startingFrame; ++i)
            {
                rng.GetNext64BitNumber();
            }
            // max of 4 calls per hollow
            var rngArray = new uint[MaxAdvances + OpenHollows * 4];

            for (int i = 0; i < rngArray.Length; ++i)
            {
                rngArray[i] = rng.GetNext32BitNumber();
            }
            return(rngArray);
        }
Ejemplo n.º 5
0
 // todo: remove this
 private static void SlotAdvances(BWRng pidrng, MersenneTwister ivrng)
 {
     pidrng.GetNext64BitNumber();
     pidrng.GetNext64BitNumber();
     pidrng.GetNext64BitNumber();
     pidrng.GetNext64BitNumber();
     pidrng.GetNext64BitNumber();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
 }
Ejemplo n.º 6
0
        private DreamRadarFrame GeneratePokemon(BWRng pidrng2, MersenneTwister ivrng2)
        {
            var pidrng = new BWRng(pidrng2.Seed);
            var ivrng  = new MersenneTwister(ivrng2);
            var frame  = new DreamRadarFrame();

            frame.Pid = GeneratePID(pidrng);
            // two unknown advances
            pidrng.GetNext64BitNumber();
            pidrng.GetNext64BitNumber();
            frame.Nature = pidrng.GetNext32BitNumber(25);
            // IVs
            frame.Hp  = ivrng.Next() >> 27;
            frame.Atk = ivrng.Next() >> 27;
            frame.Def = ivrng.Next() >> 27;
            frame.Spa = ivrng.Next() >> 27;
            frame.Spd = ivrng.Next() >> 27;
            frame.Spe = ivrng.Next() >> 27;

            return(frame);
        }
Ejemplo n.º 7
0
        public static string ChatotResponses64(ulong seed, Profile profile)
        {
            string responses = "";

            var rng = new BWRng(seed);
            uint initialFrame = Functions.initialPIDRNG(seed, profile);

            for (uint cnt = 1; cnt < initialFrame; cnt++)
            {
                rng.Next();
            }

            for (uint cnt = 0; cnt < 20; cnt++)
            {
                responses += ChatotResponse64Short(rng.GetNext32BitNumber());
                // skip last item
                if (cnt != 19)
                {
                    responses += ", ";
                }
            }

            return responses;
        }
Ejemplo n.º 8
0
        public static string ChatotResponses64(ulong seed, Profile profile)
        {
            string responses = "";

            var  rng          = new BWRng(seed);
            uint initialFrame = Functions.initialPIDRNG(seed, profile);

            for (uint cnt = 1; cnt < initialFrame; cnt++)
            {
                rng.Next();
            }

            for (uint cnt = 0; cnt < 20; cnt++)
            {
                responses += ChatotResponse64Short(rng.GetNext32BitNumber());
                // skip last item
                if (cnt != 19)
                {
                    responses += ", ";
                }
            }

            return(responses);
        }
Ejemplo n.º 9
0
        private void buttonGenerate_Click(object sender, EventArgs e)
        {
            //  Initial seed that we are going to used for our frame generation
            ulong seed = 0;

            if (textBoxSeed.Text != "")
            {
                seed = ulong.Parse(textBoxSeed.Text, NumberStyles.HexNumber);
            }

            uint maxFrames = 1000;

            if (maskedTextBoxMaxFrames.Text != "")
            {
                maxFrames = uint.Parse(maskedTextBoxMaxFrames.Text);
            }

            //  Generic RNG Interface
            IRNG   rng   = null;
            IRNG64 rng64 = null;

            //  Instantiate based on the type that
            //  the user has selected ------------
            if (radioButtonCommon.Checked)
            {
                switch (comboBoxRNG.SelectedIndex)
                {
                case 0:
                    rng = new PokeRng((uint)seed);
                    break;

                case 1:
                    rng = new PokeRngR((uint)seed);
                    break;

                case 2:
                    // if the given seed is 64 bit, remove the lower 32 bits.
                    if (seed >= 0x100000000)
                    {
                        seed >>= 32;
                    }
                    rng = new MersenneTwister((uint)seed);
                    break;

                case 3:
                    rng64 = new BWRng(seed);
                    break;

                case 4:
                    rng64 = new BWRngR(seed);
                    break;

                case 5:
                    rng = new XdRng((uint)seed);
                    break;

                case 6:
                    rng = new XdRngR((uint)seed);
                    break;

                case 7:
                    rng = new ARng((uint)seed);
                    break;

                case 8:
                    rng = new ARngR((uint)seed);
                    break;

                case 9:
                    rng = new GRng((uint)seed);
                    break;

                case 10:
                    rng = new GRngR((uint)seed);
                    break;

                case 11:
                    rng = new EncounterRng((uint)seed);
                    break;

                case 12:
                    rng = new EncounterRngR((uint)seed);
                    break;

                case 13:
                    rng = new MersenneTwisterUntempered((int)seed);
                    break;

                case 14:
                    rng = new MersenneTwisterFast((uint)seed, (int)maxFrames);
                    break;

                case 15:
                    rng = new MersenneTwisterTable((uint)seed);
                    break;
                }
            }

            if (radioButtonCustom.Checked)
            {
                //  Check to see if we had valid values in the entry fields, and if so
                //  covert them over to the adding and multiplier so we can instantiate
                //  a generic LCRNG.

                ulong mult = 0;
                ulong add  = 0;

                if (textBoxMult.Text != "")
                {
                    mult = ulong.Parse(textBoxMult.Text, NumberStyles.HexNumber);
                }

                if (textBoxAdd.Text != "")
                {
                    add = ulong.Parse(textBoxAdd.Text, NumberStyles.HexNumber);
                }

                if (checkBox64bit.Checked)
                {
                    rng64 = new GenericRng64(seed, mult, add);
                }
                else
                {
                    rng = new GenericRng((uint)seed, (uint)mult, (uint)add);
                }
            }

            //  This is our collection of operators. At some point, if this gets
            //  fancy, we may want to break it off and have it in it's own class
            var calculators = new Dictionary <string, Calculator>();

            calculators["%"]  = (x, y) => x % y;
            calculators["*"]  = (x, y) => x * y;
            calculators["/"]  = (x, y) => y == 0 ? 0 : x / y;
            calculators["&"]  = (x, y) => x & y;
            calculators["^"]  = (x, y) => x ^ y;
            calculators["|"]  = (x, y) => x | y;
            calculators["+"]  = (x, y) => x + y;
            calculators["-"]  = (x, y) => x - y;
            calculators[">>"] = (x, y) => x >> (int)y;
            calculators["<<"] = (x, y) => x << (int)y;

            bool calcCustom1 =
                textBoxRValue1.Text != "" &&
                (string)comboBoxOperator1.SelectedItem != null &&
                (string)comboBoxLValue1.SelectedItem != null;
            bool calcCustom2 =
                (textBoxRValue2.Text != "" || comboBoxRValue2.SelectedIndex != 0) &&
                (string)comboBoxOperator2.SelectedItem != null &&
                (string)comboBoxLValue2.SelectedItem != null;
            bool calcCustom3 =
                (textBoxRValue3.Text != "" || comboBoxRValue3.SelectedIndex != 0) &&
                (string)comboBoxOperator3.SelectedItem != null &&
                (string)comboBoxLValue3.SelectedItem != null;
            bool calcCustom4 =
                (textBoxRValue4.Text != "" || comboBoxRValue4.SelectedIndex != 0) &&
                (string)comboBoxOperator4.SelectedItem != null &&
                (string)comboBoxLValue4.SelectedItem != null;
            bool calcCustom5 =
                (textBoxRValue5.Text != "" || comboBoxRValue5.SelectedIndex != 0) &&
                (string)comboBoxOperator5.SelectedItem != null &&
                (string)comboBoxLValue5.SelectedItem != null;
            bool calcCustom6 =
                (textBoxRValue6.Text != "" || comboBoxRValue6.SelectedIndex != 0) &&
                (string)comboBoxOperator6.SelectedItem != null &&
                (string)comboBoxLValue6.SelectedItem != null;
            bool calcCustom7 =
                (textBoxRValue7.Text != "" || comboBoxRValue7.SelectedIndex != 0) &&
                (string)comboBoxOperator7.SelectedItem != null &&
                (string)comboBoxLValue7.SelectedItem != null;

            //  Build our custom item transform classes so that we can use them in
            //  the future without having to do a parse of all of the items.

            ulong customRValue1;
            ulong customRValue2;
            ulong customRValue3;
            ulong customRValue4;
            ulong customRValue5;
            ulong customRValue6;
            ulong customRValue7;

            try
            {
                customRValue1 = (textBoxRValue1.Text == ""
                                     ? 0
                                     : (checkBoxCustom1Hex.Checked
                                            ? ulong.Parse(textBoxRValue1.Text, NumberStyles.HexNumber)
                                            : ulong.Parse(textBoxRValue1.Text)));
                customRValue2 = (textBoxRValue2.Text == ""
                                     ? 0
                                     : (checkBoxCustom2Hex.Checked
                                            ? ulong.Parse(textBoxRValue2.Text, NumberStyles.HexNumber)
                                            : ulong.Parse(textBoxRValue2.Text)));
                customRValue3 = (textBoxRValue3.Text == ""
                                     ? 0
                                     : (checkBoxCustom3Hex.Checked
                                            ? ulong.Parse(textBoxRValue3.Text, NumberStyles.HexNumber)
                                            : ulong.Parse(textBoxRValue3.Text)));
                customRValue4 = (textBoxRValue4.Text == ""
                                     ? 0
                                     : (checkBoxCustom4Hex.Checked
                                            ? ulong.Parse(textBoxRValue4.Text, NumberStyles.HexNumber)
                                            : ulong.Parse(textBoxRValue4.Text)));
                customRValue5 = (textBoxRValue5.Text == ""
                                     ? 0
                                     : (checkBoxCustom5Hex.Checked
                                            ? ulong.Parse(textBoxRValue5.Text, NumberStyles.HexNumber)
                                            : ulong.Parse(textBoxRValue5.Text)));
                customRValue6 = (textBoxRValue6.Text == ""
                                     ? 0
                                     : (checkBoxCustom6Hex.Checked
                                            ? ulong.Parse(textBoxRValue6.Text, NumberStyles.HexNumber)
                                            : ulong.Parse(textBoxRValue6.Text)));
                customRValue7 = (textBoxRValue7.Text == ""
                                     ? 0
                                     : (checkBoxCustom7Hex.Checked
                                            ? ulong.Parse(textBoxRValue7.Text, NumberStyles.HexNumber)
                                            : ulong.Parse(textBoxRValue7.Text)));
            }
            catch (Exception ex)
            {
                MessageBox.Show("You must check off the Hex box in order to calculate using hex values.", ex.Message);
                return;
            }

            Calculator custom1Calc = ((string)comboBoxOperator1.SelectedItem == null
                                          ? null
                                          : calculators[(string)comboBoxOperator1.SelectedItem]);
            Calculator custom2Calc = ((string)comboBoxOperator2.SelectedItem == null
                                          ? null
                                          : calculators[(string)comboBoxOperator2.SelectedItem]);
            Calculator custom3Calc = ((string)comboBoxOperator3.SelectedItem == null
                                          ? null
                                          : calculators[(string)comboBoxOperator3.SelectedItem]);
            Calculator custom4Calc = ((string)comboBoxOperator4.SelectedItem == null
                                          ? null
                                          : calculators[(string)comboBoxOperator4.SelectedItem]);
            Calculator custom5Calc = ((string)comboBoxOperator5.SelectedItem == null
                                          ? null
                                          : calculators[(string)comboBoxOperator5.SelectedItem]);
            Calculator custom6Calc = ((string)comboBoxOperator6.SelectedItem == null
                                          ? null
                                          : calculators[(string)comboBoxOperator6.SelectedItem]);
            Calculator custom7Calc = ((string)comboBoxOperator7.SelectedItem == null
                                          ? null
                                          : calculators[(string)comboBoxOperator7.SelectedItem]);

            //  Decide on whether we are going to display each of these items as
            //  decimal or hex. Can be very useful either way, so it is an option.
            Custom1.DefaultCellStyle.Format = checkBoxCustom1Hex.Checked ? "X8" : "";

            Custom2.DefaultCellStyle.Format = checkBoxCustom2Hex.Checked ? "X8" : "";

            Custom3.DefaultCellStyle.Format = checkBoxCustom3Hex.Checked ? "X8" : "";

            Custom4.DefaultCellStyle.Format = checkBoxCustom4Hex.Checked ? "X8" : "";
            Custom5.DefaultCellStyle.Format = checkBoxCustom5Hex.Checked ? "X8" : "";
            Custom6.DefaultCellStyle.Format = checkBoxCustom6Hex.Checked ? "X8" : "";
            Custom7.DefaultCellStyle.Format = checkBoxCustom7Hex.Checked ? "X8" : "";

            var frames = new List <FrameResearch>();

            bool rngIs64Bit = (comboBoxRNG.SelectedIndex == 3 || comboBoxRNG.SelectedIndex == 4 ||
                               checkBox64bit.Checked && radioButtonCustom.Checked);

            //  Loop through X times and create our research frames.
            for (uint cnt = 0; cnt < maxFrames; cnt++)
            {
                FrameResearch frame;
                if (!rngIs64Bit)
                {
                    Column64Bit.Visible     = false;
                    Column32Bit.Visible     = true;
                    Column32BitHigh.Visible = false;
                    Column32BitLow.Visible  = false;

                    uint rngResult = rng.Next();

                    //  Start building the research frame that we are going to use
                    frame = new FrameResearch {
                        RNG64bit = rngIs64Bit, FrameNumber = cnt + 1, Full32 = rngResult
                    };
                }
                else
                {
                    Column64Bit.Visible     = true;
                    Column32Bit.Visible     = false;
                    Column32BitHigh.Visible = true;
                    Column32BitLow.Visible  = true;

                    ulong rngResult = rng64.Next();

                    //  Start building the research frame that we are going to use
                    frame = new FrameResearch {
                        RNG64bit = rngIs64Bit, FrameNumber = cnt + 1, Full64 = rngResult
                    };
                }

                //  Call Custom 1 ////////////////////////////////////////////////////////////////
                if (calcCustom1)
                {
                    ulong customLValue1 = CustomCalcs(comboBoxLValue1, frame, frames);

                    if (!rngIs64Bit)
                    {
                        customLValue1 = (uint)customLValue1;
                    }

                    frame.Custom1 = custom1Calc(customLValue1, customRValue1);
                }
                //////////////////////////////////////////////////////////////////////////////////

                //  Call Custom 2 ////////////////////////////////////////////////////////////////
                if (calcCustom2)
                {
                    ulong customLValue2 = CustomCalcs(comboBoxLValue2, frame, frames);
                    if ((string)comboBoxRValue2.SelectedItem != "None")
                    {
                        customRValue2 = CustomCalcs(comboBoxRValue2, frame, frames);
                    }

                    if (!rngIs64Bit)
                    {
                        customLValue2 = (uint)customLValue2;
                    }

                    frame.Custom2 = custom2Calc(customLValue2, customRValue2);
                }
                //////////////////////////////////////////////////////////////////////////////////

                //  Call Custom 3 ////////////////////////////////////////////////////////////////
                if (calcCustom3)
                {
                    ulong customLValue3 = CustomCalcs(comboBoxLValue3, frame, frames);
                    if ((string)comboBoxRValue3.SelectedItem != "None")
                    {
                        customRValue3 = CustomCalcs(comboBoxRValue3, frame, frames);
                    }

                    if (!rngIs64Bit)
                    {
                        customLValue3 = (uint)customLValue3;
                    }

                    frame.Custom3 = custom3Calc(customLValue3, customRValue3);
                }
                //////////////////////////////////////////////////////////////////////////////////

                //  Call Custom 4 ////////////////////////////////////////////////////////////////
                if (calcCustom4)
                {
                    ulong customLValue4 = CustomCalcs(comboBoxLValue4, frame, frames);
                    if ((string)comboBoxRValue4.SelectedItem != "None")
                    {
                        customRValue4 = CustomCalcs(comboBoxRValue4, frame, frames);
                    }

                    if (!rngIs64Bit)
                    {
                        customLValue4 = (uint)customLValue4;
                    }

                    frame.Custom4 = custom4Calc(customLValue4, customRValue4);
                }
                //////////////////////////////////////////////////////////////////////////////////

                //  Call Custom 5 ////////////////////////////////////////////////////////////////
                if (calcCustom5)
                {
                    ulong customLValue5 = CustomCalcs(comboBoxLValue5, frame, frames);
                    if ((string)comboBoxRValue5.SelectedItem != "None")
                    {
                        customRValue5 = CustomCalcs(comboBoxRValue5, frame, frames);
                    }

                    if (!rngIs64Bit)
                    {
                        customLValue5 = (uint)customLValue5;
                    }

                    frame.Custom5 = custom5Calc(customLValue5, customRValue5);
                }
                //////////////////////////////////////////////////////////////////////////////////

                //  Call Custom 6 ////////////////////////////////////////////////////////////////
                if (calcCustom6)
                {
                    ulong customLValue6 = CustomCalcs(comboBoxLValue6, frame, frames);
                    if ((string)comboBoxRValue6.SelectedItem != "None")
                    {
                        customRValue6 = CustomCalcs(comboBoxRValue6, frame, frames);
                    }

                    if (!rngIs64Bit)
                    {
                        customLValue6 = (uint)customLValue6;
                    }

                    frame.Custom6 = custom6Calc(customLValue6, customRValue6);
                }
                //////////////////////////////////////////////////////////////////////////////////

                //  Call Custom 7 ////////////////////////////////////////////////////////////////
                if (calcCustom7)
                {
                    ulong customLValue7 = CustomCalcs(comboBoxLValue7, frame, frames);
                    if ((string)comboBoxRValue7.SelectedItem != "None")
                    {
                        customRValue7 = CustomCalcs(comboBoxRValue7, frame, frames);
                    }

                    if (!rngIs64Bit)
                    {
                        customLValue7 = (uint)customLValue7;
                    }

                    frame.Custom7 = custom7Calc(customLValue7, customRValue7);
                }
                //////////////////////////////////////////////////////////////////////////////////

                frames.Add(frame);
            }

            //  Bind to the grid
            dataGridViewValues.DataSource = frames;
            dataGridViewValues.Focus();
        }
        private void Search(DateTime date, uint vcountMin, uint vcountMax,
                            uint timer0Min, uint timer0Max, uint vframeMin, uint vframeMax, uint gxstatMin,
                            uint gxstatMax, bool minmaxgxstat, int secondsMin, int secondsMax, bool softreset,
                            Version version, Language language,
                            DSType dstype, bool memorylink, ulong macaddress, uint buttons, uint[] pattern)
        {
            var array = new uint[80];

            array[6] = (uint)(macaddress & 0xFFFF);
            if (softreset)
            {
                array[6] = array[6] ^ 0x01000000;
            }
            Array.Copy(Nazos.Nazo(version, language, dstype), array, 5);

            array[10] = 0x00000000;
            array[11] = 0x00000000;
            array[13] = 0x80000000;
            array[14] = 0x00000000;
            array[15] = 0x000001A0;

            array[12] = buttons;

            string yearMonth  = String.Format("{0:00}", date.Year % 2000) + String.Format("{0:00}", date.Month);
            string dateString = String.Format("{0:00}", (int)date.DayOfWeek);

            dateString = String.Format("{0:00}", date.Day) + dateString;
            dateString = yearMonth + dateString;
            array[8]   = uint.Parse(dateString, NumberStyles.HexNumber);
            array[9]   = 0x0;
            //uint[] alpha = Functions.alphaSHA1(array, 8);

            var upperMAC = (uint)(macaddress >> 16);

            for (uint vcount = vcountMin; vcount <= vcountMax; ++vcount)
            {
                for (uint timer0 = timer0Min; timer0 <= timer0Max; ++timer0)
                {
                    array[5] = (vcount << 16) + timer0;
                    array[5] = Functions.Reorder(array[5]);

                    for (uint vframe = vframeMin; vframe <= vframeMax; ++vframe)
                    {
                        for (uint gxstat = gxstatMin; gxstat <= gxstatMax; ++gxstat)
                        {
                            array[7] = (upperMAC ^ (vframe * 0x1000000) ^ gxstat);
                            uint[] alpha = Functions.alphaSHA1(array);

                            array[16] = Functions.RotateLeft(array[13] ^ array[8] ^ array[2] ^ array[0], 1);
                            array[18] = Functions.RotateLeft(array[15] ^ array[10] ^ array[4] ^ array[2], 1);
                            array[19] = Functions.RotateLeft(array[16] ^ array[11] ^ array[5] ^ array[3], 1);
                            array[21] = Functions.RotateLeft(array[18] ^ array[13] ^ array[7] ^ array[5], 1);
                            array[22] = Functions.RotateLeft(array[19] ^ array[14] ^ array[8] ^ array[6], 1);
                            array[24] = Functions.RotateLeft(array[21] ^ array[16] ^ array[10] ^ array[8], 1);
                            array[27] = Functions.RotateLeft(array[24] ^ array[19] ^ array[13] ^ array[11], 1);

                            for (int second = secondsMin; second <= secondsMax; ++second)
                            {
                                array[9] = Functions.seedSecond(second) | Functions.seedMinute(date.Minute) |
                                           Functions.seedHour(date.Hour, dstype);
                                ulong seed = Functions.EncryptSeed(array, alpha, 9);
                                // it appears to have the same initial seed as in the main game
                                // pressing Unova link does the same probability table calls
                                uint initial = Functions.initialPIDRNG(seed, version, memorylink);
                                var  rng     = new BWRng(seed);
                                for (uint i = 0; i < initial; ++i)
                                {
                                    rng.GetNext64BitNumber();
                                }
                                bool found = true;
                                for (uint i = 0; i < pattern.Length; ++i)
                                {
                                    if (pattern[i] != rng.GetNext32BitNumber(8))
                                    {
                                        found = false;
                                        break;
                                    }
                                    // there's another RNG call here unreleated to the spinner
                                    rng.GetNext64BitNumber();
                                }
                                progressSearched++;
                                if (found)
                                {
                                    var parameter = new DSParameterCapture
                                    {
                                        ActualSeconds = second,
                                        GxStat        = gxstat,
                                        Seed          = seed,
                                        Timer0        = timer0,
                                        VCount        = vcount,
                                        VFrame        = vframe
                                    };
                                    dsParameters.Add(parameter);
                                    refreshQueue = true;
                                    progressFound++;
                                }
                            }


                            if (minmaxgxstat && gxstatMax > gxstatMin)
                            {
                                gxstat = gxstatMax - 1;
                            }
                        }
                    }
                }
            }
        }
 private uint[] FillRNGArray(uint startingFrame, ulong seed)
 {
     var rng = new BWRng(seed);
     for (uint i = 1; i < startingFrame; ++i)
     {
         rng.GetNext64BitNumber();
     }
     // max of 4 calls per hollow
     var rngArray = new uint[MaxAdvances + OpenHollows*4];
     for (int i = 0; i < rngArray.Length; ++i)
     {
         rngArray[i] = rng.GetNext32BitNumber();
     }
     return rngArray;
 }
Ejemplo n.º 12
0
        private DreamRadarFrame GeneratePokemon(BWRng pidrng2, MersenneTwister ivrng2)
        {
            var pidrng = new BWRng(pidrng2.Seed);
            var ivrng = new MersenneTwister(ivrng2);
            var frame = new DreamRadarFrame();

            frame.Pid = GeneratePID(pidrng);
            // two unknown advances
            pidrng.GetNext64BitNumber();
            pidrng.GetNext64BitNumber();
            frame.Nature = pidrng.GetNext32BitNumber(25);
            // IVs
            frame.Hp = ivrng.Next() >> 27;
            frame.Atk = ivrng.Next() >> 27;
            frame.Def = ivrng.Next() >> 27;
            frame.Spa = ivrng.Next() >> 27;
            frame.Spd = ivrng.Next() >> 27;
            frame.Spe = ivrng.Next() >> 27;

            return frame;
        }
Ejemplo n.º 13
0
 private uint GeneratePID(BWRng rng)
 {
     uint pid = rng.GetNext32BitNumber();
     if (Genderless) return pid;
     // clear out the lower byte
     pid &= 0xFFFFFF00;
     switch (GenderThreashold)
     {
             // all male
         case 0:
             pid += rng.GetNext32BitNumber(0xF6) + 8;
             break;
             // all female
         case 254:
             pid += rng.GetNext32BitNumber(0x8) + 1;
             break;
         default:
             if (Male)
                 pid += rng.GetNext32BitNumber(0xFE - GenderThreashold) + GenderThreashold;
             else
                 pid += rng.GetNext32BitNumber(GenderThreashold - 1) + 1;
             break;
     }
     return pid;
 }
Ejemplo n.º 14
0
 private void Advance(BWRng pidrng, MersenneTwister ivrng, List<DreamRadarFrame.Spin> spins)
 {
     // first PIDRNG advance = spin
     spins.Add((DreamRadarFrame.Spin) pidrng.GetNext32BitNumber(8));
     pidrng.GetNext64BitNumber();
     ivrng.Next();
     ivrng.Next();
 }
Ejemplo n.º 15
0
 // todo: remove this
 private static void SlotAdvances(BWRng pidrng, MersenneTwister ivrng)
 {
     pidrng.GetNext64BitNumber();
     pidrng.GetNext64BitNumber();
     pidrng.GetNext64BitNumber();
     pidrng.GetNext64BitNumber();
     pidrng.GetNext64BitNumber();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
     ivrng.Next();
 }
Ejemplo n.º 16
0
        public List<DreamRadarFrame> Generate(ulong seed, Profile profile)
        {
            var frames = new List<DreamRadarFrame>();
            // Build the PIDRNG
            uint initialFrame = Functions.initialPIDRNG(seed, profile);
            var pidrng = new BWRng(seed);
            pidrng.Advance(initialFrame);

            // Build the MTRNG
            // todo: use fast MTRNG when available
            var ivrng = new MersenneTwister((uint) (seed >> 32));
            // advance 8 frames for BW2
            for (uint i = 0; i < 10; ++i) ivrng.Next();

            // one single advancement for entering the menu
            pidrng.GetNext64BitNumber();

            var spins = new List<DreamRadarFrame.Spin>();
            // initial advances
            for (uint i = 0; i < initialFrame; ++i) Advance(pidrng, ivrng, spins);

            // slot advances
            // we're always doing the slot 1 advance here
            pidrng.GetNext64BitNumber();

            for (uint i = 1; i < TargetSlot; ++i) SlotAdvances(pidrng, ivrng);

            for (uint i = initialFrame; i <= MaxFrame; ++i)
            {
                DreamRadarFrame frame = GeneratePokemon(pidrng, ivrng);

                var arrSpins = new DreamRadarFrame.Spin[spins.Count];
                spins.CopyTo(arrSpins);
                frame.Spins = arrSpins;

                // add checks/comparisons on the frame here
                // nature/IVs
                frames.Add(frame);
                Advance(pidrng, ivrng, spins);
            }

            return frames;
        }