Skip to content

Instantly share code, notes, and snippets.

@Lusamine
Last active July 15, 2023 20:42
Show Gist options
  • Save Lusamine/87ecd66f2c07bc549a9ca0f42a39d74f to your computer and use it in GitHub Desktop.
Save Lusamine/87ecd66f2c07bc549a9ca0f42a39d74f to your computer and use it in GitHub Desktop.
LINQPad version for searching static encounter spreads.
// Global settings to make things easier.
// 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;
int FlawlessIVs = 3;
void Main()
{
// Initial state
string ram = "E1CEA3FF1E3A9B5CB709ACB78FF71808";
string str0 = ram.Substring(16).Trim();
string str1 = ram.Substring(0, 16);
ulong s0 = Convert.ToUInt64(str0, 16);
ulong s1 = Convert.ToUInt64(str1, 16);
// Set this for how far you want to search.
int maxAdvance = 1_000_000;
Console.WriteLine(" Adv | s0 | s1 | EC | PID | IVs | A | G | Nature\n-------+------------------+------------------+----------+----------+-------------------+---+---+-----------");
var rng = new Xoroshiro128Plus(s0, s1);
for (int advances = 0; advances < maxAdvance; advances++)
{
GetStateStatic(advances, rng);
rng.Next();
}
}
// You can define other methods, fields, classes and namespaces here
private void GetStateStatic(int advance, Xoroshiro128Plus rng)
{
var (s0, s1) = rng.GetState();
var output = $"{advance, 6} | {s0:x16} | {s1:x16} |";
var ec = rng.NextInt();
output += $" {ec:x8} |";
var fakeTID = rng.NextInt();
bool isShiny = false;
var pid = rng.NextInt();
var ShinyXor = GetShinyXor((uint)pid, (uint)fakeTID);
isShiny = ShinyXor < 16;
if (isShiny)
pid ^= 1000_0000; // antishiny
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}";
var ability = rng.NextInt(2);
output += $" | {ability}";
var genderchar = "-";
if (GenderCompare != -1)
{
var genderval = rng.NextInt(253) + 1;
if ((int)genderval < GenderCompare)
genderchar = "F";
else
genderchar = "M";
}
output += $" | {genderchar}";
var nature = (int)rng.NextInt(25);
output += $" | {GameInfo.GetStrings(1).Natures[nature]}";
// Height/weight are not generated for static encounters.
// 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);
}
private static bool GetIsShiny(int tid, int sid, uint pid)
{
return GetShinyXor(pid, (uint)((sid << 16) | tid)) < 16;
}
private static uint GetShinyXor(uint pid, uint oid)
{
var xor = pid ^ oid;
return (xor ^ (xor >> 16)) & 0xFFFF;
}
@Lusamine
Copy link
Author

Lusamine commented Sep 5, 2022

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.

This is just a working script until someone decides to make something better.

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