mirror of
https://github.com/notwa/mm
synced 2025-02-05 13:23:23 -08:00
refactor actor iteration
This commit is contained in:
parent
2676397fd9
commit
9bfad76e3d
1 changed files with 115 additions and 90 deletions
|
@ -16,22 +16,67 @@ else
|
||||||
actor_names = require "actor names"
|
actor_names = require "actor names"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function T(x, y, s, color, pos)
|
||||||
|
color = color or "white"
|
||||||
|
pos = pos or "bottomright"
|
||||||
|
gui.text(10*x + 2, 16*y + 4, s, nil, color, pos)
|
||||||
|
end
|
||||||
|
|
||||||
|
function T_BR(x, y, s, color) T(x, y, s, color, "bottomright") end
|
||||||
|
function T_BL(x, y, s, color) T(x, y, s, color, "bottomleft") end
|
||||||
|
function T_TL(x, y, s, color) T(x, y, s, color, "topleft") end
|
||||||
|
function T_TR(x, y, s, color) T(x, y, s, color, "topright") end
|
||||||
|
|
||||||
|
function pmask(p)
|
||||||
|
return bit.band(p, 0x7FFFFFFF)
|
||||||
|
end
|
||||||
|
|
||||||
function get_actor_count(i)
|
function get_actor_count(i)
|
||||||
return R4(addrs.actor_count_0.addr + i*al_next)
|
return R4(addrs.actor_count_0.addr + i*al_next)
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_first_actor(i)
|
function get_first_actor(i)
|
||||||
return bit.band(R4(addrs.actor_first_0.addr + i*al_next), 0x7FFFFFFF)
|
return pmask(R4(addrs.actor_first_0.addr + i*al_next))
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_next_actor(addr)
|
function get_next_actor(addr)
|
||||||
return bit.band(R4(addr + actor_t.next.addr), 0x7FFFFFFF)
|
return pmask(R4(addr + actor_t.next.addr))
|
||||||
end
|
end
|
||||||
|
|
||||||
function T(x, y, s, color, pos)
|
function count_actors()
|
||||||
color = color or "white"
|
local counts = {}
|
||||||
pos = pos or "bottomright"
|
for i = 0, 11 do
|
||||||
gui.text(10*x + 2, 16*y + 4, s, nil, color, pos)
|
counts[i] = get_actor_count(i)
|
||||||
|
end
|
||||||
|
return counts
|
||||||
|
end
|
||||||
|
|
||||||
|
function iter_actors(counts)
|
||||||
|
local at, ai = 0, 0
|
||||||
|
local once = false
|
||||||
|
local addr
|
||||||
|
return function()
|
||||||
|
if once then ai = ai + 1 end
|
||||||
|
once = true
|
||||||
|
|
||||||
|
while ai >= counts[at] do
|
||||||
|
ai = 0
|
||||||
|
at = at + 1
|
||||||
|
if at >= 12 then return nil end
|
||||||
|
end
|
||||||
|
|
||||||
|
if ai == 0 then
|
||||||
|
addr = get_first_actor(at)
|
||||||
|
else
|
||||||
|
addr = get_next_actor(addr)
|
||||||
|
if addr == 0 then
|
||||||
|
T_TR(0, 0, "no actor found", "yellow")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return at, ai, addr
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local seen = {}
|
local seen = {}
|
||||||
|
@ -39,23 +84,31 @@ local seen_strs = {}
|
||||||
local seen_strs_sorted = {}
|
local seen_strs_sorted = {}
|
||||||
local last_any = 0
|
local last_any = 0
|
||||||
|
|
||||||
|
-- hack to avoid N64 logo spitting errors
|
||||||
local stupid = addrs.actor_count_0.addr - 0x8
|
local stupid = addrs.actor_count_0.addr - 0x8
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local any = 0
|
local any = 0
|
||||||
for i = 0, 11 do
|
local game_count = 0
|
||||||
local count = get_actor_count(i)
|
local counts = nil
|
||||||
T(0, 13 - i, ("#%2i: %2i"):format(i, count), nil, "bottomright")
|
|
||||||
any = any + count
|
|
||||||
end
|
|
||||||
T(0, 1, ("sum:%3i"):format(any), nil, "bottomright")
|
|
||||||
if addrs.actor_count then
|
|
||||||
T(10, 1, ("sum:%3i"):format(R1(addrs.actor_count.addr)), 'cyan', "bottomright")
|
|
||||||
end
|
|
||||||
|
|
||||||
if R4(stupid) ~= 0 then
|
if R4(stupid) ~= 0 then
|
||||||
T(0, 14, "stupid", "red", "bottomright")
|
T_BR(0, 14, "stupid", "red")
|
||||||
any = 0
|
any = 0
|
||||||
|
else
|
||||||
|
counts = count_actors()
|
||||||
|
for i = 0, 11 do
|
||||||
|
any = any + counts[i]
|
||||||
|
T_BR(0, 13 - i, ("#%2i: %2i"):format(i, counts[i]))
|
||||||
|
end
|
||||||
|
T_BR(0, 1, ("sum:%3i"):format(any))
|
||||||
|
|
||||||
|
if addrs.actor_count then
|
||||||
|
game_count = R1(addrs.actor_count.addr)
|
||||||
|
if game_count ~= any then
|
||||||
|
T_BR(8, 1, "mismatch!", "red")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if any == 0 then
|
if any == 0 then
|
||||||
|
@ -69,82 +122,54 @@ while true do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local seen_new = false
|
local needs_update = false
|
||||||
|
local at = 2
|
||||||
local actor_type = 2
|
local ai = 0
|
||||||
local actor_index = 0
|
|
||||||
local once = false
|
|
||||||
local j = 0
|
local j = 0
|
||||||
while any > 0 and last_any ~= any do
|
for at, ai, addr in iter_actors(counts) do
|
||||||
if once and actor_type == 2 and actor_index == 0 then
|
--T(0, 0, ("%02i:%02i"):format(at, ai))
|
||||||
break
|
--print(("%02i:%02i"):format(at, ai))
|
||||||
end
|
--local num = R2(addr + actor_t.num.addr)
|
||||||
actor_index = actor_index + 1
|
local num = R2(addr)
|
||||||
|
local name = actor_names[num]
|
||||||
|
|
||||||
local actor_count = get_actor_count(actor_type)
|
if name == nil and num < 0x300 then
|
||||||
while actor_index >= actor_count do
|
name = "NEW"
|
||||||
actor_type = (actor_type + 1) % 12
|
actor_names[num] = name
|
||||||
actor_count = get_actor_count(actor_type)
|
print(("\t[0x%03X]=\"NEW\","):format(num))
|
||||||
actor_index = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
local addr = get_first_actor(actor_type)
|
if actor_t.damage_table and actor_t.hp then
|
||||||
if actor_index > 0 then
|
local dmg = pmask(addr + actor_t.damage_table.addr)
|
||||||
for i = 0, actor_index - 1 do
|
if dmg == 0 then
|
||||||
addr = get_next_actor(addr)
|
print("(no damage table)")
|
||||||
if addr == 0 then
|
|
||||||
T(0, 3, "no actor found", "yellow")
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
--T(0, 0, ("%02i:%02i"):format(actor_type, actor_index))
|
|
||||||
--print(("%02i:%02i"):format(actor_type, actor_index))
|
|
||||||
|
|
||||||
if addr ~= 0 then
|
|
||||||
--local num = R2(addr + actor_t.num.addr)
|
|
||||||
local num = R2(addr)
|
|
||||||
local name = actor_names[num]
|
|
||||||
|
|
||||||
if name == nil and num < 0x300 then
|
|
||||||
name = "NEW"
|
|
||||||
actor_names[num] = name
|
|
||||||
print(("\t[0x%03X]=\"NEW\","):format(num))
|
|
||||||
|
|
||||||
if actor_t.damage_table and actor_t.hp then
|
|
||||||
local dmg = bit.band(addr + actor_t.damage_table.addr, 0x7FFFFFFF)
|
|
||||||
if dmg == 0 then
|
|
||||||
print("(no damage table)")
|
|
||||||
else
|
|
||||||
local hp = R1(addr + actor_t.hp.addr)
|
|
||||||
s = ("%04X\t%02X\t%02X"):format(num, actor_type, hp)
|
|
||||||
for i = 0, 31 do
|
|
||||||
s = s..("\t%02X"):format(R1(dmg + i))
|
|
||||||
end
|
|
||||||
print(s)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if num > 0x300 then
|
|
||||||
print(("BAD %06X %04X (%2i:%2i)"):format(addr, num, actor_type, actor_index))
|
|
||||||
actor_names[num] = "BAD"
|
|
||||||
elseif not seen[num] then
|
|
||||||
seen[num] = true
|
|
||||||
seen_new = true
|
|
||||||
local str
|
|
||||||
if name:sub(1,1) == "?" then
|
|
||||||
str = ("%s (%03X)"):format(name, num)
|
|
||||||
else
|
else
|
||||||
str = ("%s"):format(name)
|
local hp = R1(addr + actor_t.hp.addr)
|
||||||
|
s = ("%04X\t%02X\t%02X"):format(num, at, hp)
|
||||||
|
for i = 0, 31 do
|
||||||
|
s = s..("\t%02X"):format(R1(dmg + i))
|
||||||
|
end
|
||||||
|
print(s)
|
||||||
end
|
end
|
||||||
seen_strs[num] = str
|
|
||||||
print(str)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if num > 0x300 then
|
||||||
|
print(("BAD %06X %04X (%2i:%2i)"):format(addr, num, at, ai))
|
||||||
|
actor_names[num] = "BAD"
|
||||||
|
elseif not seen[num] then
|
||||||
|
seen[num] = true
|
||||||
|
needs_update = true
|
||||||
|
local str
|
||||||
|
if name:sub(1,1) == "?" then
|
||||||
|
str = ("%s (%03X)"):format(name, num)
|
||||||
|
else
|
||||||
|
str = ("%s"):format(name)
|
||||||
|
end
|
||||||
|
seen_strs[num] = str
|
||||||
|
print(str)
|
||||||
|
end
|
||||||
|
|
||||||
j = j + 1
|
j = j + 1
|
||||||
once = true
|
|
||||||
if j > 255 then
|
if j > 255 then
|
||||||
print("something went terribly wrong")
|
print("something went terribly wrong")
|
||||||
do return end
|
do return end
|
||||||
|
@ -164,22 +189,22 @@ while true do
|
||||||
return sorted
|
return sorted
|
||||||
end
|
end
|
||||||
|
|
||||||
if seen_new then
|
if needs_update then
|
||||||
seen_strs_sorted = sort_by_key(seen_strs)
|
seen_strs_sorted = sort_by_key(seen_strs)
|
||||||
end
|
end
|
||||||
for i, t in ipairs(seen_strs_sorted) do
|
for i, t in ipairs(seen_strs_sorted) do
|
||||||
T(0, i - 1, t.v, nil, "topleft")
|
T_TL(0, i - 1, t.v)
|
||||||
end
|
end
|
||||||
|
|
||||||
T(0, 0, ("unique:%3i"):format(#seen_strs_sorted), nil, "bottomright")
|
T_BR(0, 0, ("unique:%3i"):format(#seen_strs_sorted))
|
||||||
|
|
||||||
if once then
|
if any > 0 then
|
||||||
local cursor = bit.band(addrs.z_cursor_actor(), 0x7FFFFFFF)
|
local cursor = pmask(addrs.z_cursor_actor())
|
||||||
local target = bit.band(addrs.z_target_actor(), 0x7FFFFFFF)
|
local target = pmask(addrs.z_target_actor())
|
||||||
local z = target or cursor
|
local z = target or cursor
|
||||||
if z then
|
if z then
|
||||||
local num = R2(z)
|
local num = R2(z)
|
||||||
T(0, 0, seen_strs[num], nil, "topright")
|
T_TR(0, 0, seen_strs[num])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue