Skip to content

Instantly share code, notes, and snippets.

@Lusamine
Last active June 1, 2025 15:23
Show Gist options
  • Save Lusamine/f020b4d8747b76cd77bc343062e41958 to your computer and use it in GitHub Desktop.
Save Lusamine/f020b4d8747b76cd77bc343062e41958 to your computer and use it in GitHub Desktop.
// Global settings to make things easier.
int FlawlessIVs = 3;
// Set these values for your gender ratio:
// Fixed gender = -1
// 50 M : 50 F = 127
// 25 M : 75 F = 191
// 75 M : 25 F = 63
// 87.5 M : 12.5 F = 31
// Litleo line doesn't exist in LA so we can ignore the last case.
int GenderCompare = 127;
// Set this for how far you want to search.
int maxAdvance = 300;
// Set this for how many shiny rolls you have for this species.
int shinyRolls = 7;
string output = "";
void Main()
{
// Initial state
ulong group_seed = 0x286e5c32787a9d20u; // group seed
ulong init = unchecked(group_seed);
Xoroshiro128Plus rng = new(init);
output = $"Initial Group Seed: {group_seed:x16}\n";
Console.WriteLine(output);
Console.WriteLine("Adv | Generator Seed | Pokemon Seed | PID | IVs | G | Nature\n----+------------------+------------------+-----------+-------------------+---+--------");
for (int advances = 0; advances < maxAdvance; advances++)
{
output = $"{advances, 3} | ";
GenerateSpawn(advances, ref rng);
}
}
// You can define other methods, fields, classes and namespaces here
private void GenerateSpawn(int advance, ref Xoroshiro128Plus rng)
{
// Group seed generates the generator seed and alphamove seed.
var genseed = rng.Next();
output += $"{genseed:X16} | ";
var alphamoveseed = rng.Next();
// Generator seed generates the slot, mon seed, and level.
var slotrng = new Xoroshiro128Plus(genseed);
var slot = slotrng.Next();
var seed = slotrng.Next();
output += $"{seed:X16} | ";
GeneratePoke(seed);
// Reseed the RNG for the next spawn.
var newseed2 = rng.Next();
rng = new Xoroshiro128Plus(newseed2);
}
private void GeneratePoke(ulong seed)
{
var rng = new Xoroshiro128Plus(seed);
rng.NextInt(); // EC
// Fake TID
var fakeTID = (uint)rng.NextInt();
// PID
var pid = (uint)rng.NextInt();
uint ShinyXor = 0;
var isShiny = false;
for (int i = 1; i < shinyRolls; i++)
{
ShinyXor = GetShinyXor(pid, fakeTID);
isShiny = ShinyXor < 16;
if (isShiny)
break;
pid = (uint)rng.NextInt();
}
var shiny_type = " ";
if (isShiny)
shiny_type = ShinyXor == 0 ? "■" : "★";
output += $"{shiny_type}{pid:x8}";
Span<int> ivs = stackalloc[] { -1, -1, -1, -1, -1, -1 };
const int MAX = 31;
for (int i = 0; i < FlawlessIVs; i++)
{
int index;
do { index = (int)rng.NextInt(6); }
while (ivs[index] != -1);
ivs[index] = MAX;
}
var ivstring = "";
for (int i = 0; i < ivs.Length; i++)
{
if (ivs[i] == -1)
ivs[i] = (int)rng.NextInt(32);
ivstring += $"{ivs[i], 2}";
if (i < 5)
ivstring += "/";
}
output += $" | {ivstring}";
rng.NextInt(2);
var genderchar = "-";
if (GenderCompare != -1)
{
var genderval = rng.NextInt(252) + 1;
if ((int)genderval < GenderCompare)
genderchar = "F";
else
genderchar = "M";
}
output += $" | {genderchar}";
var nature = (int)rng.NextInt(25);
output += $" | {GameInfo.GetStrings("en").Natures[nature]}";
// Add your filters here.
if (!isShiny)
return;
//if (nature != (int)Nature.Timid)
// return;
//if (genderchar != "M")
// return;
//if (ivs[0] != 31 || ivs[1] != 0 || ivs[2] != 31 || ivs[3] != 31 || ivs[4] != 31 || ivs[5] != 31)
// return;
Console.WriteLine(output);
}
private static uint GetShinyXor(uint pid, uint oid)
{
var xor = pid ^ oid;
return (xor ^ (xor >> 16)) & 0xFFFF;
}
@Lusamine
Copy link
Author

This script shows future advancements for regular spawners that generate 1 Pokémon at a time in LA such as alpha Tangrowth. This allows for RNG manipulation when given a group seed. Use this script to solve 2 Pokémon for a group seed.

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 type PKHeX.Core into the second tab,
  4. Change the language at the top to C# program, then copy/paste the script in verbatim.
  5. Edit your params (thresholds, advances, gender).
  6. Click run.

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;
    }
    

This is not meant to be a polished or complete tool in itself, nor are there plans to make an easier tool with a GUI.

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