Skip to content

Commit

Permalink
Add shiny raids
Browse files Browse the repository at this point in the history
  • Loading branch information
Leanny committed Dec 11, 2019
1 parent 896d7cf commit 5f95551
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 26 deletions.
11 changes: 11 additions & 0 deletions PKHeX_Raid_Plugin/DenIVs.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 22 additions & 5 deletions PKHeX_Raid_Plugin/DenIVs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ namespace PKHeX_Raid_Plugin
{
public partial class DenIVs : Form
{

public DenIVs(ulong seed)
{
InitializeComponent();
for(int i=0; i<150; i++)
{
string[] content = {i.ToString(), "", "", "", "", ""};
bool shiny = getShiny(seed);
string[] content = {i.ToString(), shiny.ToString(), "", "", "", "", ""};
for(int k=1; k<6; k++)
{
int[] ivs = getIVs(seed, k);
content[k] = string.Format("{0}/{1}/{2}/{3}/{4}/{5}", ivs[0], ivs[1], ivs[2], ivs[3], ivs[4], ivs[5]);
content[k+1] = string.Format("{0}/{1}/{2}/{3}/{4}/{5}", ivs[0], ivs[1], ivs[2], ivs[3], ivs[4], ivs[5]);
}
dataGridView1.Rows.Add(content);
XOROSHIRO rng = new XOROSHIRO(seed);
Expand All @@ -30,12 +32,18 @@ public DenIVs(ulong seed)

}

private uint get_SV(uint num) {
uint high = num >> 16;
uint low = num & 0xFFFF;
return (high ^ low) >> 4;
}

private int[] getIVs(ulong seed, int FlawlessIVs)
{
XOROSHIRO rng = new XOROSHIRO(seed);
rng.nextInt();
rng.nextInt();
rng.nextInt();
rng.nextInt(0xFFFFFFFF);
rng.nextInt(0xFFFFFFFF);
rng.nextInt(0xFFFFFFFF);
int[] ivs = { -1, -1, -1, -1, -1, -1 };
for (int i = 0; i < FlawlessIVs; i++)
{
Expand All @@ -52,5 +60,14 @@ private int[] getIVs(ulong seed, int FlawlessIVs)
}
return ivs;
}

private bool getShiny(ulong seed)
{
XOROSHIRO rng = new XOROSHIRO(seed);
rng.nextInt(0xFFFFFFFF);
uint SIDTID = (uint) rng.nextInt(0xFFFFFFFF);
uint PID = (uint) rng.nextInt(0xFFFFFFFF);
return (get_SV(SIDTID) ^ get_SV(PID)) == 0x0;
}
}
}
3 changes: 3 additions & 0 deletions PKHeX_Raid_Plugin/DenIVs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column7.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
Expand Down
81 changes: 73 additions & 8 deletions PKHeX_Raid_Plugin/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 81 additions & 13 deletions PKHeX_Raid_Plugin/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,26 +175,70 @@ private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
}
Nest res = denDetails.Where(nest => nest.TableID == hash).FirstOrDefault();
Entry pkmn = getPkmn(res.entries, stars, roll);
Image sprite = PKHeX.Drawing.SpriteUtil.GetSprite(pkmn.Species, pkmn.AltForm, 0, 0, false, false);
if(pkmn.IsGigantamax)
// calculate IVs
bool shiny;
int[] ivs = { -1, -1, -1, -1, -1, -1 };
XOROSHIRO rng = getData(raid.Seed, pkmn.FlawlessIVs, ivs, out shiny);
// ability
uint ability = 0;
if (pkmn.Ability == 3)
{
var gm = Properties.Resources.dyna;
sprite = ImageUtil.LayerImage(sprite, gm, (sprite.Width - gm.Width) / 2, 0);
ability = (uint) rng.nextInt(2);
}
else if (pkmn.Ability == 4)
{
ability = (uint) rng.nextInt(3);
}
PB_PK1.BackgroundImage = sprite;

