Documentation Index
Fetch the complete documentation index at: https://mintlify.com/n64decomp/sm64/llms.txt
Use this file to discover all available pages before exploring further.
MarioState is the single struct instance (gMarioState) that the game reads and writes every frame to represent the player. Every system — movement, collision, animation, camera, audio — reaches into this struct. Understanding its layout is the foundation for reading or modifying any Mario behavior in the decomp.
The global instance is declared in src/game/level_update.c and initialised at level load by init_mario_from_save_file() followed by init_mario().
Type aliases
Before looking at the struct, it helps to know the primitive aliases used throughout the codebase (defined ininclude/types.h):
Vec3f is a float triplet with Y as the vertical axis. Vec3s is the signed-16-bit counterpart used for angles (in N64 angle units where 0x10000 = 360°). Mat4 is a standard 4×4 row-major float matrix.
Controller struct
Mario reads input through aController pointer each frame. The raw N64 stick axes are normalised into float ranges.
Raw signed integer values read directly from the N64 controller hardware before any scaling.
Normalised float stick axes in the range
[-64, 64]. Positive X is right, positive Y is up. These are what action code uses for movement intent.Euclidean distance of the stick from centre, clamped to
[0, 64]. Used directly as m->intendedMag after further scaling.Bitmask of all buttons currently held. Common constants:
A_BUTTON, B_BUTTON, Z_TRIG, START_BUTTON.Bitmask of buttons that transitioned from released to held on this frame. Used for single-press detection (jump, attack).
MarioState struct
The full struct as it appears ininclude/types.h:
Field groups
Input and flags
Processed input bitmask computed each frame from the controller state plus environmental conditions. Key bits (defined in
include/sm64.h):| Constant | Value | Meaning |
|---|---|---|
INPUT_NONZERO_ANALOG | 0x0001 | Stick deflected past dead zone |
INPUT_A_PRESSED | 0x0002 | A button newly pressed this frame |
INPUT_OFF_FLOOR | 0x0004 | Mario is airborne |
INPUT_ABOVE_SLIDE | 0x0008 | Floor angle exceeds slide threshold |
INPUT_FIRST_PERSON | 0x0010 | First-person look mode active |
INPUT_SQUISHED | 0x0040 | Mario is being crushed by geometry |
INPUT_A_DOWN | 0x0080 | A button held |
INPUT_IN_POISON_GAS | 0x0100 | Inside HMC poison gas |
INPUT_IN_WATER | 0x0200 | Below water level |
INPUT_STOMPED | 0x0400 | Hit by an enemy stomp |
INPUT_B_PRESSED | 0x2000 | B button newly pressed this frame |
INPUT_Z_DOWN | 0x4000 | Z trigger held |
INPUT_Z_PRESSED | 0x8000 | Z trigger newly pressed this frame |
Persistent per-frame flags about Mario’s state. Key constants from
include/sm64.h:| Constant | Value | Meaning |
|---|---|---|
MARIO_NORMAL_CAP | 0x00000001 | Wearing the normal cap |
MARIO_VANISH_CAP | 0x00000002 | Wearing the vanish cap |
MARIO_METAL_CAP | 0x00000004 | Wearing the metal cap |
MARIO_WING_CAP | 0x00000008 | Wearing the wing cap |
MARIO_CAP_ON_HEAD | 0x00000010 | Cap is on Mario’s head |
MARIO_CAP_IN_HAND | 0x00000020 | Cap is held in Mario’s hand |
MARIO_TELEPORTING | 0x00000080 | Mid-teleport |
MARIO_ACTION_SOUND_PLAYED | 0x00010000 | Action sound was already played this action |
MARIO_PUNCHING | 0x00100000 | Punch animation active |
MARIO_KICKING | 0x00200000 | Kick animation active |
MARIO_TRIPPING | 0x00400000 | Trip animation active |
Bitmask controlling which particle effects spawn this frame. Return value of
execute_mario_action(). Examples: PARTICLE_DUST (1<<0), PARTICLE_SPARKLES (1<<3), PARTICLE_FIRE (1<<11), PARTICLE_SNOW (1<<14).Action system
The current action ID. The upper bits encode the group and flags; the lower 9 bits (
ACT_ID_MASK = 0x1FF) identify the specific action within its group. This value drives the dispatch switch in execute_mario_action().The action from the previous frame, saved by
set_mario_action() before overwriting action. Used by jump logic to determine double/triple jump eligibility.A small integer counter local to the current action. Reset to 0 on every action change. Individual action handlers use it as a sub-state index (e.g. phase 0 = rising, phase 1 = falling).
A frame counter incremented by individual action handlers. Reset to 0 on action change.
An arbitrary argument passed to
set_mario_action() and stored here for the action handler to read. Meaning depends on the action (e.g. lava boost direction, knockback source).Added to footstep sound IDs to select the correct terrain variant (grass, stone, snow, sand, etc.). Computed each frame from the floor’s terrain type bits.
Intended movement (from controller)
The desired movement speed derived from the stick magnitude, scaled to game units. Used by walking and airborne code to compute acceleration.
The world-space yaw direction the stick is pointing, in N64 angle units (0x0 = north, 0x4000 = east). Computed from
stickX/stickY plus the camera angle.Timers and cooldowns
Frames of invincibility remaining after taking damage. Counted down each frame.
Frames elapsed since the A or B button was last pressed. Initialised to
0xFF (never pressed) and reset to 0 on each press. Used for combo detection.Frames remaining in the wall-kick window after Mario contacts a wall while airborne. Nonzero allows
ACT_WALL_KICK_AIR.Frames remaining in the double/triple jump window after landing. Nonzero enables multi-jump chains.
Orientation and physics
Mario’s facing orientation as pitch/yaw/roll in N64 angle units. The yaw component (
faceAngle[1]) is the most frequently written field — it is what determines which direction Mario walks.Angular velocity for pitch/yaw/roll, used by airborne spinning moves such as twirling.
The yaw direction Mario is sliding in during butt/stomach slide actions, separate from
faceAngle.Accumulates rotation during
ACT_TWIRLING. Separate from faceAngle so the facing direction is preserved after the twirl ends.World-space position
{x, y, z} in game units. Y is the vertical axis. This is the authoritative position used for collision queries and rendering.World-space velocity in units/frame.
vel[1] is the vertical velocity, positive = upward. Gravity is applied by subtracting from vel[1] each frame.Signed speed along Mario’s facing direction. Positive = forward, negative = backward. This is the primary speed value for ground movement;
vel[0] and vel[2] are recomputed from it each step.Separate velocity components used during slide actions (butt slide, stomach slide) where movement direction diverges from facing angle.
Collision references
Pointer to the wall surface Mario is currently in contact with, or
NULL. Updated each frame by the movement step functions.Pointer to the ceiling surface directly above Mario, or
NULL.Pointer to the floor surface Mario is standing on or above. This field must not be
NULL during action execution; execute_mario_action() returns early if it is (out-of-bounds detection).Y coordinate of the ceiling directly above Mario’s position. Set to
CELL_HEIGHT_LIMIT (20000) when no ceiling exists.Y coordinate of the floor surface beneath Mario. Used to determine when Mario is airborne (
pos[1] > floorHeight).Yaw angle of the steepest descent direction of the current floor, derived from the floor’s normal vector. Used to determine slide direction.
Y coordinate of the water surface in the current area. Compared against
pos[1] to decide between swimming and walking states on each frame.Object references
The object Mario is interacting with this frame (enemy, item, NPC). Cleared between frames.
The object Mario is currently carrying (
NULL if not holding anything). Affects which action variants are available (e.g. ACT_HOLD_WALKING vs ACT_WALKING).The object Mario is currently using (cannons, doors, signs).
The object Mario is riding (Yoshi, Koopa shells).
Pointer to Mario’s own
Object node in the object list. Provides access to the graphics node (marioObj->header.gfx), animation info, position mirroring, and hitbox data.Spawn point data for the current level entry, including start position and start angle. Read during
init_mario().The current level area. Contains the camera pointer, terrain type, object lists, and warp nodes.
Shared state passed to the camera system each frame (position, facing angle, action).
Controls the visual body pose: cap state, eye state, hand state, torso/head angles, and the held-object last position (HOLP).
Pointer to the
Controller struct for player 1. Initialised to &gControllers[0].DMA handler for streaming Mario’s animations from ROM. Passed to
set_mario_animation() and set_mario_anim_with_accel().Bitmask of interaction types from objects that overlapped Mario’s hitbox this frame. Drives the interaction system in
mario_process_interactions().Game state (coins, stars, health)
Coins collected in the current level session. Displayed on the HUD. Resets between courses.
Total stars collected across all courses in the save file. Read from the save file on level init.
Unused key mechanic left from an earlier design. Always 0 in the shipped game.
Remaining lives. Initialised to 4. Decremented by death;
numLives == -1 triggers Game Over.Health in units of
0x100 per wedge. Full health is 0x880 (8 wedges + 8 sub-units). The HUD wedges field mirrors health >> 8. Decremented by damage, incremented by healing.Countdown timers driving the hurt and heal animations. Set by
hurt_and_set_mario_action() and various healing interactions; decremented until they reach 0.Frames remaining while Mario is squished flat (e.g. crushed by a platform). Forces a shorter hitbox and prevents certain jumps.
Frames remaining on a timed special cap (vanish, metal, or wing). Counts down to 0, at which point the cap expires.
The highest Y position Mario has reached during the current airborne phase. Used to calculate fall damage: if
peakHeight - pos[1] > 1150, Mario takes damage on landing.How far Mario has sunk into quicksand in game units. Incremented while standing on quicksand surfaces; thresholds control when Mario transitions to death or escape actions.
Custom gravity value applied during
ACT_GETTING_BLOWN (wind-blown action). Overrides the normal gravitational acceleration for that action.Reading Mario’s position and action
gMarioState is a pointer to the first element of the gMarioStates array. In the decomp there is only one active player, so gMarioState == &gMarioStates[0] always holds.