Skip to content

Commit a06e845

Browse files
author
BuildTools
committed
- added the ability to change the shiny status of pokemon (big thanks to @shearx)
1 parent de79fae commit a06e845

1 file changed

Lines changed: 41 additions & 84 deletions

File tree

PQSE-GUI/PQSE-GUI/EditPokemon.xaml.cs

Lines changed: 41 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -76,67 +76,37 @@ private void LoadStuff()
7676

7777
}
7878

79+
80+
/// <summary>
81+
/// HNUGE THANKS TO shearx! Provided this function, Maths, Explaination! Complete god.
82+
/// </summary>
83+
/// <param name="inputId"></param>
84+
/// <param name="inputrr"></param>
85+
/// <returns></returns>
7986
public bool CheckShinyStatus(uint inputId, uint inputrr)
8087
{
81-
uint pokeId = inputId;
82-
uint pokeRR = inputrr;
83-
84-
var id = BitConverter.GetBytes(pokeId);
85-
var rr = BitConverter.GetBytes(pokeRR);
86-
87-
byte[] p1Bytes = new byte[2];
88-
p1Bytes[0] = id[0];
89-
p1Bytes[1] = id[1];
90-
p1Bytes[0] = Convert.ToByte(p1Bytes[0].ToString().PadLeft(16, '0'));
91-
p1Bytes[1] = Convert.ToByte(p1Bytes[1].ToString().PadLeft(16, '0'));
92-
93-
byte[] p2Bytes = new byte[2];
94-
p2Bytes[0] = id[2];
95-
p2Bytes[1] = id[3];
96-
//p2Bytes[0] = Convert.ToByte(p2Bytes[0].ToString().PadLeft(16, '0'));
97-
//p2Bytes[1] = Convert.ToByte(p2Bytes[1].ToString().PadLeft(16, '0'));
98-
99-
100-
byte[] p3Bytes = new byte[2];
101-
p3Bytes[0] = rr[0];
102-
p3Bytes[1] = rr[1];
103-
//p3Bytes[0] = Convert.ToByte(p3Bytes[0].ToString().PadLeft(16, '0'));
104-
//p3Bytes[1] = Convert.ToByte(p3Bytes[1].ToString().PadLeft(16, '0'));
105-
106-
107-
byte[] p4Bytes = new byte[2];
108-
p4Bytes[0] = rr[2];
109-
p4Bytes[1] = rr[3];
110-
//p4Bytes[0] = Convert.ToByte(p4Bytes[0].ToString().PadLeft(16, '0'));
111-
//p4Bytes[1] = Convert.ToByte(p4Bytes[1].ToString().PadLeft(16, '0'));
112-
113-
114-
var r1 = ((p1Bytes[0] << 8) + p1Bytes[1]) ^ ((p2Bytes[0] << 8) + p2Bytes[1]);
115-
var r2 = r1 ^ ((p3Bytes[0] << 8) + p3Bytes[1]);
116-
var r3 = r2 ^ ((p4Bytes[0] << 8) + p4Bytes[1]);
88+
string id = Convert.ToString(inputId, 2).PadLeft(32, '0');
89+
string rr = Convert.ToString(inputrr, 2).PadLeft(32, '0');
11790

118-
//BitArray b = new BitArray(BitConverter.GetBytes(r3));
119-
//int[] bits = b.Cast<bool>().Select(bit => bit ? 1 : 0).ToArray();
91+
string target = Convert.ToString(14, 2).PadLeft(16, '0');
92+
BitArray targetVal = new BitArray(target.Select(s => s == '1').ToArray());
12093

121-
byte[] bt = BitConverter.GetBytes(r3);
94+
BitArray p1 = new BitArray(id.Substring(0, 16).Select(s => s == '1').ToArray());
95+
BitArray p2 = new BitArray(id.Substring(16, 16).Select(s => s == '1').ToArray());
96+
BitArray p3 = new BitArray(rr.Substring(0, 16).Select(s => s == '1').ToArray());
97+
BitArray p4 = new BitArray(rr.Substring(16, 16).Select(s => s == '1').ToArray());
12298

123-
string strBin = string.Empty;
124-
byte btindx = 0;
125-
string strAllbin = string.Empty;
99+
var r1 = p1.Xor(p2);
100+
var r2 = r1.Xor(p3);
101+
var r3 = r2.Xor(p4);
126102

127-
for (int i = 0; i < bt.Length; i++)
103+
for (var i = 0; i < r3.Length; i++)
128104
{
129-
btindx = bt[i];
130-
131-
strBin = Convert.ToString(btindx, 2); // Convert from Byte to Bin
132-
//strBin = strBin.PadLeft(4, '0'); // Zero Pad
133-
134-
strAllbin += strBin;
105+
if (r3[i] != targetVal[i])
106+
return false;
135107
}
108+
return true;
136109

137-
if (strAllbin.StartsWith("0111"))
138-
return true;
139-
return false;
140110
}
141111

142112
/// <summary>
@@ -248,30 +218,6 @@ private void InitPStones()
248218

249219
internal SaveCharacterData GetPokeResult()
250220
{
251-
// name
252-
// level
253-
// exp
254-
// monsterNo
255-
// (shiny)
256-
// attack
257-
// health
258-
// pstones
259-
// (skill stones)
260-
// skills
261-
262-
pokeResult.attack = Convert.ToInt32(pokemonAttack.Text);
263-
pokeResult.exp = (uint)Convert.ToInt32(pokemonExp.Text);
264-
//pokeResult.formNo
265-
pokeResult.hp = Convert.ToInt32(pokemonHealth.Text);
266-
//pokeResult.id
267-
//pokeResult.isEvolve
268-
pokeResult.level = (ushort)Convert.ToInt32(pokemonLevel.Text);
269-
pokeResult.monsterNo = (ushort)Convert.ToInt32(comboAllPoke.SelectedIndex + 1);
270-
pokeResult.name = pokemonName.Text.ToList();
271-
SavePStoneTypes();
272-
//pokeResult.rareRandom = (uint)Convert.ToInt32(pokemonRR.Text);
273-
//pokeResult.seikaku = (byte)Convert.ToInt32(pokemonSeikaku.Text);
274-
//pokeResult.trainingSkillCount
275221
return pokeResult;
276222
}
277223

@@ -290,30 +236,41 @@ private void SavePStoneTypes()
290236

291237
private void Button_Click(object sender, RoutedEventArgs e)
292238
{
239+
pokeResult.attack = Convert.ToInt32(pokemonAttack.Text);
240+
pokeResult.exp = (uint)Convert.ToInt32(pokemonExp.Text);
241+
//pokeResult.formNo
242+
pokeResult.hp = Convert.ToInt32(pokemonHealth.Text);
243+
//pokeResult.id
244+
//pokeResult.isEvolve
245+
pokeResult.level = (ushort)Convert.ToInt32(pokemonLevel.Text);
246+
pokeResult.monsterNo = (ushort)Convert.ToInt32(comboAllPoke.SelectedIndex + 1);
247+
pokeResult.name = pokemonName.Text.ToList();
248+
SavePStoneTypes();
249+
//pokeResult.rareRandom = (uint)Convert.ToInt32(pokemonRR.Text);
250+
//pokeResult.seikaku = (byte)Convert.ToInt32(pokemonSeikaku.Text);
251+
//pokeResult.trainingSkillCount
252+
253+
254+
293255
this.DialogResult = true;
294256
}
295257

296258
private void setToShiny_Click(object sender, RoutedEventArgs e)
297259
{
298260
Random rnd = new Random();
299261
bool foundShinyVals = false;
300-
uint shinyValId = 0;
301262
uint shinyValRR = 0;
302263

303-
while(foundShinyVals == false)
264+
while (foundShinyVals == false)
304265
{
305-
uint randId = (uint)rnd.Next(Int32.MaxValue);
306-
uint randRR = (uint)rnd.Next(999999999);
307-
if (CheckShinyStatus(randId, randRR) == true)
266+
uint randRR = (uint)rnd.Next(int.MaxValue);
267+
if (CheckShinyStatus(pokeResult.id, randRR) == true)
308268
{
309-
shinyValId = randId;
310269
shinyValRR = randRR;
311270
foundShinyVals = true;
312271
//MessageBox.Show("Found shiny value: " + System.Environment.NewLine + "id: " + randId + System.Environment.NewLine + "rareRandom: " + randRR);
313272
}
314273
}
315-
316-
pokeResult.id = shinyValId;
317274
pokeResult.rareRandom = shinyValRR;
318275
LoadStuff();
319276
}

0 commit comments

Comments
 (0)