From d53d20c11c5c89efdc4eb8abea463181068b0896 Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Mon, 10 Feb 2025 18:31:59 +1000 Subject: [PATCH] HOOK_ON_DIALOG fixes, expose set_dialog_box_state --- autogen/convert_functions.py | 2 +- autogen/lua_definitions/constants.lua | 2 +- autogen/lua_definitions/functions.lua | 5 +++++ docs/lua/functions-3.md | 20 ++++++++++++++++++++ docs/lua/functions.md | 1 + src/game/ingame_menu.c | 27 +++++++++++---------------- src/game/ingame_menu.h | 1 + src/pc/lua/smlua_constants_autogen.c | 2 +- src/pc/lua/smlua_functions_autogen.c | 18 ++++++++++++++++++ 9 files changed, 59 insertions(+), 19 deletions(-) diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py index c7cd44689..fe8309c2a 100644 --- a/autogen/convert_functions.py +++ b/autogen/convert_functions.py @@ -87,7 +87,7 @@ override_allowed_functions = { "src/game/level_update.h": [ "level_trigger_warp", "get_painting_warp_node", "initiate_painting_warp", "warp_special", "lvl_set_current_level", "level_control_timer_running", "fade_into_special_warp", "get_instant_warp" ], "src/game/area.h": [ "area_get_warp_node" ], "src/engine/level_script.h": [ "area_create_warp_node" ], - "src/game/ingame_menu.h": [ "set_min_dialog_width", "set_dialog_override_pos", "reset_dialog_override_pos", "set_dialog_override_color", "reset_dialog_override_color", "set_menu_mode", "create_dialog_box", "create_dialog_box_with_var", "create_dialog_inverted_box", "create_dialog_box_with_response", "reset_dialog_render_state", "close_dialog_box", ], + "src/game/ingame_menu.h": [ "set_min_dialog_width", "set_dialog_override_pos", "reset_dialog_override_pos", "set_dialog_override_color", "reset_dialog_override_color", "set_menu_mode", "create_dialog_box", "create_dialog_box_with_var", "create_dialog_inverted_box", "create_dialog_box_with_response", "reset_dialog_render_state", "set_dialog_box_state", ], "src/audio/seqplayer.h": [ "sequence_player_set_tempo", "sequence_player_set_tempo_acc", "sequence_player_set_transposition", "sequence_player_get_tempo", "sequence_player_get_tempo_acc", "sequence_player_get_transposition" ] } diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 706ae506d..542ebd628 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -12517,7 +12517,7 @@ MAX_VERSION_LENGTH = 32 MINOR_VERSION_NUMBER = 1 --- @type string -SM64COOPDX_VERSION = "v1.1.1" +SM64COOPDX_VERSION = "v1.2.0" --- @type integer VERSION_NUMBER = 38 diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 218c25c4d..740d2624f 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -4214,6 +4214,11 @@ 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) -- ... diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md index 7d14f4ec5..344663c39 100644 --- a/docs/lua/functions-3.md +++ b/docs/lua/functions-3.md @@ -4356,6 +4356,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:](#) + +
+ ## [create_dialog_box](#create_dialog_box) ### Lua Example diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 2a5fef61b..1dd1f627a 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -842,6 +842,7 @@
- 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) diff --git a/src/game/ingame_menu.c b/src/game/ingame_menu.c index bf7304bf2..883fa09d5 100644 --- a/src/game/ingame_menu.c +++ b/src/game/ingame_menu.c @@ -1160,30 +1160,27 @@ void handle_special_dialog_text(s16 dialogID) { // dialog ID tables, in order static u8 sHookString[255]; static bool sOverrideDialogString = false; void convert_string_ascii_to_sm64(u8 *str64, const char *strAscii, bool menu); -void handle_dialog_hook(s16 dialogId) { +bool handle_dialog_hook(s16 dialogId) { bool open = false; const char *str = smlua_call_event_hooks_int_ret_bool_and_string(HOOK_ON_DIALOG, dialogId, &open); + if (!open) { + if (gCamera->cutscene == CUTSCENE_READ_MESSAGE) { gCamera->cutscene = 0; } + return false; + } sOverrideDialogString = str != NULL; if (sOverrideDialogString) { convert_string_ascii_to_sm64(sHookString, str, false); } - if (!open) { - gDialogLineNum = 1; - gDialogBoxState = DIALOG_STATE_CLOSING; - gDialogBoxOpenTimer = 20; - handle_special_dialog_text(dialogId); - } + return true; } void create_dialog_box(s16 dialog) { - handle_dialog_hook(dialog); - if (gDialogID == -1) { + if (handle_dialog_hook(dialog) && gDialogID == -1) { gDialogID = dialog; gDialogBoxType = DIALOG_TYPE_ROTATE; } } void create_dialog_box_with_var(s16 dialog, s32 dialogVar) { - handle_dialog_hook(dialog); - if (gDialogID == -1) { + if (handle_dialog_hook(dialog) && gDialogID == -1) { gDialogID = dialog; gDialogVariable = dialogVar; gDialogBoxType = DIALOG_TYPE_ROTATE; @@ -1191,16 +1188,14 @@ void create_dialog_box_with_var(s16 dialog, s32 dialogVar) { } void create_dialog_inverted_box(s16 dialog) { - handle_dialog_hook(dialog); - if (gDialogID == -1) { + if (handle_dialog_hook(dialog) && gDialogID == -1) { gDialogID = dialog; gDialogBoxType = DIALOG_TYPE_ZOOM; } } void create_dialog_box_with_response(s16 dialog) { - handle_dialog_hook(dialog); - if (gDialogID == -1) { + if (handle_dialog_hook(dialog) && gDialogID == -1) { gDialogID = dialog; gDialogBoxType = DIALOG_TYPE_ROTATE; gLastDialogResponse = 1; @@ -3596,7 +3591,7 @@ void reset_dialog_override_color(void) { gOverrideDialogColor = 0; } -void close_dialog_box(u8 state) { +void set_dialog_box_state(u8 state) { if (state > DIALOG_STATE_CLOSING) { return; } gDialogBoxState = state; } diff --git a/src/game/ingame_menu.h b/src/game/ingame_menu.h index b4a55a787..122049dfd 100644 --- a/src/game/ingame_menu.h +++ b/src/game/ingame_menu.h @@ -179,5 +179,6 @@ void set_dialog_override_pos(s16 x, s16 y); void reset_dialog_override_pos(); void set_dialog_override_color(u8 bgR, u8 bgG, u8 bgB, u8 bgA, u8 textR, u8 textG, u8 textB, u8 textA); void reset_dialog_override_color(); +void set_dialog_box_state(u8 state); #endif // INGAME_MENU_H diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 3c4ff3d1d..044288a0f 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -4318,7 +4318,7 @@ char gSmluaConstants[] = "" "COOP_OBJ_FLAG_LUA = (1 << 1)\n" "COOP_OBJ_FLAG_NON_SYNC = (1 << 2)\n" "COOP_OBJ_FLAG_INITIALIZED = (1 << 3)\n" -"SM64COOPDX_VERSION = 'v1.1.1'\n" +"SM64COOPDX_VERSION = 'v1.2.0'\n" "VERSION_TEXT = 'v'\n" "VERSION_NUMBER = 38\n" "MINOR_VERSION_NUMBER = 1\n" diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index bae6512b1..87caa2556 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -13388,6 +13388,23 @@ 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; } @@ -32805,6 +32822,7 @@ 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);