Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Emerald Steps v1.0 --
- -- written by ProjectRevoTPP --
- -- KNOWN BUG: do not start the script during or before the copyright logo. The step counter changes during this when loading the variable from save block, so it would falsely increment steps by 1. --
- -- recommended to start it after hitting new game or in the field doing tests. --
- IWRAM = 0x03000000
- EWRAM = 0x02000000
- EMERALD_SAVEBLOCK_1_PTR = 0x3005D8C
- EMERALD_STEPCOUNTER_OFFSET = 0x314C -- the counter is 8-bit, so we need to observe it changing and then keep a local step counter track.
- EMERALD_CAN_PLAYER_MOVE = 0x3000F2C -- if 0, player can move, if 1, do not allow counter to increase.
- EMERALD_RNG_COUNTER_ADDR = 0x020249C0
- ------------------------------------
- globaladdrchange = 0 -- used for pcall protect
- is_vba = 0
- true_step_counter = 0
- 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
- elseif is_vba == 1 then -- the reason we return 0 is because addresses are direct in VBA.
- return 0
- 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))
- elseif is_vba == 1 then
- returnVar = memory.readbyte(addr)
- else
- print("Error changing memory domains.")
- return
- end
- elseif readtype == 16 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u16_le(addr - getMemOffset(domaintype))
- elseif is_vba == 1 then
- returnVar = memory.readword(addr)
- else
- print("Error changing memory domains.")
- return
- end
- elseif readtype == 24 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u24_le(addr - getMemOffset(domaintype))
- elseif is_vba == 1 then
- returnVar = memory.read_u24_le(addr)
- else
- print("Error changing memory domains.")
- return
- end
- elseif readtype == 32 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u32_le(addr - getMemOffset(domaintype))
- elseif is_vba == 1 then
- returnVar = memory.readdword(addr)
- 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))
- elseif is_vba == 1 then
- returnVar = memory.readbyte(addr)
- else
- print("Error changing memory domains.")
- return
- end
- elseif readtype == 16 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u16_be(addr - getMemOffset(domaintype))
- elseif is_vba == 1 then
- returnVar = memory.readword(addr)
- else
- print("Error changing memory domains.")
- return
- end
- elseif readtype == 24 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u24_be(addr - getMemOffset(domaintype))
- elseif is_vba == 1 then
- returnVar = memory.read_u24_be(addr)
- else
- print("Error changing memory domains.")
- return
- end
- elseif readtype == 32 then
- if pcall(trychangedomain) then
- returnVar = memory.read_u32_be(addr - getMemOffset(domaintype))
- elseif is_vba == 1 then
- returnVar = memory.readdword(addr)
- 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(steps, rng_counter)
- gui.text(1,10,string.format("Current 8-bit Steps: %i",steps))
- if is_vba == 0 then
- gui.text(1,26,string.format("Current RNG Counter: %i",rng_counter))
- else
- gui.text(1,18,string.format("Current RNG Counter: %i",rng_counter))
- end
- 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
- is_vba = 1
- end
- local save_ptr = readSpecific("IWRAM", 32, 0, EMERALD_SAVEBLOCK_1_PTR) -- load save ptr once
- last_step_counter = readSpecific("EWRAM", 32, 0, save_ptr + EMERALD_STEPCOUNTER_OFFSET) -- set the last step counter.
- repeat
- local save_ptr = readSpecific("IWRAM", 32, 0, EMERALD_SAVEBLOCK_1_PTR)
- local new_step_counter = readSpecific("EWRAM", 32, 0, save_ptr + EMERALD_STEPCOUNTER_OFFSET)
- local rng_counter = readSpecific("EWRAM", 32, 0, EMERALD_RNG_COUNTER_ADDR)
- drawguitext(new_step_counter, rng_counter)
- emu.frameadvance()
- until false
- gui.register(drawguitext)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement