Last active
October 16, 2024 09:09
-
-
Save Lusamine/87ecd66f2c07bc549a9ca0f42a39d74f to your computer and use it in GitHub Desktop.
LINQPad version for searching static encounter spreads.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup is:
PKHeX.Core
to second tab,Recommended LINQPad settings so output is monospaced:
This is just a working script until someone decides to make something better.