User File #40688149441849445

Upload All User Files

#40688149441849445 - Wizards & Warriors III Hitbox Lua for FCEUX

WW3_hitboxes.lua
915 downloads
Uploaded 7/29/2017 9:14 AM by Dacicus (see all 26)
For use in FCEUX. Displays hitboxes for Kuros's weapon and other things. The other hitboxes are derived from the thief 2 and 3 guild bosses, so there may be errors for objects other than those bosses.
local status_offset, status_hitbox_x, status_hitbox_y
local camera_x, camera_y, x_pos, x_low, x_high, y_pos, y_low, y_high
local kuros_state, kuros_weapon, kuros_facing_left, x_reg, y_reg
local D6E1_var, D6E2_var, D6E3_var, D6E4_var, D7E0_var, D80A_var, D834_var, D861_var
local hitbox_x, hitbox_y, hitbox_length, hitbox_height

local function KurosWeaponHitbox()
  camera_x = memory.readwordunsigned(0x0079)
  camera_y = memory.readwordunsigned(0x007B)

  x_low = memory.readbyteunsigned(0x02EE)
  x_high = memory.readbyteunsigned(0x0308)
  x_pos = x_low + x_high * 0x0100

  y_low = memory.readbyteunsigned(0x033C)
  y_high = memory.readbyteunsigned(0x0356)
  y_pos = y_low + y_high * 0x0100

  kuros_state = memory.readbyteunsigned(0x0440)
  kuros_weapon = memory.readbyteunsigned(0x008A)
  kuros_facing_left = memory.readbyteunsigned(0x03F2)

  x_reg = rom.readbyteunsigned(0xD6C9 + kuros_state) + rom.readbyteunsigned(0xD791 + kuros_weapon)
  y_reg = kuros_state * 4

  D6E1_var = rom.readbyteunsigned(0xD6F1 + y_reg)
  D6E2_var = rom.readbyteunsigned(0xD6F2 + y_reg)
  D6E3_var = rom.readbyteunsigned(0xD6F3 + y_reg)
  D6E4_var = rom.readbyteunsigned(0xD6F4 + y_reg)

  D7E0_var = rom.readbyteunsigned(0xD7F0 + x_reg)
  D80A_var = rom.readbyteunsigned(0xD81A + x_reg)
  D834_var = rom.readbyteunsigned(0xD844 + x_reg)
  D861_var = rom.readbyteunsigned(0xD871 + x_reg)

  if (kuros_facing_left == 0) then
    hitbox_x = (x_high + D6E2_var) * 0x0100 + x_low + D6E1_var + D7E0_var
  elseif (kuros_facing_left == 1) then
    hitbox_x = (x_high - D6E2_var) * 0x0100 + x_low - D6E1_var - D7E0_var + 8 - D834_var
  end

  hitbox_y = (y_high + D6E4_var) * 0x0100 + y_low + D6E3_var + D80A_var

  if (D7E0_var > 127) then
    if (kuros_facing_left == 0) then
      hitbox_x = hitbox_x - 256
    elseif (kuros_facing_left == 1) then
      hitbox_x = hitbox_x + 256
    end
  end

  if (D80A_var > 127) then
    hitbox_y = hitbox_y - 256
  end

  hitbox_x = AND(hitbox_x, 0xFFFF)
  hitbox_y = AND(hitbox_y, 0xFFFF)

  hitbox_length = rom.readbytesigned(0xD844 + x_reg)
  hitbox_height = rom.readbytesigned(0xD871 + x_reg)

  if (hitbox_length == 0) or (hitbox_height == 0) then --This is true for some thief 2 stances
    gui.drawbox(hitbox_x - camera_x - 4, hitbox_y - camera_y - 4, hitbox_x - camera_x + 4, hitbox_y - camera_y + 4, "#00FF00FF", "#00FF007F")
    gui.drawline(hitbox_x - camera_x - 4, hitbox_y - camera_y, hitbox_x - camera_x + 4, hitbox_y - camera_y, "#0000FFFF")
    gui.drawline(hitbox_x - camera_x, hitbox_y - camera_y - 4, hitbox_x - camera_x, hitbox_y - camera_y + 4, "#0000FFFF")
  else
    gui.drawrect(hitbox_x - camera_x, hitbox_y - camera_y, hitbox_x - camera_x + hitbox_length, hitbox_y - camera_y + hitbox_height, "#00FF007F", "#00FF00FF")
  end
end

local function ItemHitbox()
  camera_x = memory.readwordunsigned(0x0079)
  camera_y = memory.readwordunsigned(0x007B)

  for i = 0, 0x67 do
    status_offset = memory.readbyteunsigned(0x0440 + i)
    if (status_offset ~= 0xFF) and (status_offset ~= 0) then
      x_low = memory.readbyteunsigned(0x02EE + i)
      x_high = memory.readbyteunsigned(0x0308 + i)
      x_pos = x_high * 0x0100 + x_low - camera_x

      y_low = memory.readbyteunsigned(0x033C + i)
      y_high = memory.readbyteunsigned(0x0356 + i)
      y_pos = y_high * 0x0100 + y_low - camera_y

      status_hitbox_x = rom.readbyteunsigned(0x92F1 + status_offset)
      status_hitbox_y = rom.readbyteunsigned(0xA6AD + status_offset)
      gui.drawbox(x_pos - status_hitbox_x, y_pos - status_hitbox_y, x_pos + status_hitbox_x, y_pos + status_hitbox_y)
    end
  end
end

while true do
  KurosWeaponHitbox()
  ItemHitbox()

  emu.frameadvance()
end