Add HOOK_ALLOW_FORCE_WATER_ACTION (#731)

* Update constants.md

* Update constants.lua

* Update smlua_constants_autogen.c

* Update surface_terrains.h

* Update hooks.md

* Add files via upload

* Update constants.lua

* Update smlua_hooks.h

* Update smlua_constants_autogen.c

* Update constants.md

* Update mario_actions_airborne.c

* Update mario_actions_airborne.c

* Update mario_actions_stationary.c

* Update mario_actions_automatic.c

* Update mario_actions_object.c

* Update mario_actions_moving.c

* Update mario_actions_submerged.c

* Update mario_actions_airborne.c

* Update mario_actions_stationary.c

* Update mario_actions_automatic.c

* Update mario_actions_object.c

* Update mario_actions_moving.c

* Update mario_actions_submerged.c

* Update hooks.md

* Update hooks.md

* Update mario_actions_submerged.c

* Update hooks.md

* deal with gCamera being exposed incorrectly

* update gCamera as the pointer is updated

* served time for crimes against C

* Update revamped flying damage (#722)

* forgot to null check it

* lois (#5)

* deal with gCamera being exposed incorrectly

* update gCamera as the pointer is updated

* served time for crimes against C

* Update revamped flying damage (#722)

* forgot to null check it

* Fix/optimize/improve lighting engine

* Camera fixes

---------

Co-authored-by: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com>
Co-authored-by: Sunk <69110309+Sunketchupm@users.noreply.github.com>
Co-authored-by: Agent X <44549182+AgentXLP@users.noreply.github.com>

* Update lighting_engine.c

* Update lighting_engine.c

* bart (#6)

* deal with gCamera being exposed incorrectly

* update gCamera as the pointer is updated

* served time for crimes against C

* Update revamped flying damage (#722)

* forgot to null check it

* Fix/optimize/improve lighting engine

* Camera fixes

* Fix small LE whoopsie

* Update CS to v1.13

* New coopnet libraries for macOS (#725)

* Fix camera issues (#726)

* Fix vanilla camera in automatic

* Correct dpad movement direction

Matches the same direction as romhack camera now

* Make Git hash only dev or debug

* Fixes

* fix some script errors in mods that pass in nil objects

technically this is the mod's fault, but this is more consistent behavior for a cheap fix

* Further fix camera (#727)

* Further fix camera

* Remove re-override

* fix scrolling textures simply not scrolling

this was caused by the duplicated vertices commit

* free stuff

---------

Co-authored-by: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com>
Co-authored-by: Sunk <69110309+Sunketchupm@users.noreply.github.com>
Co-authored-by: Agent X <44549182+AgentXLP@users.noreply.github.com>
Co-authored-by: EmeraldLockdown <86802223+EmeraldLoc@users.noreply.github.com>

* Update smlua_cobject.c

* Update mario_step.c

* Update bettercamera.inc.h

* Update camera.c

* Update smlua_cobject.h

* Update camera.c

* Add files via upload

* Update constants.lua

* Update constants.md

* Update hooks.md

* Update smlua_constants_autogen.c

* Update smlua_hooks.h

* Update smlua_hooks.h

* Update smlua_hooks.c

* Update mario_actions_airborne.c

* Update mario_actions_automatic.c

* Update mario_actions_moving.c

* Update mario_actions_object.c

* Update mario_actions_stationary.c

* Update mario_actions_submerged.c

* Update mario_step.c

* Update mario_actions_airborne.c

* Update mario_actions_automatic.c

* Update mario_actions_moving.c

* Update mario_actions_object.c

* Update mario_actions_stationary.c

* Update mario_actions_submerged.c

* Update hooks.md

* Update mario_actions_airborne.c

* Update mario_actions_automatic.c

* Update mario_actions_moving.c

* Update mario_actions_object.c

* Update mario_actions_stationary.c

* Update mario_actions_submerged.c

* Update mario_actions_submerged.c

* Update mario_step.c

* Update mario_actions_stationary.c

* Update mario_actions_submerged.c

* Update mario_step.c

* Update mario_actions_airborne.c

* Update mario_actions_airborne.c

* Update mario_actions_automatic.c

* Update mario_actions_moving.c

* Update mario_actions_object.c

* Update mario_actions_submerged.c

---------

Co-authored-by: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com>
Co-authored-by: Sunk <69110309+Sunketchupm@users.noreply.github.com>
Co-authored-by: Agent X <44549182+AgentXLP@users.noreply.github.com>
Co-authored-by: EmeraldLockdown <86802223+EmeraldLoc@users.noreply.github.com>
This commit is contained in:
Baconator2558 2025-04-07 17:47:52 -05:00 committed by GitHub
parent 42f05cc790
commit ce8350514c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 126 additions and 46 deletions

View file

@ -8865,7 +8865,8 @@ HOOK_BEFORE_GEO_PROCESS = 49 --- @type LuaHookedEventType
HOOK_ON_GEO_PROCESS_CHILDREN = 50 --- @type LuaHookedEventType
HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS = 51 --- @type LuaHookedEventType
HOOK_ON_INTERACTIONS = 52 --- @type LuaHookedEventType
HOOK_MAX = 53 --- @type LuaHookedEventType
HOOK_ALLOW_FORCE_WATER_ACTION = 53 --- @type LuaHookedEventType
HOOK_MAX = 54 --- @type LuaHookedEventType
--- @alias LuaHookedEventType
--- | `HOOK_UPDATE`
@ -8921,6 +8922,7 @@ HOOK_MAX = 53 --- @type LuaHookedEventType
--- | `HOOK_ON_GEO_PROCESS_CHILDREN`
--- | `HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS`
--- | `HOOK_ON_INTERACTIONS`
--- | `HOOK_ALLOW_FORCE_WATER_ACTION`
--- | `HOOK_MAX`
ACTION_HOOK_EVERY_FRAME = 0 --- @type LuaActionHookType

View file

@ -3769,7 +3769,8 @@
| HOOK_ON_GEO_PROCESS_CHILDREN | 50 |
| HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS | 51 |
| HOOK_ON_INTERACTIONS | 52 |
| HOOK_MAX | 53 |
| HOOK_ALLOW_FORCE_WATER_ACTION | 53 |
| HOOK_MAX | 54 |
### [enum LuaActionHookType](#LuaActionHookType)
| Identifier | Value |

View file

@ -145,6 +145,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh
| HOOK_ON_GEO_PROCESS_CHILDREN | Called when the children of a GeoLayout node is processed **Note:** You must set the `hookProcess` field of the parent graph node to a non-zero value | [GraphNode](../structs.md#GraphNode) graphNode, `integer` matStackIndex |
| HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS | Called before running Mario's geometry input logic, return `false` to not run it. | [MarioState](../structs.md) m |
| HOOK_ON_INTERACTIONS | Called when the Mario interactions are processed | [MarioState](../structs.md#MarioState) mario |
| HOOK_ALLOW_FORCE_WATER_ACTION | Called when executing a non-water action while under the water's surface, or vice versa. Return `false` to prevent the player from being forced out of the action at the water's surface | [MarioState](../structs.md#MarioState) mario, `boolean` isInWaterAction |
### Parameters

View file

@ -12524,4 +12524,3 @@ s32 update_rom_hack_camera(struct Camera *c, Vec3f focus, Vec3f pos) {
c->nextYaw = c->yaw;
return camYaw;
}

View file

@ -2297,18 +2297,25 @@ if on certain wind surfaces. Also resets `m.quicksandDepth`
|descriptionEnd| */
s32 check_common_airborne_cancels(struct MarioState *m) {
if (!m) { return 0; }
bool allow = true;
if (m->pos[1] < m->waterLevel - 100) {
return set_water_plunge_action(m);
smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow);
if (allow) {
return set_water_plunge_action(m);
}
}
allow = true;
if (m->input & INPUT_SQUISHED) {
return drop_and_set_mario_action(m, ACT_SQUISHED, 0);
}
bool allow = true;
smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_VERTICAL_WIND, &allow);
if (allow && m->floor && m->floor->type == SURFACE_VERTICAL_WIND && (m->action & ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)) {
return drop_and_set_mario_action(m, ACT_VERTICAL_WIND, 0);
if (m->floor && m->floor->type == SURFACE_VERTICAL_WIND && (m->action & ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)) {
smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_VERTICAL_WIND, &allow);
if (allow) {
return drop_and_set_mario_action(m, ACT_VERTICAL_WIND, 0);
}
}
m->quicksandDepth = 0.0f;

View file

@ -1161,7 +1161,11 @@ Checks if Mario should cancel his current automatic action, primarily by detecti
s32 check_common_automatic_cancels(struct MarioState *m) {
if (!m) { return 0; }
if (m->pos[1] < m->waterLevel - 100) {
return set_water_plunge_action(m);
bool allow = true;
smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow);
if (allow) {
return set_water_plunge_action(m);
}
}
return FALSE;

View file

@ -2175,7 +2175,11 @@ Performs common checks when Mario is in a moving state, transitions to water plu
s32 check_common_moving_cancels(struct MarioState *m) {
if (!m) { return FALSE; }
if (m->pos[1] < m->waterLevel - 100) {
return set_water_plunge_action(m);
bool allow = true;
smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow);
if (allow) {
return set_water_plunge_action(m);
}
}
if (!(m->action & ACT_FLAG_INVULNERABLE) && (m->input & INPUT_UNKNOWN_10)) {

View file

@ -478,9 +478,12 @@ s32 check_common_object_cancels(struct MarioState *m) {
if (!m) { return 0; }
if (m->playerIndex != 0) { return FALSE; }
f32 waterSurface = m->waterLevel - 100;
if (m->pos[1] < waterSurface) {
return set_water_plunge_action(m);
if (m->pos[1] < m->waterLevel - 100) {
bool allow = true;
smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow);
if (allow) {
return set_water_plunge_action(m);
}
}
if (m->input & INPUT_SQUISHED) {

View file

@ -1151,15 +1151,18 @@ s32 act_first_person(struct MarioState *m) {
s32 check_common_stationary_cancels(struct MarioState *m) {
if (!m) { return 0; }
if (m->playerIndex != 0) { return FALSE; }
if (m->pos[1] < m->waterLevel - 100) {
if (m->action == ACT_SPAWN_SPIN_LANDING) {
if (m == &gMarioStates[0]) {
load_level_init_text(0);
bool allow = true;
smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow);
if (allow) {
if (m->action == ACT_SPAWN_SPIN_LANDING) {
if (m == &gMarioStates[0]) {
load_level_init_text(0);
}
}
update_mario_sound_and_camera(m);
return set_water_plunge_action(m);
}
update_mario_sound_and_camera(m);
return set_water_plunge_action(m);
}
if (m->input & INPUT_SQUISHED) {

View file

@ -203,10 +203,14 @@ u32 perform_water_step(struct MarioState *m) {
nextPos[0] = m->pos[0] + step[0];
nextPos[1] = m->pos[1] + step[1];
nextPos[2] = m->pos[2] + step[2];
if (nextPos[1] > m->waterLevel - 80) {
nextPos[1] = m->waterLevel - 80;
m->vel[1] = 0.0f;
bool allow = true;
smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, true, &allow);
if (allow) {
nextPos[1] = m->waterLevel - 80;
m->vel[1] = 0.0f;
}
}
stepResult = perform_water_full_step(m, nextPos);
@ -528,7 +532,10 @@ static s32 check_water_jump(struct MarioState *m) {
s32 probe = (s32)(m->pos[1] + 1.5f);
if (m->input & INPUT_A_PRESSED) {
if (probe >= m->waterLevel - 80 && m->faceAngle[0] >= 0 && m->controller->stickY < -60.0f) {
if (probe >= m->waterLevel - 80 && m->faceAngle[0] >= 0 && m->controller->stickY < -60.0f) {
bool allow = true;
smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, true, &allow);
if (!allow) { return FALSE; }
vec3s_set(m->angleVel, 0, 0, 0);
m->vel[1] = 62.0f;
@ -1614,20 +1621,24 @@ static s32 act_hold_metal_water_fall_land(struct MarioState *m) {
static s32 check_common_submerged_cancels(struct MarioState *m) {
if (!m) { return 0; }
if (m->pos[1] > m->waterLevel - 80) {
if (m->waterLevel - 80 > m->floorHeight) {
m->pos[1] = m->waterLevel - 80;
} else {
//! If you press B to throw the shell, there is a ~5 frame window
// where your held object is the shell, but you are not in the
// water shell swimming action. This allows you to hold the water
// shell on land (used for cloning in DDD).
if (m->action == ACT_WATER_SHELL_SWIMMING && m->heldObj != NULL && m->playerIndex == 0) {
m->heldObj->oInteractStatus = INT_STATUS_STOP_RIDING;
m->heldObj = NULL;
stop_shell_music();
}
return transition_submerged_to_walking(m);
bool allow = true;
smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, true, &allow);
if (allow) {
if (m->waterLevel - 80 > m->floorHeight) {
m->pos[1] = m->waterLevel - 80;
} else {
//! If you press B to throw the shell, there is a ~5 frame window
// where your held object is the shell, but you are not in the
// water shell swimming action. This allows you to hold the water
// shell on land (used for cloning in DDD).
if (m->action == ACT_WATER_SHELL_SWIMMING && m->heldObj != NULL && m->playerIndex == 0) {
m->heldObj->oInteractStatus = INT_STATUS_STOP_RIDING;
m->heldObj = NULL;
stop_shell_music();
}
return transition_submerged_to_walking(m);
}
}
}

View file

@ -310,9 +310,13 @@ static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) {
}
if ((m->action & ACT_FLAG_RIDING_SHELL) && floorHeight < waterLevel) {
floorHeight = waterLevel;
floor = &gWaterSurfacePseudoFloor;
floor->originOffset = floorHeight; //! Wrong origin offset (no effect)
bool allow = true;
smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow);
if (allow) {
floorHeight = waterLevel;
floor = &gWaterSurfacePseudoFloor;
floor->originOffset = floorHeight; //! Wrong origin offset (no effect)
}
}
if (nextPos[1] > floorHeight + 100.0f) {
@ -495,9 +499,13 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr
}
if ((m->action & ACT_FLAG_RIDING_SHELL) && floorHeight < waterLevel) {
floorHeight = waterLevel;
floor = &gWaterSurfacePseudoFloor;
floor->originOffset = floorHeight; //! Incorrect origin offset (no effect)
bool allow = true;
smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow);
if (allow) {
floorHeight = waterLevel;
floor = &gWaterSurfacePseudoFloor;
floor->originOffset = floorHeight; //! Incorrect origin offset (no effect)
}
}
//! This check uses f32, but findFloor uses short (overflow jumps)

View file

@ -84,4 +84,4 @@ void smlua_cobject_init_globals(void);
void smlua_cobject_init_per_file_globals(const char* path);
void smlua_bind_cobject(void);
#endif
#endif

View file

@ -3630,7 +3630,8 @@ char gSmluaConstants[] = ""
"HOOK_ON_GEO_PROCESS_CHILDREN=50\n"
"HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS=51\n"
"HOOK_ON_INTERACTIONS=52\n"
"HOOK_MAX=53\n"
"HOOK_ALLOW_FORCE_WATER_ACTION=53\n"
"HOOK_MAX=54\n"
"ACTION_HOOK_EVERY_FRAME=0\n"
"ACTION_HOOK_GRAVITY=1\n"
"ACTION_HOOK_MAX=2\n"
@ -4749,4 +4750,4 @@ char gSmluaConstants[] = ""
"VERSION_NUMBER=40\n"
"MINOR_VERSION_NUMBER=0\n"
"MAX_VERSION_LENGTH=128\n"
;
;

View file

@ -955,6 +955,39 @@ bool smlua_call_event_hooks_mario_param_and_int_ret_int(enum LuaHookedEventType
return false;
}
void smlua_call_event_hooks_mario_param_and_bool_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, bool param, bool* returnValue) {
lua_State* L = gLuaState;
if (L == NULL) { return; }
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);
// push param
lua_pushboolean(L, param);
// call the callback
if (0 != smlua_call_hook(L, 2, 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_TBOOLEAN) {
*returnValue = smlua_to_boolean(L, -1);
}
lua_settop(L, prevTop);
}
}
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; }

View file

@ -65,6 +65,7 @@ enum LuaHookedEventType {
HOOK_ON_GEO_PROCESS_CHILDREN,
HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS,
HOOK_ON_INTERACTIONS,
HOOK_ALLOW_FORCE_WATER_ACTION,
HOOK_MAX,
};
@ -122,6 +123,7 @@ static const char* LuaHookedEventTypeName[] = {
"HOOK_ON_GEO_PROCESS_CHILDREN",
"HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS",
"HOOK_ON_INTERACTIONS",
"HOOK_ALLOW_FORCE_WATER_ACTION",
"HOOK_MAX"
};
@ -196,6 +198,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);
void smlua_call_event_hooks_mario_param_and_bool_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, bool param, bool* 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);