diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 28f750976..50fdbbb9e 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -7940,7 +7940,10 @@ HOOK_USE_ACT_SELECT = 23 HOOK_ON_CHANGE_CAMERA_ANGLE = 24 --- @type LuaHookedEventType -HOOK_MAX = 25 +HOOK_ON_SCREEN_TRANSITION = 25 + +--- @type LuaHookedEventType +HOOK_MAX = 26 --- @class HudDisplayFlags diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 12867f61f..0b39917e0 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -2807,7 +2807,8 @@ | HOOK_ON_PACKET_RECEIVE | 22 | | HOOK_USE_ACT_SELECT | 23 | | HOOK_ON_CHANGE_CAMERA_ANGLE | 24 | -| HOOK_MAX | 25 | +| HOOK_ON_SCREEN_TRANSITION | 25 | +| HOOK_MAX | 26 | [:arrow_up_small:](#) diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index 2d50ca50b..b2c7798fc 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -111,6 +111,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_ON_PACKET_RECEIVE | Called when the mod receives a packet that used `network_send()` or `network_send_to()` | `table` dataTable | | HOOK_USE_ACT_SELECT | Called when the level changes, return `true` to show act selection screen and `false` otherwise | `integer` levelNum | | HOOK_ON_CHANGE_CAMERA_ANGLE | Called when the player changes the camera mode to Lakitu cam or Mario cam, return `false` to prevent the change. | `integer` mode | +| HOOK_ON_SCREEN_TRANSITION | Called when the game is about to play a transition, returun `false` to prevent the transition from playing. | `integer` type | ### Parameters diff --git a/src/game/area.c b/src/game/area.c index 2b3d9b51b..aaf527d41 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -24,6 +24,7 @@ #include "gfx_dimensions.h" #include "game/ingame_menu.h" #include "pc/network/network.h" +#include "pc/lua/smlua_hooks.h" struct SpawnInfo gPlayerSpawnInfos[MAX_PLAYERS]; struct GraphNode *D_8033A160[MAX_LOADED_GRAPH_NODES]; @@ -341,6 +342,10 @@ void area_update_objects(void) { * transition type, time in frames, and the RGB color that will fill the screen. */ void play_transition(s16 transType, s16 time, u8 red, u8 green, u8 blue) { + bool returnValue = true; + smlua_call_event_hooks_int_params_ret_bool(HOOK_ON_SCREEN_TRANSITION, transType, &returnValue); + if (!returnValue) { return; } + gWarpTransition.isActive = TRUE; gWarpTransition.type = transType; gWarpTransition.time = time; diff --git a/src/game/camera.c b/src/game/camera.c index f96cdf55e..51e774003 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -3068,12 +3068,12 @@ void update_camera(struct Camera *c) { if ((sCurrPlayMode != PLAY_MODE_PAUSED) && gPlayer1Controller->buttonPressed & R_TRIG) { bool returnValue = true; if (set_cam_angle(0) == CAM_ANGLE_LAKITU) { - smlua_call_event_hooks_change_camera_angle_params(HOOK_ON_CHANGE_CAMERA_ANGLE, CAM_ANGLE_MARIO, &returnValue); + smlua_call_event_hooks_int_params_ret_bool(HOOK_ON_CHANGE_CAMERA_ANGLE, CAM_ANGLE_MARIO, &returnValue); if (returnValue) { set_cam_angle(CAM_ANGLE_MARIO); } } else { - smlua_call_event_hooks_change_camera_angle_params(HOOK_ON_CHANGE_CAMERA_ANGLE, CAM_ANGLE_LAKITU, &returnValue); + smlua_call_event_hooks_int_params_ret_bool(HOOK_ON_CHANGE_CAMERA_ANGLE, CAM_ANGLE_LAKITU, &returnValue); if (returnValue) { set_cam_angle(CAM_ANGLE_LAKITU); } diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 322f47563..302124570 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -2826,7 +2826,8 @@ char gSmluaConstants[] = "" "HOOK_ON_PACKET_RECEIVE = 22\n" "HOOK_USE_ACT_SELECT = 23\n" "HOOK_ON_CHANGE_CAMERA_ANGLE = 24\n" -"HOOK_MAX = 25\n" +"HOOK_ON_SCREEN_TRANSITION = 25\n" +"HOOK_MAX = 26\n" "ACTION_HOOK_EVERY_FRAME = 0\n" "ACTION_HOOK_GRAVITY = 1\n" "ACTION_HOOK_MAX = 2\n" diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index e04aa5cc6..72d518436 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -477,7 +477,7 @@ void smlua_call_event_hooks_set_camera_mode_params(enum LuaHookedEventType hookT } } -void smlua_call_event_hooks_change_camera_angle_params(enum LuaHookedEventType hookType, s16 mode, bool* returnValue) { +void smlua_call_event_hooks_int_params_ret_bool(enum LuaHookedEventType hookType, s16 param, bool* returnValue) { lua_State* L = gLuaState; if (L == NULL) { return; } *returnValue = true; @@ -490,7 +490,7 @@ void smlua_call_event_hooks_change_camera_angle_params(enum LuaHookedEventType h lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); // push params - lua_pushinteger(L, mode); + lua_pushinteger(L, param); // call the callback if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index a006f6d36..c7c6a54ca 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -36,6 +36,7 @@ enum LuaHookedEventType { HOOK_ON_PACKET_RECEIVE, HOOK_USE_ACT_SELECT, HOOK_ON_CHANGE_CAMERA_ANGLE, + HOOK_ON_SCREEN_TRANSITION, HOOK_MAX, }; @@ -65,6 +66,7 @@ static const char* LuaHookedEventTypeName[] = { "HOOK_ON_PACKET_RECEIVE", "HOOK_USE_ACT_SELECT", "HOOK_ON_CHANGE_CAMERA_ANGLE", + "HOOK_ON_SCREEN_TRANSITION", "HOOK_MAX" }; @@ -96,7 +98,7 @@ void smlua_call_event_hooks_interact_params_ret_bool(enum LuaHookedEventType hoo void smlua_call_event_hooks_object_param(enum LuaHookedEventType hookType, struct Object* obj); bool smlua_call_event_hooks_ret_int(enum LuaHookedEventType hookType, s32* returnValue); void smlua_call_event_hooks_set_camera_mode_params(enum LuaHookedEventType hookType, struct Camera *c, s16 mode, s16 frames, bool* returnValue); -void smlua_call_event_hooks_change_camera_angle_params(enum LuaHookedEventType hookType, s16 mode, bool* returnValue); +void smlua_call_event_hooks_int_params_ret_bool(enum LuaHookedEventType hookType, s16 param, bool* returnValue); void smlua_call_event_hooks_value_param(enum LuaHookedEventType hookType, int modIndex, int valueIndex); void smlua_call_event_hooks_use_act_select(enum LuaHookedEventType hookType, int value, bool* foundHook, bool* returnValue);