-- HUD for X-Men 2 (Genesis)
-- original by feos, 2012
-- updated by Truncated 2021-02-23
xvel_prev = 0
yvel_prev = 0
xcam_prev = 0
ycam_prev = 0
x_prev = 0
xsub_prev = 0
y_prev = 0
ysub_prev = 0
lagframes = 0
--gui.register(function()
event.onframestart(function()
--factors for text positioning, since gui.text ignores window scaling in Bizhawk
xf = client.screenwidth() / 320
yf = client.screenheight() / 224
x = memory.read_u16_be(0xFFEAB1)
y = memory.read_u16_be(0xFFEAB5)
xvel = memory.read_s16_be (0xFFEABE)
yvel = memory.read_s16_be (0xFFEAC0)
xsub = memory.read_u8(0xFFEAB3)
ysub = memory.read_u8(0xFFEAB7)
xcam = memory.read_u16_be(0xFFCD72)
xcam_bug = memory.read_u16_be(0xFFC73E)
ycam = memory.read_u16_be(0xFFCD70)
xacc = xvel - xvel_prev
yacc = yvel - yvel_prev
xvel_prev = xvel
yvel_prev = yvel
xgui = 120
ygui = 190
xscr = x-xcam
yscr = y-ycam
--boss_x = memory.read_s32_be(0xFF0EA0)/0xff-xcam
--boss_y = memory.read_s32_be(0xFF0EA4)/0xff-ycam
--gui.pixelText(100, 100, boss_x .. ", " .. boss_y, "white")
--object structure
--property address offset def
--base: 0E98 0
--x-pos: 0EA0 8 2bu
--y-pos: 0EA4 C 2bu
--health: 0F01 69 1bs
--hb y1: $0EE4 4C 2bu
--hb x1: $0EE6 4E 2bu
--hb y2: $0EF0 58 2bu
--hb x2: $0EF2 5A 2bu
boss_y1 = memory.read_s16_be(0xFF0EE4)-ycam
boss_x1 = memory.read_s16_be(0xFF0EE6)-xcam
boss_y2 = memory.read_s16_be(0xFF0EF0)-ycam
boss_x2 = memory.read_s16_be(0xFF0EF2)-xcam
gui.drawBox(boss_x1, boss_y1, boss_x2, boss_y2, "purple")
boss2_y1 = memory.read_s16_be(0xFF0F8A)-ycam
boss2_x1 = memory.read_s16_be(0xFF0F8C)-xcam
boss2_y2 = memory.read_s16_be(0xFF0F96)-ycam
boss2_x2 = memory.read_s16_be(0xFF0F98)-xcam
gui.drawBox(boss2_x1, boss2_y1, boss2_x2, boss2_y2, "purple")
p1_y1 = memory.read_s16_be(0xFFeaf4)-ycam
p1_x1 = memory.read_s16_be(0xFFeaf6)-xcam
p1_y2 = memory.read_s16_be(0xFFeb00)-ycam
p1_x2 = memory.read_s16_be(0xFFeb02)-xcam
gui.drawBox(p1_x1, p1_y1, p1_x2, p1_y2, "green")
h1_y1 = memory.read_s16_be(0xFFeafC)-ycam
h1_x1 = memory.read_s16_be(0xFFeafE)-xcam
h1_y2 = memory.read_s16_be(0xFFeaF8)-ycam
h1_x2 = memory.read_s16_be(0xFFeaFA)-xcam
gui.drawPixel(h1_x1, h1_y1, "yellow")
gui.drawPixel(h1_x2, h1_y2, "yellow")
--gui.drawBox(h1_x1, h1_y1, h1_x2, h1_y2, "yellow")
--console.writeline("Prev: " .. x_prev .. ":" .. xsub_prev .. " / " .. y_prev .. ":" .. ysub_prev)
-- Velocities
if xvel < 0 then
xvel_sign = "-"
else
xvel_sign = ""
end
xvel_sub = math.abs(xvel) % 256
xvel_pix = (math.abs(xvel) - xvel_sub)/256
if yvel < 0 then
yvel_sign = "-"
else
yvel_sign = ""
end
yvel_sub = math.abs(yvel) % 256
yvel_pix = (math.abs(yvel) - yvel_sub)/256
-- Accelerations
if xacc < 0 then
xacc_sign = "-"
else
xacc_sign = ""
end
xacc_sub = math.abs(xacc) % 256
xacc_pix = (math.abs(xacc) - xacc_sub)/256
if yacc < 0 then
yacc_sign = "-"
else
yacc_sign = ""
end
yacc_sub = math.abs(yacc) % 256
yacc_pix = (math.abs(yacc) - yacc_sub)/256
--screen and character locked?
if (xcam_prev == xcam) and (ycam_prev == ycam) then
--gui.text(xf*130, yf*100, "SCREEN LOCK! SCREEN LOCK!", "red", "black")
end
xcam_prev = xcam
ycam_prev = ycam
if (x_prev == x) and (xsub_prev == xsub) and
(y_prev == y) and (ysub_prev == ysub)
then
--gui.text(xf*138, yf*108, "CHAR LOCK! CHAR LOCK!", "white", "red")
end
if (xcam_prev == xcam) and (ycam_prev == ycam) and
(x_prev == x) and (xsub_prev == xsub) and
(y_prev == y) and (ysub_prev == ysub)
then
lagframes = lagframes + 1
-- print(lagframes)
end
x_prev = x
xsub_prev = xsub
y_prev = y
ysub_prev = ysub
--print HUD to screen
gui.text(xf*(xgui+30), yf*(ygui), "X Y", "magenta")
gui.text(xf*(xgui), yf*(ygui+8), "Pos:", "green")
gui.text(xf*(xgui+23), yf*(ygui+8), x..":"..xsub, "green")
gui.text(xf*(xgui+60), yf*(ygui+8), y..":"..ysub, "green")
gui.text(xf*(xgui), yf*(ygui+16), "Vel:", "yellow")
gui.text(xf*(xgui+23), yf*(ygui+16), xvel_sign .. xvel_pix .. ":" .. xvel_sub, "yellow")
gui.text(xf*(xgui+60), yf*(ygui+16), yvel_sign .. yvel_pix .. ":" .. yvel_sub, "yellow")
gui.text(xf*(xgui), yf*(ygui+24), "Acc:", "red")
gui.text(xf*(xgui+23), yf*(ygui+24), xacc_sign .. xacc_pix .. ":" .. xacc_sub, "red")
gui.text(xf*(xgui+60), yf*(ygui+24), yacc_sign .. yacc_pix .. ":" .. yacc_sub, "red")
gui.text(xf*(xscr-18), yf*(yscr-7), "I'm here!", "green")
gui.text(xf*100, yf*50, xcam, "green")
gui.text(xf*100, yf*60, xcam_bug, "green")
end)