User File #40224233649342720

Upload All User Files

#40224233649342720 - Wizards & Warriors III Kuros Weapon Hitbox Display

WW3_Kuros_weapon_hitbox.lua
896 downloads
Uploaded 7/8/2017 11:48 AM by Dacicus (see all 26)
Draws the hitbox for the currently held weapon. The thief 2 crowbar is special because its hitbox has length and height of 0 in certain stances. This is why it is so hard to cause damage with it. In those cases, a box is drawn with a target inside, and the coordinates for the hitbox are at the center of the target. As far as I can tell, enemies have to hit that center point to take damage.
local camera_x, camera_y, x_low, x_high, y_low, y_high, x_pos, y_pos
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

while true do
  camera_x = memory.read_u16_le(0x0079)
  camera_y = memory.read_u16_le(0x007B)

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

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

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

  x_reg = memory.read_u8(0xD6B9 + kuros_state, "PRG ROM") + memory.read_u8(0xD781 + kuros_weapon, "PRG ROM")
  y_reg = kuros_state * 4

  D6E1_var = memory.read_u8(0xD6E1 + y_reg, "PRG ROM")
  D6E2_var = memory.read_u8(0xD6E2 + y_reg, "PRG ROM")
  D6E3_var = memory.read_u8(0xD6E3 + y_reg, "PRG ROM")
  D6E4_var = memory.read_u8(0xD6E4 + y_reg, "PRG ROM")

  D7E0_var = memory.read_u8(0xD7E0 + x_reg, "PRG ROM")
  D80A_var = memory.read_u8(0xD80A + x_reg, "PRG ROM")
  D834_var = memory.read_u8(0xD834 + x_reg, "PRG ROM")
  D861_var = memory.read_u8(0xD861 + x_reg, "PRG ROM")

  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 = bit.band(hitbox_x, 0xFFFF)
  hitbox_y = bit.band(hitbox_y, 0xFFFF)

--[[ Display some variables for debugging
  gui.drawText(0, 16, x_reg)
  gui.drawText(0, 32, y_reg)

  gui.drawText(50, 16, D6E1_var)
  gui.drawText(50, 32, D6E2_var)
  gui.drawText(50, 48, D6E3_var)
  gui.drawText(50, 64, D6E4_var)

  gui.drawText(100, 16, D7E0_var)
  gui.drawText(100, 32, D80A_var)
  gui.drawText(100, 48, D834_var)
  gui.drawText(100, 64, D861_var)

  gui.drawText(150, 16, hitbox_x)
  gui.drawText(150, 32, hitbox_y)
--]]

  hitbox_length = memory.read_s8(0xD834 + x_reg, "PRG ROM")
  hitbox_height = memory.read_s8(0xD861 + x_reg, "PRG ROM")

  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, 0xFF00FF00, 0x7F00FF00)
    gui.drawLine(hitbox_x - camera_x - 4, hitbox_y - camera_y, hitbox_x - camera_x + 4, hitbox_y - camera_y, 0xFF0000FF)
    gui.drawLine(hitbox_x - camera_x, hitbox_y - camera_y - 4, hitbox_x - camera_x, hitbox_y - camera_y + 4, 0xFF0000FF)
  else
    gui.drawRectangle(hitbox_x - camera_x, hitbox_y - camera_y, hitbox_length, hitbox_height, 0xFF00FF00, 0x7F00FF00)
  end

  emu.frameadvance()
end