Skip to content

Instantly share code, notes, and snippets.

@atshane253
Last active October 4, 2017 15:58
Show Gist options
  • Save atshane253/95e2e0561ee30293bcac244734b6571b to your computer and use it in GitHub Desktop.
Save atshane253/95e2e0561ee30293bcac244734b6571b to your computer and use it in GitHub Desktop.
ALTTP Randomizer HUD Watcher lua script
local timer = 15 * 60
-- sram trace
local address = 0x1E00
local range = 0x01E0
-- private
local old
local log = {}
local _timer = timer
function hudwatch()
local new
memory.usememorydomain("CARTRAM")
if not old then
old = memory.readbyterange(address, range)
return
end
new = memory.readbyterange(address, range)
if not tablesequal(old, new) then
logtablediff(old,new)
old = new
end
end
function tablesequal(t1, t2, keys)
keys = keys or t1
for k,_ in pairs(keys) do
if t1[k] ~= t2[k] then
return false
end
end
return true
end
function logtablediff(t1, t2)
local v1
local v2
for k,_ in pairs(t1) do
v1 = t1[k]
v2 = t2[k]
if v1 ~= v2 then
if log[k] == nil then
log[k] = { v1 }
end
table.insert(log[k], v2)
end
end
end
function printlog()
local s
local sorted = {}
for k,_ in pairs(log) do
table.insert(sorted,k)
end
table.sort(sorted)
console.log("---" .. emu.framecount() .. "---")
for _,k in ipairs(sorted) do
s = string.format("0x%04X -> %s",k,table.concat(log[k],", "))
console.log(s)
end
end
while true do
hudwatch()
_timer = _timer - 1
if _timer < 1 and log ~= {} then
printlog()
log = {}
_timer = timer
end
emu.frameadvance();
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment