From 9a13c298ad7b3ad0ce982a5412b5e4c44e07ee67 Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Tue, 11 Feb 2025 17:58:57 +1000 Subject: [PATCH] added HOOK_ON_INTERACTIONS this is called after mario's interactions are processed --- autogen/lua_definitions/constants.lua | 5 +++- autogen/lua_definitions/functions.lua | 10 +++---- docs/lua/constants.md | 3 +- docs/lua/functions-3.md | 40 +++++++++++++-------------- docs/lua/functions.md | 2 +- docs/lua/guides/hooks.md | 1 + src/game/interaction.c | 2 ++ src/pc/lua/smlua_constants_autogen.c | 3 +- src/pc/lua/smlua_functions_autogen.c | 36 ++++++++++++------------ src/pc/lua/smlua_hooks.h | 3 ++ 10 files changed, 58 insertions(+), 47 deletions(-) diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 542ebd628..300492b41 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -9187,7 +9187,10 @@ HOOK_ON_GEO_PROCESS_CHILDREN = 50 HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS = 51 --- @type LuaHookedEventType -HOOK_MAX = 52 +HOOK_ON_INTERACTIONS = 52 + +--- @type LuaHookedEventType +HOOK_MAX = 53 --- @class LuaModMenuElementType diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 740d2624f..be2983747 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -4214,11 +4214,6 @@ function set_first_person_enabled(enable) -- ... end ---- @param state integer -function set_dialog_box_state(state) - -- ... -end - --- @param dialog integer function create_dialog_box(dialog) -- ... @@ -4252,6 +4247,11 @@ function reset_dialog_render_state() -- ... end +--- @param state integer +function set_dialog_box_state(state) + -- ... +end + --- @param bgR integer --- @param bgG integer --- @param bgB integer diff --git a/docs/lua/constants.md b/docs/lua/constants.md index ecfcc5943..d199fe596 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -3349,7 +3349,8 @@ | HOOK_BEFORE_GEO_PROCESS | 49 | | HOOK_ON_GEO_PROCESS_CHILDREN | 50 | | HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS | 51 | -| HOOK_MAX | 52 | +| HOOK_ON_INTERACTIONS | 52 | +| HOOK_MAX | 53 | ### [enum LuaModMenuElementType](#LuaModMenuElementType) | Identifier | Value | diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md index 344663c39..8f270e70e 100644 --- a/docs/lua/functions-3.md +++ b/docs/lua/functions-3.md @@ -4356,26 +4356,6 @@ Sets if first person is enabled
-## [set_dialog_box_state](#set_dialog_box_state) - -### Lua Example -`set_dialog_box_state(state)` - -### Parameters -| Field | Type | -| ----- | ---- | -| state | `integer` | - -### Returns -- None - -### C Prototype -`void set_dialog_box_state(u8 state);` - -[:arrow_up_small:](#) - -
- ## [create_dialog_box](#create_dialog_box) ### Lua Example @@ -4511,6 +4491,26 @@ Sets if first person is enabled
+## [set_dialog_box_state](#set_dialog_box_state) + +### Lua Example +`set_dialog_box_state(state)` + +### Parameters +| Field | Type | +| ----- | ---- | +| state | `integer` | + +### Returns +- None + +### C Prototype +`void set_dialog_box_state(u8 state);` + +[:arrow_up_small:](#) + +
+ ## [set_dialog_override_color](#set_dialog_override_color) ### Lua Example diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 1dd1f627a..25e52d015 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -842,7 +842,6 @@
- ingame_menu.h - - [set_dialog_box_state](functions-3.md#set_dialog_box_state) - [create_dialog_box](functions-3.md#create_dialog_box) - [create_dialog_box_with_response](functions-3.md#create_dialog_box_with_response) - [create_dialog_box_with_var](functions-3.md#create_dialog_box_with_var) @@ -850,6 +849,7 @@ - [reset_dialog_override_color](functions-3.md#reset_dialog_override_color) - [reset_dialog_override_pos](functions-3.md#reset_dialog_override_pos) - [reset_dialog_render_state](functions-3.md#reset_dialog_render_state) + - [set_dialog_box_state](functions-3.md#set_dialog_box_state) - [set_dialog_override_color](functions-3.md#set_dialog_override_color) - [set_dialog_override_pos](functions-3.md#set_dialog_override_pos) - [set_menu_mode](functions-3.md#set_menu_mode) diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index ac905eda7..6033e553a 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -142,6 +142,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_ON_GEO_PROCESS | Called when a GeoLayout is processed **Note:** You must set the `hookProcess` field of the graph node to a non-zero value | [GraphNode](../structs.md#GraphNode) graphNode, `integer` matStackIndex | | HOOK_BEFORE_GEO_PROCESS | Called before a GeoLayout is processed **Note:** You must set the `hookProcess` field of the graph node to a non-zero value | [GraphNode](../structs.md#GraphNode) graphNode, `integer` matStackIndex | | 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_ON_INTERACTIONS | Called when the Mario interactions are processed | [MarioState](../structs.md#MarioState) mario | ### Parameters diff --git a/src/game/interaction.c b/src/game/interaction.c index c5ef686b4..e1dd7cb22 100644 --- a/src/game/interaction.c +++ b/src/game/interaction.c @@ -2349,6 +2349,8 @@ void mario_process_interactions(struct MarioState *m) { m->invincTimer -= 1; } + smlua_call_event_hooks_mario_param(HOOK_ON_INTERACTIONS, m); + //! If the kick/punch flags are set and an object collision changes Mario's // action, he will get the kick/punch wall speed anyway. check_kick_or_punch_wall(m); diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 044288a0f..d5f5d31a1 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -3211,7 +3211,8 @@ char gSmluaConstants[] = "" "HOOK_BEFORE_GEO_PROCESS = 49\n" "HOOK_ON_GEO_PROCESS_CHILDREN = 50\n" "HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS = 51\n" -"HOOK_MAX = 52\n" +"HOOK_ON_INTERACTIONS = 52\n" +"HOOK_MAX = 53\n" "ACTION_HOOK_EVERY_FRAME = 0\n" "ACTION_HOOK_GRAVITY = 1\n" "ACTION_HOOK_MAX = 2\n" diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 87caa2556..a6831924b 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -13388,23 +13388,6 @@ int smlua_func_set_first_person_enabled(lua_State* L) { // ingame_menu.h // /////////////////// -int smlua_func_set_dialog_box_state(lua_State* L) { - if (L == NULL) { return 0; } - - int top = lua_gettop(L); - if (top != 1) { - LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "set_dialog_box_state", 1, top); - return 0; - } - - u8 state = smlua_to_integer(L, 1); - if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_dialog_box_state"); return 0; } - - set_dialog_box_state(state); - - return 1; -} - int smlua_func_create_dialog_box(lua_State* L) { if (L == NULL) { return 0; } @@ -13520,6 +13503,23 @@ int smlua_func_reset_dialog_render_state(UNUSED lua_State* L) { return 1; } +int smlua_func_set_dialog_box_state(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 1) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "set_dialog_box_state", 1, top); + return 0; + } + + u8 state = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_dialog_box_state"); return 0; } + + set_dialog_box_state(state); + + return 1; +} + int smlua_func_set_dialog_override_color(lua_State* L) { if (L == NULL) { return 0; } @@ -32822,7 +32822,6 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "set_first_person_enabled", smlua_func_set_first_person_enabled); // ingame_menu.h - smlua_bind_function(L, "set_dialog_box_state", smlua_func_set_dialog_box_state); smlua_bind_function(L, "create_dialog_box", smlua_func_create_dialog_box); smlua_bind_function(L, "create_dialog_box_with_response", smlua_func_create_dialog_box_with_response); smlua_bind_function(L, "create_dialog_box_with_var", smlua_func_create_dialog_box_with_var); @@ -32830,6 +32829,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "reset_dialog_override_color", smlua_func_reset_dialog_override_color); smlua_bind_function(L, "reset_dialog_override_pos", smlua_func_reset_dialog_override_pos); smlua_bind_function(L, "reset_dialog_render_state", smlua_func_reset_dialog_render_state); + smlua_bind_function(L, "set_dialog_box_state", smlua_func_set_dialog_box_state); smlua_bind_function(L, "set_dialog_override_color", smlua_func_set_dialog_override_color); smlua_bind_function(L, "set_dialog_override_pos", smlua_func_set_dialog_override_pos); smlua_bind_function(L, "set_menu_mode", smlua_func_set_menu_mode); diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index 4b88d04c7..f55ad4981 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -10,6 +10,7 @@ // forward declare struct Camera; +// ! Hooks must be added at the end enum LuaHookedEventType { HOOK_UPDATE, HOOK_MARIO_UPDATE, @@ -63,6 +64,7 @@ enum LuaHookedEventType { HOOK_BEFORE_GEO_PROCESS, HOOK_ON_GEO_PROCESS_CHILDREN, HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS, + HOOK_ON_INTERACTIONS, HOOK_MAX, }; @@ -119,6 +121,7 @@ static const char* LuaHookedEventTypeName[] = { "HOOK_BEFORE_GEO_PROCESS", "HOOK_ON_GEO_PROCESS_CHILDREN", "HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS", + "HOOK_ON_INTERACTIONS", "HOOK_MAX" };