Skip to content

Instantly share code, notes, and snippets.

@Lusamine
Last active September 24, 2022 01:06
Show Gist options
  • Save Lusamine/c3a86d26e025ccce0a0b6a5e30ccdb05 to your computer and use it in GitHub Desktop.
Save Lusamine/c3a86d26e025ccce0a0b6a5e30ccdb05 to your computer and use it in GitHub Desktop.
Go anywhere where the advances go +1 at a time. Delay is 0 on this script, or you can figure it out for yourself.
int FlawlessIVs = 0;
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 = 150000;
var rng = new XorShift128(s0, s1);
for (int advances = 0; advances < maxAdvance; advances++)
{
GetStateMysteryGift(advances, rng);
rng.Next();
}
Console.WriteLine("Search completed.");
}
// You can define other methods, fields, classes and namespaces here
private void GetStateMysteryGift(int advance, XorShift128 rng)
{
var (s0, s1) = rng.GetState64();
var output = $"{advance} | {s0:x16} | {s1:x16} |";
rng.Next(); // need this roll, but we don't care what it is.
var ec = rng.NextUInt();
output = output + $" {ec:x8} |";
var pid = rng.NextUInt();
output = output + $" {pid:x8} |";
Span<int> ivs = stackalloc[] { -1, -1, -1, -1, -1, -1 };
var i = 0;
while (i < FlawlessIVs)
{
var next = (int)rng.Next();
next = next - (next / 6) * 6;
if (ivs[next] == -1)
{
ivs[next] = 31;
i++;
}
}
var ivstring = "";
for (i = 0; i < 6; i++)
{
if (ivs[i] == -1)
ivs[i] = rng.NextInt(0, 32);
ivstring += ivs[i];
if (i < 5)
ivstring += "/";
}
output = output + $" {ivstring} |";
var nature = rng.NextUInt(25);
output = output + $" {GameInfo.GetStrings(1).Natures[(int)nature]}";
// Add your filters here.
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).
  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