Decided to experiment with the onloadstate() event and the results are a little weird. I want this to be toggle-able, which the simple one-liner doesn't accomplish. Once I load the script, the event seems to be registered until I close the instance of the emulator. I attempted to address this by combining the script methods, and it MOSTLY works but has one key flaw. First, here's the code I have so far:
local function_name = "randomize_rng_on_load_state"
function randomize_rng()
local new_rng1 = math.random(0, 255)
local new_rng2 = math.random(0, 15)
memory.usememorydomain("Combined WRAM")
memory.writebyte(0x040FB4, new_rng1)
memory.writebyte(0x040FB5, new_rng2)
end
function clean_load_state_event()
event.unregisterbyname(function_name)
end
event.onloadstate(randomize_rng, function_name)
event.onexit(clean_load_state_event)
while true do
emu.frameadvance()
end
The flaw is that approximately half the time when toggling the script off, it throws a scary looking error message. It still toggles off properly and you can close the error without the instance crashing, but I'd love to stop that from happening at all if possible