local R1u, R1s= memory.readbyte , memory.readbytesigned
local R2u, R2s= memory.readword , memory.readwordsigned
local R4u, R4s= memory.readdword, memory.readdwordsigned
--*****************************************************************************
local function HexStr(v)
--*****************************************************************************
local Str= "+"
if v < 0 then v= -v; Str= "-" end
return Str .. string.format("%4X",v)
end
--*****************************************************************************
local function WordToAngle(v)
--*****************************************************************************
-- Input: Angle in 1/65536 of a revolution
-- Output: Angle in radians
return (v/32768)*math.pi
end
local CompassX,CompassY , CompassL= 120,80 , 60
--*****************************************************************************
local function CompassHUD(n)
--*****************************************************************************
-- Looks nifty, provides an intuitive feel (I hope), but you still need numbers
local a= 0x02012D60 + n*0xCC
local Facing, Momentum= R2s(a+0x78),R2s(a+0x7A)
local z= WordToAngle(Facing)
local x= CompassX + CompassL*math.cos(z)
local y= CompassY + CompassL*math.sin(z)
gui.line(CompassX, CompassY,x,y,0xFF00FFFF)
z= WordToAngle(Momentum)
x= CompassX + CompassL*math.cos(z)
y= CompassY + CompassL*math.sin(z)
gui.line(CompassX, CompassY,x,y,0x00FF00FF)
end
--*****************************************************************************
local function MachineHUD(n)
--*****************************************************************************
local a= 0x02012D60 + n*0xCC
local x, y= R4s(a+0x00), R4s(a+0x04)
gui.text( 0, 0,string.format("%8X",x))
gui.text( 0, 7,string.format("%8X",y))
gui.text( 0, 14,string.format("%8X",R4s(a+0x74))) --Speed
gui.text( 0, 21,string.format("%8X",R4s(a+0x78))) --Facing & Momentum
x= x - R4s(a+0x08)
y= y - R4s(a+0x0C)
local v= math.floor(math.sqrt(x*x + y*y))
gui.text( 36, 14,string.format("%5X",v)) -- Change in position
v= (R2u(a+0x78) - R2u(a+0x7A) + 0x8000)%0x10000 - 0x8000
gui.text( 36, 21,HexStr(v))
gui.text(224, 0,string.format("%4X",R2u(a+0x8A))) --Pow
gui.text(224,153,string.format("%4d",R2u(a+0x8C))) --Boost timer
gui.text(224,145,string.format("%4d",R1u(a+0xA1))) --Trigger timer
end
--*****************************************************************************
local function BasicHUD()
--*****************************************************************************
MachineHUD(3)
CompassHUD(3)
end
gui.register(BasicHUD)
--[[
02012D60 [size=0xCC]
+0x00,4s = X pos
+0x04,4s = Y pos
+0x08,4s = X pos (-1 frame)
+0x0C,4s = Y pos (-1 frame)
+0x10,4s = X pos (-1 frame)
+0x14,4s = Y pos (-1 frame)
+0x18,4s = X pos (-2 frame)
+0x1C,4s = Y pos (-2 frame)
+0x20,4s = X pos (-3 frame)
+0x24,4s = Y pos (-3 frame)
+0x28,4s = X pos (-4 frame)
+0x2C,4s = Y pos (-4 frame)
+0x30
+0x34
+0x38
+0x3C
+0x40
+0x44
+0x48
+0x4C
+0x50
+0x54,4s = Height
+0x58
+0x5C
+0x60
+0x64
+0x68
+0x6C
+0x70
+0x74,2u = Speed
+0x78,2x = Facing
+0x7A,2x = Momentum
+0x7C
+0x80
+0x84,2s = Vertical speed
+0x8A,2u = Pow
+0x8C,2u = Boost timer
+0x8E,2u = Boost timer (false; Counts down only when accel pressed)
+0x90
+0x94,4x = Apparent health
+0x98
+0x9C
+0xA0,1u
+0xA1,1u = Boost trigger timer (hold the boost button!)
+0xA4
+0xA8
+0xAC
+0xB0
+0xB4
+0xB8
+0xBC
+0xC0
+0xC4
+0xC8
]]--