Prev() public method

public Prev ( ) : uint
return uint
Ejemplo n.º 1
0
        public static bool GenerateIVs( ushort natid, uint pid, int iv1, int iv2, int hometown, bool checknature, bool palpark )
        {
            bool matches = false;

            uint slow = ( pid & 0xFFFF ) << 0x10;
            uint shigh = (uint)(pid & ~0xFFFF) >> 0x10;

            uint elow = ( pid & 0xFFFF );
            uint ehigh = (uint)(pid & ~0xFFFF);

            PokePRNG rand = new PokePRNG();
            for ( uint j = 0; j < 0x10000; j++ )
            {
                bool validnature = false;

                rand.Seed = slow + j;
                if ( ( rand.NextNum() >> 0x10 ) == shigh ) // A-B
                {
                    //Console.WriteLine( "Seed: {0:X}", A );
                    int C = (int)rand.SetNext().HighBits & 0x7FFF;
                    int D = (int)rand.SetNext().HighBits & 0x7FFF;
                    int E = (int)rand.SetNext().HighBits & 0x7FFF;
                    int F = (int)rand.SetNext().HighBits & 0x7FFF;

                    //Console.WriteLine( "AB-C: {0:X}\nAB-D: {1:X}\nAB-E: {2:X}\nAB-F: {3:X}", C,D,E,F );

                    validnature = checknature && IsLegal( iv1, iv2, C, D ) && ValidNature( slow + j, pid % 25 );

                    if ( palpark )
                    {
                        if ( IsLegal( iv1, iv2, C, D ) ) //Normal Pokemon
                        {
                            WriteType( GetABGBAIVType( 3, 4 ) );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, C, E ) ) //Normal GBA
                        {
                            WriteType( GetABGBAIVType( 3, 5 ) );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, C, F ) )
                        {
                            WriteType( GetABGBAIVType( 3, 6 ) );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, D, E ) ) //Normal
                        {
                            Console.WriteLine( "Seed Found: {0:X8}", new PokePRNG( slow + j ).Prev() );
                            WriteType( GetABGBAIVType( 4, 5 ) );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, D, F ) ) //Rare GBA
                        {
                            WriteType( GetABGBAIVType( 4, 6 ) );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, E, F ) ) //Ultra Rare GBA
                        {
                            WriteType( GetABGBAIVType( 5, 6 ) );
                            matches = true;
                        }

                        if ( ( hometown == 1 || hometown == 2 || hometown == 4 || hometown == 5 ) && ( IsRoaming( C, iv1, iv2 ) || IsRoaming( D, iv1, iv2 ) || IsRoaming( E, iv1, iv2 ) ) )
                        {
                            WriteType( "Roaming GBA" );
                            matches = true;
                        }
                    }
                    else
                    {
                        if ( IsLegal( iv1, iv2, C, D ) ) //Normal Pokemon
                        {
                            string message = GetABNDSIVType( 3, 4 );
                            if ( checknature )
                                WriteSyncType( message, validnature );
                            else
                                WriteType( message );
                            matches = true;
                        }
                    }
                }
                else if ( palpark && ( rand.NextNum() >> 0x10 ) == shigh ) //A-C
                {
                    int D = (int)rand.SetNext().HighBits & 0x7FFF;
                    int E = (int)rand.SetNext().HighBits & 0x7FFF;
                    int F = (int)rand.SetNext().HighBits & 0x7FFF;

                    if ( IsLegal( iv1, iv2, D, E ) )
                    {
                        WriteType( GetACIVType( 4, 5 ) );
                        matches = true;
                    }

                    if ( IsLegal( iv1, iv2, D, F ) )
                    {
                        WriteType( GetACIVType( 4, 6 ) );
                        matches = true;
                    }

                    if ( IsLegal( iv1, iv2, E, F ) )
                    {
                        WriteType( GetACIVType( 5, 6 ) );
                        matches = true;
                    }

                    if ( ( hometown == 1 || hometown == 2 || hometown == 4 || hometown == 5 ) && ( IsRoaming( D, iv1, iv2 ) || IsRoaming( E, iv1, iv2 ) ) )
                    {
                        WriteType( "Roaming GBA [Theoretical]" );
                        matches = true;
                    }
                }
                else if ( palpark && ( rand.NextNum() >> 0x10 ) == shigh ) //A-D
                {
                    int E = (int)rand.SetNext().HighBits & 0x7FFF;
                    int F = (int)rand.SetNext().HighBits & 0x7FFF;

                    validnature = checknature && IsLegal( iv1, iv2, E, F ) && ValidNature( slow + j, pid % 25 );

                    if ( IsLegal( iv1, iv2, E, F ) )
                    {
                        WriteType( GetADIVType( 5, 6 ) );
                        matches = true;
                    }

                    if ( ( hometown == 1 || hometown == 2 || hometown == 4 || hometown == 5 ) && IsRoaming( E, iv1, iv2 ) )
                    {
                        WriteType( "Roaming GBA [Theoretical]" );
                        matches = true;
                    }
                }

                rand.Seed = ehigh + j;
                bool rest = rand.Prev() <= 0xFFFF;
                if ( ( rand.NextNum() >> 0x10 ) == elow ) // B-A (Events)
                {
                    int C = (int)rand.SetNext().HighBits & 0x7FFF;
                    int D = (int)rand.SetNext().HighBits & 0x7FFF;
                    int E = (int)rand.SetNext().HighBits & 0x7FFF;
                    int F = (int)rand.SetNext().HighBits & 0x7FFF;

                    if ( palpark && natid == 201 && ( hometown == 4 || hometown == 5 ) ) //unown
                    {
                        if ( IsLegal( iv1, iv2, C, D ) )
                        {
                            WriteType( GetUnownIVType( 3, 4 ) );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, C, E ) )
                        {
                            WriteType( GetUnownIVType( 3, 5 ) );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, C, F ) )
                        {
                            WriteType( GetUnownIVType( 3, 6 ) );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, D, E ) )
                        {
                            WriteType( GetUnownIVType( 4, 5 ) );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, D, F ) )
                        {
                            WriteType( GetUnownIVType( 4, 6 ) );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, E, F ) )
                        {
                            WriteType( GetUnownIVType( 5, 6 ) );
                            matches = true;
                        }
                    }
                    else
                    {
                        if ( IsLegal( iv1, iv2, C, D ) )
                        {
                            WriteEventType( GetBAIVType( 3, 4 ), rest );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, C, E ) )
                        {
                            WriteEventType( GetBAIVType( 3, 5 ), rest );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, C, F ) )
                        {
                            WriteEventType( GetBAIVType( 3, 6 ), rest );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, D, E ) )
                        {
                            WriteEventType( GetBAIVType( 4, 5 ), rest );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, D, F ) )
                        {
                            WriteEventType( GetBAIVType( 4, 6 ), rest );
                            matches = true;
                        }

                        if ( IsLegal( iv1, iv2, E, F ) )
                        {
                            WriteEventType( GetBAIVType( 5, 6 ), rest );
                            matches = true;
                        }
                    }

                }
            }

            return matches;
        }