Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- emerald mudkip script v0.5 --
- -- written by ProjectRevoTPP --
- -- BIZHAWK ONLY FOR NOW --
- IWRAM = 0x03000000
- EWRAM = 0x02000000
- RNG_ADDR = 0x3005D80
- RNG_ADDR2 = 0x3005D84
- RTC_ERROR_STATUS = 0x3000DB8 -- this needs to be
- RNG_COUNTER = 0x020249C0
- CORRECT_MUDKIP = 0x0E1AB5A1
- CORRECT_MUDKIP_RNG_COUNTER = 1023 -- the function that actually creates the mudkip needs 1026, but the counter advances a few times before the correct function is called when this is 1026.
- -- config --
- force_mudkip = 1 -- 1 for true, 0 for false
- display_gui = 0 -- 1 for true, 0 for false
- ------------------------
- local last_known_rng = 0
- local last_known_rng2 = 0
- framecount = 0
- rng_count = 0
- globaladdrchange = 0 -- used for pcall protect
- 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 drawguitext(last_known_rng, rng_count, framecount)
- gui.text(1,10,string.format("Current RNG1: %08x",last_known_rng))
- gui.text(1,24,string.format("RNG Counter: %i",rng_count))
- gui.text(1,38,string.format("Frame Counter: %i",framecount))
- 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
- 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 input = {}
- input["A"] = true
- -- force correct mudkip and advance --.
- if force_mudkip == 1 then
- memory.write_u32_le(RNG_ADDR - getMemOffset("IWRAM"), CORRECT_MUDKIP) -- force RNG1
- --memory.write_u32_le() -- force RNG2 (unsure of correct behavior yet)
- memory.usememorydomain("EWRAM")
- memory.write_u32_le(RNG_COUNTER - getMemOffset("EWRAM"), CORRECT_MUDKIP_RNG_COUNTER) -- force RNG Counter
- memory.usememorydomain("IWRAM")
- -- press A. --
- joypad.set(input)
- -- advance frame and unpause.
- emu.frameadvance()
- print("Speedrun mudkip forced, proceeding")
- end
- 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
- last_known_rng = readSpecific("IWRAM", 32, 0, RNG_ADDR)
- last_known_rng2 = readSpecific("IWRAM", 32, 0, RNG_ADDR2)
- rng_count = readSpecific("EWRAM", 32, 0, RNG_COUNTER)
- framecount = emu.framecount()
- if display_gui == 1 then
- drawguitext(last_known_rng, rng_count, framecount)
- end
- emu.frameadvance()
- until false
- gui.register(drawguitext)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement