Jump to content

Recommended Posts

Posted

With the help of SCV I was able to start calculating a PID in my program. It works fine, but when I try to make it shiny, it takes a very long time to calculate it, compared to how in Pokesav it is instant.

Video to show how slow it is.

[video=youtube;Ry6HR_6u9bk]

Here is my code.

           Random random = new Random();
           UInt32 RandomPID = 0, RandomPIDHigh = 0, RandomPIDLow = 0;
           UInt32 PIDcount = 0;
           bool NatureBool = true, AbilityBool = true, GenderBool = true, ShinyBool = true, UnownBool = true;

           while (NatureBool || AbilityBool || GenderBool || ShinyBool || UnownBool)
           {
               RandomPIDHigh = Convert.ToUInt32(random.Next(0xFFFF));
               RandomPIDLow = Convert.ToUInt32(random.Next(0xFFFF));
               RandomPID = (RandomPIDHigh * 0x10000) + RandomPIDLow;

               //Nature
               if ((RandomPID % 25 == NatureNumber))
               {
                   NatureBool = false;
               }
               else
               {
                   NatureBool = true;
               }

               //AbilityCheck
               if (1 < comboBox_Ability.Items.Count)
               {
                   //Ability
                   if (RandomPID % 2 == comboBox_Ability.SelectedIndex)
                   {
                       AbilityBool = false;
                   }
                   else
                   {
                       AbilityBool = true;
                   }
               }
               else
               {
                   AbilityBool = false;
               }

               //GenderCheck
               if (GenderRatio != "Male0_Female1" || GenderRatio != "Male1_Female0" || GenderRatio != "Genderless")
               {
                   //GenderCheck2
                   if (radioButton_GenderMale.Checked)
                   {
                       //Gender (Male)
                       if (RandomPID % 256 >= GenderNumber)
                       {
                           GenderBool = false;
                       }
                       else
                       {
                           GenderBool = true;
                       }
                   }
                   else
                   {
                       //Gender (Female)
                       if (RandomPID % 256 <= GenderNumber)
                       {
                           GenderBool = false;
                       }
                       else
                       {
                           GenderBool = true;
                       }
                   }
               }
               else
               {
                   GenderBool = false;
               }

               //ShinyCheck
               if (checkBox_Shiny.Checked)
               {
                   //Shiny
                   if ((RandomPIDHigh ^ RandomPIDLow ^ Convert.ToInt32(textBox_TrainerID.Text) ^ Convert.ToInt32(textBox_SecretID.Text)) < 8)
                   {
                       ShinyBool = false;
                   }
                   else
                   {
                       ShinyBool = true;
                   }
               }
               else
               {
                   ShinyBool = false;
               }

               //UnownCheck
               if (comboBox_Pokemon.Text == "UNOWN")
               {
                   //UnownShape
                   if (true)
                   {
                       UnownBool = false;
                   }
                   else
                   {
                       UnownBool = true;
                   }
               }
               else
               {
                   UnownBool = false;
               }

               PIDcount += 1;
               textBox1.Text = PIDcount.ToString();
               this.Update();
           }

           textBox_PID.Text = RandomPID.ToString();

Posted

There is no IV checking at all. All it checks for are if the random pid generated in each loop matches for the selected nature, ability number if more than 1 ability, gender if it has 2 genders, if it is shiny if the shiny box is checked, and eventually if i can figure it out, if it has the desired Unown shape if its an Unown.

Posted

I'm sure Pokesav doesn't keep cycling through random PIDs until one works. Most likely takes a randomly generated 32-bit number and modifies it so it fits the requirements.

What you could try is the chained shiny PID generation method. Make a random call to generate the lower 16 bits of the PID, then create an upper 16 bits that makes the whole Pokemon shiny. Since the last three bits of each 16-bit piece doesn't matter to shininess, you can modify them until the Pokemon has the nature you want. Then, if you can't get it shiny AND the right nature, throw it out.

Posted
That won't work for every Pokémon though, right? Like Pokémon that can't be encountered using the PokéRadar?

If he just needs to generate a shiny PID with no regard for whether it's valid or not, then the chained shiny algorithm is fast and works for his purposes.

Kazo, what does the code look like now?

Posted
If he just needs to generate a shiny PID with no regard for whether it's valid or not, then the chained shiny algorithm is fast and works for his purposes.

Kazo, what does the code look like now?

Random random = new Random();
           UInt32 RandomPID = 0, RandomPIDHigh = 0, RandomPIDLow = 0;
           bool NatureBool = true, AbilityBool = true, GenderBool = true, ShinyBool = true, UnownBool = true;

           while (NatureBool || AbilityBool || GenderBool || ShinyBool || UnownBool)
           {
               RandomPIDLow = Convert.ToUInt32(random.Next(0xFFFF));

               if (checkBox_Shiny.Checked)
               {
                   RandomPIDHigh = Convert.ToUInt32(RandomPIDLow ^ Convert.ToInt32(textBox_TrainerID.Text) ^ Convert.ToInt32(textBox_SecretID.Text));
               }
               else
               {
                   RandomPIDHigh = Convert.ToUInt32(random.Next(0xFFFF));
               }

                   RandomPID = (RandomPIDHigh * 0x10000) + RandomPIDLow;

               //Nature
               if ((RandomPID % 25 == NatureNumber))
               {
                   NatureBool = false;
               }
               else
               {
                   NatureBool = true;
               }

               //AbilityCheck
               if (1 < comboBox_Ability.Items.Count)
               {
                   //Ability
                   if (RandomPID % 2 == comboBox_Ability.SelectedIndex)
                   {
                       AbilityBool = false;
                   }
                   else
                   {
                       AbilityBool = true;
                   }
               }
               else
               {
                   AbilityBool = false;
               }

               //GenderCheck
               if ((GenderRatio != "Male0_Female1") && (GenderRatio != "Male1_Female0") && (GenderRatio != "Genderless"))
               {
                   //GenderCheck2
                   if (radioButton_GenderMale.Checked)
                   {
                       //Gender (Male)
                       if (RandomPID % 256 >= GenderNumber)
                       {
                           GenderBool = false;
                       }
                       else
                       {
                           GenderBool = true;
                       }
                   }
                   else
                   {
                       //Gender (Female)
                       if (RandomPID % 256 <= GenderNumber)
                       {
                           GenderBool = false;
                       }
                       else
                       {
                           GenderBool = true;
                       }
                   }
               }
               else
               {
                   GenderBool = false;
               }

               //ShinyCheck
               if (checkBox_Shiny.Checked)
               {
                   //Shiny
                   if ((RandomPIDHigh ^ RandomPIDLow ^ Convert.ToInt32(textBox_TrainerID.Text) ^ Convert.ToInt32(textBox_SecretID.Text)) < 8)
                   {
                       ShinyBool = false;
                   }
                   else
                   {
                       ShinyBool = true;
                   }
               }
               else
               {
                   //Shiny
                   if ((RandomPIDHigh ^ RandomPIDLow ^ Convert.ToInt32(textBox_TrainerID.Text) ^ Convert.ToInt32(textBox_SecretID.Text)) < 8)
                   {
                       ShinyBool = true;
                   }
                   else
                   {
                       ShinyBool = false;
                   }
               }

               //UnownCheck
               if (comboBox_Pokemon.Text == "UNOWN")
               {
                   //UnownShape
                   if (true)
                   {
                       UnownBool = false;
                   }
                   else
                   {
                       UnownBool = true;
                   }
               }
               else
               {
                   UnownBool = false;
               }
           }

           textBox_PID.Text = RandomPID.ToString();
       }

This is the what is currently used in my program, I still need to add an Unown shapes check, but from what I read it seems kinda complicated.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...