User File #638629979422795995

Upload All User Files

#638629979422795995 - Crush 3D

Crush 3D.lua
Game: Crush 3D ( 3DS, see all files )
16 downloads
Uploaded 9/27/2024 1:39 AM by inconsistent (see all 30)
Displays the position, speed, and state in the OSD. Only for US version on Old 3DS (3ds --> Settings --> Sync Settings --> Is New 3DS must be set to False)
-- Crush 3D Lua (Values for USA ver... OLD 3DS ONLY!)
local prevX, prevY, prevZ, X, Y, Z = 0, 0, 0, 0, 0, 0
local speed, speedY, frameDifference = 0, 0, 0
local how_long_is_stopped = 0 
--[[crush runs at 30fps, but encore core still
    reads the values at 60fps. this means
    without checking how long danny's stopped,
    the speed values will alternate between
    0 and the actual speed every other frame
    (so 0.0, 0.2, 0.0, 0.2, etc)
--]]
local X_Addr = 0x02B7E458  -- x coord address
local s_Addr = 0x02B99AEE  -- state address
local prevFrameCount = emu.framecount()

local function calc_speed()
    -- update previous positions
    prevX, prevY, prevZ = X, Y, Z

    -- read current positions + state
    X = mainmemory.readfloat(X_Addr, false)
    Y = mainmemory.readfloat(X_Addr + 4, false)
    Z = mainmemory.readfloat(X_Addr + 8, false)
    s = mainmemory.read_u8(s_Addr) -- state

    -- get frame difference
    local currentFrameCount = emu.framecount()
    frameDifference = currentFrameCount - prevFrameCount

    -- calculate horizontal speed
    if (prevX ~= X or prevZ ~= Z) and frameDifference ~= 0 then
        local deltaX = X - prevX
        local deltaZ = Z - prevZ
        local distance = math.sqrt(deltaX * deltaX + deltaZ * deltaZ)
        speed = distance / frameDifference
        how_long_is_stopped = 0
    else
        how_long_is_stopped = how_long_is_stopped + 1
        if how_long_is_stopped > 2 then
            speed = 0
        end
    end

    -- calculate vertical speed
    if (prevY ~= Y) and frameDifference ~= 0 then
        local deltaY = Y - prevY
        speedY = deltaY / frameDifference
        how_long_is_stopped = 0
    else
        how_long_is_stopped = how_long_is_stopped + 1
        if how_long_is_stopped > 2 then
            speedY = 0
        end
    end

    -- display
    gui.text(1, 120, string.format("X: %.4f", X), "white")
    gui.text(1, 140, string.format("Y: %.4f", Y), "white")
    gui.text(1, 160, string.format("Z: %.4f", Z), "white")
    gui.text(1, 180, "State: " .. s, "white")
    gui.text(1, 200, string.format("Horizontal Speed: %.4f", speed), "white")
    gui.text(1, 220, string.format("Vertical Speed: %.4f", speedY), "white")

    -- update previous frame count
    prevFrameCount = currentFrameCount
end

while true do
    calc_speed()
    emu.frameadvance()
end