From cda2480ba471b90430856fe0ef0484ec7eec56d4 Mon Sep 17 00:00:00 2001 From: MysterD Date: Tue, 7 Nov 2023 15:50:49 -0800 Subject: [PATCH] Added HOOK_ON_RENDER_BEHIND, deprecated djui_hud_set_render_behind_hud() --- autogen/lua_definitions/constants.lua | 5 ++- autogen/lua_definitions/functions.lua | 12 +++---- autogen/lua_definitions/structs.lua | 1 + docs/lua/constants.md | 3 +- docs/lua/functions-3.md | 20 ------------ docs/lua/functions.md | 1 - docs/lua/structs.md | 1 + src/game/area.c | 4 +-- src/pc/djui/djui.c | 8 +---- src/pc/djui/djui.h | 1 - src/pc/djui/djui_hud_utils.c | 4 --- src/pc/djui/djui_hud_utils.h | 3 -- src/pc/lua/smlua_cobject_autogen.c | 3 +- src/pc/lua/smlua_constants_autogen.c | 5 +-- src/pc/lua/smlua_functions_autogen.c | 36 ++++++++++----------- src/pc/lua/smlua_hooks.c | 46 +++++++++++++++++++++++++-- src/pc/lua/smlua_hooks.h | 5 ++- src/pc/lua/utils/smlua_deprecated.c | 6 ++++ src/pc/lua/utils/smlua_deprecated.h | 2 ++ src/pc/mods/mod.h | 1 + src/pc/network/network.c | 1 - 21 files changed, 96 insertions(+), 72 deletions(-) diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index a85292c1..00214a6a 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -8999,7 +8999,10 @@ HOOK_ON_OBJECT_ANIM_UPDATE = 32 HOOK_ON_DIALOG = 33 --- @type LuaHookedEventType -HOOK_MAX = 34 +HOOK_ON_HUD_RENDER_BEHIND = 34 + +--- @type LuaHookedEventType +HOOK_MAX = 35 --- @class HudDisplayFlags diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index f0d4d668..418516a4 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -3742,12 +3742,6 @@ function djui_hud_set_mouse_locked(locked) -- ... end ---- @param enable boolean ---- @return nil -function djui_hud_set_render_behind_hud(enable) - -- ... -end - --- @param resolutionType HudUtilsResolution --- @return nil function djui_hud_set_resolution(resolutionType) @@ -8266,6 +8260,12 @@ function smlua_collision_util_get(name) -- ... end +--- @param enable boolean +--- @return nil +function djui_hud_set_render_behind_hud(enable) + -- ... +end + --- @param localIndex integer --- @return string function network_discord_id_from_local_index(localIndex) diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index 6af99336..2eca4d6b 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -1028,6 +1028,7 @@ --- @field public isDirectory boolean --- @field public name string --- @field public relativePath string +--- @field public renderBehindHud boolean --- @field public selectable boolean --- @class ModFile diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 7458a85b..f7d32d5a 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -3198,7 +3198,8 @@ | HOOK_JOINED_GAME | 31 | | HOOK_ON_OBJECT_ANIM_UPDATE | 32 | | HOOK_ON_DIALOG | 33 | -| HOOK_MAX | 34 | +| HOOK_ON_HUD_RENDER_BEHIND | 34 | +| HOOK_MAX | 35 | [:arrow_up_small:](#) diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md index e6309459..ca629aa0 100644 --- a/docs/lua/functions-3.md +++ b/docs/lua/functions-3.md @@ -2406,26 +2406,6 @@
-## [djui_hud_set_render_behind_hud](#djui_hud_set_render_behind_hud) - -### Lua Example -`djui_hud_set_render_behind_hud(enable)` - -### Parameters -| Field | Type | -| ----- | ---- | -| enable | `boolean` | - -### Returns -- None - -### C Prototype -`void djui_hud_set_render_behind_hud(bool enable);` - -[:arrow_up_small:](#) - -
- ## [djui_hud_set_resolution](#djui_hud_set_resolution) ### Lua Example diff --git a/docs/lua/functions.md b/docs/lua/functions.md index c2e00834..860c459c 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -738,7 +738,6 @@ - [djui_hud_set_color](functions-3.md#djui_hud_set_color) - [djui_hud_set_font](functions-3.md#djui_hud_set_font) - [djui_hud_set_mouse_locked](functions-3.md#djui_hud_set_mouse_locked) - - [djui_hud_set_render_behind_hud](functions-3.md#djui_hud_set_render_behind_hud) - [djui_hud_set_resolution](functions-3.md#djui_hud_set_resolution) - [djui_hud_set_rotation](functions-3.md#djui_hud_set_rotation) - [djui_hud_world_pos_to_screen_pos](functions-3.md#djui_hud_world_pos_to_screen_pos) diff --git a/docs/lua/structs.md b/docs/lua/structs.md index 4b803a89..55a2deca 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -1381,6 +1381,7 @@ | isDirectory | `boolean` | read-only | | name | `string` | read-only | | relativePath | `string` | read-only | +| renderBehindHud | `boolean` | read-only | | selectable | `boolean` | read-only | [:arrow_up_small:](#) diff --git a/src/game/area.c b/src/game/area.c index f7b1374a..a1ce1571 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -442,11 +442,11 @@ void render_game(void) { gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, 0, BORDER_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - BORDER_HEIGHT); - if (!gDjuiDisabled && gDjuiRenderBehindHud) { + if (!gDjuiDisabled) { djui_reset_hud_params(); create_dl_ortho_matrix(); djui_gfx_displaylist_begin(); - smlua_call_event_hooks_with_reset_func(HOOK_ON_HUD_RENDER, djui_reset_hud_params); + smlua_call_event_on_hud_render_behind(djui_reset_hud_params); djui_gfx_displaylist_end(); } render_hud(); diff --git a/src/pc/djui/djui.c b/src/pc/djui/djui.c index 39138a1b..20a2f1ba 100644 --- a/src/pc/djui/djui.c +++ b/src/pc/djui/djui.c @@ -23,7 +23,6 @@ static struct DjuiText* sDjuiLuaError = NULL; static u32 sDjuiLuaErrorTimeout = 0; bool gDjuiInMainMenu = true; bool gDjuiDisabled = false; -bool gDjuiRenderBehindHud = false; static bool sDjuiInited = false; bool sDjuiRendered60fps = false; @@ -49,8 +48,6 @@ void patch_djui_before(void) { } void patch_djui_interpolated(UNUSED f32 delta) { - if (gDjuiRenderBehindHud && !gDjuiPanelPauseCreated) { return; } - // reset the head and re-render DJUI if (delta >= 0.5f && !sDjuiRendered60fps && (gDjuiInMainMenu || gDjuiPanelPauseCreated)) { sDjuiRendered60fps = true; @@ -132,10 +129,7 @@ void djui_render(void) { create_dl_ortho_matrix(); djui_gfx_displaylist_begin(); - if (!gDjuiRenderBehindHud) { - djui_reset_hud_params(); - smlua_call_event_hooks_with_reset_func(HOOK_ON_HUD_RENDER, djui_reset_hud_params); - } + smlua_call_event_on_hud_render(djui_reset_hud_params); djui_panel_update(); djui_popup_update(); diff --git a/src/pc/djui/djui.h b/src/pc/djui/djui.h index 08f71726..06303142 100644 --- a/src/pc/djui/djui.h +++ b/src/pc/djui/djui.h @@ -37,7 +37,6 @@ extern struct DjuiRoot* gDjuiRoot; extern bool gDjuiInMainMenu; extern bool gDjuiDisabled; -extern bool gDjuiRenderBehindHud; void djui_init(void); void djui_init_late(void); diff --git a/src/pc/djui/djui_hud_utils.c b/src/pc/djui/djui_hud_utils.c index 53f2efa3..20ab2a81 100644 --- a/src/pc/djui/djui_hud_utils.c +++ b/src/pc/djui/djui_hud_utils.c @@ -554,10 +554,6 @@ bool djui_hud_world_pos_to_screen_pos(Vec3f pos, Vec3f out) { return true; } -void djui_hud_set_render_behind_hud(bool enable) { - gDjuiRenderBehindHud = enable; -} - bool djui_hud_is_pause_menu_created(void) { return gDjuiPanelPauseCreated; } diff --git a/src/pc/djui/djui_hud_utils.h b/src/pc/djui/djui_hud_utils.h index 7372338b..c9816a9f 100644 --- a/src/pc/djui/djui_hud_utils.h +++ b/src/pc/djui/djui_hud_utils.h @@ -64,9 +64,6 @@ void djui_hud_render_rect(f32 x, f32 y, f32 width, f32 height); void djui_hud_render_rect_interpolated(f32 prevX, f32 prevY, f32 prevWidth, f32 prevHeight, f32 x, f32 y, f32 width, f32 height); bool djui_hud_world_pos_to_screen_pos(Vec3f pos, Vec3f out); - -void djui_hud_set_render_behind_hud(bool enable); - bool djui_hud_is_pause_menu_created(void); void djui_open_pause_menu(void); diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index 110eb9ab..d111cb1a 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -1131,7 +1131,7 @@ static struct LuaObjectField sMarioStateFields[LUA_MARIO_STATE_FIELD_COUNT] = { { "waterLevel", LVT_S16, offsetof(struct MarioState, waterLevel), false, LOT_NONE }, }; -#define LUA_MOD_FIELD_COUNT 11 +#define LUA_MOD_FIELD_COUNT 12 static struct LuaObjectField sModFields[LUA_MOD_FIELD_COUNT] = { { "basePath", LVT_STRING, offsetof(struct Mod, basePath), true, LOT_NONE }, { "customBehaviorIndex", LVT_U8, offsetof(struct Mod, customBehaviorIndex), true, LOT_NONE }, @@ -1143,6 +1143,7 @@ static struct LuaObjectField sModFields[LUA_MOD_FIELD_COUNT] = { { "isDirectory", LVT_BOOL, offsetof(struct Mod, isDirectory), true, LOT_NONE }, { "name", LVT_STRING_P, offsetof(struct Mod, name), true, LOT_NONE }, { "relativePath", LVT_STRING, offsetof(struct Mod, relativePath), true, LOT_NONE }, + { "renderBehindHud", LVT_BOOL, offsetof(struct Mod, renderBehindHud), true, LOT_NONE }, { "selectable", LVT_BOOL, offsetof(struct Mod, selectable), true, LOT_NONE }, // { "size", LVT_???, offsetof(struct Mod, size), true, LOT_??? }, <--- UNIMPLEMENTED }; diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 17e2d7bf..581f83be 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -3193,7 +3193,8 @@ char gSmluaConstants[] = "" "HOOK_JOINED_GAME = 31\n" "HOOK_ON_OBJECT_ANIM_UPDATE = 32\n" "HOOK_ON_DIALOG = 33\n" -"HOOK_MAX = 34\n" +"HOOK_ON_HUD_RENDER_BEHIND = 34\n" +"HOOK_MAX = 35\n" "ACTION_HOOK_EVERY_FRAME = 0\n" "ACTION_HOOK_GRAVITY = 1\n" "ACTION_HOOK_MAX = 2\n" @@ -4298,4 +4299,4 @@ char gSmluaConstants[] = "" "VERSION_REGION = 'US'\n" "MAX_VERSION_LENGTH = 32\n" "MAX_LOCAL_VERSION_LENGTH = 36\n" -; +; \ No newline at end of file diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 0ee3b764..3d4a2ed5 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -12388,23 +12388,6 @@ int smlua_func_djui_hud_set_mouse_locked(lua_State* L) { return 1; } -int smlua_func_djui_hud_set_render_behind_hud(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", "djui_hud_set_render_behind_hud", 1, top); - return 0; - } - - bool enable = smlua_to_boolean(L, 1); - if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "djui_hud_set_render_behind_hud"); return 0; } - - djui_hud_set_render_behind_hud(enable); - - return 1; -} - int smlua_func_djui_hud_set_resolution(lua_State* L) { if (L == NULL) { return 0; } @@ -27510,6 +27493,23 @@ int smlua_func_smlua_collision_util_get(lua_State* L) { // smlua_deprecated.h // //////////////////////// +int smlua_func_djui_hud_set_render_behind_hud(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", "djui_hud_set_render_behind_hud", 1, top); + return 0; + } + + bool enable = smlua_to_boolean(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "djui_hud_set_render_behind_hud"); return 0; } + + djui_hud_set_render_behind_hud(enable); + + return 1; +} + int smlua_func_network_discord_id_from_local_index(lua_State* L) { if (L == NULL) { return 0; } @@ -31721,7 +31721,6 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "djui_hud_set_color", smlua_func_djui_hud_set_color); smlua_bind_function(L, "djui_hud_set_font", smlua_func_djui_hud_set_font); smlua_bind_function(L, "djui_hud_set_mouse_locked", smlua_func_djui_hud_set_mouse_locked); - smlua_bind_function(L, "djui_hud_set_render_behind_hud", smlua_func_djui_hud_set_render_behind_hud); smlua_bind_function(L, "djui_hud_set_resolution", smlua_func_djui_hud_set_resolution); smlua_bind_function(L, "djui_hud_set_rotation", smlua_func_djui_hud_set_rotation); smlua_bind_function(L, "djui_hud_world_pos_to_screen_pos", smlua_func_djui_hud_world_pos_to_screen_pos); @@ -32472,6 +32471,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "smlua_collision_util_get", smlua_func_smlua_collision_util_get); // smlua_deprecated.h + smlua_bind_function(L, "djui_hud_set_render_behind_hud", smlua_func_djui_hud_set_render_behind_hud); smlua_bind_function(L, "network_discord_id_from_local_index", smlua_func_network_discord_id_from_local_index); // smlua_level_utils.h diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index d968127d..b1a32b12 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -173,20 +173,60 @@ void smlua_call_event_hooks(enum LuaHookedEventType hookType) { } } -void smlua_call_event_hooks_with_reset_func(enum LuaHookedEventType hookType, void (*resetFunc)(void)) { +void smlua_call_event_on_hud_render(void (*resetFunc)(void)) { lua_State* L = gLuaState; if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; + if (resetFunc) { resetFunc(); } + + struct LuaHookedEvent* hook = &sHookedEvents[HOOK_ON_HUD_RENDER]; + for (int i = 0; i < hook->count; i++) { + // support deprecated render behind hud + if (hook->mod[i]->renderBehindHud) { continue; } + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // call the callback + if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the event_hook callback: %u", HOOK_ON_HUD_RENDER); + } + if (resetFunc) { resetFunc(); } + } +} + +void smlua_call_event_on_hud_render_behind(void (*resetFunc)(void)) { + lua_State* L = gLuaState; + if (L == NULL) { return; } + if (resetFunc) { resetFunc(); } + + struct LuaHookedEvent* hook = &sHookedEvents[HOOK_ON_HUD_RENDER_BEHIND]; for (int i = 0; i < hook->count; i++) { // push the callback onto the stack lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); // call the callback if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the event_hook callback: %u", hookType); + LOG_LUA("Failed to call the event_hook callback: %u", HOOK_ON_HUD_RENDER_BEHIND); } if (resetFunc) { resetFunc(); } } + + // support deprecated render behind hud + hook = &sHookedEvents[HOOK_ON_HUD_RENDER]; + for (int i = 0; i < hook->count; i++) { + // support deprecated render behind hud + if (!hook->mod[i]->renderBehindHud) { continue; } + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // call the callback + if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the event_hook callback: %u", HOOK_ON_HUD_RENDER); + } + if (resetFunc) { resetFunc(); } + } + } void smlua_call_event_hooks_bool_param(enum LuaHookedEventType hookType, bool value) { diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index 3b6740cf..aecb9b75 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -45,6 +45,7 @@ enum LuaHookedEventType { HOOK_JOINED_GAME, HOOK_ON_OBJECT_ANIM_UPDATE, HOOK_ON_DIALOG, + HOOK_ON_HUD_RENDER_BEHIND, HOOK_MAX, }; @@ -83,6 +84,7 @@ static const char* LuaHookedEventTypeName[] = { "HOOK_JOINED_GAME", "HOOK_ON_OBJECT_ANIM_UPDATE", "HOOK_ON_DIALOG", + "HOOK_ON_HUD_RENDER_BEHIND", "HOOK_MAX" }; @@ -103,7 +105,8 @@ extern u32 gLuaMarioActionIndex[]; int smlua_hook_custom_bhv(BehaviorScript *bhvScript, const char *bhvName); void smlua_call_event_hooks(enum LuaHookedEventType hookType); -void smlua_call_event_hooks_with_reset_func(enum LuaHookedEventType hookType, void (*resetFunc)(void)); +void smlua_call_event_on_hud_render(void (*resetFunc)(void)); +void smlua_call_event_on_hud_render_behind(void (*resetFunc)(void)); void smlua_call_event_hooks_bool_param(enum LuaHookedEventType hookType, bool value); void smlua_call_event_hooks_bool_param_ret_bool(enum LuaHookedEventType hookType, bool value, bool* returnValue); void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct MarioState* m); diff --git a/src/pc/lua/utils/smlua_deprecated.c b/src/pc/lua/utils/smlua_deprecated.c index 9a9c7e6c..60126066 100644 --- a/src/pc/lua/utils/smlua_deprecated.c +++ b/src/pc/lua/utils/smlua_deprecated.c @@ -3,6 +3,7 @@ #ifdef DISCORD_SDK #include "pc/discord/discord.h" #endif +#include "pc/lua/smlua.h" char* network_discord_id_from_local_index(u8 localIndex) { #ifdef DISCORD_SDK @@ -14,3 +15,8 @@ char* network_discord_id_from_local_index(u8 localIndex) { #endif return NULL; } + +void djui_hud_set_render_behind_hud(bool enable) { + if (!gLuaActiveMod) { return; } + gLuaActiveMod->renderBehindHud = enable; +} diff --git a/src/pc/lua/utils/smlua_deprecated.h b/src/pc/lua/utils/smlua_deprecated.h index 09622d33..34d52558 100644 --- a/src/pc/lua/utils/smlua_deprecated.h +++ b/src/pc/lua/utils/smlua_deprecated.h @@ -1,3 +1,5 @@ #pragma once char* network_discord_id_from_local_index(u8 localIndex); +void djui_hud_set_render_behind_hud(bool enable); + diff --git a/src/pc/mods/mod.h b/src/pc/mods/mod.h index ce6e66fa..2ca5238f 100644 --- a/src/pc/mods/mod.h +++ b/src/pc/mods/mod.h @@ -33,6 +33,7 @@ struct Mod { bool isDirectory; bool enabled; bool selectable; + bool renderBehindHud; size_t size; u8 customBehaviorIndex; }; diff --git a/src/pc/network/network.c b/src/pc/network/network.c index a9a1223a..2c200cde 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -639,7 +639,6 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect gLightingColor[2] = 255; gOverrideBackground = -1; gOverrideEnvFx = -1; - gDjuiRenderBehindHud = false; gRomhackCameraAllowCentering = TRUE; gRomhackCameraAllowDpad = FALSE; camera_reset_overrides();