Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 25 additions & 53 deletions Lua/SMG2_Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,15 @@ function core.GameID()
end

-- Pointer based on version
local function RefPointer()
local function getPlayerData(offset)
local address = nil
if core.GameID() == "SB4E01" then address = 0xC7A2C8 -- jp, na
if core.GameID() == "SB4E01" then address = 0x8107C694 -- jp(?), na
elseif core.GameID() == "SB4P01" then address = nil -- eu, unknown ?
end
if address == nil then return nil
else return GetPointerNormal(address)
else return GetPointerNormal(address, 0x2D0, 0x0, offset)
end
end

-- most values are relative to this
local function PosRef()
if RefPointer() == nil then
return nil
else
return GetPointerNormal(RefPointer() + 0x750)
end
end

-- helper function to safely read any 1 value
local function readValue(pointer, offset, readFunc)
if pointer == nil then
return 0
else
return readFunc(pointer + offset)
end
end

-- helper function to read 3 values in a row
local function readTriple(pointer, offset, readFunc, keys)
local data = {}
for i = 1,3 do
data[keys[i]] = readValue(pointer, offset + 4 * (i - 1), readFunc)
end
return data
end

-- STATIC Addresses

-- returns the in-gamer timer in frames
Expand Down Expand Up @@ -88,11 +60,11 @@ end
-- DYNAMIC Addresses

function core.Pos()
return readTriple(PosRef(), - 0x8670, ReadValueFloat, {"X", "Y", "Z"})
return {X = ReadValueFloat(getPlayerData(0x14)), Y = ReadValueFloat(getPlayerData(0x18)), Z = ReadValueFloat(getPlayerData(0x1C))}
end

function core.PrevPos()
return readTriple(PosRef(), 0x14 - 0x8C58, ReadValueFloat, {"X", "Y", "Z"})
return {X = ReadValueFloat(getPlayerData(0x5C4)), Y = ReadValueFloat(getPlayerData(0x5C8)), Z = ReadValueFloat(getPlayerData(0x5CC))}
end

-- Speed based off position change
Expand All @@ -110,12 +82,11 @@ end

-- Set the player's position to certain coordinates
function core.setPos(x, y, z)
local offset1 = 0x14 - 0x8C58
local address = PosRef()
local positionVector = getPlayerData(0x14)
if address ~= nil then
WriteValueFloat(address + offset1, x)
WriteValueFloat(address + offset1 + 4, y)
WriteValueFloat(address + offset1 + 8, z)
WriteValueFloat(positionVector, x)
WriteValueFloat(positionVector + 4, y)
WriteValueFloat(positionVector + 8, z)
end
end

Expand All @@ -129,76 +100,77 @@ end
-- displacement from moving platforms and launch stars are not accounted for
-- this is the velocity that's observed on the NEXT frame
function core.BaseVelocity()
return readTriple(PosRef(), 0x38 - 0x8C58, ReadValueFloat, {"X", "Y", "Z"})
return {X = ReadValueFloat(getPlayerData(0x38)), Y = ReadValueFloat(getPlayerData(0x3C)), Z = ReadValueFloat(getPlayerData(0x40))}
end

-- direction of gravity
function core.DownGravity()
return readTriple(PosRef(), - 0x86C4, ReadValueFloat, {"X", "Y", "Z"})
return {X = ReadValueFloat(getPlayerData(0x594)), Y = ReadValueFloat(getPlayerData(0x598)), Z = ReadValueFloat(getPlayerData(0x59C))}
end

-- Different from gavity + tilt
-- This responds to tilting slopes
-- Unlike tilt, this 'straightens out' to match gravity a few frames after jumping
function core.DownAccel()
return readTriple(PosRef(), - 0x7D88, ReadValueFloat, {"X", "Y", "Z"})
return {X = ReadValueFloat(getPlayerData(0xED0)), Y = ReadValueFloat(getPlayerData(0xED4)), Z = ReadValueFloat(getPlayerData(0xED8))}
end

-- Tilt offset from the upwards gravity vector
function core.Tilt()
return readTriple(PosRef(), - 0x5018, ReadValueFloat, {"X", "Y", "Z"})
return {X = ReadValueFloat(getPlayerData(0x584), 0x1F0), Y = ReadValueFloat(getPlayerData(0x584), 0x1F4), Z = ReadValueFloat(getPlayerData(0x584), 0x1F8)}
end

-- Shaking related information
function core.WiimoteShake()
return readValue(PosRef(), - 0x7C4A, ReadValue8)
return ReadValue8(getPlayerData(0x100E))
end

function core.NunchuckShake()
return readValue(PosRef(), - 0x7C49, ReadValue8)
return ReadValue8(getPlayerData(0x100F))
end

function core.SpinCooldownTimer()
return readValue(PosRef(), - 0x7E19, ReadValue8)
return ReadValue16(getPlayerData(0xE3E))
end

function core.SpinAttackTimer()
return readValue(PosRef(), - 0x7E1C, ReadValue8)
return ReadValue8(getPlayerData(0xE3C))
end

-- this keeps counting up if you do multiple mini-spins in one jump
function core.SpinFrames()
return readValue(PosRef(), - 0x7E1B, ReadValue8)
return ReadValue8(getPlayerData(0xE3D))
end

-- Counts up during a ground spin. If interrupted by jumping, tapping crouch
-- while standing still, etc., stops counting up.
-- Doesn't apply to a crouching spin (couldn't find a similar value that applies)
function core.SpinAnimationFrames()
return readValue(PosRef(), - 0x1BE1, ReadValue8)
return ReadValue16(getPlayerData(0x584), 0x980, 0x12)
end

function core.LumaReturnAnimationTimer()
return readValue(PosRef(), - 0x7E15, ReadValue8)
return ReadValue16(getPlayerData(0xE42))
end

function core.MidairSpinTimer()
return readValue(PosRef(), - 0x4E05, ReadValue8)
return ReadValue16(getPlayerData(0x584), 0x402)
end

function core.MidairSpinType()
return readValue(PosRef(), - 0x4DE1, ReadValue8)
return ReadValue16(getPlayerData(0x584), 0x426)
end

-- Other/misc/unknown purpose for the following addresses
function core.LastJumpType()
return readValue(PosRef(), - 0x4DD9, ReadValue8)
return ReadValue16(getPlayerData(0x584), 0x42C)
end

function core.GroundTurnTimer()
return readValue(PosRef(), - 0x4DFB, ReadValue8)
return ReadValue16(getPlayerData(0x584), 0x40C)
end

-- TODO: find out what this structure variable in-game is
function core.UnknownState()
return readValue(PosRef(), - 0x7D23, ReadValue8)
end
Expand Down