Add HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED

This commit is contained in:
Agent X 2023-12-13 16:57:38 -05:00
parent c27b67574e
commit c2e85a0bcf
7 changed files with 54 additions and 7 deletions

View file

@ -9260,7 +9260,10 @@ HOOK_ON_COLLIDE_LEVEL_BOUNDS = 37
HOOK_MIRROR_MARIO_RENDER = 38
--- @type LuaHookedEventType
HOOK_MAX = 39
HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED = 39
--- @type LuaHookedEventType
HOOK_MAX = 40
--- @class HudDisplayFlags

View file

@ -3319,7 +3319,8 @@
| HOOK_ON_HUD_RENDER_BEHIND | 36 |
| HOOK_ON_COLLIDE_LEVEL_BOUNDS | 37 |
| HOOK_MIRROR_MARIO_RENDER | 38 |
| HOOK_MAX | 39 |
| HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED | 39 |
| HOOK_MAX | 40 |
[:arrow_up_small:](#)

View file

@ -124,8 +124,9 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh
| HOOK_ON_DIALOG | Called when a dialog appears. Return `false` to prevent it from appearing | `integer` dialogId |
| HOOK_ON_EXIT | Called before the game shuts down | None |
| HOOK_DIALOG_SOUND | Called when a dialog box sound is going to play, return a `DS_*` constant to override the sound | `integer` dialogSound |
| HOOK_ON_COLLIDE_LEVEL_BOUNDS | Called when a mario collides with the level boundaries | [MarioState](structs.md#MarioState)mario |
| HOOK_MIRROR_MARIO_RENDER | Called when a Mirror Mario is rendered. | [GraphNodeObject](structs.md#GraphNodeObject) mirrorMario | `integer` mirrorMarioIndex |
| HOOK_ON_COLLIDE_LEVEL_BOUNDS | Called when a mario collides with the level boundaries | [MarioState](structs.md#MarioState) mario |
| HOOK_MIRROR_MARIO_RENDER | Called when a Mirror Mario is rendered | [GraphNodeObject](structs.md#GraphNodeObject) mirrorMario | `integer` mirrorMarioIndex |
| HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED | Called when slope defacto speed for walking is being calculated, overrides the floor normal in the equation | [MarioState](structs.md#MarioState) mario |
### Parameters

View file

@ -362,8 +362,12 @@ s32 perform_ground_step(struct MarioState *m) {
for (i = 0; i < 4; i++) {
Vec3f step = { 0 };
if (m->floor) {
step[0] = m->floor->normal.y * (m->vel[0] / 4.0f);
step[2] = m->floor->normal.y * (m->vel[2] / 4.0f);
f32 floorNormal;
if (!smlua_call_event_hooks_mario_param_ret_float(HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED, m, &floorNormal)) {
floorNormal = m->floor->normal.y;
}
step[0] = floorNormal * (m->vel[0] / 4.0f);
step[2] = floorNormal * (m->vel[2] / 4.0f);
}
intendedPos[0] = m->pos[0] + step[0];

View file

@ -3280,7 +3280,8 @@ char gSmluaConstants[] = ""
"HOOK_ON_HUD_RENDER_BEHIND = 36\n"
"HOOK_ON_COLLIDE_LEVEL_BOUNDS = 37\n"
"HOOK_MIRROR_MARIO_RENDER = 38\n"
"HOOK_MAX = 39\n"
"HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED = 39\n"
"HOOK_MAX = 40\n"
"ACTION_HOOK_EVERY_FRAME = 0\n"
"ACTION_HOOK_GRAVITY = 1\n"
"ACTION_HOOK_MAX = 2\n"

View file

@ -877,6 +877,40 @@ bool smlua_call_event_hooks_mario_param_and_int_ret_int(enum LuaHookedEventType
return false;
}
bool smlua_call_event_hooks_mario_param_ret_float(enum LuaHookedEventType hookType, struct MarioState* m, f32* returnValue) {
lua_State* L = gLuaState;
if (L == NULL) { return false; }
struct LuaHookedEvent* hook = &sHookedEvents[hookType];
for (int i = 0; i < hook->count; i++) {
s32 prevTop = lua_gettop(L);
// push the callback onto the stack
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
// push mario state
lua_getglobal(L, "gMarioStates");
lua_pushinteger(L, m->playerIndex);
lua_gettable(L, -2);
lua_remove(L, -2);
// call the callback
if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) {
LOG_LUA("Failed to call the callback: %u", hookType);
continue;
}
// output the return value
if (lua_type(L, -1) == LUA_TNUMBER) {
*returnValue = smlua_to_number(L, -1);
}
lua_settop(L, prevTop);
return true;
}
return false;
}
bool smlua_call_event_hooks_mario_param_and_int_and_int_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, u32 args, s32* returnValue) {
lua_State* L = gLuaState;
if (L == NULL) { return false; }

View file

@ -50,6 +50,7 @@ enum LuaHookedEventType {
HOOK_ON_HUD_RENDER_BEHIND,
HOOK_ON_COLLIDE_LEVEL_BOUNDS,
HOOK_MIRROR_MARIO_RENDER,
HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED,
HOOK_MAX,
};
@ -93,6 +94,7 @@ static const char* LuaHookedEventTypeName[] = {
"HOOK_ON_HUD_RENDER_BEHIND",
"HOOK_ON_COLLIDE_LEVEL_BOUNDS",
"HOOK_MIRROR_MARIO_RENDER",
"HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED",
"HOOK_MAX"
};
@ -137,6 +139,7 @@ bool smlua_call_event_hooks_mario_character_sound_param_ret_int(enum LuaHookedEv
void smlua_call_event_hooks_mario_action_params_ret_int(enum LuaHookedEventType hookType, struct MarioState *m, u32 action, u32* returnValue);
void smlua_call_event_hooks_mario_param_and_int_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, bool* returnValue);
bool smlua_call_event_hooks_mario_param_and_int_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, s32* returnValue);
bool smlua_call_event_hooks_mario_param_ret_float(enum LuaHookedEventType hookType, struct MarioState* m, f32* returnValue);
bool smlua_call_event_hooks_mario_param_and_int_and_int_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, u32 args, s32* returnValue);
void smlua_call_event_hooks_graph_node_object_and_int_param(enum LuaHookedEventType hookType, struct GraphNodeObject* node, s32 param);