Пример #1
0
        public List<Frame> Generate(
            FrameCompare frameCompare,
            uint hp,
            uint atk,
            uint def,
            uint spa,
            uint spd,
            uint spe,
            List<uint> natures,
            uint minEfgh,
            uint maxEfgh,
            uint id,
            uint sid)
        {
            frames = new List<Frame>();
            var candidates = new List<Frame>();

            var rng = new PokeRngR(0);

            uint x_test = spe | (spa << 5) | (spd << 10);
            uint y_test = hp | (atk << 5) | (def << 10);

            #region

            // Experimentally derived
            // Any possible test seed will have at most
            // a difference of 0x31 from the target seed.
            // If it's close enough, we can then modify it
            // to match.

            /*
            for (uint cnt = 0xFFFF; cnt > 0xF2CC; cnt--)
            {
                uint seed = (x_test << 16) | cnt;

                // Do a quick search for matching seeds
                // with a lower 16-bits between 0xFFFF and 0xF2CD.
                // We'll take the closest matches and subtract 0xD33
                // until it produces the correct seed (or doesn't).

                // Best we can do until we find a way to
                // calculate them directly.

                rng.Seed = seed;
                ushort rng1 = rng.GetNext16BitNumber();

                // We don't have to worry about unsigned overflow
                // because y_test is never more than 0x7FFF
                if (y_test < 0x31)
                {
                    if (rng1 <= (y_test - 0x31))
                    {
                        while ((seed & 0xFFFF) > 0xD32 && (rng1 & 0x7FFF) < y_test)
                        {
                            seed = seed - 0xD33;
                            rng.Seed = seed;
                            rng1 = rng.GetNext16BitNumber();
                        }
                    }
                }
                else
                {
                    if (rng1 >= (y_test - 0x31))
                    {
                        while ((seed & 0xFFFF) > 0xD32 && (rng1 & 0x7FFF) < y_test)
                        {
                            seed = seed - 0xD33;
                            rng.Seed = seed;
                            rng1 = rng.GetNext16BitNumber();
                        }
                    }
                }
                */

            #endregion

            for (uint cnt = 0x0; cnt < 0xFFFF; cnt++)
            {
                uint seed = (x_test << 16) | cnt;

                rng.Seed = seed;
                ushort rng1 = rng.GetNext16BitNumber();
                // Check to see if the next frame yields
                // the HP, Attack, and Defense IVs we're searching for
                // If not, skip 'em.
                if ((rng1 & 0x7FFF) != y_test)
                    continue;

                //  We have a max of 5 total RNG calls
                //  to make a pokemon and we already have
                //  one so lets go ahead and get 4 more.
                uint seedWondercard = rng.GetNext32BitNumber();
                var rng2 = (ushort) (seedWondercard >> 16);
                ushort rng3 = rng.GetNext16BitNumber();
                ushort rng4 = rng.GetNext16BitNumber();

                uint method1Seed = rng.Seed;

                // Instead of re-searching the entire space for seeds that are
                // basically identical except for the upper bit, we'll
                // just flip the upper seed bits instead.
                for (int upperBit = 0; upperBit < 2; upperBit++)
                {
                    rng2 = (ushort) (rng2 ^ 0x8000);
                    rng3 = (ushort) (rng3 ^ 0x8000);
                    rng4 = (ushort) (rng4 ^ 0x8000);
                    method1Seed = method1Seed ^ 0x80000000;
                    rng.Seed = rng.Seed ^ 0x80000000;

                    if (frameType == FrameType.WondercardIVs)
                    {
                        seedWondercard = seedWondercard ^ 0x80000000;
                        frame = Frame.GenerateFrame(seedWondercard,
                                                    frameType, EncounterType,
                                                    0,
                                                    seedWondercard,
                                                    0, 0,
                                                    rng1, x_test,
                                                    id, sid,
                                                    0, 0);

                        candidates.Add(frame);
                    }

                    foreach (uint nature in natures)
                    {
                        if (frameType == FrameType.ChainedShiny)
                        {
                            var testRng = new PokeRngR(rng.Seed);
                            var rngCalls = new uint[15];

                            rngCalls[0] = rng2;
                            rngCalls[1] = rng3;
                            rngCalls[2] = rng4;

                            for (int calls = 3; calls < 15; calls++)
                            {
                                rngCalls[calls] = testRng.GetNext16BitNumber();
                            }

                            testRng.GetNext32BitNumber();
                            testRng.GetNext32BitNumber();

                            uint chainedPIDLower = Functions.ChainedPIDLower(
                                rngCalls[14],
                                rngCalls[0],
                                rngCalls[1],
                                rngCalls[2],
                                rngCalls[3],
                                rngCalls[4],
                                rngCalls[5],
                                rngCalls[6],
                                rngCalls[7],
                                rngCalls[8],
                                rngCalls[9],
                                rngCalls[10],
                                rngCalls[11],
                                rngCalls[12]);

                            uint chainedPIDUpper = Functions.ChainedPIDUpper(rngCalls[13], chainedPIDLower, id, sid);

                            if (IVtoSeed.CheckPID(chainedPIDUpper, chainedPIDLower, nature))
                            {
                                frame = Frame.GenerateFrame(testRng.Seed,
                                                            frameType, EncounterType,
                                                            0,
                                                            testRng.Seed,
                                                            chainedPIDLower, chainedPIDUpper,
                                                            rng1, x_test,
                                                            id, sid,
                                                            0, 0);

                                candidates.Add(frame);
                            }
                        }

                        if (frameType == FrameType.Method1)
                        {
                            //  Check Method 1
                            // [PID] [PID] [IVs] [IVs]
                            // [rng3] [rng2] [rng1] [START]

                            if (IVtoSeed.CheckPID(rng2, rng3, nature))
                            {
                                frame = Frame.GenerateFrame(method1Seed,
                                                            frameType, EncounterType,
                                                            0,
                                                            method1Seed,
                                                            rng3, rng2,
                                                            rng1, x_test,
                                                            id, sid,
                                                            0, 0);

                                candidates.Add(frame);
                            }
                        }

                        if (frameType == FrameType.MethodJ)
                        {
                            //  Check Method 1, then roll back to see if it is a hittable frame
                            if (IVtoSeed.CheckPID(rng2, rng3, nature))
                            {
                                var testRng = new PokeRngR(rng.Seed);

                                uint testPid;
                                uint nextRng = rng4;
                                uint nextRng2 = testRng.GetNext32BitNumber();
                                uint slot = 0;

                                // A spread is only made accessible if there are no other PIDs between
                                // it and the calling frame that have the same nature as the spread.

                                do
                                {
                                    bool skipFrame = false;
                                    // Check to see if this is a valid non-Synch calling frame
                                    // If it is, we won't bother checking it with Synch because it works either way

                                    if (nextRng/0xA3E == nature)
                                    {
                                        uint testSeed = testRng.Seed;
                                        var encounterMod = EncounterMod.None;

                                        if (EncounterType != EncounterType.Stationary)
                                        {
                                            testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                            slot = nextRng2;
                                            if (EncounterType == EncounterType.WildSurfing)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                            }
                                            else if (EncounterType == EncounterType.WildOldRod)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                uint nibble = (testSeed >> 16)/656;
                                                if (nibble <= 48)
                                                {
                                                    if (nibble > 24)
                                                    {
                                                        encounterMod = EncounterMod.SuctionCups;
                                                    }
                                                    testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                }
                                                else
                                                    skipFrame = true;
                                            }
                                            else if (EncounterType == EncounterType.WildGoodRod)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                uint nibble = (testSeed >> 16)/656;
                                                if (nibble <= 98)
                                                {
                                                    if (nibble > 49)
                                                    {
                                                        encounterMod = EncounterMod.SuctionCups;
                                                    }
                                                    testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                }
                                                else
                                                    skipFrame = true;
                                            }
                                            else if (EncounterType == EncounterType.WildSuperRod)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                uint nibble = (testSeed >> 16)/656;
                                                if (nibble <= 99)
                                                {
                                                    if (nibble > 74)
                                                    {
                                                        encounterMod = EncounterMod.SuctionCups;
                                                    }
                                                    testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                }
                                                else
                                                    skipFrame = true;
                                            }
                                        }

                                        if (!skipFrame)
                                        {
                                            frame = Frame.GenerateFrame(testSeed,
                                                                        frameType, EncounterType,
                                                                        0,
                                                                        testSeed,
                                                                        rng3, rng2,
                                                                        rng1, x_test,
                                                                        id, sid,
                                                                        0, 0);

                                            frame.EncounterSlot = EncounterSlotCalc.encounterSlot(slot, frameType,
                                                                                                  EncounterType);
                                            frame.EncounterMod = encounterMod;
                                            candidates.Add(frame);
                                        }

                                        // Check if the frame appears as the result of a failed Synch
                                        if (nextRng2 >> 31 == 1)
                                        {
                                            if (EncounterType == EncounterType.WildOldRod)
                                            {
                                                uint nibble = (testSeed >> 16)/656;
                                                if (nibble > 24)
                                                {
                                                    skipFrame = true;
                                                }
                                            }
                                            else if (EncounterType == EncounterType.WildGoodRod)
                                            {
                                                uint nibble = (testSeed >> 16)/656;
                                                if (nibble > 49)
                                                {
                                                    skipFrame = true;
                                                }
                                            }
                                            else if (EncounterType == EncounterType.WildSuperRod)
                                            {
                                                uint nibble = (testSeed >> 16)/656;
                                                if (nibble > 74)
                                                {
                                                    skipFrame = true;
                                                }
                                            }

                                            slot = slot*0xeeb9eb65 + 0xa3561a1;
                                            testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;

                                            if (!skipFrame)
                                            {
                                                frame = Frame.GenerateFrame(testSeed,
                                                                            frameType, EncounterType,
                                                                            0,
                                                                            testSeed,
                                                                            rng3, rng2,
                                                                            rng1, x_test,
                                                                            id, sid,
                                                                            0, 0);

                                                frame.EncounterSlot = EncounterSlotCalc.encounterSlot(slot, frameType,
                                                                                                      EncounterType);

                                                frame.EncounterMod = EncounterMod.Synchronize;
                                                candidates.Add(frame);
                                            }
                                        }
                                    }
                                        // Check to see if the spread is hittable with Synchronize
                                    else if (nextRng >> 15 == 0)
                                    {
                                        uint testSeed = testRng.Seed;

                                        if (EncounterType != EncounterType.Stationary)
                                        {
                                            testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                            slot = nextRng2;
                                            if (EncounterType == EncounterType.WildSurfing)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                            }
                                            else if (EncounterType == EncounterType.WildOldRod)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                uint nibble = (testSeed >> 16)/656;
                                                if (nibble > 24)
                                                {
                                                    skipFrame = true;
                                                }
                                                else
                                                {
                                                    testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                }
                                            }
                                            else if (EncounterType == EncounterType.WildGoodRod)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                uint nibble = (testSeed >> 16)/656;

                                                if (nibble > 49)
                                                {
                                                    skipFrame = true;
                                                }
                                                else
                                                {
                                                    testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                }
                                            }
                                            else if (EncounterType == EncounterType.WildSuperRod)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;

                                                uint nibble = (testSeed >> 16)/656;
                                                if (nibble > 74)
                                                {
                                                    skipFrame = true;
                                                }
                                                else
                                                {
                                                    testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                }
                                            }
                                        }

                                        if (!skipFrame)
                                        {
                                            frame = Frame.GenerateFrame(testSeed,
                                                                        frameType, EncounterType,
                                                                        0,
                                                                        testSeed,
                                                                        rng3, rng2,
                                                                        rng1, x_test,
                                                                        id, sid,
                                                                        0, 0);

                                            frame.Synchable = true;
                                            frame.EncounterMod = EncounterMod.Synchronize;
                                            frame.EncounterSlot = EncounterSlotCalc.encounterSlot(slot, frameType,
                                                                                                  EncounterType);
                                            candidates.Add(frame);
                                        }
                                    }

                                    testPid = (nextRng << 16) | nextRng2 >> 16;

                                    nextRng = testRng.GetNext16BitNumber();
                                    nextRng2 = testRng.GetNext32BitNumber();
                                } while (testPid%25 != nature);
                            }

                            //  Check DPPt Cute Charm (female)
                            //  [CC Check] [PID] [IVs] [IVs]
                            //  [rng3] [rng2] [rng1] [START]

                            if (rng3/0x5556 != 0)
                            {
                                uint CCSeed;
                                uint slot = 0;
                                bool skipFrame = false;

                                if (EncounterType == EncounterType.Stationary)
                                    CCSeed = method1Seed;
                                else
                                {
                                    CCSeed = method1Seed*0xeeb9eb65 + 0xa3561a1;
                                    slot = method1Seed;
                                    if (EncounterType == EncounterType.WildSurfing)
                                    {
                                        CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                        slot = slot*0xeeb9eb65 + 0xa3561a1;
                                    }
                                    else if (EncounterType == EncounterType.WildOldRod)
                                    {
                                        CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                        slot = slot*0xeeb9eb65 + 0xa3561a1;

                                        if ((CCSeed >> 16)/656 > 24)
                                            skipFrame = true;
                                        else
                                            CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                    }
                                    else if (EncounterType == EncounterType.WildGoodRod)
                                    {
                                        CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                        slot = slot*0xeeb9eb65 + 0xa3561a1;

                                        if ((CCSeed >> 16)/656 > 49)
                                            skipFrame = true;
                                        else
                                            CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                    }
                                    else if (EncounterType == EncounterType.WildSuperRod)
                                    {
                                        CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                        slot = slot*0xeeb9eb65 + 0xa3561a1;

                                        if ((CCSeed >> 16)/656 > 74)
                                            skipFrame = true;
                                        else
                                            CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                    }
                                }

                                // Each gender ratio has a different
                                // unbiased (non-nature-affective) number that is
                                // added to the PID
                                var choppedPID = (ushort) (rng2/0xA3E);
                                if (!skipFrame && IVtoSeed.CheckPID(0, choppedPID, nature))
                                {
                                    foreach (uint buffer in Functions.UnbiasedBuffer)
                                    {
                                        frame = Frame.GenerateFrame(CCSeed,
                                                                    frameType, EncounterType, 0,
                                                                    CCSeed,
                                                                    choppedPID + buffer, 0,
                                                                    rng1, x_test,
                                                                    id, sid,
                                                                    0, 0);

                                        frame.EncounterSlot = EncounterSlotCalc.encounterSlot(slot, frameType,
                                                                                              EncounterType);
                                        switch (buffer)
                                        {
                                            case 0x0:
                                                frame.EncounterMod = EncounterMod.CuteCharmFemale;
                                                break;
                                            case 0x96:
                                                frame.EncounterMod = EncounterMod.CuteCharm50M;
                                                break;
                                            case 0xC8:
                                                frame.EncounterMod = EncounterMod.CuteCharm25M;
                                                break;
                                            case 0x4B:
                                                frame.EncounterMod = EncounterMod.CuteCharm75M;
                                                break;
                                            case 0x32:
                                                frame.EncounterMod = EncounterMod.CuteCharm875M;
                                                break;
                                            default:
                                                frame.EncounterMod = EncounterMod.CuteCharm;
                                                break;
                                        }
                                        candidates.Add(frame);
                                    }
                                }
                            }
                        }
                        else if (frameType == FrameType.MethodK)
                        {
                            //  Check Method 1, then roll back to see if it is a hittable frame
                            if (IVtoSeed.CheckPID(rng2, rng3, nature))
                            {
                                var testRng = new PokeRngR(rng.Seed);

                                uint testPid;
                                uint nextRng = rng4;
                                uint nextRng2 = testRng.GetNext32BitNumber();
                                uint slot = 0;

                                // A spread is only made accessible if there are no other PIDs between
                                // it and the calling frame that have the same nature as the spread.

                                do
                                {
                                    bool skipFrame = false;
                                    // Check to see if this is a valid non-Synch calling frame
                                    // If it is, we won't bother checking it with Synch because it works either way

                                    if (nextRng%25 == nature)
                                    {
                                        uint testSeed = testRng.Seed;
                                        var encounterMod = EncounterMod.None;

                                        if (EncounterType != EncounterType.Stationary)
                                        {
                                            testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                            slot = nextRng2;
                                            if (EncounterType == EncounterType.WildSurfing ||
                                                EncounterType == EncounterType.BugCatchingContest ||
                                                EncounterType == EncounterType.Headbutt)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                            }
                                            else if (EncounterType == EncounterType.WildOldRod)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                uint nibble = (testSeed >> 16)%100;
                                                if (nibble <= 48)
                                                {
                                                    if (nibble > 24)
                                                    {
                                                        encounterMod = EncounterMod.SuctionCups;
                                                    }
                                                    testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                }
                                                else
                                                    skipFrame = true;
                                            }
                                            else if (EncounterType == EncounterType.WildGoodRod)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                uint nibble = (testSeed >> 16)%100;
                                                if (nibble <= 98)
                                                {
                                                    if (nibble > 49)
                                                    {
                                                        encounterMod = EncounterMod.SuctionCups;
                                                    }
                                                    testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                }
                                                else
                                                    skipFrame = true;
                                            }
                                            else if (EncounterType == EncounterType.WildSuperRod)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                uint nibble = (testSeed >> 16)%100;
                                                if (nibble <= 99)
                                                {
                                                    if (nibble > 74)
                                                    {
                                                        encounterMod = EncounterMod.SuctionCups;
                                                    }
                                                    testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                }
                                                else
                                                    skipFrame = true;
                                            }
                                        }

                                        if (!skipFrame)
                                        {
                                            frame = Frame.GenerateFrame(testSeed,
                                                                        frameType, EncounterType,
                                                                        0,
                                                                        testSeed,
                                                                        rng3, rng2,
                                                                        rng1, x_test,
                                                                        id, sid,
                                                                        0, 0);

                                            frame.EncounterSlot = EncounterSlotCalc.encounterSlot(slot, frameType,
                                                                                                  EncounterType);
                                            frame.EncounterMod = encounterMod;
                                            candidates.Add(frame);
                                        }

                                        // Check if the frame appears as the result of a failed Synch
                                        if (((nextRng2 >> 16) & 1) == 1)
                                        {
                                            if (EncounterType == EncounterType.WildOldRod)
                                            {
                                                uint nibble = (testSeed >> 16)%100;
                                                if (nibble > 24)
                                                {
                                                    skipFrame = true;
                                                }
                                            }
                                            else if (EncounterType == EncounterType.WildGoodRod)
                                            {
                                                uint nibble = (testSeed >> 16)%100;
                                                if (nibble > 49)
                                                {
                                                    skipFrame = true;
                                                }
                                            }
                                            else if (EncounterType == EncounterType.WildSuperRod)
                                            {
                                                uint nibble = (testSeed >> 16)%100;
                                                if (nibble > 74)
                                                {
                                                    skipFrame = true;
                                                }
                                            }

                                            slot = slot*0xeeb9eb65 + 0xa3561a1;
                                            testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;

                                            if (!skipFrame)
                                            {
                                                frame = Frame.GenerateFrame(testSeed,
                                                                            frameType, EncounterType,
                                                                            0,
                                                                            testSeed,
                                                                            rng3, rng2,
                                                                            rng1, x_test,
                                                                            id, sid,
                                                                            0, 0);

                                                frame.EncounterSlot = EncounterSlotCalc.encounterSlot(slot, frameType,
                                                                                                      EncounterType);

                                                frame.EncounterMod = EncounterMod.Synchronize;
                                                candidates.Add(frame);
                                            }
                                        }
                                    }
                                        // Check to see if the spread is hittable with Synchronize
                                    else if ((nextRng & 1) == 0)
                                    {
                                        uint testSeed = testRng.Seed;

                                        if (EncounterType != EncounterType.Stationary)
                                        {
                                            testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                            slot = nextRng2;
                                            if (EncounterType == EncounterType.WildSurfing ||
                                                EncounterType == EncounterType.BugCatchingContest ||
                                                EncounterType == EncounterType.Headbutt)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                            }
                                            else if (EncounterType == EncounterType.WildOldRod)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                uint nibble = (testSeed >> 16)%100;
                                                if (nibble > 24)
                                                {
                                                    skipFrame = true;
                                                }
                                                else
                                                {
                                                    testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                }
                                            }
                                            else if (EncounterType == EncounterType.WildGoodRod)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                uint nibble = (testSeed >> 16)%100;

                                                if (nibble > 49)
                                                {
                                                    skipFrame = true;
                                                }
                                                else
                                                {
                                                    testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                }
                                            }
                                            else if (EncounterType == EncounterType.WildSuperRod)
                                            {
                                                slot = testSeed;
                                                testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;

                                                uint nibble = (testSeed >> 16)%100;
                                                if (nibble > 74)
                                                {
                                                    skipFrame = true;
                                                }
                                                else
                                                {
                                                    testSeed = testSeed*0xeeb9eb65 + 0xa3561a1;
                                                }
                                            }
                                        }

                                        if (!skipFrame)
                                        {
                                            frame = Frame.GenerateFrame(testSeed,
                                                                        frameType, EncounterType,
                                                                        0,
                                                                        testSeed,
                                                                        rng3, rng2,
                                                                        rng1, x_test,
                                                                        id, sid,
                                                                        0, 0);

                                            frame.Synchable = true;
                                            frame.EncounterMod = EncounterMod.Synchronize;
                                            frame.EncounterSlot = EncounterSlotCalc.encounterSlot(slot, frameType,
                                                                                                  EncounterType);
                                            candidates.Add(frame);
                                        }
                                    }

                                    testPid = (nextRng << 16) | nextRng2 >> 16;

                                    nextRng = testRng.GetNext16BitNumber();
                                    nextRng2 = testRng.GetNext32BitNumber();
                                } while (testPid%25 != nature);
                            }

                            if (rng3%3 != 0)
                            {
                                uint CCSeed;
                                uint slot = 0;
                                bool skipFrame = false;

                                if (EncounterType == EncounterType.Stationary)
                                    CCSeed = method1Seed;
                                else
                                {
                                    CCSeed = method1Seed*0xeeb9eb65 + 0xa3561a1;
                                    slot = method1Seed;
                                    if (EncounterType == EncounterType.WildSurfing ||
                                        EncounterType == EncounterType.BugCatchingContest)
                                    {
                                        CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                        slot = slot*0xeeb9eb65 + 0xa3561a1;
                                    }
                                    else if (EncounterType == EncounterType.WildOldRod)
                                    {
                                        CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                        slot = slot*0xeeb9eb65 + 0xa3561a1;

                                        if ((CCSeed >> 16)%100 > 24)
                                            skipFrame = true;
                                        else
                                            CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                    }
                                    else if (EncounterType == EncounterType.WildGoodRod)
                                    {
                                        CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                        slot = slot*0xeeb9eb65 + 0xa3561a1;

                                        if ((CCSeed >> 16)%100 > 49)
                                            skipFrame = true;
                                        else
                                            CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                    }
                                    else if (EncounterType == EncounterType.WildSuperRod)
                                    {
                                        CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                        slot = slot*0xeeb9eb65 + 0xa3561a1;

                                        if ((CCSeed >> 16)%100 > 74)
                                            skipFrame = true;
                                        else
                                            CCSeed = CCSeed*0xeeb9eb65 + 0xa3561a1;
                                    }
                                }

                                //  Check HGSS Cute Charm
                                //  [CC Check] [PID] [IVs] [IVs]
                                //  [rng3] [rng2] [rng1] [START]

                                // Each gender ratio has a different
                                // unbiased (non-nature-affective) number that is
                                // added to the PID
                                var choppedPID = (ushort) (rng2%25);
                                if (!skipFrame && IVtoSeed.CheckPID(0, choppedPID, nature))
                                {
                                    foreach (uint buffer in Functions.UnbiasedBuffer)
                                    {
                                        frame = Frame.GenerateFrame(CCSeed,
                                                                    frameType, EncounterType, 0,
                                                                    CCSeed,
                                                                    choppedPID + buffer, 0,
                                                                    rng1, x_test,
                                                                    id, sid,
                                                                    0, 0);

                                        frame.EncounterSlot = EncounterSlotCalc.encounterSlot(slot, frameType,
                                                                                              EncounterType);
                                        switch (buffer)
                                        {
                                            case 0x0:
                                                frame.EncounterMod = EncounterMod.CuteCharmFemale;
                                                break;
                                            case 0x96:
                                                frame.EncounterMod = EncounterMod.CuteCharm50M;
                                                break;
                                            case 0xC8:
                                                frame.EncounterMod = EncounterMod.CuteCharm25M;
                                                break;
                                            case 0x4B:
                                                frame.EncounterMod = EncounterMod.CuteCharm75M;
                                                break;
                                            case 0x32:
                                                frame.EncounterMod = EncounterMod.CuteCharm875M;
                                                break;
                                            default:
                                                frame.EncounterMod = EncounterMod.CuteCharm;
                                                break;
                                        }
                                        candidates.Add(frame);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Now that we have some possibilities for frames,
            // We'll filter out ones that don't meet user criteria
            // Then roll back the RNG for each of them to make sure
            // each is within the user-specified maximum frames
            // from a DPPtHGSS-style seed.
            foreach (Frame candidate in candidates)
            {
                if (frameCompare.Compare(candidate))
                {
                    // start backing up frames until the user-specified max
                    rng.Seed = candidate.Seed;

                    const uint start = 1;

                    for (uint backCount = start; backCount <= MaxResults; backCount++)
                    {
                        uint testSeed = rng.Seed;

                        //uint seedAB = testSeed >> 24;
                        uint seedCD = (testSeed & 0x00FF0000) >> 16;
                        uint seedEFGH = testSeed & 0x0000FFFF;

                        // Check to see if seed follows ABCDEFGH format
                        // And matches-user specified delay
                        if (seedEFGH > minEfgh && seedEFGH < maxEfgh)
                        {
                            // CD must be between 0-23
                            if (seedCD < 23)
                            {
                                if (backCount >= InitialFrame)
                                {
                                    Frame frameCopy = Frame.Clone(candidate);

                                    frameCopy.Seed = testSeed;
                                    frameCopy.Number = backCount;
                                    frames.Add(frameCopy);
                                }
                            }
                        }

                        rng.GetNext32BitNumber();
                    }
                }
            }

            return frames;
        }
Пример #2
0
        // Overloaded method for SeedFinder's Open Search
        public static List <Seed> GetSeeds(
            uint hp,
            uint atk,
            uint def,
            uint spa,
            uint spd,
            uint spe,
            uint nature)
        {
            var seeds = new List <Seed>();

            uint ivs2 = spe | (spa << 5) | (spd << 10);

            uint ivs1 = hp | (atk << 5) | (def << 10);

            uint x_test = ivs2 << 16;

            //  Now we want to start with IV2 and call the RNG for
            //  values between 0 and FFFF in the low order bits.
            for (uint cnt = 0; cnt <= 0xFFFF; cnt++)
            {
                //  Set our test seed here so we can start
                //  working backwards to see if the rest
                //  of the information we were provided
                //  is a match.

                uint seed = x_test | cnt;

                var rng = new PokeRngR(seed);

                //  Right now, this simply assumes method
                //  1 and gets the value previous to check
                //  for  match.  We need a clean way to do
                //  this for all of our methods.

                uint rng1 = rng.GetNext16BitNumber();

                //Check if ivs line up
                if ((rng1 & 0x7FFF) == ivs1)
                {
                    //  We have a max of 5 total RNG calls
                    //  to make a pokemon and we already have
                    //  one so lets go ahead and get 4 more.
                    uint rng2        = rng.GetNext16BitNumber();
                    uint rng3        = rng.GetNext16BitNumber();
                    uint rng4        = rng.GetNext16BitNumber();
                    uint pid         = (rng2 << 16) | rng3;
                    uint method1Seed = rng.Seed;

                    //  Check Method 1
                    // [PID] [PID] [IVs] [IVs]
                    // [rng3] [rng2] [rng1] [START]
                    if (pid % 25 == nature)
                    {
                        //  Build a seed to add to our collection
                        var newSeed = new Seed
                        {
                            Method      = "Method 1",
                            Pid         = pid,
                            MonsterSeed = method1Seed
                        };
                        seeds.Add(newSeed);
                    }

                    // Check Method 1 XOR
                    // [PID] [PID] [IVs] [IVs]
                    // [rng3] [rng2] [rng1] [START]
                    pid ^= 0x80008000;
                    if (pid % 25 == nature)
                    {
                        //  Build a seed to add to our collection
                        var newSeed = new Seed
                        {
                            Method      = "Method 1",
                            Pid         = pid,
                            MonsterSeed = method1Seed ^ 0x80000000
                        };
                        seeds.Add(newSeed);
                    }
                }
            }
            return(seeds);
        }
Пример #3
0
        private void buttonGenerate_Click(object sender, EventArgs e)
        {
            uint hp = 0;
            uint atk = 0;
            uint def = 0;
            uint spa = 0;
            uint spd = 0;
            uint spe = 0;

            if (maskedTextBoxHP_A.Text != "")
                hp = uint.Parse(maskedTextBoxHP_A.Text);
            if (maskedTextBoxAtk_A.Text != "")
                atk = uint.Parse(maskedTextBoxAtk_A.Text);
            if (maskedTextBoxDef_A.Text != "")
                def = uint.Parse(maskedTextBoxDef_A.Text);
            if (maskedTextBoxSpA_A.Text != "")
                spa = uint.Parse(maskedTextBoxSpA_A.Text);
            if (maskedTextBoxSpD_A.Text != "")
                spd = uint.Parse(maskedTextBoxSpD_A.Text);
            if (maskedTextBoxSpe_A.Text != "")
                spe = uint.Parse(maskedTextBoxSpe_A.Text);

            uint year_a = 0;
            uint month_a = 1;
            uint date_a = 1;
            uint hours_a = 0;
            uint minutes_a = 0;

            if (maskedTextBoxYear_A.Text != "")
                year_a = uint.Parse(maskedTextBoxYear_A.Text);

            if (maskedTextBoxMonth_A.Text != "")
                month_a = uint.Parse(maskedTextBoxMonth_A.Text);

            if (maskedTextBoxDate_A.Text != "")
                date_a = uint.Parse(maskedTextBoxDate_A.Text);

            if (maskedTextBoxHours_A.Text != "")
                hours_a = uint.Parse(maskedTextBoxHours_A.Text);

            if (maskedTextBoxMinutes_A.Text != "")
                minutes_a = uint.Parse(maskedTextBoxMinutes_A.Text);

            var nature = (Nature) comboBoxNature_A.SelectedValue;

            bool showMonster = checkBoxShowMonster.Checked;

            //  Get a list of possible starting seeds that we are going to use
            //  to work backwards and find probable initial seeds.
            List<Seed> startingSeeds =
                IVtoSeed.GetSeeds(hp, atk, def, spa, spd, spe, (uint) nature.Number);

            //  Now that we have developed a list of possible seeds we need to
            //  start working those backwards and then building a list of
            //  initial seeds that may have been possible.
            var seeds = new List<SeedInitial>();

            bool monsterFound = false;
            bool initialFound = false;

            uint minDefaultDelay = 550;
            if (radioButton_SIV_HGSS.Checked)
                minDefaultDelay = 400;

            uint maxDefaultDelay = 3600;

            if (maskedTextBoxMinDelay_A.Text != "" && radioButton_SIV_CUSTOM.Checked)
                minDefaultDelay = uint.Parse(maskedTextBoxMinDelay_A.Text);
            if (maskedTextBoxMaxDelay_A.Text != "" && radioButton_SIV_CUSTOM.Checked)
                maxDefaultDelay = uint.Parse(maskedTextBoxMaxDelay_A.Text);

            foreach (Seed seed in startingSeeds)
            {
                if (seed.FrameType == FrameType.Method1)
                {
                    if (showMonster)
                    {
                        seeds.Add(new SeedInitial(seed.MonsterSeed, 0, "Monster", 0, 0));
                    }

                    monsterFound = true;

                    //  start backing up, we are going to back up
                    //  a grand totol of 1000 times max for the
                    //  time being,
                    var rng = new PokeRngR(seed.MonsterSeed);

                    for (uint backCount = 1; backCount < 2000; backCount++)
                    {
                        uint testSeed = rng.Seed;
                        rng.GetNext16BitNumber();

                        uint seedAB = testSeed >> 24;
                        uint seedCD = (testSeed & 0x00FF0000) >> 16;
                        uint seedEFGH = testSeed & 0x0000FFFF;

                        if ((seedEFGH > (minDefaultDelay + year_a - 2000) &&
                             seedEFGH < (maxDefaultDelay + year_a - 2000)) ||
                            radioButton_SIV_OPEN.Checked)
                        {
                            //  Disqualify on hours second as it is very likely
                            //  to be a poor choice for use to work with.
                            if ((seedCD == hours_a) || radioButton_SIV_OPEN.Checked)
                            {
                                if (!radioButton_SIV_OPEN.Checked)
                                {
                                    for (uint secondsCount = 0; secondsCount < 60; secondsCount++)
                                    {
                                        if (((month_a*date_a + minutes_a + secondsCount)%0x100) == seedAB)
                                        {
                                            var initialSeed =
                                                new SeedInitial(
                                                    testSeed,
                                                    backCount,
                                                    "Initial",
                                                    secondsCount,
                                                    seedEFGH - (year_a - 2000));

                                            seeds.Add(initialSeed);

                                            initialFound = true;
                                        }
                                    }
                                }
                                else // if (!checkBoxOpenSearch.Checked)
                                {
                                    //  Do the open search, which is completely open and does not
                                    //  honor the min/max delay of the advanced search, so we should
                                    //  likely make the selection of those mutially exclusive.
                                    if (seedCD < 24)
                                    {
                                        if ((checkBoxLowDelay.Checked && seedEFGH < 10000) || !checkBoxLowDelay.Checked)
                                        {
                                            var initialSeed =
                                                new SeedInitial(
                                                    testSeed,
                                                    backCount,
                                                    "Initial",
                                                    0,
                                                    seedEFGH - (year_a - 2000));

                                            seeds.Add(initialSeed);

                                            initialFound = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            dataGridViewValues.DataSource = seeds;

            if (!monsterFound)
            {
                MessageBox.Show("No matches found for the IVs entered.  Please check and try again.", "No Data Found",
                                MessageBoxButtons.OK);
            }
            else if (!initialFound)
            {
                MessageBox.Show("No reasonable initial seed found. Please check your DATE and TIME.", "No Data Found",
                                MessageBoxButtons.OK);
            }

            Settings.Default.YearA = year_a.ToString();
            Settings.Default.MonthA = month_a.ToString();
            Settings.Default.DateA = date_a.ToString();
            Settings.Default.MinutesA = minutes_a.ToString();
            Settings.Default.HoursA = hours_a.ToString();

            if (maskedTextBoxMinDelay_A.Text != "" && radioButton_SIV_CUSTOM.Checked)
            {
                minDefaultDelay = uint.Parse(maskedTextBoxMinDelay_A.Text);
                Settings.Default.DelayMinA = minDefaultDelay.ToString();
            }
            if (maskedTextBoxMaxDelay_A.Text != "" && radioButton_SIV_CUSTOM.Checked)
            {
                maxDefaultDelay = uint.Parse(maskedTextBoxMaxDelay_A.Text);
                Settings.Default.DelayMaxA = maxDefaultDelay.ToString();
            }

            string SIV_Mode = "DPP";
            if (radioButton_SIV_DPP.Checked)
            {
                SIV_Mode = "DPP";
            }
            else if (radioButton_SIV_HGSS.Checked)
            {
                SIV_Mode = "HGSS";
            }
            else if (radioButton_SIV_CUSTOM.Checked)
            {
                SIV_Mode = "CUSTOM";
            }
            else if (radioButton_SIV_OPEN.Checked)
            {
                SIV_Mode = "OPEN";
            }
            Settings.Default.SIVMode = SIV_Mode;
            Settings.Default.SIVLowDelay = checkBoxLowDelay.Checked;
            Settings.Default.Save();
        }
Пример #4
0
        public static List<Seed> GetSeeds(
            uint hp,
            uint atk,
            uint def,
            uint spa,
            uint spd,
            uint spe,
            uint nature,
            uint id)
        {
            var seeds = new List<Seed>();

            uint x4 = 0;
            uint x4_2 = 0;

            x4 = spe + (spa << 5) + (spd << 10);
            x4_2 = x4 ^ 0x8000;

            uint x8 = 0;
            uint x8_2 = 0;

            x8 = hp + (atk << 5) + (def << 10);
            x8_2 = x8 ^ 0x8000;

            //  Now we want to start with IV2 and call the RNG for
            //  values between 0 and FFFF in the low order bits.
            for (uint cnt = 0; cnt <= 0x1FFFE; cnt++)
            {
                uint x_test;
                uint x_testXD;

                //  We want to test with the high bit
                //  both set and not set, so we're going
                //  to sneakily do them both.  god help
                //  me if i ever have to figure this out
                //  in the future.
                x_test = (cnt & 1) == 0 ? x4 : x4_2;

                x_testXD = (cnt & 1) == 0 ? x8 : x8_2;

                //  Set our test seed here so we can start
                //  working backwards to see if the rest
                //  of the information we were provided
                //  is a match.

                uint seed = (x_test << 16) + (cnt%0xFFFF);
                uint seedXD = (x_testXD << 16) + (cnt%0xFFFF);
                var rng = new PokeRngR(seed);

                var rngXD = new XdRng(seedXD);
                var rngXDR = new XdRngR(seedXD);
                uint XDColoSeed = rngXDR.GetNext32BitNumber();

                //  Right now, this simply assumes method
                //  1 and gets the value previous to check
                //  for  match.  We need a clean way to do
                //  this for all of our methods.

                //  We have a max of 5 total RNG calls
                //  to make a pokemon and we already have
                //  one so lets go ahead and get 4 more.
                ushort rng1 = rng.GetNext16BitNumber();
                ushort rng2 = rng.GetNext16BitNumber();
                ushort rng3 = rng.GetNext16BitNumber();
                ushort rng4 = rng.GetNext16BitNumber();

                ushort rng1XD = rngXD.GetNext16BitNumber();
                ushort rng2XD = rngXD.GetNext16BitNumber();
                ushort rng3XD = rngXD.GetNext16BitNumber();
                ushort rng4XD = rngXD.GetNext16BitNumber();

                uint method1Seed = rng.Seed;

                rng.GetNext16BitNumber();
                uint method234Seed = rng.Seed;
                ushort choppedPID;

                //  Check Method 1
                // [PID] [PID] [IVs] [IVs]
                // [rng3] [rng2] [rng1] [START]
                if (Check(rng1, rng2, rng3, hp, atk, def, nature))
                {
                    //  Build a seed to add to our collection
                    var newSeed = new Seed();
                    newSeed.Method = "Method 1";
                    newSeed.Pid = ((uint) rng2 << 16) + rng3;
                    newSeed.MonsterSeed = method1Seed;
                    newSeed.Sid = (rng2 ^ (uint) rng3 ^ id) & 0xFFF8;

                    seeds.Add(newSeed);
                }

                //  Check Method 2
                // [PID] [PID] [xxxx] [IVs] [IVs]
                // [rng4] [rng3] [xxxx] [rng1] [START]
                if (Check(rng1, rng3, rng4, hp, atk, def, nature))
                {
                    //  Build a seed to add to our collection
                    var newSeed = new Seed
                        {
                            Method = "Method 2",
                            Pid = ((uint) rng3 << 16) + rng4,
                            MonsterSeed = method234Seed,
                            Sid = (rng3 ^ (uint) rng4 ^ id) & 0xFFF8
                        };

                    seeds.Add(newSeed);
                }

                /*
                 * Removed because Method 3 doesn't exist in-game
                //  Check Method 3
                //  [PID] [xxxx] [PID] [IVs] [IVs]
                //  [rng4] [xxxx] [rng2] [rng1] [START]
                if (Check(rng1, rng2, rng4, hp, atk, def, nature))
                {
                    //  Build a seed to add to our collection
                    Seed newSeed = new Seed();
                    newSeed.Method = "Method 3";
                    newSeed.Pid = ((uint)rng2 << 16) + (uint)rng4;
                    newSeed.MonsterSeed = method234Seed;
                    newSeed.Sid = ((uint)rng2 ^ (uint)rng4 ^ id) & 0xFFF8;

                    seeds.Add(newSeed);
                }
                 */

                //  Check Method 4
                //  [PID] [PID] [IVs] [xxxx] [IVs]
                //  [rng4] [rng3] [rng2] [xxxx] [START]
                if (Check(rng2, rng3, rng4, hp, atk, def, nature))
                {
                    //  Build a seed to add to our collection
                    var newSeed = new Seed
                        {
                            Method = "Method 4",
                            Pid = ((uint) rng3 << 16) + rng4,
                            MonsterSeed = method234Seed,
                            Sid = (rng3 ^ (uint) rng4 ^ id) & 0xFFF8
                        };

                    seeds.Add(newSeed);
                }

                //  Check Colosseum\XD
                // [IVs] [IVs] [xxx] [PID] [PID]
                // [START] [rng1] [rng3]

                if (Check(rng1XD, rng3XD, rng4XD, spe, spa, spd, nature))
                {
                    var newSeed = new Seed
                        {
                            Method = "Colosseum/XD",
                            Pid = ((uint) rng3XD << 16) + rng4XD,
                            MonsterSeed = XDColoSeed,
                            Sid = (rng4XD ^ (uint) rng3XD ^ id) & 0xFFF8
                        };

                    seeds.Add(newSeed);
                }

                if (rng3/0x5556 != 0)
                {
                    //  Check DPPt Cute Charm
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort) (rng2/0xA3E);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                            {
                                Method = "Cute Charm (DPPt)",
                                Pid = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid = (choppedPID ^ id) & 0xFFF8
                            };

                        seeds.Add(newSeed);
                    }

                    //  Check DPPt Cute Charm (50% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort) (rng2/0xA3E + 0x96);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                            {
                                Method = "Cute Charm (DPPt)",
                                Pid = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid = (choppedPID ^ id) & 0xFFF8
                            };

                        seeds.Add(newSeed);
                    }

                    //  Check DPPt Cute Charm (25% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort) (rng2/0xA3E + 0xC8);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                            {
                                Method = "Cute Charm (DPPt)",
                                Pid = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid = (choppedPID ^ id) & 0xFFF8
                            };

                        seeds.Add(newSeed);
                    }

                    //  Check DPPt Cute Charm (75% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort) (rng2/0xA3E + 0x4B);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                            {
                                Method = "Cute Charm (DPPt)",
                                Pid = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid = (choppedPID ^ id) & 0xFFF8
                            };

                        seeds.Add(newSeed);
                    }

                    //  Check DPPt Cute Charm (87.5% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort) (rng2/0xA3E + 0x32);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                            {
                                Method = "Cute Charm (DPPt)",
                                Pid = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid = (choppedPID ^ id) & 0xFFF8
                            };

                        seeds.Add(newSeed);
                    }
                }

                if (rng3%3 != 0)
                {
                    //  Check HGSS Cute Charm
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort) (rng2%25);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                            {
                                Method = "Cute Charm (HGSS)",
                                Pid = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid = (choppedPID ^ id) & 0xFFF8
                            };

                        seeds.Add(newSeed);
                    }

                    //  Check HGSS Cute Charm (50% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort) (rng2%25 + 0x96);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                            {
                                Method = "Cute Charm (HGSS)",
                                Pid = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid = (choppedPID ^ id) & 0xFFF8
                            };

                        seeds.Add(newSeed);
                    }

                    //  Check HGSS Cute Charm (25% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort) (rng2%25 + 0xC8);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                            {
                                Method = "Cute Charm (HGSS)",
                                Pid = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid = (choppedPID ^ id) & 0xFFF8
                            };

                        seeds.Add(newSeed);
                    }

                    //  Check HGSS Cute Charm (75% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort) (rng2%25 + 0x4B);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                            {
                                Method = "Cute Charm (HGSS)",
                                Pid = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid = (choppedPID ^ id) & 0xFFF8
                            };

                        seeds.Add(newSeed);
                    }

                    //  Check HGSS Cute Charm (87.5% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort) (rng2%25 + 0x32);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                            {
                                Method = "Cute Charm (HGSS)",
                                Pid = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid = (choppedPID ^ id) & 0xFFF8
                            };

                        seeds.Add(newSeed);
                    }
                }
            }

            return seeds;
        }
