Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- User Input
- -- Please note the “Use GBA BIOS” option must be unselected for this script to work properly
- -- Or the Disable BIOS INTRO option must be enabled
- -- This program work for both Fire Red and Leaf Green without any modification
- -- Start this script immediately after SRing
- -- Please enter the seed from IVs to PID in the form 0x******** where the stars are the seed
- targetSeed = 0x125E359C
- -- Max amount of frames you are willing to wait
- maxFrame = 600000
- -- Number of Savestates to restore before SRing - the larger the better but no more than 65536
- -- If you find that the script starts only returning "0000" then try lowering this to a number below the number of seeds it had previously tested!
- looptimes = 10000
- --Don’t edit anything below this unless you know what you are doing
- local rshift = bit.rshift
- local lshift = bit.lshift
- local band = bit.band
- local mdword = memory.readdwordunsigned
- print("Starting... Please Wait")
- --Function that does the LCRNG math
- function LCRNG(s)
- local a = 0x41C6 * band(s, 0xffff) + rshift(s, 16) * 0x4E6D
- local b = 0x4E6D * band(s, 0xffff) + band(a, 0xffff) * 0x10000 + 0x6073
- return b
- end
- function round(num, numDecimalPlaces)
- local mult = 10^(numDecimalPlaces or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- initialState=savestate.create()
- targetHit = 0
- while targetHit == 0 do
- -- Advances frame to title screen
- titleScreen = 0
- while titleScreen < 2000 do
- emu.frameadvance()
- titleScreen = titleScreen + 1
- end
- savestate.save(initialState)
- -- Main loop for advancing frame and taking the base seed to test
- cutSceneCounter = 0
- while (cutSceneCounter < looptimes) and targetHit == 0 do
- cutSceneCounter=cutSceneCounter+1
- savestate.load(initialState)
- emu.frameadvance()
- savestate.save(initialState)
- frameCounter=1
- joypad.set(1,{A=true})
- a = 0
- while a < 300 do
- emu.frameadvance()
- a=a+1
- end
- baseSeed=mdword(0x02020000)
- print("Testing "..cutSceneCounter.."/"..looptimes.." "..round(((cutSceneCounter / looptimes) * 100), 5).."% (Init. "..string.format("%04X", baseSeed)..")")
- PRNG=baseSeed
- currentFrame = 0
- --Calls the LCRNG math and checks for a match
- while (maxFrame > currentFrame) and targetHit == 0 and baseSeed ~= string.format("%04X", 0000) do
- PRNG=LCRNG(PRNG)
- frameCounter=frameCounter + 1
- --print(frameCounter.."/"..maxFrame)
- if targetSeed == PRNG then
- print("Finished. Your base seed is "..string.format("%04X", baseSeed).." And it happens on frame "..string.format("%04d", frameCounter)..".")
- print("Please stop the script before unpausing.")
- emu.pause()
- targetHit=1
- end
- currentFrame = currentFrame + 1
- end
- end
- --Resets game after all frames have been tested for a given SR
- if targetHit == 0 then
- print("SRing...")
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- joypad.set(1,{A=true,B=true,select=true,start=true})
- emu.frameadvance()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement