def GCRNG(seed): return ((seed * 0x000343fd) + 0x00269ec3) & 0xffffffff def GCRNG_R(seed): return ((seed * 0xb9b33155) + 0xa170f641) & 0xffffffff def apply(f, n, x): for i in range(n): x = f(x) return x def findFrame(val): ret = [] val = val & 0xffffffff x = val & 0xffff0000 for i in range(2**16): if (GCRNG(x|i) >> 16) == (val & 0xffff): ret.append(x|i) return ret def generateU32(seed, dist=0): seed = apply(GCRNG if dist >= 0 else GCRNG_R, abs(dist), seed) return (seed & 0xffff0000) | (GCRNG(seed) >> 16) def pkmFromIVSeed(seed): #oldpid = generateU32(seed, -2) A value for the PID that is always overwritten, two RNG calls # Then two RNG calls for the IVs ivs_abil = generateU32(seed) abil = ((GCRNG(GCRNG(seed)) >> 16) & 1) != 0 # And one for the Ability (if odd, second Ability if it exists) PID = generateU32(seed, 3) # Depends. For Pokémon where there is no constraint (e.g shininess), 2 calls. order_2 = [1,2,0] IVs = [((ivs_abil >> 16) >> (5*i)) & 0x1f for i in range(3)] + [(ivs_abil >> (5*order_2[i])) & 0x1f for i in range(3)] return "PID: {0}, ".format(hex(PID)) + "Abil. {0}, IVs: {1}/{2}/{3}/{4}/{5}/{6}".format(2 if abil else 1, *IVs) def genText(seed, c): # Either the frame corresponding to the PID or the TID itself ids_seed = apply(GCRNG_R, 7 if c == 2 else 14, seed) if c != 1 else seed ids = generateU32(ids_seed) TID, SID = (ids >> 16), (ids & 0xffff) umbr = apply(GCRNG, 4, ids_seed) esp = apply(GCRNG, 11, ids_seed) s = """TID/SID: {0}/{1} (TID frame: {2}) Umbreon: {3} Espeon: {4}""".format(TID, SID, hex(ids_seed), pkmFromIVSeed(umbr), pkmFromIVSeed(esp)) return s if __name__ == '__main__': c = -1 while c not in (1,2,3): print("""Please select the value you will provide: \t1. Your TID/SID \t2. Umbreon's PID \t3. Espeon's PID""") try: c = int(input("Your choice: ")) except ValueError: continue seeds = [] if c == 1: TID = int(input("Desired TID: ")) & 0xffff SID = int(input("Desired SID: ")) & 0xffff seeds = findFrame((TID << 16) | SID) else: PID = int(input("Desired PID (in hex.): "), 16) & 0xffffffff seeds = findFrame(PID) print("") print("\n\nOR\n\n".join(genText(seed, c) for seed in seeds))