Пример #5
0
        public static List <Seed> GetSeeds(
            uint hp,
            uint atk,
            uint def,
            uint spa,
            uint spd,
            uint spe,
            uint nature,
            uint id)
        {
            var seeds = new List <Seed>();

            uint ivs2 = spe | (spa << 5) | (spd << 10);
            uint ivs1 = hp | (atk << 5) | (def << 10);

            uint x_test = ivs2 << 16;
            uint x_testXD = ivs1 << 16;
            uint pid, pidXor, sid;
            bool pass = false;

            //  Now we want to start with IV2 and call the RNG for
            //  values between 0 and FFFF in the low order bits.
            for (uint cnt = 0; cnt <= 0xFFFF; cnt++)
            {
                //Check to see if the iv calls line up
                uint seedXD = x_testXD | cnt;
                var  rngXD  = new XdRng(seedXD);
                var  rngXDR = new XdRngR(seedXD);
                uint rng1XD = rngXD.GetNext16BitNumber();

                if ((rng1XD & 0x7FFF) == ivs2)
                {
                    //Grab rest of RNG calls for XDColo
                    uint rng2XD        = rngXD.GetNext16BitNumber();
                    uint rng3XD        = rngXD.GetNext16BitNumber();
                    uint rng4XD        = rngXD.GetNext16BitNumber();
                    uint XDColoSeed    = rngXDR.GetNext32BitNumber();
                    uint XDColoSeedXor = XDColoSeed ^ 0x80000000;
                    sid = (rng4XD ^ rng3XD ^ id) & 0xFFF8;

                    //  Check Colosseum\XD
                    // [IVs] [IVs] [xxx] [PID] [PID]
                    // [START] [rng1] [rng3]
                    pid = (rng3XD << 16) | rng4XD;
                    if (pid % 25 == nature)
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Colosseum/XD",
                            Pid         = pid,
                            MonsterSeed = XDColoSeed,
                            Sid         = sid
                        };
                        seeds.Add(newSeed);
                    }

                    //  Check Colosseum\XD XOR
                    // [IVs] [IVs] [xxx] [PID] [PID]
                    // [START] [rng1] [rng3]
                    pidXor = pid ^ 0x80008000;
                    if (pidXor % 25 == nature)
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Colosseum/XD",
                            Pid         = pidXor,
                            MonsterSeed = XDColoSeedXor,
                            Sid         = sid
                        };
                        seeds.Add(newSeed);
                    }
                }

                //  Now test rest of methods
                uint seed = x_test | cnt;
                var  rng  = new PokeRngR(seed);
                uint rng1 = rng.GetNext16BitNumber();

                //  We have a max of 5 total RNG calls
                //  to make a pokemon and we already have
                //  one so lets go ahead and get 4 more.
                uint rng2           = rng.GetNext16BitNumber();
                uint rng3           = rng.GetNext16BitNumber();
                uint rng4           = rng.GetNext16BitNumber();
                uint method1Seed    = rng.Seed;
                uint method1SeedXor = method1Seed ^ 0x80000000;
                sid = (rng2 ^ rng3 ^ id) & 0xFFF8;

                rng.GetNext16BitNumber();
                uint method234Seed    = rng.Seed;
                uint method234SeedXor = method234Seed ^ 0x80000000;

                //Checks that ivs line up
                if ((rng1 & 0x7FFF) == ivs1)
                {
                    uint choppedPID;

                    //  Check Method 1
                    // [PID] [PID] [IVs] [IVs]
                    // [rng3] [rng2] [rng1] [START]
                    pid = (rng2 << 16) + rng3;
                    if (pid % 25 == nature)
                    {
                        //  Build a seed to add to our collection
                        var newSeed = new Seed
                        {
                            Method      = "Method 1",
                            Pid         = pid,
                            MonsterSeed = method1Seed,
                            Sid         = sid
                        };
                        seeds.Add(newSeed);
                    }

                    //  Check Method 1 XOR
                    // [PID] [PID] [IVs] [IVs]
                    // [rng3] [rng2] [rng1] [START]
                    pidXor = pid ^ 0x80008000;
                    if (pidXor % 25 == nature)
                    {
                        //  Build a seed to add to our collection
                        var newSeed = new Seed
                        {
                            Method      = "Method 1",
                            Pid         = pidXor,
                            MonsterSeed = method1SeedXor,
                            Sid         = sid
                        };
                        seeds.Add(newSeed);
                    }

                    //  Check Reverse Method 1
                    // [PID] [PID] [IVs] [IVs]
                    // [rng2] [rng3] [rng1] [START]
                    pid = (rng3 << 16) + rng2;
                    if (pid % 25 == nature)
                    {
                        //  Build a seed to add to our collection
                        var newSeed = new Seed
                        {
                            Method      = "Reverse Method 1",
                            Pid         = pid,
                            MonsterSeed = method1Seed,
                            Sid         = sid
                        };
                        seeds.Add(newSeed);
                    }

                    //  Check Reverse Method 1 XOR
                    // [PID] [PID] [IVs] [IVs]
                    // [rng2] [rng3] [rng1] [START]
                    pid = pid ^ 0x80008000;
                    if (pid % 25 == nature)
                    {
                        //  Build a seed to add to our collection
                        var newSeed = new Seed
                        {
                            Method      = "Reverse Method 1",
                            Pid         = pid,
                            MonsterSeed = method1SeedXor,
                            Sid         = sid
                        };
                        seeds.Add(newSeed);
                    }

                    //  Check Wishmkr
                    // [PID] [PID] [IVs] [IVs]
                    // [rng3] [rng2] [rng1] [START]
                    if (pid % 25 == nature)
                    {
                        if (method1Seed < 0x10000)
                        {
                            //  Build a seed to add to our collection
                            var newSeed = new Seed
                            {
                                Pid         = pid,
                                MonsterSeed = method1Seed,
                                Sid         = sid
                            };
                            newSeed.Method = Functions.Shiny(newSeed.Pid, 20043, 0) ? "Wishmkr Shiny" : "Wishmkr";
                            seeds.Add(newSeed);
                        }
                    }

                    //  Check Wishmkr XOR
                    // [PID] [PID] [IVs] [IVs]
                    // [rng3] [rng2] [rng1] [START]
                    if (pidXor % 25 == nature)
                    {
                        if (method1SeedXor < 0x10000)
                        {
                            //  Build a seed to add to our collection
                            var newSeed = new Seed
                            {
                                Pid         = pidXor,
                                MonsterSeed = method1SeedXor,
                                Sid         = sid
                            };
                            newSeed.Method = Functions.Shiny(newSeed.Pid, 20043, 0) ? "Wishmkr Shiny" : "Wishmkr";
                            seeds.Add(newSeed);
                        }
                    }

                    //  Check Method 2
                    // [PID] [PID] [xxxx] [IVs] [IVs]
                    // [rng4] [rng3] [xxxx] [rng1] [START]
                    pid = (rng3 << 16) + rng4;
                    sid = (rng3 ^ rng4 ^ id) & 0xFFF8;
                    if (pid % 25 == nature)
                    {
                        //  Build a seed to add to our collection
                        var newSeed = new Seed
                        {
                            Method      = "Method 2",
                            Pid         = pid,
                            MonsterSeed = method234Seed,
                            Sid         = sid
                        };
                        seeds.Add(newSeed);
                    }

                    //  Check Method 2
                    // [PID] [PID] [xxxx] [IVs] [IVs]
                    // [rng4] [rng3] [xxxx] [rng1] [START]
                    pidXor = pid ^ 0x80008000;
                    if (pidXor % 25 == nature)
                    {
                        //  Build a seed to add to our collection
                        var newSeed = new Seed
                        {
                            Method      = "Method 2",
                            Pid         = pidXor,
                            MonsterSeed = method234SeedXor,
                            Sid         = sid
                        };
                        seeds.Add(newSeed);
                    }

                    /* Removed because Method 3 doesn't exist in-game
                     * //  Check Method 3
                     * //  [PID] [xxxx] [PID] [IVs] [IVs]
                     * //  [rng4] [xxxx] [rng2] [rng1] [START]
                     * if (Check(rng1, rng2, rng4, hp, atk, def, nature))
                     * {
                     *  //  Build a seed to add to our collection
                     *  Seed newSeed = new Seed();
                     *  newSeed.Method = "Method 3";
                     *  newSeed.Pid = (rng2 << 16) + rng4;
                     *  newSeed.MonsterSeed = method234Seed;
                     *  newSeed.Sid = (rng2 ^ rng4 ^ id) & 0xFFF8;
                     *
                     *  seeds.Add(newSeed);
                     * } */

                    //  DPPt Cute Charm
                    if (rng3 / 0x5556 != 0)
                    {
                        //  Check DPPt Cute Charm
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        choppedPID = rng2 / 0xA3E;
                        pass       = choppedPID % 25 == nature;
                        if (pass)
                        {
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (DPPt)",
                                Pid         = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check DPPt Cute Charm (50% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 / 0xA3E + 0x96;
                        if (pass)
                        {
                            choppedPID += 0x96;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (DPPt)",
                                Pid         = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check DPPt Cute Charm (25% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 / 0xA3E + 0xC8;
                        if (pass)
                        {
                            choppedPID += 0x32;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (DPPt)",
                                Pid         = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check DPPt Cute Charm (75% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 / 0xA3E + 0x4B;
                        if (pass)
                        {
                            choppedPID -= 0x7D;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (DPPt)",
                                Pid         = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check DPPt Cute Charm (87.5% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 / 0xA3E + 0x32;
                        if (pass)
                        {
                            choppedPID -= 0x19;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (DPPt)",
                                Pid         = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }
                    }

                    //  HGSS Cute Charm
                    if (rng3 % 3 != 0)
                    {
                        //  Check HGSS Cute Charm
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        choppedPID = rng2 % 25;
                        pass       = choppedPID == nature;
                        if (pass)
                        {
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (HGSS)",
                                Pid         = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check HGSS Cute Charm (50% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 % 25 + 0x96;
                        if (pass)
                        {
                            choppedPID += 0x96;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (HGSS)",
                                Pid         = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check HGSS Cute Charm (25% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 % 25 + 0xC8;
                        if (pass)
                        {
                            choppedPID += 0x32;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (HGSS)",
                                Pid         = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check HGSS Cute Charm (75% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 % 25 + 0x4B;
                        if (pass)
                        {
                            choppedPID -= 0x7D;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (HGSS)",
                                Pid         = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check HGSS Cute Charm (87.5% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 % 25 + 0x32;
                        if (pass)
                        {
                            choppedPID -= 0x19;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (HGSS)",
                                Pid         = choppedPID,
                                MonsterSeed = method1Seed,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }
                    }

                    //  DPPt Cute Charm XOR
                    uint rng3Xor = rng3 ^ 0x8000;
                    uint rng2Xor = rng2 ^ 0x8000;
                    if (rng3Xor / 0x5556 != 0)
                    {
                        //  Check DPPt Cute Charm
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        choppedPID = rng2Xor / 0xA3E;
                        pass       = choppedPID % 25 == nature;
                        if (pass)
                        {
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (DPPt)",
                                Pid         = choppedPID,
                                MonsterSeed = method1SeedXor,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check DPPt Cute Charm (50% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 / 0xA3E + 0x96;
                        if (pass)
                        {
                            choppedPID += 0x96;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (DPPt)",
                                Pid         = choppedPID,
                                MonsterSeed = method1SeedXor,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check DPPt Cute Charm (25% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 / 0xA3E + 0xC8;
                        if (pass)
                        {
                            choppedPID += 0x32;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (DPPt)",
                                Pid         = choppedPID,
                                MonsterSeed = method1SeedXor,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check DPPt Cute Charm (75% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 / 0xA3E + 0x4B;
                        if (pass)
                        {
                            choppedPID -= 0x7D;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (DPPt)",
                                Pid         = choppedPID,
                                MonsterSeed = method1SeedXor,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check DPPt Cute Charm (87.5% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 / 0xA3E + 0x32;
                        if (pass)
                        {
                            choppedPID -= 0x19;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (DPPt)",
                                Pid         = choppedPID,
                                MonsterSeed = method1SeedXor,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }
                    }

                    //  HGSS Cute Charm XOR
                    if (rng3Xor % 3 != 0)
                    {
                        //  Check HGSS Cute Charm
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        choppedPID = rng2Xor % 25;
                        pass       = choppedPID == nature;
                        if (pass)
                        {
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (HGSS)",
                                Pid         = choppedPID,
                                MonsterSeed = method1SeedXor,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check HGSS Cute Charm (50% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 % 25 + 0x96;
                        if (pass)
                        {
                            choppedPID += 0x96;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (HGSS)",
                                Pid         = choppedPID,
                                MonsterSeed = method1SeedXor,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check HGSS Cute Charm (25% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 % 25 + 0xC8;
                        if (pass)
                        {
                            choppedPID += 0x32;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (HGSS)",
                                Pid         = choppedPID,
                                MonsterSeed = method1SeedXor,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check HGSS Cute Charm (75% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 % 25 + 0x4B;
                        if (pass)
                        {
                            choppedPID -= 0x7D;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (HGSS)",
                                Pid         = choppedPID,
                                MonsterSeed = method1SeedXor,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }

                        //  Check HGSS Cute Charm (87.5% male)
                        //  [CC Check] [PID] [IVs] [IVs]
                        //  [rng3] [rng2] [rng1] [START]

                        //choppedPID = rng2 % 25 + 0x32;
                        if (pass)
                        {
                            choppedPID -= 0x19;
                            var newSeed = new Seed
                            {
                                Method      = "Cute Charm (HGSS)",
                                Pid         = choppedPID,
                                MonsterSeed = method1SeedXor,
                                Sid         = (choppedPID ^ id) & 0xFFF8
                            };
                            seeds.Add(newSeed);
                        }
                    }
                }

                if ((rng2 & 0x7FFF) == ivs1)
                {
                    //  Check Method 4
                    //  [PID] [PID] [IVs] [xxxx] [IVs]
                    //  [rng4] [rng3] [rng2] [xxxx] [START]
                    pid = (rng3 << 16) + rng4;
                    sid = (rng3 ^ rng4 ^ id) & 0xFFF8;
                    if (pid % 25 == nature)
                    {
                        //  Build a seed to add to our collection
                        var newSeed = new Seed
                        {
                            Method      = "Method 4",
                            Pid         = pid,
                            MonsterSeed = method234Seed,
                            Sid         = sid
                        };
                        seeds.Add(newSeed);
                    }

                    //  Check Method 4 XOR
                    //  [PID] [PID] [IVs] [xxxx] [IVs]
                    //  [rng4] [rng3] [rng2] [xxxx] [START]
                    pidXor = pid ^ 0x80008000;
                    if (pidXor % 25 == nature)
                    {
                        //  Build a seed to add to our collection
                        var newSeed = new Seed
                        {
                            Method      = "Method 4",
                            Pid         = pidXor,
                            MonsterSeed = method234SeedXor,
                            Sid         = sid
                        };
                        seeds.Add(newSeed);
                    }
                }
            }
            return(seeds);
        }
Пример #6
0
        // Overloaded method for SeedFinder's Open Search
        public static List<Seed> GetSeeds(
            uint hp,
            uint atk,
            uint def,
            uint spa,
            uint spd,
            uint spe,
            uint nature)
        {
            var seeds = new List<Seed>();

            uint x4 = 0;
            uint x4_2 = 0;

            x4 = spe + (spa << 5) + (spd << 10);
            x4_2 = x4 ^ 0x8000;

            uint x8 = 0;
            uint x8_2 = 0;

            x8 = hp + (atk << 5) + (def << 10);
            x8_2 = x8 ^ 0x8000;

            //  Now we want to start with IV2 and call the RNG for
            //  values between 0 and FFFF in the low order bits.
            for (uint cnt = 0; cnt <= 0x1FFFE; cnt++)
            {
                uint x_test;
                uint x_testXD;

                //  We want to test with the high bit
                //  both set and not set, so we're going
                //  to sneakily do them both.  god help
                //  me if i ever have to figure this out
                //  in the future.
                x_test = (cnt & 1) == 0 ? x4 : x4_2;

                x_testXD = (cnt & 1) == 0 ? x8 : x8_2;

                //  Set our test seed here so we can start
                //  working backwards to see if the rest
                //  of the information we were provided
                //  is a match.

                uint seed = (x_test << 16) + (cnt%0xFFFF);
                uint seedXD = (x_testXD << 16) + (cnt%0xFFFF);
                var rng = new PokeRngR(seed);

                var rngXD = new XdRng(seedXD);
                var rngXDR = new XdRngR(seedXD);
                uint XDColoSeed = rngXDR.GetNext32BitNumber();

                //  Right now, this simply assumes method
                //  1 and gets the value previous to check
                //  for  match.  We need a clean way to do
                //  this for all of our methods.

                //  We have a max of 5 total RNG calls
                //  to make a pokemon and we already have
                //  one so lets go ahead and get 4 more.
                ushort rng1 = rng.GetNext16BitNumber();
                ushort rng2 = rng.GetNext16BitNumber();
                ushort rng3 = rng.GetNext16BitNumber();
                ushort rng4 = rng.GetNext16BitNumber();

                ushort rng1XD = rngXD.GetNext16BitNumber();
                ushort rng2XD = rngXD.GetNext16BitNumber();
                ushort rng3XD = rngXD.GetNext16BitNumber();
                ushort rng4XD = rngXD.GetNext16BitNumber();

                uint method1Seed = rng.Seed;

                rng.GetNext16BitNumber();
                uint method234Seed = rng.Seed;

                //  Check Method 1
                // [PID] [PID] [IVs] [IVs]
                // [rng3] [rng2] [rng1] [START]
                if (Check(rng1, rng2, rng3, hp, atk, def, nature))
                {
                    //  Build a seed to add to our collection
                    var newSeed = new Seed
                        {
                            Method = "Method 1",
                            Pid = ((uint) rng2 << 16) + rng3,
                            MonsterSeed = method1Seed
                        };

                    seeds.Add(newSeed);
                }
            }

            return seeds;
        }
Пример #7
0
        //  Add a list new Pokemon and do the breakdown
        public void Add(
            uint hp,
            uint atk,
            uint def,
            uint spa,
            uint spd,
            uint spe,
            Nature nature,
            string ability,
            GenderGenderRatio gender)
        {
            string ivs = hp + " / " + atk + " / " + def + " / " + spa + " / " + spd + " / " + spe;

            Pokemon.Add(new CalculateChainSidPokemon(ivs, nature.Name, ability, gender.ShortName));

            // Build the block for the 2nd IV here.
            uint iv2    = spe + (spa << 5) + (spd << 10);
            uint iv2set = iv2 ^ 0x8000;

            uint iv1    = hp + (atk << 5) + (def << 10);
            uint iv1set = iv1 ^ 0x8000;

            var candidatePids = new List <CandidatePid>();

            //  Now we want to start with IV2 and call the RNG for
            //  values between 0 and FFFF in the low order bits.
            for (uint cnt = 0; cnt <= 0x1FFFE; cnt++)
            {
                uint iv2_test;

                //  We want to test with the high bit
                //  both set and not set, so we're going
                //  to sneakily do them both.  god help
                //  me if i ever have to figure this out
                //  in the future.
                iv2_test = (cnt & 1) == 0 ? iv2 : iv2set;

                //  Set our test seed here so we can start
                //  working backwards to see if the rest
                //  of the information we were provided
                //  is a match.

                uint seed = (iv2_test << 16) + (cnt % 0xFFFF);

                var rng = new PokeRngR(seed);

                uint iv1_rng = rng.GetNext16BitNumber();

                //  Check for a canididate here
                if (iv1_rng == iv1 || iv1_rng == iv1set)
                {
                    //  Get the whole adjust number in a loop
                    uint adjust = 0x0;

                    for (int adjustCnt = 0; adjustCnt < 13; adjustCnt++)
                    {
                        uint adjustRng = rng.GetNext16BitNumber() & 1U;
                        adjust |= (adjustRng << (15 - adjustCnt));
                    }

                    //  Get what we think was the initial PID
                    uint pid2 = rng.GetNext16BitNumber(); //  HIGHID
                    uint pid1 = rng.GetNext16BitNumber(); //  LOWID

                    uint adjustedLow = adjust | (pid1 & 7);

                    uint abilityNumber = adjustedLow & 1;
                    uint genderNumber  = adjustedLow & 0xFF;

                    // lol make this not suck
                    if ((ability == "Single Ability" ||
                         (
                             (abilityNumber == 0 && ability == "Ability 0") ||
                             (abilityNumber == 1 && ability == "Ability 1")
                         )) &&
                        gender.Matches(genderNumber))
                    {
                        var candidatePid = new CandidatePid {
                            AdjustedLow = adjustedLow, NaturalHigh = pid2
                        };
                        candidatePids.Add(candidatePid);
                    }
                }
            }

            var newSids = new List <uint>();

            foreach (uint sid in CandidateSids)
            {
                //  Check each candiate pid that we found for the
                //  IV values and then see if the final PID with
                //  a particular nature/gender is a match.  If so
                //  we can go ahead and add the sid to the new
                //  list and exit early.
                foreach (CandidatePid candidatePid in candidatePids)
                {
                    //  Build our full adjusted PID
                    uint adjustedHigh = candidatePid.AdjustedLow ^ Id ^ sid;
                    adjustedHigh &= 0xFFF8;
                    adjustedHigh += (candidatePid.NaturalHigh & 7);

                    //  for testing out the nature comparison
                    uint pid = (adjustedHigh << 16) + candidatePid.AdjustedLow;

                    //  If any of them work, we will add this to
                    //  the new candidateSids list and break to
                    //  go to the next seed.  Check the nature.
                    uint pidNature = pid % 25;

                    if (nature.Number == pidNature)
                    {
                        newSids.Add(sid);
                        break;
                    }
                }
            }

            CandidateSids = newSids;
        }
Пример #8
0
        // Overloaded method for SeedFinder's Open Search
        public static List <Seed> GetSeeds(
            uint hp,
            uint atk,
            uint def,
            uint spa,
            uint spd,
            uint spe,
            uint nature)
        {
            var seeds = new List <Seed>();

            uint x4   = spe + (spa << 5) + (spd << 10);
            uint x4_2 = x4 ^ 0x8000;

            uint x8   = hp + (atk << 5) + (def << 10);
            uint x8_2 = x8 ^ 0x8000;

            //  Now we want to start with IV2 and call the RNG for
            //  values between 0 and FFFF in the low order bits.
            for (uint cnt = 0; cnt <= 0xFFFE; cnt++)
            {
                uint x_test;
                uint x_testXD;

                //  We want to test with the high bit
                //  both set and not set, so we're going
                //  to sneakily do them both.  god help
                //  me if i ever have to figure this out
                //  in the future.
                x_test = (cnt & 1) == 0 ? x4 : x4_2;

                x_testXD = (cnt & 1) == 0 ? x8 : x8_2;

                //  Set our test seed here so we can start
                //  working backwards to see if the rest
                //  of the information we were provided
                //  is a match.

                uint seed   = (x_test << 16) + (cnt & 0xFFFF);
                uint seedXD = (x_testXD << 16) + (cnt & 0xFFFF);

                var rng = new PokeRngR(seed);

                var  rngXD      = new XdRng(seedXD);
                var  rngXDR     = new XdRngR(seedXD);
                uint XDColoSeed = rngXDR.GetNext32BitNumber();

                //  Right now, this simply assumes method
                //  1 and gets the value previous to check
                //  for  match.  We need a clean way to do
                //  this for all of our methods.

                //  We have a max of 5 total RNG calls
                //  to make a pokemon and we already have
                //  one so lets go ahead and get 4 more.
                ushort rng1 = rng.GetNext16BitNumber();
                ushort rng2 = rng.GetNext16BitNumber();
                ushort rng3 = rng.GetNext16BitNumber();
                ushort rng4 = rng.GetNext16BitNumber();

                ushort rng1XD = rngXD.GetNext16BitNumber();
                ushort rng2XD = rngXD.GetNext16BitNumber();
                ushort rng3XD = rngXD.GetNext16BitNumber();
                ushort rng4XD = rngXD.GetNext16BitNumber();

                uint method1Seed = rng.Seed;

                rng.GetNext16BitNumber();
                uint method234Seed = rng.Seed;

                //  Check Method 1
                // [PID] [PID] [IVs] [IVs]
                // [rng3] [rng2] [rng1] [START]
                if (Check(rng1, rng2, rng3, hp, atk, def, nature))
                {
                    //  Build a seed to add to our collection
                    var newSeed = new Seed
                    {
                        Method      = "Method 1",
                        Pid         = ((uint)rng2 << 16) + rng3,
                        MonsterSeed = method1Seed
                    };

                    seeds.Add(newSeed);
                }
            }

            //  Now we want to start with IV2 and call the RNG for
            //  values between 0 and FFFF in the low order bits.
            for (uint cnt = 0xFFFF; cnt <= 0x1FFFE; cnt++)
            {
                uint x_test;
                uint x_testXD;

                //  We want to test with the high bit
                //  both set and not set, so we're going
                //  to sneakily do them both.  god help
                //  me if i ever have to figure this out
                //  in the future.
                x_test = (cnt & 1) == 0 ? x4 : x4_2;

                x_testXD = (cnt & 1) == 0 ? x8 : x8_2;

                //  Set our test seed here so we can start
                //  working backwards to see if the rest
                //  of the information we were provided
                //  is a match.

                uint seed   = (x_test << 16) + ((cnt + 1) & 0xFFFF);
                uint seedXD = (x_testXD << 16) + ((cnt + 1) & 0xFFFF);

                var rng = new PokeRngR(seed);

                var  rngXD      = new XdRng(seedXD);
                var  rngXDR     = new XdRngR(seedXD);
                uint XDColoSeed = rngXDR.GetNext32BitNumber();

                //  Right now, this simply assumes method
                //  1 and gets the value previous to check
                //  for  match.  We need a clean way to do
                //  this for all of our methods.

                //  We have a max of 5 total RNG calls
                //  to make a pokemon and we already have
                //  one so lets go ahead and get 4 more.
                ushort rng1 = rng.GetNext16BitNumber();
                ushort rng2 = rng.GetNext16BitNumber();
                ushort rng3 = rng.GetNext16BitNumber();
                ushort rng4 = rng.GetNext16BitNumber();

                ushort rng1XD = rngXD.GetNext16BitNumber();
                ushort rng2XD = rngXD.GetNext16BitNumber();
                ushort rng3XD = rngXD.GetNext16BitNumber();
                ushort rng4XD = rngXD.GetNext16BitNumber();

                uint method1Seed = rng.Seed;

                rng.GetNext16BitNumber();
                uint method234Seed = rng.Seed;

                //  Check Method 1
                // [PID] [PID] [IVs] [IVs]
                // [rng3] [rng2] [rng1] [START]
                if (Check(rng1, rng2, rng3, hp, atk, def, nature))
                {
                    //  Build a seed to add to our collection
                    var newSeed = new Seed
                    {
                        Method      = "Method 1",
                        Pid         = ((uint)rng2 << 16) + rng3,
                        MonsterSeed = method1Seed
                    };

                    seeds.Add(newSeed);
                }
            }

            return(seeds);
        }
Пример #9
0
        public static List <Seed> GetSeeds(
            uint hp,
            uint atk,
            uint def,
            uint spa,
            uint spd,
            uint spe,
            uint nature,
            uint id)
        {
            var seeds = new List <Seed>();

            uint x4   = spe + (spa << 5) + (spd << 10);
            uint x4_2 = x4 ^ 0x8000;

            uint x8   = hp + (atk << 5) + (def << 10);
            uint x8_2 = x8 ^ 0x8000;

            //  Now we want to start with IV2 and call the RNG for
            //  values between 0 and FFFF in the low order bits.
            for (uint cnt = 0; cnt <= 0xFFFE; cnt++)
            {
                uint x_test;
                uint x_testXD;

                //  We want to test with the high bit
                //  both set and not set, so we're going
                //  to sneakily do them both.  god help
                //  me if i ever have to figure this out
                //  in the future.
                x_test = (cnt & 1) == 0 ? x4 : x4_2;

                x_testXD = (cnt & 1) == 0 ? x8 : x8_2;

                //  Set our test seed here so we can start
                //  working backwards to see if the rest
                //  of the information we were provided
                //  is a match.

                uint seed   = (x_test << 16) + cnt;
                uint seedXD = (x_testXD << 16) + cnt;
                var  rng    = new PokeRngR(seed);

                var  rngXD      = new XdRng(seedXD);
                var  rngXDR     = new XdRngR(seedXD);
                uint XDColoSeed = rngXDR.GetNext32BitNumber();

                //  Right now, this simply assumes method
                //  1 and gets the value previous to check
                //  for  match.  We need a clean way to do
                //  this for all of our methods.

                //  We have a max of 5 total RNG calls
                //  to make a pokemon and we already have
                //  one so lets go ahead and get 4 more.
                ushort rng1 = rng.GetNext16BitNumber();
                ushort rng2 = rng.GetNext16BitNumber();
                ushort rng3 = rng.GetNext16BitNumber();
                ushort rng4 = rng.GetNext16BitNumber();

                ushort rng1XD = rngXD.GetNext16BitNumber();
                ushort rng2XD = rngXD.GetNext16BitNumber();
                ushort rng3XD = rngXD.GetNext16BitNumber();
                ushort rng4XD = rngXD.GetNext16BitNumber();

                uint method1Seed = rng.Seed;

                rng.GetNext16BitNumber();
                uint   method234Seed = rng.Seed;
                ushort choppedPID;

                //  Check Method 1
                // [PID] [PID] [IVs] [IVs]
                // [rng3] [rng2] [rng1] [START]
                if (Check(rng1, rng2, rng3, hp, atk, def, nature))
                {
                    //  Build a seed to add to our collection
                    var newSeed = new Seed();
                    newSeed.Method      = "Method 1";
                    newSeed.Pid         = ((uint)rng2 << 16) + rng3;
                    newSeed.MonsterSeed = method1Seed;
                    newSeed.Sid         = (rng2 ^ (uint)rng3 ^ id) & 0xFFF8;

                    seeds.Add(newSeed);
                }

                //  Check Wishmkr
                // [PID] [PID] [IVs] [IVs]
                // [rng3] [rng2] [rng1] [START]
                if (Check(rng1, rng3, rng2, hp, atk, def, nature))
                {
                    if (method1Seed < 0x10000)
                    {
                        //  Build a seed to add to our collection
                        var newSeed = new Seed();
                        newSeed.Pid         = ((uint)rng3 << 16) + rng2;
                        newSeed.MonsterSeed = method1Seed;
                        newSeed.Sid         = (rng2 ^ (uint)rng3 ^ id) & 0xFFF8;
                        if (Functions.Shiny(newSeed.Pid, 20043, 0))
                        {
                            newSeed.Method = "Wishmkr Shiny";
                        }
                        else
                        {
                            newSeed.Method = "Wishmkr";
                        }
                        seeds.Add(newSeed);
                    }
                }

                //  Check Method 2
                // [PID] [PID] [xxxx] [IVs] [IVs]
                // [rng4] [rng3] [xxxx] [rng1] [START]
                if (Check(rng1, rng3, rng4, hp, atk, def, nature))
                {
                    //  Build a seed to add to our collection
                    var newSeed = new Seed
                    {
                        Method      = "Method 2",
                        Pid         = ((uint)rng3 << 16) + rng4,
                        MonsterSeed = method234Seed,
                        Sid         = (rng3 ^ (uint)rng4 ^ id) & 0xFFF8
                    };

                    seeds.Add(newSeed);
                }

                /*
                 * Removed because Method 3 doesn't exist in-game
                 * //  Check Method 3
                 * //  [PID] [xxxx] [PID] [IVs] [IVs]
                 * //  [rng4] [xxxx] [rng2] [rng1] [START]
                 * if (Check(rng1, rng2, rng4, hp, atk, def, nature))
                 * {
                 *  //  Build a seed to add to our collection
                 *  Seed newSeed = new Seed();
                 *  newSeed.Method = "Method 3";
                 *  newSeed.Pid = ((uint)rng2 << 16) + (uint)rng4;
                 *  newSeed.MonsterSeed = method234Seed;
                 *  newSeed.Sid = ((uint)rng2 ^ (uint)rng4 ^ id) & 0xFFF8;
                 *
                 *  seeds.Add(newSeed);
                 * }
                 */

                //  Check Method 4
                //  [PID] [PID] [IVs] [xxxx] [IVs]
                //  [rng4] [rng3] [rng2] [xxxx] [START]
                if (Check(rng2, rng3, rng4, hp, atk, def, nature))
                {
                    //  Build a seed to add to our collection
                    var newSeed = new Seed
                    {
                        Method      = "Method 4",
                        Pid         = ((uint)rng3 << 16) + rng4,
                        MonsterSeed = method234Seed,
                        Sid         = (rng3 ^ (uint)rng4 ^ id) & 0xFFF8
                    };

                    seeds.Add(newSeed);
                }

                //  Check Colosseum\XD
                // [IVs] [IVs] [xxx] [PID] [PID]
                // [START] [rng1] [rng3]

                if (Check(rng1XD, rng3XD, rng4XD, spe, spa, spd, nature))
                {
                    var newSeed = new Seed
                    {
                        Method      = "Colosseum/XD",
                        Pid         = ((uint)rng3XD << 16) + rng4XD,
                        MonsterSeed = XDColoSeed,
                        Sid         = (rng4XD ^ (uint)rng3XD ^ id) & 0xFFF8
                    };


                    seeds.Add(newSeed);
                }

                if (rng3 / 0x5556 != 0)
                {
                    //  Check DPPt Cute Charm
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 / 0xA3E);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (DPPt)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check DPPt Cute Charm (50% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 / 0xA3E + 0x96);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (DPPt)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check DPPt Cute Charm (25% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 / 0xA3E + 0xC8);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (DPPt)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check DPPt Cute Charm (75% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 / 0xA3E + 0x4B);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (DPPt)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check DPPt Cute Charm (87.5% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 / 0xA3E + 0x32);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (DPPt)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }
                }

                if (rng3 % 3 != 0)
                {
                    //  Check HGSS Cute Charm
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 % 25);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (HGSS)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check HGSS Cute Charm (50% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 % 25 + 0x96);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (HGSS)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check HGSS Cute Charm (25% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 % 25 + 0xC8);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (HGSS)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check HGSS Cute Charm (75% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 % 25 + 0x4B);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (HGSS)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check HGSS Cute Charm (87.5% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 % 25 + 0x32);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (HGSS)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }
                }
            }

            //  Now we want to start with IV2 and call the RNG for
            //  values between 0 and FFFF in the low order bits.
            for (uint cnt = 0xFFFF; cnt <= 0x1FFFE; cnt++)
            {
                uint x_test;
                uint x_testXD;

                //  We want to test with the high bit
                //  both set and not set, so we're going
                //  to sneakily do them both.  god help
                //  me if i ever have to figure this out
                //  in the future.
                x_test = (cnt & 1) == 0 ? x4 : x4_2;

                x_testXD = (cnt & 1) == 0 ? x8 : x8_2;

                //  Set our test seed here so we can start
                //  working backwards to see if the rest
                //  of the information we were provided
                //  is a match.

                uint seed   = (x_test << 16) + ((cnt + 1) & 0xFFFF);
                uint seedXD = (x_testXD << 16) + ((cnt + 1) & 0xFFFF);

                var rng = new PokeRngR(seed);

                var  rngXD      = new XdRng(seedXD);
                var  rngXDR     = new XdRngR(seedXD);
                uint XDColoSeed = rngXDR.GetNext32BitNumber();

                //  Right now, this simply assumes method
                //  1 and gets the value previous to check
                //  for  match.  We need a clean way to do
                //  this for all of our methods.

                //  We have a max of 5 total RNG calls
                //  to make a pokemon and we already have
                //  one so lets go ahead and get 4 more.
                ushort rng1 = rng.GetNext16BitNumber();
                ushort rng2 = rng.GetNext16BitNumber();
                ushort rng3 = rng.GetNext16BitNumber();
                ushort rng4 = rng.GetNext16BitNumber();

                ushort rng1XD = rngXD.GetNext16BitNumber();
                ushort rng2XD = rngXD.GetNext16BitNumber();
                ushort rng3XD = rngXD.GetNext16BitNumber();
                ushort rng4XD = rngXD.GetNext16BitNumber();

                uint method1Seed = rng.Seed;

                rng.GetNext16BitNumber();
                uint   method234Seed = rng.Seed;
                ushort choppedPID;

                //  Check Method 1
                // [PID] [PID] [IVs] [IVs]
                // [rng3] [rng2] [rng1] [START]
                if (Check(rng1, rng2, rng3, hp, atk, def, nature))
                {
                    //  Build a seed to add to our collection
                    var newSeed = new Seed();
                    newSeed.Method      = "Method 1";
                    newSeed.Pid         = ((uint)rng2 << 16) + rng3;
                    newSeed.MonsterSeed = method1Seed;
                    newSeed.Sid         = (rng2 ^ (uint)rng3 ^ id) & 0xFFF8;

                    seeds.Add(newSeed);
                }

                //  Check Wishmkr
                // [PID] [PID] [IVs] [IVs]
                // [rng3] [rng2] [rng1] [START]
                if (Check(rng1, rng3, rng2, hp, atk, def, nature))
                {
                    if (method1Seed < 0x10000)
                    {
                        //  Build a seed to add to our collection
                        var newSeed = new Seed();
                        newSeed.Pid         = ((uint)rng3 << 16) + rng2;
                        newSeed.MonsterSeed = method1Seed;
                        newSeed.Sid         = (rng2 ^ (uint)rng3 ^ id) & 0xFFF8;
                        if (Functions.Shiny(newSeed.Pid, 20043, 0))
                        {
                            newSeed.Method = "Wishmkr Shiny";
                        }
                        else
                        {
                            newSeed.Method = "Wishmkr";
                        }
                        seeds.Add(newSeed);
                    }
                }

                //  Check Method 2
                // [PID] [PID] [xxxx] [IVs] [IVs]
                // [rng4] [rng3] [xxxx] [rng1] [START]
                if (Check(rng1, rng3, rng4, hp, atk, def, nature))
                {
                    //  Build a seed to add to our collection
                    var newSeed = new Seed
                    {
                        Method      = "Method 2",
                        Pid         = ((uint)rng3 << 16) + rng4,
                        MonsterSeed = method234Seed,
                        Sid         = (rng3 ^ (uint)rng4 ^ id) & 0xFFF8
                    };

                    seeds.Add(newSeed);
                }

                /*
                 * Removed because Method 3 doesn't exist in-game
                 * //  Check Method 3
                 * //  [PID] [xxxx] [PID] [IVs] [IVs]
                 * //  [rng4] [xxxx] [rng2] [rng1] [START]
                 * if (Check(rng1, rng2, rng4, hp, atk, def, nature))
                 * {
                 *  //  Build a seed to add to our collection
                 *  Seed newSeed = new Seed();
                 *  newSeed.Method = "Method 3";
                 *  newSeed.Pid = ((uint)rng2 << 16) + (uint)rng4;
                 *  newSeed.MonsterSeed = method234Seed;
                 *  newSeed.Sid = ((uint)rng2 ^ (uint)rng4 ^ id) & 0xFFF8;
                 *
                 *  seeds.Add(newSeed);
                 * }
                 */

                //  Check Method 4
                //  [PID] [PID] [IVs] [xxxx] [IVs]
                //  [rng4] [rng3] [rng2] [xxxx] [START]
                if (Check(rng2, rng3, rng4, hp, atk, def, nature))
                {
                    //  Build a seed to add to our collection
                    var newSeed = new Seed
                    {
                        Method      = "Method 4",
                        Pid         = ((uint)rng3 << 16) + rng4,
                        MonsterSeed = method234Seed,
                        Sid         = (rng3 ^ (uint)rng4 ^ id) & 0xFFF8
                    };

                    seeds.Add(newSeed);
                }

                //  Check Colosseum\XD
                // [IVs] [IVs] [xxx] [PID] [PID]
                // [START] [rng1] [rng3]

                if (Check(rng1XD, rng3XD, rng4XD, spe, spa, spd, nature))
                {
                    var newSeed = new Seed
                    {
                        Method      = "Colosseum/XD",
                        Pid         = ((uint)rng3XD << 16) + rng4XD,
                        MonsterSeed = XDColoSeed,
                        Sid         = (rng4XD ^ (uint)rng3XD ^ id) & 0xFFF8
                    };


                    seeds.Add(newSeed);
                }

                if (rng3 / 0x5556 != 0)
                {
                    //  Check DPPt Cute Charm
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 / 0xA3E);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (DPPt)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check DPPt Cute Charm (50% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 / 0xA3E + 0x96);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (DPPt)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check DPPt Cute Charm (25% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 / 0xA3E + 0xC8);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (DPPt)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check DPPt Cute Charm (75% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 / 0xA3E + 0x4B);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (DPPt)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check DPPt Cute Charm (87.5% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 / 0xA3E + 0x32);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (DPPt)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }
                }

                if (rng3 % 3 != 0)
                {
                    //  Check HGSS Cute Charm
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 % 25);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (HGSS)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check HGSS Cute Charm (50% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 % 25 + 0x96);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (HGSS)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check HGSS Cute Charm (25% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 % 25 + 0xC8);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (HGSS)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check HGSS Cute Charm (75% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 % 25 + 0x4B);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (HGSS)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }

                    //  Check HGSS Cute Charm (87.5% male)
                    //  [CC Check] [PID] [IVs] [IVs]
                    //  [rng3] [rng2] [rng1] [START]

                    choppedPID = (ushort)(rng2 % 25 + 0x32);
                    if (Check(rng1, 0, choppedPID, hp, atk, def, nature))
                    {
                        var newSeed = new Seed
                        {
                            Method      = "Cute Charm (HGSS)",
                            Pid         = choppedPID,
                            MonsterSeed = method1Seed,
                            Sid         = (choppedPID ^ id) & 0xFFF8
                        };


                        seeds.Add(newSeed);
                    }
                }
            }

            return(seeds);
        }
Пример #10
0
        //  Add a list new Pokemon and do the breakdown
        public void Add(
            uint hp,
            uint atk,
            uint def,
            uint spa,
            uint spd,
            uint spe,
            Nature nature,
            string ability,
            GenderGenderRatio gender)
        {
            string ivs = hp + " / " + atk + " / " + def + " / " + spa + " / " + spd + " / " + spe;
            Pokemon.Add(new CalculateChainSidPokemon(ivs, nature.Name, ability, gender.ShortName));

            // Build the block for the 2nd IV here.
            uint iv2 = spe + (spa << 5) + (spd << 10);
            uint iv2set = iv2 ^ 0x8000;

            uint iv1 = hp + (atk << 5) + (def << 10);
            uint iv1set = iv1 ^ 0x8000;

            var candidatePids = new List<CandidatePid>();

            //  Now we want to start with IV2 and call the RNG for
            //  values between 0 and FFFF in the low order bits.
            for (uint cnt = 0; cnt <= 0x1FFFE; cnt++)
            {
                uint iv2_test;

                //  We want to test with the high bit
                //  both set and not set, so we're going
                //  to sneakily do them both.  god help
                //  me if i ever have to figure this out
                //  in the future.
                iv2_test = (cnt & 1) == 0 ? iv2 : iv2set;

                //  Set our test seed here so we can start
                //  working backwards to see if the rest
                //  of the information we were provided
                //  is a match.

                uint seed = (iv2_test << 16) + (cnt%0xFFFF);

                var rng = new PokeRngR(seed);

                uint iv1_rng = rng.GetNext16BitNumber();

                //  Check for a canididate here
                if (iv1_rng == iv1 || iv1_rng == iv1set)
                {
                    //  Get the whole adjust number in a loop
                    uint adjust = 0x0;

                    for (int adjustCnt = 0; adjustCnt < 13; adjustCnt++)
                    {
                        uint adjustRng = rng.GetNext16BitNumber()%2U;
                        adjust |= (adjustRng << (15 - adjustCnt));
                    }

                    //  Get what we think was the initial PID
                    uint pid2 = rng.GetNext16BitNumber(); //  HIGHID
                    uint pid1 = rng.GetNext16BitNumber(); //  LOWID

                    uint adjustedLow = adjust | (pid1 & 7);

                    uint abilityNumber = adjustedLow%0x2;
                    uint genderNumber = adjustedLow & 0xFF;

                    // lol make this not suck
                    if ((ability == "Single Ability" ||
                         (
                             (abilityNumber == 0 && ability == "Ability 0") ||
                             (abilityNumber == 1 && ability == "Ability 1")
                         )) &&
                        gender.Matches(genderNumber))
                    {
                        var candidatePid = new CandidatePid {AdjustedLow = adjustedLow, NaturalHigh = pid2};
                        candidatePids.Add(candidatePid);
                    }
                }
            }

            var newSids = new List<uint>();

            foreach (uint sid in CandidateSids)
            {
                //  Check each candiate pid that we found for the
                //  IV values and then see if the final PID with
                //  a particular nature/gender is a match.  If so
                //  we can go ahead and add the sid to the new
                //  list and exit early.
                foreach (CandidatePid candidatePid in candidatePids)
                {
                    //  Build our full adjusted PID
                    uint adjustedHigh = candidatePid.AdjustedLow ^ Id ^ sid;
                    adjustedHigh &= 0xFFF8;
                    adjustedHigh += (candidatePid.NaturalHigh & 7);

                    //  for testing out the nature comparison
                    uint pid = (adjustedHigh << 16) + candidatePid.AdjustedLow;

                    //  If any of them work, we will add this to
                    //  the new candidateSids list and break to
                    //  go to the next seed.  Check the nature.
                    uint pidNature = pid%25;

                    if (nature.Number == pidNature)
                    {
                        newSids.Add(sid);
                        break;
                    }
                }
            }

            CandidateSids = newSids;
        }