コード例 #1
0
ファイル: Functions.cs プロジェクト: Slashmolder/RNGReporter
        public static uint initialPIDRNGBW2(ulong seed, Profile profile)
        {
            var rng = new BWRng(seed);
            uint frameCount = 1;

            for (int i = 0; i < 5; i++)
            {
                for (int k = 0; k < 6; k++)
                {
                    for (int j = 0; j < 5; j++)
                    {
                        if (probabilityTable[k, j] == 100)
                            break;

                        frameCount++;
                        uint rn = rng.GetNext32BitNumber(101);

                        if (rn <= probabilityTable[k, j])
                            break;
                    }
                }
                if (i == 0)
                {
                    //BW2 has 3 advances after the first table call and before the rest
                    //it is only 2 advances after memorylink
                    int advances = profile.MemoryLink ? 2 : 3;
                    for (int j = 0; j < advances; ++j)
                    {
                        frameCount++;
                        rng.GetNext64BitNumber();
                    }
                }
            }

            frameCount = initialPIDRNGBW2_extra(rng, frameCount);
            return frameCount;
        }
コード例 #2
0
ファイル: Functions.cs プロジェクト: Slashmolder/RNGReporter
        public static uint initialPIDRNGBW2_ID(ulong seed, bool saveFile)
        {
            // we are ignoring the saveFile command because it hasn't been properly researched without a save file
            var rng = new BWRng(seed);
            uint frameCount = 1;

            //int rounds = saveFile ? 4 : 3;
            const int rounds = 3;

            for (int i = 0; i < rounds; i++)
            {
                for (int k = 0; k < 6; k++)
                {
                    for (int j = 0; j < 5; j++)
                    {
                        if (probabilityTable[k, j] == 100)
                            break;

                        frameCount++;
                        uint rn = rng.GetNext32BitNumber(101);

                        if (rn <= probabilityTable[k, j])
                            break;
                    }
                }
                if (i == 0)
                {
                    //two advances after the first table call
                    for (int j = 0; j < 2; ++j)
                    {
                        frameCount++;
                        rng.GetNext64BitNumber();
                    }
                }
                if (i == 1)
                {
                    //BW2 has 4 advances after the second table call and before the rest
                    for (int j = 0; j < 4; ++j)
                    {
                        frameCount++;
                        rng.GetNext64BitNumber();
                    }
                }
            }
            // three more advances at the end
            return frameCount + 3;
        }
コード例 #3
0
        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, 8);

                            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;
                        }
                    }
                }
            }
        }