Last active
September 5, 2022 02:28
-
-
Save Lusamine/7acf49319a9da5a484a46d30767a7e14 to your computer and use it in GitHub Desktop.
LINQPad version for quickly searching BDSP stationary and wild spreads. Slots are referenced from Poké Finder but aren't always correct, needs more research.
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 BDSP so we can ignore the last case. | |
int GenderCompare = -1; | |
// Set this to true if you are searching wild slots. | |
// Slot calculation is not currently 100% accurate. | |
// This will also shift apparent delays by 84 since slot is generated 84 advances before EC. | |
bool SlotSearch = false; | |
// Set how many flawless 31 IVs your mon is expected to have. | |
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 = 500000; | |
var rng = new XorShift128(s0, s1); | |
for (int advances = 0; advances < maxAdvance; advances++) | |
{ | |
GetStateWild(advances, rng); | |
rng.Next(); | |
} | |
} | |
// You can define other methods, fields, classes and namespaces here | |
private readonly List<byte> slots = new List<byte> {20, 40, 50, 60, 70, 80, 85, 90, 94, 98, 99, 100}; | |
private void GetStateWild(int advance, XorShift128 rng) | |
{ | |
var (s0, s1) = rng.GetState64(); | |
var output = $"{advance} | {s0:x16} | {s1:x16} |"; | |
if (SlotSearch) | |
{ | |
var encslotroll = rng.NextInt(0, 100); | |
var encslot = slots.FindIndex(z => encslotroll < z); | |
output = output + $" {encslot:00} |"; | |
for (int advances = 0; advances < 84; advances++) | |
rng.NextUInt(); | |
} | |
var ec = rng.NextUInt(); | |
output = output + $" {ec:x8} |"; | |
var fakeTid = rng.NextUInt(); | |
var pid = rng.NextUInt(); | |
output = output + $" {pid:x8}"; | |
bool isShiny = false; | |
ulong shinyXor = 0; | |
int TSV = (int)((fakeTid >> 16 ^ (fakeTid & 0xFFFF)) >> 4); | |
int PSV = (int)((pid >> 16 ^ (pid & 0xFFFF)) >> 4); | |
if (PSV == TSV) // Shiny check vs a fake trainer. | |
{ | |
var upper = (pid >> 16) ^ (fakeTid >> 16); | |
shinyXor = (pid & 0xFFFF) ^ (fakeTid & 0xFFFF) ^ upper; | |
isShiny = true; | |
var shinySymbol = shinyXor == 0 ? "Q" : "T"; | |
output = output + $" {shinySymbol} |"; | |
} | |
else | |
output = output + " |"; | |
int[] ivs = {-1, -1, -1, -1, -1, -1}; | |
var i = 0; | |
while (i < FlawlessIVs) | |
{ | |
var next = rng.NextUInt(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 ability = 1 + rng.NextUInt(2); | |
output = output + $" {ability} |"; | |
var genderchar = "-"; | |
if (GenderCompare != -1) | |
{ | |
var genderval = rng.NextUInt(253) + 1; | |
if ((int)genderval < GenderCompare) | |
genderchar = "F"; | |
else | |
genderchar = "M"; | |
} | |
output = output + $" {genderchar} |"; | |
var nature = (int)rng.NextUInt(25); | |
output = output + $" {GameInfo.GetStrings(1).Natures[nature]}"; | |
// Add your filters here. | |
if (nature != (int)Nature.Timid) | |
return; | |
if (!isShiny) | |
return; | |
//if (shinyXor != 0) | |
// 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); | |
} |
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,