public override bool IsValidAlgorithm( out string message ) { if ( IsEgg && IsValidEggLocation() ) { message = "Valid Egg"; return true; } if ( IsHatched && uint plow = ( PID & 0xFFFF ) << 0x10; uint phigh = (uint)(PID & ~0xFFFF) >> 0x10; bool valid = false; PokePRNG rand = new PokePRNG(); for ( uint j = 0;j < 0x10000; j++ ) { rand.Seed = plow + j; if ( ( rand.NextNum() >> 0x10 ) == phigh ) // A-B { int C = (int)rand.SetNext().HighBits & 0x7FFF; int D = (int)rand.SetNext().HighBits & 0x7FFF; if ( Utility.IsIVMatch( iv1, iv2, C, D ) ) { valid = true; message = "NDS (A-B-C-D)"; if ( RequiresSyncCheck ) { m_ValidSync = IsValidNature( plow + j, PID % 25 ) ); if ( m_ValidSync ) break; } } } } if ( !valid && (HomeTown == 10 || HomeTown == 11) && IsShiny() && IsGrassWild() && Location != 48 ) //Check for chaining! ~ Not in Eterna Forest { PokePRNG rand = new PokePRNG(); uint iv1 = IV1; uint iv2 = IV2; uint highbits = iv1 << 0x10; for ( uint k = 0;k < 2; k++ ) { for( uint i = 0; i < 0x10000; i++ ) { uint seed = ( k << 31 ) + highbits + i; rand.Seed = seed; if ( ( ( rand.Next() >> 0x10 ) & 0x7FFF ) == iv2 ) { for( int j = 0; j < 16; j++ ) rand.PrevNum(); uint natseed = rand.Seed; uint pid = ShinyPID( rand ); if ( realpid == pid ) { valid = true; message = "Chain Shiny"; m_RequiresSyncCheck = false; } } } } } if ( !valid ) message = "Invalid"; return valid; }
public static bool IsABCD( uint pid, int iv1, int iv2, out uint intseed ) { intseed = 0; uint slow = ( pid & 0xFFFF ) << 0x10; uint shigh = (uint)(pid & ~0xFFFF) >> 0x10; PokePRNG rand = new PokePRNG(); for ( uint j = 0; j < 0x10000; j++ ) { uint A = slow + j; rand.Seed = A; intseed = slow + j; if ( ( rand.NextNum() >> 0x10 ) == shigh ) { int C = (int)rand.SetNext().HighBits & 0x7FFF; int D = (int)rand.SetNext().HighBits & 0x7FFF; if ( IsLegal( iv1, iv2, C, D ) ) return true; } } return false; }
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; }