// calculate IVs
int[] ivs = getIVs(raid.Seed, pkmn.FlawlessIVs);
var s = GameInfo.Strings;
int[] abilities = PersonalTable.SWSH.GetAbilities(pkmn.Species, pkmn.AltForm);
abilityLbl.Text = s.Ability[abilities[ability]];

// gender
int gender = 0; // 0 = male, 1 = female, 2 = genderless
int gt = PersonalTable.SWSH[pkmn.Species].Gender;
switch (gt)
{
case 255:
gender = 2; // Genderless
break;
case 254:
gender = 1; // Female-Only
break;
case 0:
gender = 0; // Male-Only
break;
default:
gender = (int) rng.nextInt(253) < gt?1:0;
break;
}

// nature
uint nature = (uint)rng.nextInt(25);
natureLbl.Text = s.natures[nature];
TextBox[] ivtextw = { TB_HP_IV1, TB_ATK_IV1, TB_DEF_IV1, TB_SPA_IV1, TB_SPD_IV1, TB_SPE_IV1 };
for(int i=0; i < 6; i++)
{
ivtextw[i].Text = ivs[i].ToString();
}

Image sprite = PKHeX.Drawing.SpriteUtil.GetSprite(pkmn.Species, pkmn.AltForm, gender, 0, false, shiny);
if (pkmn.IsGigantamax)
{
var gm = Properties.Resources.dyna;
sprite = ImageUtil.LayerImage(sprite, gm, (sprite.Width - gm.Width) / 2, 0);
}
PB_PK1.BackgroundImage = sprite;
shinyframes.Text = shiny_in(seed).ToString();

button1.Enabled = true;
} else
{
denSeed.Text = "";
StarLbl.Text = "";
natureLbl.Text = "";
shinyframes.Text = "";
abilityLbl.Text = "";
PB_PK1.BackgroundImage = null;
TextBox[] ivtextw = { TB_HP_IV1, TB_ATK_IV1, TB_DEF_IV1, TB_SPA_IV1, TB_SPD_IV1, TB_SPE_IV1 };
for (int i = 0; i < 6; i++)
Expand All @@ -205,13 +249,37 @@ private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
}
}

private int[] getIVs(ulong seed, int FlawlessIVs)
private uint get_SV(uint num)
{
uint high = num >> 16;
uint low = num & 0xFFFF;
return (high ^ low) >> 4;
}

private int shiny_in(ulong seed)
{
int i = -1;
ulong new_seed = seed;
bool shiny = false;
do
{
i++;
XOROSHIRO rng = new XOROSHIRO(new_seed);
new_seed = rng.next();
uint SIDTID = (uint)rng.nextInt(0xFFFFFFFF);
uint PID = (uint)rng.nextInt(0xFFFFFFFF);
shiny = (get_SV(SIDTID) ^ get_SV(PID)) == 0x0;
} while (!shiny);
return i;
}

private XOROSHIRO getData(ulong seed, int FlawlessIVs, int[] ivs, out bool shiny)
{
XOROSHIRO rng = new XOROSHIRO(seed);
rng.nextInt();
rng.nextInt();
rng.nextInt();
int[] ivs = { -1, -1, -1, -1, -1, -1 };
rng.nextInt(0xFFFFFFFF);
uint SIDTID = (uint)rng.nextInt(0xFFFFFFFF);
uint PID = (uint)rng.nextInt(0xFFFFFFFF);
shiny = (get_SV(SIDTID) ^ get_SV(PID)) == 0x10;
for (int i = 0; i < FlawlessIVs; i++)
{
int idx;
Expand All @@ -225,7 +293,7 @@ private int[] getIVs(ulong seed, int FlawlessIVs)
{
if (ivs[i] == -1) ivs[i] = (int) rng.nextInt(32);
}
return ivs;
return rng;
}

private Entry getPkmn(Entry[] entries, int stars, int roll)
Expand Down

0 comments on commit 5f95551

Please sign in to comment.