Skip to content

Instantly share code, notes, and snippets.

@Lusamine
Created July 4, 2023 14:57
Show Gist options
  • Save Lusamine/950888ce3906d19b1bb654de7399743e to your computer and use it in GitHub Desktop.
Save Lusamine/950888ce3906d19b1bb654de7399743e 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 = -1;
// Set this for how far you want to search.
int maxAdvance = 100;
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);
}
}
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 genie.
var newseed2 = rng.Next();
rng = new Xoroshiro128Plus(newseed2);
}
private void GeneratePoke(ulong seed)
{
var rng = new Xoroshiro128Plus(seed);
rng.NextInt();
rng.NextInt();
var pid = rng.NextInt();
output += $"{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(1).Natures[nature]}";
// Add your filters here.
//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);
}
@Lusamine
Copy link
Author

Lusamine commented Jul 4, 2023

This script shows future advancements for overworld legendaries in LA such as Heatran and Enamorus 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 7 from https://www.linqpad.net/LINQPad7.aspx
  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. Click Edit > Preferences, select the Results tab, click "Launch Editor" and paste this in to get monospaced text.
body
{
	margin: 0.3em 0.3em 0.4em 0.4em;
	font-family: Consolas;
}
  1. Change the language at the top to C# program, then copy/paste the script in verbatim.
  2. Edit your params (thresholds, advances, gender).
  3. Click run.

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