From fc374ad5d29722ba93f7135120742fa49eab2824 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 7 Mar 2015 07:43:59 -0800 Subject: [PATCH] damage table dumping and more --- Lua/actor change.lua | 105 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 95 insertions(+), 10 deletions(-) diff --git a/Lua/actor change.lua b/Lua/actor change.lua index 1481bae..fb47781 100755 --- a/Lua/actor change.lua +++ b/Lua/actor change.lua @@ -1,5 +1,8 @@ require "boilerplate" local addrs = require "addrs" +local actor_names = require "actor names" + +local actor_t = Actor(0) -- lolololol memory leaks local actor_type = 2 local actor_index = 0 @@ -15,8 +18,9 @@ function get_first_actor(i) return bit.band(R4(addrs.actor_first_0.addr + i*0xC), 0x7FFFFFFF) end -function get_next_actor(a) - return bit.band(R4(a + 0x12C), 0x7FFFFFFF) +function get_next_actor(addr) + --return bit.band(Actor(addr).next(), 0x7FFFFFFF) + return bit.band(R4(addr + actor_t.next.addr), 0x7FFFFFFF) end function T(x, y, s, color, pos) @@ -25,6 +29,41 @@ function T(x, y, s, color, pos) gui.text(10*x + 2, 16*y + 4, s, nil, color, pos) end +damage_names = { + [0]="Nut", + "Stick", + "Epona", + "Bomb", + "(Z)Fins", + "Bow", + "Mirror?", + "Hook", + "(G)Punch", + "Sword", + "(G)Pound", + "Fire", + "Ice", + "Light", + "(G)Spikes", + "(D)Spin", + "(D)Shoot", + "(D)Dive", + "(D)Bomb", + "(Z)Barrier", + "?", + "?", + "Bush", + "(Z)Karate", + "M. Spin", + "(F)Beam", + "Roll", + "?", + "?", + "?", + "?", + "Keg", +} + while true do local j = joypad.getimmediate() @@ -40,7 +79,7 @@ while true do pressed[k] = ctrl[k] and not old_ctrl[k] end - if pressed.left then + if pressed.left or ctrl.enter then actor_index = actor_index - 1 end if pressed.right then @@ -55,9 +94,10 @@ while true do local any = 0 for i = 0, 11 do local count = get_actor_count(i) - T(0, 11 - i, ("#%2i: %2i"):format(i, count), "white", "bottomleft") + T(0, 12 - i, ("#%2i: %2i"):format(i, count), "white", "bottomleft") any = any + count end + T(0, 0, ("sum:%3i"):format(any), "white", "bottomleft") local actor_count = get_actor_count(actor_type) if any > 0 then @@ -72,21 +112,66 @@ while true do actor_index = 0 end - local actor = get_first_actor(actor_type) + local addr = get_first_actor(actor_type) T(0, 2, ('type: %02X'):format(actor_type)) T(0, 1, ('index: %02X'):format(actor_index)) T(0, 0, ('count: %02X'):format(actor_count)) if actor_index > 0 then - for i = 0, actor_index do - actor = get_next_actor(actor) - if actor == 0 then + for i = 0, actor_index - 1 do + addr = get_next_actor(addr) + if addr == 0 then T(0, 3, "no actor found", "yellow") break end end end - if actor ~= 0 then - addrs.camera_target(0x80000000 + actor) + if addr ~= 0 then + --local actor = Actor(addr) + local num = R2(addr + actor_t.num.addr) + local var = R2(addr + actor_t.var.addr) + local hp = R1(addr + actor_t.hp.addr) + T(0, 3, ('80%06X'):format(addr)) + T(0, 5, ('No.: %03X'):format(num), 'cyan') + T(0, 4, ('Var: %04X'):format(var)) + T(0, 6, ('HP: %02X'):format(hp)) + local name = actor_names[num] + if name then + local color = name == "TODO" and "red" or "orange" + T(0, 8, name, color) + else + actor_names[num] = "TODO" + print(('\t[0x%03X]="???",'):format(num)) + end + --T(0, 3, ('Type: %02X'):format(R1(addr+2))) + + local dmg_t = R4(addr + actor_t.damage_table.addr) + local dmg = bit.band(dmg_t, 0x7FFFFFFF) + if dmg == 0 then + T(0, 7, "no damage table") + else + for i = 0, 31 do + --T(0, 11 - i/4, ('dmg %02i: %08X'):format(i, R4(dmg + i))) + local name = damage_names[i] + local str = ('%9s: %02X'):format(name, R1(dmg + i)) + local pos = 'topleft' + if i >= 16 then i = i - 16; pos = 'topright' end + T(0, i, str, 'white', pos) + end + + if pressed.up then + console.clear() + 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 + + --T(0, 12, ("%08X"):format(addrs.camera_target()), 'white', 'bottomleft') + -- avoid floating point error by our write small + W1(addrs.camera_target.addr, 0x80) + W3(addrs.camera_target.addr + 1, addr) end end