private uint ShinyPID( PokePRNG rand ) { uint subID = ( TID ^ SID ) >> 0x3; uint low6 = rand.SetNext().HighBits & 0x7; uint high5 = rand.SetNext().HighBits & 0x7; for( int i = 0; i < 13; i++ ) { bool subidcheck = (subID & (1<<i)) != 0; bool randcheck = (rand.SetNext().HighBits & 0x1) != 0; if ( randcheck ) low6 |= ( 1u << ( i + 3 ) ); if ( randcheck != subidcheck ) high5 |= ( 1u << ( i + 3 ) ); } return ( high5 << 0x10 ) | low6; }
public static bool IsValidNature( uint pid1seed, uint nature ) { PokePRNG rand = new PokePRNG( pid1seed ); //PID_LOW (FULL SEED) bool cont = true; do { uint newseed = rand.PrevNum(); //POSSIBLE SEED POINTER uint newhigh = rand.SetPrev().HighBits; //PID2 uint newlow = rand.SetPrev().HighBits; //PID1 uint newpid = ( newhigh << 0x10 ) | newlow; if ( (newseed / 0xA3E) == nature || (newseed >> 15 == 0) ) return true; else if ( (newpid % 25) == nature ) cont = false; } while ( cont ); return false; }
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 ChainedPID( uint iv1, uint iv2, uint tid, uint sid, uint realpid ) { PokePRNG rand = new PokePRNG(0); 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 ) { //Console.WriteLine( "Seed Found: {0:X}", seed ); for( int j = 0; j < 16; j++ ) rand.PrevNum(); uint natseed = rand.Seed; //Console.WriteLine( "Modified Seed: {0:X}", rand.Seed ); uint pid = ShinyPID( tid, sid, rand ); //Console.WriteLine( "Found PID: {0:X}", pid ); if ( realpid == pid ) { bool validnature = ValidNature( natseed, realpid % 25 ); Console.Write( "Chained Sync: " ); if ( validnature ) { PushColor( ConsoleColor.DarkGreen ); Console.WriteLine( "Valid" ); } else { PushColor( ConsoleColor.Red ); Console.WriteLine( "Invalid" ); } PopColor(); return true; } } } } return false; }
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 ValidGlitchZig( uint pid, uint tid, int oivs1, int oivs2 ) { PokePRNG rand = new PokePRNG(); for ( uint i = 0; i < 2; ++i ) { for ( uint j = 0; j < 0x10000; j++ ) { rand.Seed = (i << 31) + ((uint)oivs2 << 16) + j; uint iv1 = rand.Seed; uint second = ( rand.SetPrev().Seed >> 0x10 ) & 0x7FFF; uint iv2 = rand.Seed; if ( second == (uint)oivs1 ) { uint afull = rand.PrevNum(); //Variance uint a = rand.HighBits; uint bfull = rand.PrevNum(); //Unknown (Gender Check?) uint b = rand.HighBits; uint cfull = rand.PrevNum(); //High PID uint c = rand.HighBits; uint dfull = rand.PrevNum(); //Seed uint d = rand.HighBits; if ( d == 0 && (dfull & 0xFFFF) <= 0xFF ) { uint calcshiny = c ^ tid ^ 0; uint var = ( ( calcshiny ^ a ) & 0x7 ); uint calclowpid = calcshiny ^ var; if ( ( ( c << 0x10 ) | calclowpid ) == pid ) 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; }
public static uint ShinyPID( uint tid, uint sid, PokePRNG rand ) { uint subID = ( tid ^ sid ) >> 0x3; uint low6 = rand.SetNext().HighBits & 0x7; uint high5 = rand.SetNext().HighBits & 0x7; //Console.WriteLine( "Low6: {0:X}\nHigh5: {1:X}", low6, high5 ); for( int i = 0; i < 13; i++ ) { bool subidcheck = (subID & (1<<i)) != 0; bool randcheck = (rand.SetNext().HighBits & 0x1) != 0; if ( randcheck ) low6 |= ( 1u << ( i + 3 ) ); if ( randcheck != subidcheck ) high5 |= ( 1u << ( i + 3 ) ); } return ( high5 << 0x10 ) | low6; }