private List <uint> recoverLower16BitsPID(uint pid) { uint add; uint k; uint mult; byte[] low = new byte[0x10000]; bool[] flags = new bool[0x10000]; k = 0xC64E6D00; // Mult << 8 mult = 0x41c64e6d; // pokerng constant add = 0x6073; // pokerng constant uint count = 0; foreach (byte element in low) { low[count] = 0; count++; } count = 0; foreach (bool element in flags) { flags[count] = false; count++; } for (short i = 0; i < 256; i++) { uint right = (uint)(mult * i + add); ushort val = (ushort)(right >> 16); flags[val] = true; low[val--] = (byte)(i); flags[val] = true; low[val] = (byte)(i); } List <uint> origin = new List <uint>(); uint first = pid << 16; uint second = pid & 0xFFFF0000; uint search = second - first * mult; for (uint i = 0; i < 256; i++, search -= k) { if (flags[search >> 16]) { uint test = first | (i << 8) | low[search >> 16]; if (((test * mult + add) & 0xffff0000) == second) { PokeRNGR rng = new PokeRNGR(test); uint seed = rng.nextUInt(); origin.Add(seed); } } } return(origin); }
private List <uint> getInitial(uint seed) { uint advances = 0; PokeRNGR rng = new PokeRNGR(seed); while (rng.seed > 0xFFFF) { rng.nextUInt(); advances += 1; } return(new List <uint> { rng.seed, advances }); }