HOOK_ON_INSTANT_WARP (#747)

* make HOOK_ON_WARP trigger on instant warps

* oops

* HOOK_ON_INSTANT_WARP

* make the displacement a Vec3s, hooks.md

* fix hooks.md oversight

* get rid of this
This commit is contained in:
Blockyyy 2025-04-27 23:21:17 +02:00 committed by GitHub
parent 15d6f6ae07
commit ea353af5c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 53 additions and 15 deletions

View file

@ -7815,7 +7815,8 @@ HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS = 51 --- @type LuaHookedEventType
HOOK_ON_INTERACTIONS = 52 --- @type LuaHookedEventType
HOOK_ALLOW_FORCE_WATER_ACTION = 53 --- @type LuaHookedEventType
HOOK_BEFORE_WARP = 54 --- @type LuaHookedEventType
HOOK_MAX = 55 --- @type LuaHookedEventType
HOOK_ON_INSTANT_WARP = 55 --- @type LuaHookedEventType
HOOK_MAX = 56 --- @type LuaHookedEventType
--- @alias LuaHookedEventType
--- | `HOOK_UPDATE`
@ -7873,6 +7874,7 @@ HOOK_MAX = 55 --- @type LuaHookedEventType
--- | `HOOK_ON_INTERACTIONS`
--- | `HOOK_ALLOW_FORCE_WATER_ACTION`
--- | `HOOK_BEFORE_WARP`
--- | `HOOK_ON_INSTANT_WARP`
--- | `HOOK_MAX`
ACTION_HOOK_EVERY_FRAME = 0 --- @type LuaActionHookType

View file

@ -3441,7 +3441,8 @@
| HOOK_ON_INTERACTIONS | 52 |
| HOOK_ALLOW_FORCE_WATER_ACTION | 53 |
| HOOK_BEFORE_WARP | 54 |
| HOOK_MAX | 55 |
| HOOK_ON_INSTANT_WARP | 55 |
| HOOK_MAX | 56 |
### [enum LuaActionHookType](#LuaActionHookType)
| Identifier | Value |

View file

@ -146,7 +146,8 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh
| 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 |
| HOOK_BEFORE_WARP | Called before the local player warps. Return a table with `destLevel`, `destArea`, `destWarpNode`, and `arg` to override the warp | `integer` destLevel, `integer` destArea, `integer` destWarpNode, `integer` arg |
| HOOK_BEFORE_WARP | Called before the local player warps. Return a table with `destLevel`, `destArea`, `destAreaWarpNode`, and `arg` to override the warp | `integer` destLevel, `integer` destArea, `integer` destAreaWarpNode, `integer` arg |
| HOOK_ON_INSTANT_WARP | Called when the local player goes through an instant warp.| `integer` area, `integer` id, `Vec3s` displacement|
### Parameters

View file

@ -56,7 +56,6 @@
struct SavedWarpValues gReceiveWarp = { 0 };
extern s8 sReceivedLoadedActNum;
u8 gRejectInstantWarp = 0;
u16 gFanFareDebounce = 0;
s16 gChangeLevel = -1;
@ -647,10 +646,6 @@ void check_instant_warp(void) {
s16 cameraAngle;
struct Surface *floor;
if (gRejectInstantWarp > 0) {
gRejectInstantWarp--;
}
if (gCurrLevelNum == LEVEL_CASTLE
&& save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1) >= gLevelValues.infiniteStairsRequirement) {
return;
@ -661,11 +656,6 @@ void check_instant_warp(void) {
if (index >= INSTANT_WARP_INDEX_START && index < INSTANT_WARP_INDEX_STOP && gCurrentArea->instantWarps != NULL) {
struct InstantWarp *warp = &gCurrentArea->instantWarps[index];
if (warp->id != 0) {
if (gRejectInstantWarp > 0) {
vec3f_copy(gMarioStates[0].pos, gMarioStates[0].nonInstantWarpPos);
//vec3f_mul(gMarioStates[0].vel, -0.8f);
return;
}
mario_drop_held_object(&gMarioStates[0]);
u8 changeOfArea = (gCurrAreaIndex != warp->area);
@ -695,6 +685,8 @@ void check_instant_warp(void) {
skip_camera_interpolation();
gMarioStates[0].area->camera->yaw = cameraAngle;
smlua_call_event_hooks_instant_warp_params(HOOK_ON_INSTANT_WARP, warp->area, warp->id, warp->displacement);
return;
}
}

View file

@ -131,7 +131,6 @@ struct SavedWarpValues {
extern struct WarpDest sWarpDest;
extern s8 sWarpCheckpointActive;
extern u8 gRejectInstantWarp;
extern u16 gFanFareDebounce;
extern s16 D_80339EE0;

View file

@ -3288,7 +3288,8 @@ char gSmluaConstants[] = ""
"HOOK_ON_INTERACTIONS=52\n"
"HOOK_ALLOW_FORCE_WATER_ACTION=53\n"
"HOOK_BEFORE_WARP=54\n"
"HOOK_MAX=55\n"
"HOOK_ON_INSTANT_WARP=55\n"
"HOOK_MAX=56\n"
"ACTION_HOOK_EVERY_FRAME=0\n"
"ACTION_HOOK_GRAVITY=1\n"
"ACTION_HOOK_MAX=2\n"

View file

@ -656,6 +656,45 @@ void smlua_call_event_hooks_warp_params(enum LuaHookedEventType hookType, u8 typ
}
}
void smlua_call_event_hooks_instant_warp_params(enum LuaHookedEventType hookType, u8 area, u8 warpId, Vec3s displacement) {
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 params
lua_pushinteger(L, area);
lua_pushinteger(L, warpId);
lua_newtable(L);
int tbl = lua_gettop(L);
lua_pushstring(L, "x");
lua_pushinteger(L, displacement[0]);
lua_settable(L, tbl);
lua_pushstring(L, "y");
lua_pushinteger(L, displacement[1]);
lua_settable(L, tbl);
lua_pushstring(L, "z");
lua_pushinteger(L, displacement[2]);
lua_settable(L, tbl);
// call the callback
if (0 != smlua_call_hook(L, 3, 0, 0, hook->mod[i])) {
LOG_LUA("Failed to call the callback: %u", hookType);
continue;
}
lua_settop(L, prevTop);
}
}
void smlua_call_event_hooks_int_params_ret_string(enum LuaHookedEventType hookType, s32 param, char** returnValue) {
lua_State* L = gLuaState;
if (L == NULL) { return; }

View file

@ -67,6 +67,7 @@ enum LuaHookedEventType {
HOOK_ON_INTERACTIONS,
HOOK_ALLOW_FORCE_WATER_ACTION,
HOOK_BEFORE_WARP,
HOOK_ON_INSTANT_WARP,
HOOK_MAX,
};
@ -126,6 +127,7 @@ static const char* LuaHookedEventTypeName[] = {
"HOOK_ON_INTERACTIONS",
"HOOK_ALLOW_FORCE_WATER_ACTION",
"HOOK_BEFORE_WARP",
"HOOK_ON_INSTANT_WARP"
"HOOK_MAX"
};
@ -208,6 +210,7 @@ void smlua_call_event_hooks_graph_node_and_int_param(enum LuaHookedEventType hoo
void smlua_call_event_hooks_on_seq_load(enum LuaHookedEventType hookType, u32 player, u32 seqId, s32 loadAsync, s16* returnValue);
void smlua_call_event_hooks_before_warp(enum LuaHookedEventType hookType, s16 *destLevel, s16 *destArea, s16 *destWarpNode, s32 *arg);
void smlua_call_event_hooks_warp_params(enum LuaHookedEventType hookType, u8 type, s16 levelNum, u8 areaIdx, u8 nodeId, u32 arg);
void smlua_call_event_hooks_instant_warp_params(enum LuaHookedEventType hookType, u8 area, u8 warpId, Vec3s displacement);
const char *smlua_call_event_hooks_int_ret_bool_and_string(enum LuaHookedEventType hookType, s32 param, bool* returnValue);
void smlua_call_event_hooks_string_param(enum LuaHookedEventType hookType, const char* string);