mirror of
https://github.com/notwa/mm
synced 2024-11-04 22:39:02 -08:00
write dumper for all exit values
This commit is contained in:
parent
d4c612bc15
commit
0b9d5ccb83
1 changed files with 53 additions and 15 deletions
|
@ -5,6 +5,8 @@ require "addrs.init"
|
|||
local scene_names = require "data.scene names"
|
||||
local entrance_names = require "data.entrance names"
|
||||
|
||||
local open = io.open
|
||||
|
||||
function sdata(i)
|
||||
local a = addrs.scene_table.addr + i*4*3
|
||||
-- entrance count, entrance table (ptr), name (ptr)
|
||||
|
@ -18,59 +20,95 @@ function mirror(scene_id)
|
|||
return scene_id
|
||||
end
|
||||
|
||||
function calc_dump(a)
|
||||
function calc_dump(a, writer)
|
||||
if type(a) ~= "number" then
|
||||
print('[crash]')
|
||||
writer('[crash]')
|
||||
return
|
||||
end
|
||||
if is_ptr(R4(a)) then
|
||||
a = deref(R4(a))
|
||||
end
|
||||
a = deref(R4(a)) or a
|
||||
local scene_id = mirror(R1(a))
|
||||
local entrance = R1(a + 1)
|
||||
local t = entrance_names[scene_id]
|
||||
if t == nil then
|
||||
print("err")
|
||||
writer("err")
|
||||
return
|
||||
end
|
||||
print(scene_names[scene_id])
|
||||
writer(scene_names[scene_id])
|
||||
if t[entrance] then
|
||||
print(t[entrance])
|
||||
writer(t[entrance])
|
||||
else
|
||||
print("[unknown entrance]")
|
||||
writer("[unknown entrance]")
|
||||
end
|
||||
end
|
||||
|
||||
function split_exit(exit)
|
||||
return bit.rshift(exit, 9), bit.band(bit.rshift(exit, 4), 0x1F), bit.band(exit, 0xF)
|
||||
end
|
||||
|
||||
function calc(exit)
|
||||
console.clear()
|
||||
local scene = bit.rshift(exit, 9)
|
||||
local entrance = bit.band(bit.rshift(exit, 4), 0x1F)
|
||||
local offset = bit.band(exit, 0xF)
|
||||
local scene, entrance, offset = split_exit(exit)
|
||||
printf("%i, %i, %i", scene, entrance, offset)
|
||||
|
||||
local sd = sdata(scene)
|
||||
local first_entrance = deref(sd[2])
|
||||
print("# Scene:")
|
||||
calc_dump(first_entrance)
|
||||
calc_dump(first_entrance, print)
|
||||
|
||||
if not first_entrance then return end
|
||||
|
||||
local orig_entrance = first_entrance + entrance*4
|
||||
local entr_before_offset = deref(R4(orig_entrance))
|
||||
print("# Scene + Entrance:")
|
||||
calc_dump(entr_before_offset)
|
||||
calc_dump(entr_before_offset, print)
|
||||
|
||||
if not entr_before_offset then return end
|
||||
|
||||
local final_entrance = entr_before_offset + offset*4
|
||||
print("# Scene + Entrance + Offset:")
|
||||
calc_dump(final_entrance)
|
||||
calc_dump(final_entrance, print)
|
||||
|
||||
-- TODO: read until \x00
|
||||
--print('internal name:')
|
||||
--print(asciize(mainmemory.readbyterange(deref(sd[3]), 8)))
|
||||
end
|
||||
|
||||
function dump_all_exits(fn)
|
||||
local f = open(fn or 'data/_exits.csv', 'w')
|
||||
if f == nil then
|
||||
print("couldn't open file for writing")
|
||||
return
|
||||
end
|
||||
f:write('ID,Scene,Entrance,Offset,Original Scene,(entrance),Scene + Entrance,(entrance),Scene + Entrance + Offset,(entrance)\n')
|
||||
for i = 0, 0xFFFF do
|
||||
local fail = function()
|
||||
f:write(('"0x%04X"'):format(i))
|
||||
f:write(',,,,,,,,,\n')
|
||||
end
|
||||
for _ = 1, 1 do -- "continue" hack
|
||||
local scene, entrance, offset = split_exit(i)
|
||||
|
||||
local sd = sdata(scene)
|
||||
local first_entrance = deref(sd[2])
|
||||
if not first_entrance then fail(); break end
|
||||
local orig_entrance = first_entrance + entrance*4
|
||||
local entr_before_offset = deref(R4(orig_entrance))
|
||||
if not entr_before_offset then fail(); break end
|
||||
local final_entrance = entr_before_offset + offset*4
|
||||
|
||||
f:write(('"0x%04X",%i,%i,%i'):format(i, scene, entrance, offset))
|
||||
local writer = function(...)
|
||||
return f:write(',"') and f:write(...) and f:write('"')
|
||||
end
|
||||
calc_dump(orig_entrance, writer)
|
||||
calc_dump(entr_before_offset, writer)
|
||||
calc_dump(final_entrance, writer)
|
||||
f:write("\n")
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
end
|
||||
|
||||
local old_value = -1
|
||||
while true do
|
||||
local exit_value = addrs.exit_value()
|
||||
|
|
Loading…
Reference in a new issue