Skip to content

Instantly share code, notes, and snippets.

@Lusamine
Last active November 12, 2024 20:12
Show Gist options
  • Select an option

  • Save Lusamine/c3a86d26e025ccce0a0b6a5e30ccdb05 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
Author

Lusamine commented Dec 9, 2021

Setup is:

  1. Download/install LINQPad (latest version is fine).
  2. Download dev build PKHeX from https://projectpokemon.org/home/files/file/2445-pkhex-development-build/
  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.

Recommended LINQPad settings so output is monospaced:

  1. Edit > Preferences > Results
  2. Click "Launch Editor" under Style Sheet for text (HTML) results.
  3. Paste this snippet and "Apply Changes".
    body
    {
    	margin: 0.3em 0.3em 0.4em 0.4em;
    	font-family: Consolas;
    }
    

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