mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-12-22 16:30:23 +00:00
Lua stuff
Added HOOK_BEFORE_MARIO_UPDATE Added support for Vec3f/Vec3s in autogenerated lua functions Added more lua functions from mario_actions_submerged.c, and thread6.c Renamed animation-related fields in CObject wrappers Moved coss and sins to wrapper Extended Moveset: Fixed rolling angle bug Added rumble calls Set facing direction when spinning Added ledge parkour Corrected ground pound animation
This commit is contained in:
parent
cc2324d35e
commit
8f3ca4c6ea
15 changed files with 698 additions and 146 deletions
|
@ -6,6 +6,9 @@ integer_types = ["u8", "u16", "u32", "u64", "s8", "s16", "s32", "s64", "int"]
|
|||
number_types = ["f32", "float"]
|
||||
cobject_types = ["struct MarioState*", "struct Object*", "struct Surface*"]
|
||||
cobject_lot_types = ["LOT_MARIO_STATE", "LOT_OBJECT", "LOT_SURFACE"]
|
||||
param_override_build = {}
|
||||
|
||||
###########################################################
|
||||
|
||||
template = """/* THIS FILE IS AUTOGENERATED */
|
||||
/* SHOULD NOT BE MANUALLY CHANGED */
|
||||
|
@ -29,6 +32,50 @@ $[BINDS]
|
|||
}
|
||||
"""
|
||||
|
||||
###########################################################
|
||||
|
||||
param_vec3f_before_call = """
|
||||
f32* $[IDENTIFIER] = smlua_get_vec3f_from_buffer();
|
||||
$[IDENTIFIER][0] = smlua_get_number_field($[INDEX], "x");
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
$[IDENTIFIER][1] = smlua_get_number_field($[INDEX], "y");
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
$[IDENTIFIER][2] = smlua_get_number_field($[INDEX], "z");
|
||||
"""
|
||||
|
||||
param_vec3f_after_call = """
|
||||
smlua_push_number_field($[INDEX], "x", $[IDENTIFIER][0]);
|
||||
smlua_push_number_field($[INDEX], "y", $[IDENTIFIER][1]);
|
||||
smlua_push_number_field($[INDEX], "z", $[IDENTIFIER][2]);
|
||||
"""
|
||||
|
||||
param_override_build['Vec3f'] = {
|
||||
'before': param_vec3f_before_call,
|
||||
'after': param_vec3f_after_call
|
||||
}
|
||||
|
||||
param_vec3s_before_call = """
|
||||
s16* $[IDENTIFIER] = smlua_get_vec3s_from_buffer();
|
||||
$[IDENTIFIER][0] = smlua_get_integer_field($[INDEX], "x");
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
$[IDENTIFIER][1] = smlua_get_integer_field($[INDEX], "y");
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
$[IDENTIFIER][2] = smlua_get_integer_field($[INDEX], "z");
|
||||
"""
|
||||
|
||||
param_vec3s_after_call = """
|
||||
smlua_push_integer_field($[INDEX], "x", $[IDENTIFIER][0]);
|
||||
smlua_push_integer_field($[INDEX], "y", $[IDENTIFIER][1]);
|
||||
smlua_push_integer_field($[INDEX], "z", $[IDENTIFIER][2]);
|
||||
"""
|
||||
|
||||
param_override_build['Vec3s'] = {
|
||||
'before': param_vec3s_before_call,
|
||||
'after': param_vec3s_after_call
|
||||
}
|
||||
|
||||
###########################################################
|
||||
|
||||
built_functions = ""
|
||||
built_binds = ""
|
||||
|
||||
|
@ -111,7 +158,9 @@ def build_param(param, i):
|
|||
ptype = param['type']
|
||||
pid = param['identifier']
|
||||
|
||||
if ptype in integer_types:
|
||||
if ptype in param_override_build:
|
||||
return param_override_build[ptype]['before'].replace('$[IDENTIFIER]', str(pid)).replace('$[INDEX]', str(i))
|
||||
elif ptype in integer_types:
|
||||
return ' %s %s = smlua_to_integer(L, %d);\n' % (ptype, pid, i)
|
||||
elif ptype in number_types:
|
||||
return ' %s %s = smlua_to_number(L, %d);\n' % (ptype, pid, i)
|
||||
|
@ -121,7 +170,16 @@ def build_param(param, i):
|
|||
else:
|
||||
return ' ' + ptype + ' ' + pid + ' <--- UNIMPLEMENTED' + '\n'
|
||||
|
||||
def build_return(function):
|
||||
def build_param_after(param, i):
|
||||
ptype = param['type']
|
||||
pid = param['identifier']
|
||||
|
||||
if ptype in param_override_build:
|
||||
return param_override_build[ptype]['after'].replace('$[IDENTIFIER]', str(pid)).replace('$[INDEX]', str(i))
|
||||
else:
|
||||
return ''
|
||||
|
||||
def build_call(function):
|
||||
ftype = function['type']
|
||||
fid = function['identifier']
|
||||
|
||||
|
@ -155,7 +213,14 @@ def build_function(function):
|
|||
if do_extern:
|
||||
s += ' extern %s\n' % function['line']
|
||||
|
||||
s += build_return(function)
|
||||
s += build_call(function)
|
||||
|
||||
i = 1
|
||||
for param in function['params']:
|
||||
s += build_param_after(param, i)
|
||||
i += 1
|
||||
s += '\n'
|
||||
|
||||
s += ' return 1;\n}\n'
|
||||
|
||||
function['implemented'] = 'UNIMPLEMENTED' not in s
|
||||
|
|
1
autogen/lua_functions/external.h
Normal file
1
autogen/lua_functions/external.h
Normal file
|
@ -0,0 +1 @@
|
|||
void play_sound(s32 soundBits, Vec3f pos);
|
|
@ -1,4 +1,6 @@
|
|||
void set_swimming_at_surface_particles(struct MarioState *m, u32 particleFlag);
|
||||
u32 perform_water_step(struct MarioState *m);
|
||||
u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos);
|
||||
s32 mario_execute_submerged_action(struct MarioState *m);
|
||||
void float_surface_gfx(struct MarioState *m);
|
||||
void float_surface_gfx(struct MarioState *m);
|
||||
void apply_water_current(struct MarioState *m, Vec3f step);
|
||||
|
|
3
autogen/lua_functions/thread6.c
Normal file
3
autogen/lua_functions/thread6.c
Normal file
|
@ -0,0 +1,3 @@
|
|||
void queue_rumble_data(s16 a0, s16 a1);
|
||||
void queue_rumble_data_object(struct Object* object, s16 a0, s16 a1);
|
||||
void queue_rumble_data_mario(struct MarioState* m, s16 a0, s16 a1);
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
HOOK_UPDATE = 0
|
||||
HOOK_MARIO_UPDATE = 1
|
||||
HOOK_MAX = 2
|
||||
HOOK_BEFORE_MARIO_UPDATE = 2
|
||||
HOOK_MAX = 3
|
||||
|
||||
_CObject = {
|
||||
__index = function (t,k)
|
||||
|
|
240
mods/test.lua
240
mods/test.lua
|
@ -41,52 +41,75 @@ for i=0,(MAX_PLAYERS-1) do
|
|||
e.lastPos.x = m.pos.x
|
||||
e.lastPos.y = m.pos.y
|
||||
e.lastPos.z = m.pos.z
|
||||
end
|
||||
|
||||
---------------
|
||||
-- utilities --
|
||||
---------------
|
||||
|
||||
function sins(theta)
|
||||
return math.sin(theta * math.pi / (2 * 16384))
|
||||
end
|
||||
|
||||
function coss(theta)
|
||||
return math.cos(theta * math.pi / (2 * 16384))
|
||||
e.fakeSavedAction = 0
|
||||
e.fakeSavedPrevAction = 0
|
||||
e.fakeSavedActionTimer = 0
|
||||
e.fakeWroteAction = 0
|
||||
e.fakeSaved = false
|
||||
end
|
||||
|
||||
----------
|
||||
-- roll --
|
||||
----------
|
||||
|
||||
function increase_roll_yaw(m)
|
||||
local newFacingDYaw = m.faceAngle.y - m.slideYaw
|
||||
function update_roll_sliding_angle(m, accel, lossFactor)
|
||||
local floor = m.floor
|
||||
local slopeAngle = atan2s(floor.normal.z, floor.normal.x)
|
||||
local steepness = math.sqrt(floor.normal.x * floor.normal.x + floor.normal.z * floor.normal.z)
|
||||
|
||||
m.slideVelX = m.slideVelX + accel * steepness * sins(slopeAngle)
|
||||
m.slideVelZ = m.slideVelZ + accel * steepness * coss(slopeAngle)
|
||||
|
||||
m.slideVelX = m.slideVelX * lossFactor
|
||||
m.slideVelZ = m.slideVelZ * lossFactor
|
||||
|
||||
m.slideYaw = atan2s(m.slideVelZ, m.slideVelX)
|
||||
|
||||
local facingDYaw = m.faceAngle.y - m.slideYaw
|
||||
local newFacingDYaw = facingDYaw
|
||||
|
||||
if newFacingDYaw > 0 and newFacingDYaw <= 0x4000 then
|
||||
newFacingDYaw = newFacingDYaw - 0x200
|
||||
if newFacingDYaw < 0 then
|
||||
newFacingDYaw = 0
|
||||
end
|
||||
elseif newFacingDYaw > -0x4000 and newFacingDYaw < 0 then
|
||||
if newFacingDYaw < 0 then newFacingDYaw = 0 end
|
||||
|
||||
elseif newFacingDYaw >= -0x4000 and newFacingDYaw < 0 then
|
||||
newFacingDYaw = newFacingDYaw + 0x200
|
||||
if newFacingDYaw > 0 then
|
||||
newFacingDYaw = 0
|
||||
end
|
||||
if newFacingDYaw > 0 then newFacingDYaw = 0 end
|
||||
|
||||
elseif newFacingDYaw > 0x4000 and newFacingDYaw < 0x8000 then
|
||||
newFacingDYaw = newFacingDYaw + 0x200
|
||||
if newFacingDYaw > 0x8000 then
|
||||
newFacingDYaw = 0x8000
|
||||
end
|
||||
if newFacingDYaw > 0x8000 then newFacingDYaw = 0x8000 end
|
||||
|
||||
elseif newFacingDYaw > -0x8000 and newFacingDYaw < -0x4000 then
|
||||
newFacingDYaw = newFacingDYaw - 0x200
|
||||
if newFacingDYaw < -0x8000 then
|
||||
newFacingDYaw = -0x8000
|
||||
end
|
||||
if newFacingDYaw < -0x8000 then newFacingDYaw = -0x8000 end
|
||||
end
|
||||
|
||||
m.faceAngle.y = m.slideYaw + newFacingDYaw
|
||||
|
||||
m.vel.x = m.slideVelX
|
||||
m.vel.y = 0.0
|
||||
m.vel.z = m.slideVelZ
|
||||
|
||||
mario_update_moving_sand(m)
|
||||
mario_update_windy_ground(m)
|
||||
|
||||
--! Speed is capped a frame late (butt slide HSG)
|
||||
m.forwardVel = math.sqrt(m.slideVelX * m.slideVelX + m.slideVelZ * m.slideVelZ)
|
||||
if m.forwardVel > 100.0 then
|
||||
m.slideVelX = m.slideVelX * 100.0 / m.forwardVel
|
||||
m.slideVelZ = m.slideVelZ * 100.0 / m.forwardVel
|
||||
end
|
||||
|
||||
if newFacingDYaw < -0x4000 or newFacingDYaw > 0x4000 then
|
||||
m.forwardVel = m.forwardVel * -1.0
|
||||
m.faceAngle.y = m.faceAngle.y + 0x4000
|
||||
end
|
||||
|
||||
-- HACK: instead of approaching slideYaw, just set faceAngle to it
|
||||
-- this is different than the original Extended Movement... just couldn't figure out the bug
|
||||
m.faceAngle.y = m.slideYaw
|
||||
end
|
||||
|
||||
function update_roll_sliding(m, stopSpeed)
|
||||
|
@ -109,7 +132,7 @@ function update_roll_sliding(m, stopSpeed)
|
|||
--! This is uses trig derivatives to rotate Mario's speed.
|
||||
-- In vanilla, it was slightly off/asymmetric since it uses the new X speed, but the old
|
||||
-- Z speed. I've gone and fixed it here.
|
||||
local angleChange = (m.intendedMag / 32.0) --* 0.6
|
||||
local angleChange = (m.intendedMag / 32.0) * 0.6
|
||||
local modSlideVelX = m.slideVelZ * angleChange * sideward * 0.05
|
||||
local modSlideVelZ = m.slideVelX * angleChange * sideward * 0.05
|
||||
|
||||
|
@ -123,8 +146,7 @@ function update_roll_sliding(m, stopSpeed)
|
|||
m.slideVelZ = m.slideVelZ * oldSpeed / newSpeed
|
||||
end
|
||||
|
||||
update_sliding_angle(m, accel, lossFactor)
|
||||
increase_roll_yaw(m)
|
||||
update_roll_sliding_angle(m, accel, lossFactor)
|
||||
|
||||
if m.playerIndex == 0 and mario_floor_is_slope(m) == 0 and m.forwardVel * m.forwardVel < stopSpeed * stopSpeed then
|
||||
mario_set_forward_vel(m, 0.0)
|
||||
|
@ -153,57 +175,58 @@ function act_roll(m)
|
|||
end
|
||||
elseif m.actionTimer >= ROLL_CANCEL_LOCKOUT_TIME or m.actionArg == 1 then
|
||||
if (m.input & INPUT_Z_DOWN) == 0 then
|
||||
return set_mario_action(m, ACT_WALKING, 0);
|
||||
return set_mario_action(m, ACT_WALKING, 0)
|
||||
end
|
||||
end
|
||||
|
||||
if (m.input & INPUT_B_PRESSED) ~= 0 then
|
||||
return set_jumping_action(m, ACT_FORWARD_ROLLOUT, 0);
|
||||
queue_rumble_data_mario(m, 5, 80)
|
||||
return set_jumping_action(m, ACT_FORWARD_ROLLOUT, 0)
|
||||
end
|
||||
|
||||
if (m.input & INPUT_A_PRESSED) ~= 0 then
|
||||
return set_jumping_action(m, ACT_LONG_JUMP, 0);
|
||||
return set_jumping_action(m, ACT_LONG_JUMP, 0)
|
||||
end
|
||||
|
||||
if (m.controller.buttonPressed & R_TRIG) ~= 0 and m.actionTimer > 0 then
|
||||
m.vel.y = 19.0;
|
||||
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, 0);
|
||||
m.vel.y = 19.0
|
||||
play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, 0)
|
||||
|
||||
if e.boostTimer >= BOOST_LOCKOUT_TIME then
|
||||
e.boostTimer = 0;
|
||||
e.boostTimer = 0
|
||||
|
||||
if m.forwardVel < MAX_NORMAL_ROLL_SPEED then
|
||||
mario_set_forward_vel(m, math.min(m.forwardVel + ROLL_BOOST_GAIN, MAX_NORMAL_ROLL_SPEED));
|
||||
mario_set_forward_vel(m, math.min(m.forwardVel + ROLL_BOOST_GAIN, MAX_NORMAL_ROLL_SPEED))
|
||||
end
|
||||
|
||||
m.particleFlags = m.particleFlags | PARTICLE_HORIZONTAL_STAR;
|
||||
m.particleFlags = m.particleFlags | PARTICLE_HORIZONTAL_STAR
|
||||
|
||||
-- ! playing this after the call to play_mario_sound seems to matter in making this sound play
|
||||
play_sound(SOUND_ACTION_SPIN, m.marioObj.header.gfx.cameraToObject)
|
||||
end
|
||||
|
||||
return set_mario_action(m, ACT_ROLL_AIR, m.actionArg);
|
||||
return set_mario_action(m, ACT_ROLL_AIR, m.actionArg)
|
||||
end
|
||||
|
||||
set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING);
|
||||
set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING)
|
||||
|
||||
if update_roll_sliding(m, 10.0) ~= 0 then
|
||||
return set_mario_action(m, ACT_CROUCH_SLIDE, 0);
|
||||
return set_mario_action(m, ACT_CROUCH_SLIDE, 0)
|
||||
end
|
||||
|
||||
common_slide_action(m, ACT_CROUCH_SLIDE, ACT_ROLL_AIR, MARIO_ANIM_FORWARD_SPINNING);
|
||||
common_slide_action(m, ACT_CROUCH_SLIDE, ACT_ROLL_AIR, MARIO_ANIM_FORWARD_SPINNING)
|
||||
|
||||
e.rotAngle = e.rotAngle + (0x80 * m.forwardVel);
|
||||
e.rotAngle = e.rotAngle + (0x80 * m.forwardVel)
|
||||
if e.rotAngle > 0x10000 then
|
||||
e.rotAngle = e.rotAngle - 0x10000;
|
||||
e.rotAngle = e.rotAngle - 0x10000
|
||||
end
|
||||
set_anim_to_frame(m, 10 * e.rotAngle / 0x10000);
|
||||
set_anim_to_frame(m, 10 * e.rotAngle / 0x10000)
|
||||
|
||||
e.boostTimer = e.boostTimer + 1;
|
||||
e.boostTimer = e.boostTimer + 1
|
||||
|
||||
m.actionTimer = m.actionTimer + 1;
|
||||
m.actionTimer = m.actionTimer + 1
|
||||
|
||||
return 0;
|
||||
return 0
|
||||
end
|
||||
|
||||
function act_roll_air(m)
|
||||
|
@ -231,6 +254,7 @@ function act_roll_air(m)
|
|||
return set_mario_action(m, ACT_ROLL, m.actionArg)
|
||||
end
|
||||
elseif air_step == AIR_STEP_HIT_WALL then
|
||||
queue_rumble_data_mario(m, 5, 40)
|
||||
mario_bonk_reflection(m, false)
|
||||
m.faceAngle.y = m.faceAngle.y + 0x8000
|
||||
|
||||
|
@ -295,10 +319,6 @@ function update_roll(m)
|
|||
if (m.input & INPUT_ABOVE_SLIDE) == 0 then
|
||||
if (m.input & INPUT_Z_DOWN) ~= 0 and m.actionTimer < 2 then
|
||||
return set_mario_action(m, ACT_ROLL, 1)
|
||||
elseif (m.input & INPUT_B_PRESSED) ~= 0 then
|
||||
-- dive hop
|
||||
-- m.vel.y = 21.0
|
||||
-- return set_mario_action(m, ACT_DIVE, 1)
|
||||
end
|
||||
end
|
||||
m.actionTimer = m.actionTimer + 1
|
||||
|
@ -306,8 +326,8 @@ function update_roll(m)
|
|||
|
||||
if m.action == ACT_LONG_JUMP_LAND then
|
||||
if (m.input & INPUT_Z_DOWN) ~= 0 and m.forwardVel > 15.0 and m.actionTimer < 1 then
|
||||
play_mario_landing_sound_once(m, SOUND_ACTION_TERRAIN_LANDING);
|
||||
return set_mario_action(m, ACT_ROLL, 1);
|
||||
play_mario_landing_sound_once(m, SOUND_ACTION_TERRAIN_LANDING)
|
||||
return set_mario_action(m, ACT_ROLL, 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -473,6 +493,12 @@ function act_spin_jump(m)
|
|||
common_air_action_step(m, ACT_DOUBLE_JUMP_LAND, MARIO_ANIM_TWIRL,
|
||||
AIR_STEP_CHECK_HANG)
|
||||
|
||||
-- set facing direction
|
||||
-- not part of original Extended Moveset
|
||||
local yawDiff = m.faceAngle.y - m.intendedYaw
|
||||
e.rotAngle = e.rotAngle + yawDiff
|
||||
m.faceAngle.y = m.intendedYaw
|
||||
|
||||
e.rotAngle = e.rotAngle + 0x2867
|
||||
if (e.rotAngle > 0x10000) then e.rotAngle = e.rotAngle - 0x10000 end
|
||||
if (e.rotAngle < -0x10000) then e.rotAngle = e.rotAngle + 0x10000 end
|
||||
|
@ -526,6 +552,7 @@ function act_spin_pound(m)
|
|||
local stepResult = perform_air_step(m, 0)
|
||||
if stepResult == AIR_STEP_LANDED then
|
||||
if should_get_stuck_in_ground(m) ~= 0 then
|
||||
queue_rumble_data_mario(m, 5, 80)
|
||||
play_sound(SOUND_MARIO_OOOF2, m.marioObj.header.gfx.cameraToObject)
|
||||
m.particleFlags = m.particleFlags | PARTICLE_MIST_CIRCLE
|
||||
set_mario_action(m, ACT_BUTT_STUCK_IN_GROUND, 0)
|
||||
|
@ -547,6 +574,12 @@ function act_spin_pound(m)
|
|||
set_mario_action(m, ACT_BACKWARD_AIR_KB, 0)
|
||||
end
|
||||
|
||||
-- set facing direction
|
||||
-- not part of original Extended Moveset
|
||||
local yawDiff = m.faceAngle.y - m.intendedYaw
|
||||
e.rotAngle = e.rotAngle + yawDiff
|
||||
m.faceAngle.y = m.intendedYaw
|
||||
|
||||
e.rotAngle = e.rotAngle + 0x3053
|
||||
if e.rotAngle > 0x10000 then e.rotAngle = e.rotAngle - 0x10000 end
|
||||
if e.rotAngle < -0x10000 then e.rotAngle = e.rotAngle + 0x10000 end
|
||||
|
@ -662,6 +695,10 @@ function act_water_ground_pound(m)
|
|||
end
|
||||
|
||||
m.particleFlags = m.particleFlags | PARTICLE_WATER_SPLASH
|
||||
|
||||
if (m.prevAction & ACT_FLAG_AIR) ~= 0 then
|
||||
queue_rumble_data_mario(m, 5, 80)
|
||||
end
|
||||
end
|
||||
|
||||
m.actionState = m.actionArg
|
||||
|
@ -684,7 +721,7 @@ function act_water_ground_pound(m)
|
|||
end
|
||||
|
||||
m.actionTimer = m.actionTimer + 1
|
||||
if (m.actionTimer >= m.marioObj.header.gfx.unk38.curAnim.unk08 + 4) then
|
||||
if (m.actionTimer >= m.marioObj.header.gfx.animInfo.curAnim.loopEnd + 4) then
|
||||
-- play_sound(SOUND_MARIO_GROUND_POUND_WAH, m.marioObj.header.gfx.cameraToObject)
|
||||
play_sound(SOUND_ACTION_SWIM_FAST, m.marioObj.header.gfx.cameraToObject)
|
||||
m.vel.y = -45.0
|
||||
|
@ -864,6 +901,56 @@ function act_water_ground_pound_jump(m)
|
|||
return 0
|
||||
end
|
||||
|
||||
-------------------
|
||||
-- ledge parkour --
|
||||
-------------------
|
||||
|
||||
function act_ledge_parkour(m)
|
||||
set_mario_animation(m, MARIO_ANIM_SLIDEFLIP)
|
||||
|
||||
local animFrame = m.marioObj.header.gfx.animInfo.animFrame
|
||||
|
||||
if m.actionTimer == 0 then
|
||||
play_sound(SOUND_MARIO_HAHA_2, m.marioObj.header.gfx.cameraToObject)
|
||||
elseif m.actionTimer == 1 then
|
||||
play_sound(SOUND_ACTION_SIDE_FLIP_UNK, m.marioObj.header.gfx.cameraToObject)
|
||||
end
|
||||
|
||||
update_air_without_turn(m)
|
||||
|
||||
local step = perform_air_step(m, AIR_STEP_CHECK_LEDGE_GRAB)
|
||||
if step == AIR_STEP_NONE then
|
||||
-- play the side flip animation at double speed for a portion of it
|
||||
if animFrame < 15 then
|
||||
animFrame = animFrame + 2
|
||||
elseif animFrame > 23 then
|
||||
animFrame = 23
|
||||
else
|
||||
animFrame = animFrame + 1
|
||||
end
|
||||
|
||||
set_anim_to_frame(m, animFrame)
|
||||
m.marioObj.header.gfx.angle.y = m.marioObj.header.gfx.angle.y + 0x8000
|
||||
|
||||
elseif step == AIR_STEP_LANDED then
|
||||
m.marioObj.header.gfx.angle.y = m.marioObj.header.gfx.angle.y + 0x8000
|
||||
set_mario_action(m, ACT_FREEFALL_LAND_STOP, 0)
|
||||
play_mario_landing_sound(m, SOUND_ACTION_TERRAIN_LANDING)
|
||||
|
||||
elseif step == AIR_STEP_HIT_WALL then
|
||||
m.marioObj.header.gfx.angle.y = m.marioObj.header.gfx.angle.y + 0x8000
|
||||
mario_set_forward_vel(m, 0.0)
|
||||
|
||||
elseif step == AIR_STEP_HIT_LAVA_WALL then
|
||||
m.marioObj.header.gfx.angle.y = m.marioObj.header.gfx.angle.y + 0x8000
|
||||
lava_boost_on_wall(m)
|
||||
end
|
||||
|
||||
m.actionTimer = m.actionTimer + 1
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
---------------------------------------------------------
|
||||
|
||||
function mario_action_on_change(m)
|
||||
|
@ -889,6 +976,36 @@ function mario_action_on_change(m)
|
|||
m.vel.z = 0
|
||||
elseif m.action == ACT_WATER_PLUNGE and e.actionLastFrame == ACT_GROUND_POUND then
|
||||
return set_mario_action(m, ACT_WATER_GROUND_POUND, 1)
|
||||
elseif m.action == ACT_GROUND_POUND and e.actionLastFrame == ACT_SIDE_FLIP then
|
||||
-- correct animation
|
||||
m.marioObj.header.gfx.angle.y = m.marioObj.header.gfx.angle.y - 0x8000
|
||||
elseif m.action == ACT_LEDGE_GRAB then
|
||||
e.rotAngle = m.forwardVel
|
||||
end
|
||||
end
|
||||
|
||||
function before_mario_update(m)
|
||||
local e = gMarioStateExtras[m.playerIndex]
|
||||
-- revert fake saved action
|
||||
if e.fakeSaved == true then
|
||||
if m.action == e.fakeWroteAction and m.prevAction == e.fakeSavedPrevAction and m.actionTimer == e.fakeSavedActionTimer then
|
||||
m.action = e.fakeSavedAction
|
||||
end
|
||||
e.fakeSaved = false
|
||||
end
|
||||
end
|
||||
|
||||
function after_mario_update(m)
|
||||
local e = gMarioStateExtras[m.playerIndex]
|
||||
-- pretend *_POUND_LAND is ACT_GROUND_POUND_LAND so switches work correctly
|
||||
if m.action == ACT_SPIN_POUND_LAND or m.action == ACT_WATER_GROUND_POUND_LAND then
|
||||
e.fakeSavedAction = m.action
|
||||
e.fakeSavedPrevAction = m.prevAction
|
||||
e.fakeSavedActionTimer = m.actionTimer
|
||||
|
||||
m.action = ACT_GROUND_POUND_LAND
|
||||
e.fakeWroteAction = m.action
|
||||
e.fakeSaved = true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -943,6 +1060,17 @@ function mario_update(m)
|
|||
m.marioObj.header.gfx.angle.y = m.marioObj.header.gfx.angle.y - e.rotAngle
|
||||
end
|
||||
|
||||
-- edge parkour
|
||||
if m.action == ACT_LEDGE_GRAB and m.actionTimer < 4 and (m.input & INPUT_B_PRESSED) ~= 0 then
|
||||
local hasSpaceForMario = (m.ceilHeight - m.floorHeight >= 160.0)
|
||||
if hasSpaceForMario and (e.rotAngle >= 31.0 or m.forwardVel >= 31.0) then
|
||||
mario_set_forward_vel(m, e.rotAngle + 5.0)
|
||||
m.vel.y = 25.0
|
||||
queue_rumble_data_mario(m, 5, 80)
|
||||
set_mario_action(m, ACT_LEDGE_PARKOUR, 0)
|
||||
end
|
||||
end
|
||||
|
||||
-- action change event
|
||||
if e.actionLastFrame ~= m.action then
|
||||
mario_action_on_change(m)
|
||||
|
@ -954,13 +1082,16 @@ function mario_update(m)
|
|||
e.lastPos.y = m.pos.y
|
||||
e.lastPos.z = m.pos.z
|
||||
|
||||
after_mario_update(m)
|
||||
end
|
||||
|
||||
function update()
|
||||
end
|
||||
|
||||
hook_event(HOOK_UPDATE, update)
|
||||
hook_event(HOOK_BEFORE_MARIO_UPDATE, before_mario_update)
|
||||
hook_event(HOOK_MARIO_UPDATE, mario_update)
|
||||
|
||||
hook_mario_action(ACT_ROLL, act_roll)
|
||||
hook_mario_action(ACT_ROLL_AIR, act_roll_air)
|
||||
hook_mario_action(ACT_SPIN_JUMP, act_spin_jump)
|
||||
|
@ -972,3 +1103,4 @@ hook_mario_action(ACT_WATER_GROUND_POUND, act_water_ground_pound)
|
|||
hook_mario_action(ACT_WATER_GROUND_POUND_LAND, act_water_ground_pound_land)
|
||||
hook_mario_action(ACT_WATER_GROUND_POUND_STROKE, act_water_ground_pound_stroke)
|
||||
hook_mario_action(ACT_WATER_GROUND_POUND_JUMP, act_water_ground_pound_jump)
|
||||
hook_mario_action(ACT_LEDGE_PARKOUR, act_ledge_parkour)
|
||||
|
|
|
@ -187,7 +187,7 @@ void update_sliding_angle(struct MarioState *m, f32 accel, f32 lossFactor) {
|
|||
if ((newFacingDYaw -= 0x200) < 0) {
|
||||
newFacingDYaw = 0;
|
||||
}
|
||||
} else if (newFacingDYaw >= -0x4000 && newFacingDYaw < 0) {
|
||||
} else if (newFacingDYaw > -0x4000 && newFacingDYaw < 0) {
|
||||
if ((newFacingDYaw += 0x200) > 0) {
|
||||
newFacingDYaw = 0;
|
||||
}
|
||||
|
|
|
@ -281,6 +281,8 @@ void bhv_mario_update(void) {
|
|||
vec3f_copy(gMarioState->marioBodyState->torsoPos, gMarioState->pos);
|
||||
}
|
||||
|
||||
smlua_call_event_hooks_mario_param(HOOK_BEFORE_MARIO_UPDATE, gMarioState);
|
||||
|
||||
u32 particleFlags = 0;
|
||||
s32 i;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#ifdef DEBUG
|
||||
|
||||
static u8 warpToLevel = LEVEL_SSL;
|
||||
static u8 warpToLevel = LEVEL_BOB;
|
||||
static u8 warpToArea = 27;
|
||||
// warpToArea: 26 = basement
|
||||
// warpToArea: 27 = upstairs
|
||||
|
@ -44,7 +44,6 @@ static void debug_warp_level(u8 level) {
|
|||
gCurrLevelNum = 0;
|
||||
gCurrAreaIndex = 0;
|
||||
gCurrActStarNum = 0;
|
||||
gCurrAreaIndex = 0;
|
||||
gChangeLevel = level;
|
||||
return;
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
enum LuaHookedEventType {
|
||||
HOOK_UPDATE,
|
||||
HOOK_MARIO_UPDATE,
|
||||
HOOK_BEFORE_MARIO_UPDATE,
|
||||
HOOK_MAX,
|
||||
};
|
||||
|
||||
|
|
|
@ -189,8 +189,8 @@ static struct LuaObjectField sObjectNodeFields[LUA_OBJECTNODE_FIELD_COUNT] = {
|
|||
|
||||
#define LUA_GRAPHNODEOBJECT_FIELD_COUNT 14
|
||||
static struct LuaObjectField sGraphNodeObjectFields[LUA_GRAPHNODEOBJECT_FIELD_COUNT] = {
|
||||
{ "unk18", LVT_S8, offsetof(struct GraphNodeObject, unk18), false, LOT_NONE },
|
||||
{ "unk19", LVT_S8, offsetof(struct GraphNodeObject, unk19), false, LOT_NONE },
|
||||
{ "areaIndex", LVT_S8, offsetof(struct GraphNodeObject, unk18), false, LOT_NONE },
|
||||
{ "activeAreaIndex", LVT_S8, offsetof(struct GraphNodeObject, unk19), false, LOT_NONE },
|
||||
{ "angle", LVT_COBJECT, offsetof(struct GraphNodeObject, angle), false, LOT_VEC3S },
|
||||
{ "pos", LVT_COBJECT, offsetof(struct GraphNodeObject, pos), false, LOT_VEC3F },
|
||||
{ "prevAngle", LVT_COBJECT, offsetof(struct GraphNodeObject, prevAngle), false, LOT_VEC3S },
|
||||
|
@ -201,7 +201,7 @@ static struct LuaObjectField sGraphNodeObjectFields[LUA_GRAPHNODEOBJECT_FIELD_CO
|
|||
{ "scale", LVT_COBJECT, offsetof(struct GraphNodeObject, scale), false, LOT_VEC3F },
|
||||
{ "prevScale", LVT_COBJECT, offsetof(struct GraphNodeObject, prevScale), false, LOT_VEC3F },
|
||||
{ "prevScaleTimestamp", LVT_U32, offsetof(struct GraphNodeObject, prevScaleTimestamp), false, LOT_NONE },
|
||||
{ "unk38", LVT_COBJECT, offsetof(struct GraphNodeObject, unk38), false, LOT_GRAPHNODEOBJECTSUB },
|
||||
{ "animInfo", LVT_COBJECT, offsetof(struct GraphNodeObject, unk38), false, LOT_GRAPHNODEOBJECTSUB },
|
||||
{ "cameraToObject", LVT_COBJECT, offsetof(struct GraphNodeObject, cameraToObject), false, LOT_VEC3F },
|
||||
/* unimplemented
|
||||
struct GraphNode node;
|
||||
|
@ -253,13 +253,13 @@ static struct LuaObjectField sGraphNodeObjectSubFields[LUA_GRAPHNODEOBJECTSUB_FI
|
|||
|
||||
#define LUA_ANIMATION_FIELD_COUNT 7
|
||||
static struct LuaObjectField sAnimationFields[LUA_ANIMATION_FIELD_COUNT] = {
|
||||
{ "flags", LVT_S16, offsetof(struct Animation, flags), false, LOT_NONE },
|
||||
{ "unk02", LVT_S16, offsetof(struct Animation, unk02), false, LOT_NONE },
|
||||
{ "unk04", LVT_S16, offsetof(struct Animation, unk04), false, LOT_NONE },
|
||||
{ "unk06", LVT_S16, offsetof(struct Animation, unk06), false, LOT_NONE },
|
||||
{ "unk08", LVT_S16, offsetof(struct Animation, unk08), false, LOT_NONE },
|
||||
{ "unk0A", LVT_S16, offsetof(struct Animation, unk0A), false, LOT_NONE },
|
||||
{ "length", LVT_U32, offsetof(struct Animation, length), false, LOT_NONE },
|
||||
{ "flags", LVT_S16, offsetof(struct Animation, flags), false, LOT_NONE },
|
||||
{ "animYTransDivisor", LVT_S16, offsetof(struct Animation, unk02), false, LOT_NONE },
|
||||
{ "startFrame", LVT_S16, offsetof(struct Animation, unk04), false, LOT_NONE },
|
||||
{ "loopStart", LVT_S16, offsetof(struct Animation, unk06), false, LOT_NONE },
|
||||
{ "loopEnd", LVT_S16, offsetof(struct Animation, unk08), false, LOT_NONE },
|
||||
{ "unusedBoneCount", LVT_S16, offsetof(struct Animation, unk0A), false, LOT_NONE },
|
||||
{ "length", LVT_U32, offsetof(struct Animation, length), false, LOT_NONE },
|
||||
/*
|
||||
const s16 *values;
|
||||
const u16 *index;
|
||||
|
|
|
@ -13,63 +13,22 @@
|
|||
// misc //
|
||||
//////////
|
||||
|
||||
int smlua_play_sound(lua_State* L) {
|
||||
s32 soundsBits = lua_tointeger(L, 1);
|
||||
|
||||
f32* pos = smlua_get_vec3f_from_buffer();
|
||||
pos[0] = smlua_get_number_field(2, "x");
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
pos[1] = smlua_get_number_field(2, "y");
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
pos[2] = smlua_get_number_field(2, "z");
|
||||
int smlua_func_sins(lua_State* L) {
|
||||
f32 x = smlua_to_number(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
extern void play_sound(s32 soundBits, f32 * pos);
|
||||
play_sound(soundsBits, pos);
|
||||
|
||||
lua_pushnumber(L, sins(x));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_perform_water_full_step(lua_State* L) {
|
||||
struct MarioState* m = (struct MarioState*)smlua_to_cobject(L, 1, LOT_MARIO_STATE);
|
||||
int smlua_func_coss(lua_State* L) {
|
||||
f32 x = smlua_to_number(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
f32* nextPos = smlua_get_vec3f_from_buffer();
|
||||
nextPos[0] = smlua_get_number_field(2, "x");
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
nextPos[1] = smlua_get_number_field(2, "y");
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
nextPos[2] = smlua_get_number_field(2, "z");
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
extern u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos);
|
||||
lua_pushinteger(L, perform_water_full_step(m, nextPos));
|
||||
lua_pushnumber(L, coss(x));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_apply_water_current(lua_State* L) {
|
||||
struct MarioState* m = (struct MarioState*)smlua_to_cobject(L, 1, LOT_MARIO_STATE);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
Vec3f step;
|
||||
step[0] = smlua_get_number_field(2, "x");
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
step[1] = smlua_get_number_field(2, "y");
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
step[2] = smlua_get_number_field(2, "z");
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
extern void apply_water_current(struct MarioState *m, Vec3f step);
|
||||
apply_water_current(m, step);
|
||||
|
||||
smlua_push_number_field(step[0], "x");
|
||||
smlua_push_number_field(step[1], "y");
|
||||
smlua_push_number_field(step[2], "z");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int smlua_func_atan2s(lua_State* L) {
|
||||
f32 y = smlua_to_number(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
@ -84,8 +43,7 @@ void smlua_bind_functions(void) {
|
|||
lua_State* L = gLuaState;
|
||||
|
||||
// misc
|
||||
smlua_bind_function(L, "play_sound", smlua_play_sound);
|
||||
smlua_bind_function(L, "perform_water_full_step", smlua_func_perform_water_full_step);
|
||||
smlua_bind_function(L, "apply_water_current", smlua_func_apply_water_current);
|
||||
smlua_bind_function(L, "sins", smlua_func_sins);
|
||||
smlua_bind_function(L, "coss", smlua_func_coss);
|
||||
smlua_bind_function(L, "atan2s", smlua_func_atan2s);
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -6,11 +6,20 @@ u8 gSmLuaConvertSuccess = false;
|
|||
static Vec3f sVec3fBuffer[VEC3F_BUFFER_COUNT] = { 0 };
|
||||
static u8 sVec3fBufferIndex = 0;
|
||||
|
||||
#define VEC3S_BUFFER_COUNT 64
|
||||
static Vec3s sVec3sBuffer[VEC3S_BUFFER_COUNT] = { 0 };
|
||||
static u8 sVec3sBufferIndex = 0;
|
||||
|
||||
f32* smlua_get_vec3f_from_buffer(void) {
|
||||
if (sVec3fBufferIndex > VEC3F_BUFFER_COUNT) { sVec3fBufferIndex = 0; }
|
||||
return sVec3fBuffer[sVec3fBufferIndex++];
|
||||
}
|
||||
|
||||
s16* smlua_get_vec3s_from_buffer(void) {
|
||||
if (sVec3sBufferIndex > VEC3S_BUFFER_COUNT) { sVec3sBufferIndex = 0; }
|
||||
return sVec3sBuffer[sVec3sBufferIndex++];
|
||||
}
|
||||
|
||||
void smlua_bind_function(lua_State* L, const char* name, void* func) {
|
||||
lua_pushcfunction(L, func);
|
||||
lua_setglobal(L, name);
|
||||
|
@ -99,24 +108,23 @@ void smlua_push_object(lua_State* L, enum LuaObjectType lot, void* p) {
|
|||
return;
|
||||
}
|
||||
lua_newtable(L);
|
||||
smlua_push_integer_field(lot, "_lot");
|
||||
smlua_push_integer_field((u64)p, "_pointer");
|
||||
int t = lua_gettop(L);
|
||||
smlua_push_integer_field(t, "_lot", lot);
|
||||
smlua_push_integer_field(t, "_pointer", (u64)p);
|
||||
lua_pushglobaltable(L);
|
||||
lua_getfield(gLuaState, -1, "_CObject");
|
||||
lua_setmetatable(L, -3);
|
||||
lua_pop(L, 1); // pop global table
|
||||
}
|
||||
|
||||
void smlua_push_integer_field(lua_Integer val, char* name) {
|
||||
int t = lua_gettop(gLuaState);
|
||||
void smlua_push_integer_field(int index, char* name, lua_Integer val) {
|
||||
lua_pushinteger(gLuaState, val);
|
||||
lua_setfield(gLuaState, t, name);
|
||||
lua_setfield(gLuaState, index, name);
|
||||
}
|
||||
|
||||
void smlua_push_number_field(lua_Number val, char* name) {
|
||||
int t = lua_gettop(gLuaState);
|
||||
void smlua_push_number_field(int index, char* name, lua_Number val) {
|
||||
lua_pushnumber(gLuaState, val);
|
||||
lua_setfield(gLuaState, t, name);
|
||||
lua_setfield(gLuaState, index, name);
|
||||
}
|
||||
|
||||
lua_Integer smlua_get_integer_field(int index, char* name) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
extern u8 gSmLuaConvertSuccess;
|
||||
|
||||
f32* smlua_get_vec3f_from_buffer(void);
|
||||
s16* smlua_get_vec3s_from_buffer(void);
|
||||
|
||||
void smlua_bind_function(lua_State* L, const char* name, void* func);
|
||||
|
||||
|
@ -12,8 +13,8 @@ lua_Number smlua_to_number(lua_State* L, int index);
|
|||
void* smlua_to_cobject(lua_State* L, int index, enum LuaObjectType lot);
|
||||
|
||||
void smlua_push_object(lua_State* L, enum LuaObjectType lot, void* p);
|
||||
void smlua_push_integer_field(lua_Integer val, char* name);
|
||||
void smlua_push_number_field(lua_Number val, char* name);
|
||||
void smlua_push_integer_field(int index, char* name, lua_Integer val);
|
||||
void smlua_push_number_field(int index, char* name, lua_Number val);
|
||||
|
||||
lua_Integer smlua_get_integer_field(int index, char* name);
|
||||
lua_Number smlua_get_number_field(int index, char* name);
|
||||
|
|
Loading…
Reference in a new issue