diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 1e66ac00..d120f473 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -9060,7 +9060,10 @@ HOOK_ON_EXIT = 34 HOOK_DIALOG_SOUND = 35 --- @type LuaHookedEventType -HOOK_MAX = 36 +HOOK_ON_HUD_RENDER_BEHIND = 36 + +--- @type LuaHookedEventType +HOOK_MAX = 37 --- @class HudDisplayFlags @@ -12360,9 +12363,6 @@ MINOR_VERSION_NUMBER = 0 --- @type integer PATCH_VERSION_NUMBER = 0 ---- @type string -SM64COOPDX_VERSION = "v0.1" - --- @type integer VERSION_NUMBER = 36 diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 8ab06dc6..2f59190c 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -3773,12 +3773,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) @@ -8303,6 +8297,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 6332e71d..3183e263 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -1050,6 +1050,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 c48a2829..f180d327 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -3227,7 +3227,8 @@ | HOOK_ON_DIALOG | 33 | | HOOK_ON_EXIT | 34 | | HOOK_DIALOG_SOUND | 35 | -| HOOK_MAX | 36 | +| HOOK_ON_HUD_RENDER_BEHIND | 36 | +| HOOK_MAX | 37 | [:arrow_up_small:](#) @@ -4380,7 +4381,6 @@ - MAX_VERSION_LENGTH - MINOR_VERSION_NUMBER - PATCH_VERSION_NUMBER -- SM64COOPDX_VERSION - VERSION_NUMBER - VERSION_REGION - VERSION_REGION diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md index b1fd70f8..4cf387b8 100644 --- a/docs/lua/functions-3.md +++ b/docs/lua/functions-3.md @@ -2516,26 +2516,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 a75ea83b..72783e47 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -749,7 +749,6 @@ - [djui_hud_set_filter](functions-3.md#djui_hud_set_filter) - [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 f45eef38..20ad7cef 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -1428,6 +1428,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 3c4ca2ec..288aeba2 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -444,16 +444,14 @@ void render_game(void) { gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, 0, BORDER_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - BORDER_HEIGHT); - if (!gDjuiDisabled && !gDjuiInMainMenu) { + if (!gDjuiDisabled) { + djui_reset_hud_params(); create_dl_ortho_matrix(); djui_gfx_displaylist_begin(); if (!gCoopCompatibility && gServerSettings.nametags) { nametags_render(); } - 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_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 3bf3c20d..9ac8c997 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; @@ -133,10 +130,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 9654f3aa..2275b96e 100644 --- a/src/pc/djui/djui.h +++ b/src/pc/djui/djui.h @@ -38,7 +38,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 291c0413..ba82ccaa 100644 --- a/src/pc/djui/djui_hud_utils.c +++ b/src/pc/djui/djui_hud_utils.c @@ -592,10 +592,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 00f70096..e81ddce4 100644 --- a/src/pc/djui/djui_hud_utils.h +++ b/src/pc/djui/djui_hud_utils.h @@ -82,9 +82,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 504b3582..2ceb802b 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -1160,7 +1160,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 }, @@ -1172,6 +1172,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 03c9f4c1..50664ee0 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -3212,7 +3212,8 @@ char gSmluaConstants[] = "" "HOOK_ON_DIALOG = 33\n" "HOOK_ON_EXIT = 34\n" "HOOK_DIALOG_SOUND = 35\n" -"HOOK_MAX = 36\n" +"HOOK_ON_HUD_RENDER_BEHIND = 36\n" +"HOOK_MAX = 37\n" "ACTION_HOOK_EVERY_FRAME = 0\n" "ACTION_HOOK_GRAVITY = 1\n" "ACTION_HOOK_MAX = 2\n" @@ -4308,7 +4309,6 @@ 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 = 'v0.1'\n" "VERSION_TEXT = 'v'\n" "VERSION_NUMBER = 36\n" "MINOR_VERSION_NUMBER = 0\n" @@ -4319,4 +4319,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 eb3d46c2..21b92519 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -12480,23 +12480,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; } @@ -27619,6 +27602,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; } @@ -31987,7 +31987,6 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "djui_hud_set_filter", smlua_func_djui_hud_set_filter); 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); @@ -32739,6 +32738,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 a3535aa2..59f29d88 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -168,20 +168,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 0cd805a4..8d74a463 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -47,6 +47,7 @@ enum LuaHookedEventType { HOOK_ON_DIALOG, HOOK_ON_EXIT, HOOK_DIALOG_SOUND, + HOOK_ON_HUD_RENDER_BEHIND, HOOK_MAX, }; @@ -87,6 +88,7 @@ static const char* LuaHookedEventTypeName[] = { "HOOK_ON_DIALOG", "HOOK_ON_EXIT", "HOOK_DIALOG_SOUND", + "HOOK_ON_HUD_RENDER_BEHIND", "HOOK_MAX" }; @@ -107,7 +109,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 cd4e2394..2a1a187e 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 1e82474c..fe182b67 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -655,7 +655,6 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect gFogIntensity = 1; gOverrideBackground = -1; gOverrideEnvFx = -1; - gDjuiRenderBehindHud = false; gRomhackCameraAllowCentering = TRUE; gOverrideAllowToxicGasCamera = FALSE; gRomhackCameraAllowDpad = FALSE;