Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- kyogre script for sapphire v1.2 --
- -- Written by ProjectRevoTPP --
- -- For use on Bizhawk. --
- -- TO USE: Run as soon as the map loads and your player has control ASAP and let the script do the rest to manip the right Kyogre.--
- IWRAM = 0x03000000
- EWRAM = 0x02000000
- V_BLANK_COUNTER_ADDR = 0x03001790
- RTC_ERROR_STATUS = 0x03000458
- RNG_SEED_ADDR = 0x03004818
- -- altered sapphire ROM ONLY!
- NEW_RTC_COUNTER_SAPPHIRE = 0x0203A3D8
- WHICH_KYOGRE = 1 -- 1-4 for which kyogre
- YOLOBALL_RNG_FRAME = 3613 -- which yoloball to go for
- A_PRESS_FRAME = 1337 -- kyogre offset before delay, account for bizhawk delay weirdness
- KYOGRE_DELAY = 652 -- DON'T ALTER THIS!!!
- YOLO_DELAY = 68 -- number of frames delay between A press in menu and yolo calculation.
- YOLO_DELAY_RNG = 150
- globaladdrchange = 0 -- used for pcall protect
- function FramesAdvance(nframes)
- for frame = 1, nframes do
- emu.frameadvance()
- end
- end
- function trychangedomain()
- memory.usememorydomain(globaladdrchange)
- end
- -- this can probably be cleaned up but whatever.
- function getMemOffset(domaintype)
- if domaintype == "IWRAM" then
- return IWRAM
- elseif domaintype == "EWRAM" then
- return EWRAM
- else
- print("Unsupported mem offset. Assuming main and returning 0.")
- return 0
- end
- end
- function readSpecific(domaintype, readtype, endian, addr) -- 0 endian for little, 1 for big
- local returnVar = 0xFF
- globaladdrchange = domaintype -- set the var for the pcall since pcall does not support passing arguments
- if endian == 0 then
- if readtype == 8 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u8_le(addr - getMemOffset(domaintype))
- else
- print("Error changing memory domains.")
- return
- end
- elseif readtype == 16 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u16_le(addr - getMemOffset(domaintype))
- else
- print("Error changing memory domains.")
- return
- end
- elseif readtype == 24 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u24_le(addr - getMemOffset(domaintype))
- else
- print("Error changing memory domains.")
- return
- end
- elseif readtype == 32 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u32_le(addr - getMemOffset(domaintype))
- else
- print("Error changing memory domains.")
- return
- end
- else
- print("Invalid readtype. Exiting script.")
- return
- end
- elseif endian == 1 then
- if readtype == 8 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u8_be(addr - getMemOffset(domaintype))
- else
- print("Error changing memory domains.")
- return
- end
- elseif readtype == 16 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u16_be(addr - getMemOffset(domaintype))
- else
- print("Error changing memory domains.")
- return
- end
- elseif readtype == 24 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u24_be(addr - getMemOffset(domaintype))
- else
- print("Error changing memory domains.")
- return
- end
- elseif readtype == 32 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u32_be(addr - getMemOffset(domaintype))
- else
- print("Error changing memory domains.")
- return
- end
- else
- print("Invalid readtype. Exiting script.")
- return
- end
- else
- print("Invalid endian type. Exiting script.")
- return
- end
- return returnVar
- end
- function checkEmu()
- check = console.getavailabletools --this returns an error if not on Bizhawk
- end
- if pcall(checkEmu) then
- print("Loaded script on Bizhawk, setting memory domain to IWRAM")
- memory.usememorydomain("IWRAM");
- else
- print("VBA-RR or other emulator detected - will not switch memory domain.") -- dont do anything else, only bizhawk needs the memory domain set
- end
- function drawguitext(framecount, rngcounter)
- gui.text(1,10,string.format("Frame Counter: %i",framecount))
- gui.text(1,18,string.format("RNG Counter: %i",rngcounter))
- end
- client.reboot_core()
- FramesAdvance(5)
- local rtcStatus = readSpecific("IWRAM", 16, 0, RTC_ERROR_STATUS)
- if(rtcStatus == 0x0FF0) then
- print("WARNING: RTC already in error state.")
- else
- memory.write_u16_le(RTC_ERROR_STATUS - getMemOffset("IWRAM"), 0x0FF0) -- force RTC to error.
- print("RTC forced into error state.")
- end
- -- seed has to be forced to be 0 after 5 frames due to Bizhawk/game for some reason not liking RTC error being forced before 5 frames. on real hardware, RTC hardware will return 0x0FF0 to the game, but here it has to be forced to match.
- memory.write_u32_le(RNG_SEED_ADDR - getMemOffset("IWRAM"), 0x00000000)
- rngSeed = readSpecific("IWRAM", 32, 0, RNG_SEED_ADDR)
- print(string.format("Current RNG seed is: 0x%08x", rngSeed))
- FramesAdvance(25)
- -- THIS IS A MESS LMAO but it gets in-game to Kyogre. JUST CLOSE THE ROM AND REOPEN IT BEFORE RUNNING, Bizhawk could crash.
- -- wait for intro, and press start.
- FramesAdvance(210)
- input = {}
- input["Start"] = true
- joypad.set(input)
- print("I input start")
- --wait for title screen and Mash A.
- FramesAdvance(45)
- input["A"] = true
- joypad.set(input)
- print("I input A")
- -- unpress.
- FramesAdvance(1)
- input["A"] = false
- joypad.set(input)
- print("I uninput A")
- FramesAdvance(10)
- input["Start"] = true
- joypad.set(input)
- print("I input start")
- FramesAdvance(110)
- input["A"] = true
- joypad.set(input)
- print("I input A")
- FramesAdvance(75)
- input["A"] = true
- joypad.set(input)
- print("I input A")
- FramesAdvance(5)
- input["A"] = true
- joypad.set(input)
- print("I input start")
- FramesAdvance(60)
- -- press left.
- input = {}
- input["Left"] = true
- joypad.set(input)
- -- wait 120 frames.
- FramesAdvance(120)
- -- main loop --
- local rngCounterTable = {}
- local i = 0
- repeat
- if(readSpecific("IWRAM", 16, 0, RTC_ERROR_STATUS) == 0x0000) then
- memory.write_u16_le(RTC_ERROR_STATUS - getMemOffset("IWRAM"), 0x0FF0) -- force RTC to error.
- print("RTC forced into error state.")
- end
- local vblankcounter = readSpecific("IWRAM", 32, 0, V_BLANK_COUNTER_ADDR)
- local rngcounter = readSpecific("EWRAM", 32, 0, NEW_RTC_COUNTER_SAPPHIRE)
- rngCounterTable[i] = rngcounter
- i = i + 1 -- increment i.
- drawguitext(vblankcounter, rngcounter)
- function FramesAdvanceAndPrintRng(nframes, vblankcounter, rngcounter)
- print(string.format("Final frame counter is %i.", vblankcounter))
- print(string.format("Final RNG counter is %i.", rngcounter))
- for frame = 1, nframes do
- emu.frameadvance()
- end
- end
- if(vblankcounter == (A_PRESS_FRAME - KYOGRE_DELAY - 1 + (WHICH_KYOGRE - 1))) then -- it takes 1 frame to input
- local input = {}
- input["A"] = true
- joypad.set(input)
- print("This should produce the right Kyogre.")
- print(string.format("I inputted on: %i, Kyogre RNG frame is expected to be %i",vblankcounter + 1, vblankcounter + KYOGRE_DELAY + 1)) -- it takes 1 frame to input, account for it.
- print(string.format("Final RNG counter is %i.", rngcounter))
- print(rngCounterTable)
- FramesAdvance(KYOGRE_DELAY + 1)
- local vblankcounter = readSpecific("IWRAM", 32, 0, V_BLANK_COUNTER_ADDR)
- local rngcounter = readSpecific("EWRAM", 32, 0, NEW_RTC_COUNTER_SAPPHIRE)
- print(string.format("Final frame counter is %i.", vblankcounter))
- print(string.format("Final RNG counter is %i.", rngcounter))
- FramesAdvance(1) -- rng advanced after this frame.
- local newvblankcounter = readSpecific("IWRAM", 32, 0, V_BLANK_COUNTER_ADDR)
- local newrngcounter = readSpecific("EWRAM", 32, 0, NEW_RTC_COUNTER_SAPPHIRE)
- print(string.format("Updated final frame counter is %i.", newvblankcounter))
- print(string.format("Updated final RNG counter is %i.", newrngcounter))
- break -- end loop.
- end
- emu.frameadvance()
- until false
- print("Waiting for yoloball A press window.")
- FramesAdvance(405)
- input = {}
- input["A"] = true
- joypad.set(input)
- print("I input A")
- FramesAdvance(290)
- input = {}
- input["Right"] = true
- joypad.set(input)
- print("I input Right")
- FramesAdvance(1)
- input = {}
- input["Right"] = false
- joypad.set(input)
- print("I uninput Right")
- FramesAdvance(1)
- input = {}
- input["A"] = true
- joypad.set(input)
- print("I input A")
- FramesAdvance(60)
- input = {}
- input["Right"] = true
- joypad.set(input)
- print("I input Right")
- FramesAdvance(30)
- input = {}
- input["A"] = true
- joypad.set(input)
- FramesAdvance(1)
- local rngcounter = readSpecific("EWRAM", 32, 0, NEW_RTC_COUNTER_SAPPHIRE)
- if rngcounter > YOLOBALL_RNG_FRAME - YOLO_DELAY then
- print(string.format("ERROR: Unreachable frame. Try a bigger yoloball frame than %i.", rngcounter))
- return
- end
- local vblankcounter = readSpecific("IWRAM", 32, 0, V_BLANK_COUNTER_ADDR)
- local rngcounter = readSpecific("EWRAM", 32, 0, NEW_RTC_COUNTER_SAPPHIRE)
- print(string.format("Starting frame when waiting: %i", vblankcounter))
- print(string.format("Starting RNG frame when waiting: %i", rngcounter))
- -- 2nd loop.
- repeat
- local vblankcounter = readSpecific("IWRAM", 32, 0, V_BLANK_COUNTER_ADDR)
- local rngcounter = readSpecific("EWRAM", 32, 0, NEW_RTC_COUNTER_SAPPHIRE)
- if rngcounter == YOLOBALL_RNG_FRAME - YOLO_DELAY_RNG then
- print(string.format("I input A on this frame: %i", vblankcounter))
- print(string.format("I input A on this RNG frame: %i", rngcounter))
- input = {}
- input["A"] = true
- joypad.set(input)
- FramesAdvance(1)
- print("Hope yoloball works!")
- FramesAdvance(YOLO_DELAY) -- normal frame advances, NOT RNG advances!
- local vblankcounter = readSpecific("IWRAM", 32, 0, V_BLANK_COUNTER_ADDR)
- local rngcounter = readSpecific("EWRAM", 32, 0, NEW_RTC_COUNTER_SAPPHIRE)
- print(string.format("I input A on this frame: %i", vblankcounter))
- print(string.format("I input A on this RNG frame: %i", rngcounter))
- FramesAdvance(1)
- local vblankcounter = readSpecific("IWRAM", 32, 0, V_BLANK_COUNTER_ADDR)
- local rngcounter = readSpecific("EWRAM", 32, 0, NEW_RTC_COUNTER_SAPPHIRE)
- print(string.format("I input A on this frame: %i", vblankcounter))
- print(string.format("I input A on this RNG frame: %i", rngcounter))
- return
- end
- emu.frameadvance()
- until false
- gui.register(drawguitext)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement