Skip to content

Instantly share code, notes, and snippets.

@Lusamine
Last active January 14, 2022 05:36
Show Gist options
  • Save Lusamine/cc23ef1b808b61b3c05c95d06654eb68 to your computer and use it in GitHub Desktop.
Save Lusamine/cc23ef1b808b61b3c05c95d06654eb68 to your computer and use it in GitHub Desktop.
Ignored nature because lazy and spreads are limited already; you can use Synchronize if you care.
void Main()
{
// Initial state
// s0 should be s1, s0 from CS
// s1 should be s3, s2 from CS
ulong s0 = 0x0123456789ABCDEF;
ulong s1 = 0x0123456789ABCDEF;
// Set this for how far you want to search.
int maxAdvance = 500000;
var rng = new XorShift128(s0, s1);
for (int advances = 0; advances < maxAdvance; advances++)
{
GetStateRoamer(advances, rng);
rng.Next();
}
}
// You can define other methods, fields, classes and namespaces here
private void GetStateRoamer(int advance, XorShift128 rng)
{
int FlawlessIVs = 3;
var (s0, s1) = rng.GetState64();
var output = $"{advance} | {s0:x16} | {s1:x16} |";
var seed = rng.NextUInt(); // Seed is also the EC.
output = output + $" {seed:x8} |";
var xoro = new Xoroshiro128Plus8b(seed); // Feed the seed into a xoroshiro object.
var fakeTid = xoro.NextUInt();
var pid = xoro.NextUInt();
output = output + $" {pid:x8}";
bool isShiny = false;
uint shinyXor = 0;
int TSV = (int)((fakeTid >> 16 ^ (fakeTid & 0xFFFF)) >> 4);
int PSV = (int)((pid >> 16 ^ (pid & 0xFFFF)) >> 4);
if (PSV == TSV) // Shiny check vs a fake trainer.
{
var upper = (pid >> 16) ^ (fakeTid >> 16);
shinyXor = (pid & 0xFFFF) ^ (fakeTid & 0xFFFF) ^ upper;
isShiny = true;
var shinySymbol = shinyXor == 0 ? "Q" : "T";
output = output + $" {shinySymbol} |";
}
else
output = output + "   |";
int[] ivs = {-1, -1, -1, -1, -1, -1};
var i = 0;
while (i < FlawlessIVs)
{
var next = xoro.NextUInt(6);
if (ivs[next] == -1)
{
ivs[next] = 31;
i++;
}
}
var ivstring = "";
for (i = 0; i < 6; i++)
{
if (ivs[i] == -1)
{
var next = xoro.NextUInt(32);
ivs[i] = (int)next;
}
ivstring += ivs[i];
if (i < 5)
ivstring += "/";
}
output = output + $" {ivstring}";
// Add your filters here.
if (!isShiny)
return;
if (shinyXor != 0)
return;
//if (ivs[0] != 31 || ivs[1] != 0 || ivs[2] != 31 || ivs[3] != 31 || ivs[4] != 31 || ivs[5] != 31)
// return;
Console.WriteLine(output);
}
@Lusamine
Copy link
Author

Lusamine commented Dec 9, 2021

Setup is:

  1. Download/install LINQPad 7.
  2. Download dev build PKHeX.
  3. Press F4 in LINQPad and add PKHeX.Core.dll to first tab, and PKHeX.Core to second tab,
  4. Change the language at the top to C# program, then copy/paste the script in verbatim.
  5. Edit your param (seeds, advances, and filters). The number for Nature can be referenced on Bulbapedia.
  6. Click run. Each line should be showing Advances, s0, s1, EC, PID, IVs, Nature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment