From 45bc3062bef6b4fd56279b3139cf47ce3a87ec43 Mon Sep 17 00:00:00 2001 From: jayden <46307433+kermeow@users.noreply.github.com> Date: Wed, 22 Apr 2026 02:22:18 +0100 Subject: [PATCH] Fix `get_texture_info` and add `HOOK_ON_DYNOS_PACKS_TOGGLED` (#1181) * respect overridden textures * add HOOK_ON_DYNOS_CHANGED * document HOOK_ON_DYNOS_CHANGED * HOOK_ON_DYNOS_CHANGED -> HOOK_ON_DYNOS_PACK_TOGGLED * Apply suggestions from code review Co-authored-by: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> * Update data/dynos_mgr_tex.cpp Co-authored-by: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> * add missing include * add pack name and enabled --------- Co-authored-by: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> --- autogen/lua_definitions/constants.lua | 4 +++- data/dynos_mgr_tex.cpp | 16 +++++++++++++ docs/lua/constants.md | 3 ++- docs/lua/guides/hooks.md | 1 + src/pc/djui/djui_panel_dynos.c | 2 ++ src/pc/lua/smlua_constants_autogen.c | 3 ++- src/pc/lua/smlua_hook_events.inl | 1 + src/pc/lua/smlua_hook_events_autogen.inl | 30 ++++++++++++++++++++++++ src/pc/lua/smlua_hooks.h | 1 + 9 files changed, 58 insertions(+), 3 deletions(-) diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index cbf769b73..4f14dfdaf 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -8222,7 +8222,8 @@ HOOK_ON_FIND_FLOOR = 62 --- @type LuaHookedEventType HOOK_ON_FIND_WATER_LEVEL = 63 --- @type LuaHookedEventType HOOK_ON_FIND_POISON_GAS_LEVEL = 64 --- @type LuaHookedEventType HOOK_ON_FIND_SURFACE_ON_RAY = 65 --- @type LuaHookedEventType -HOOK_MAX = 66 --- @type LuaHookedEventType +HOOK_ON_DYNOS_PACK_TOGGLED = 66 --- @type LuaHookedEventType +HOOK_MAX = 67 --- @type LuaHookedEventType --- @alias LuaHookedEventType --- | `HOOK_UPDATE` @@ -8291,6 +8292,7 @@ HOOK_MAX = 66 --- @type LuaHookedEventType --- | `HOOK_ON_FIND_WATER_LEVEL` --- | `HOOK_ON_FIND_POISON_GAS_LEVEL` --- | `HOOK_ON_FIND_SURFACE_ON_RAY` +--- | `HOOK_ON_DYNOS_PACK_TOGGLED` --- | `HOOK_MAX` --- @type integer diff --git a/data/dynos_mgr_tex.cpp b/data/dynos_mgr_tex.cpp index 50e00bf3b..7ca701b7c 100644 --- a/data/dynos_mgr_tex.cpp +++ b/data/dynos_mgr_tex.cpp @@ -502,6 +502,22 @@ bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo) { } return false; } + + // check override + auto &_DynosOverrideTextures = DynosOverrideTextures(); + auto it = _DynosOverrideTextures.find(info->texture); + if (it != _DynosOverrideTextures.end() && it->second) { + auto *_Node = it->second->node; + auto &_Data = _Node->mData; + CONVERT_TEXINFO(aTexName); + + // must link to the vanilla built in texture + // so that the texture is correctly overridden + // when DynOS_Tex_RetrieveNode is called. + aOutTexInfo->texture = info->texture; + return true; + } + *aOutTexInfo = *info; return true; } diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 1fef94781..2f67ef821 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -3546,7 +3546,8 @@ | HOOK_ON_FIND_WATER_LEVEL | 63 | | HOOK_ON_FIND_POISON_GAS_LEVEL | 64 | | HOOK_ON_FIND_SURFACE_ON_RAY | 65 | -| HOOK_MAX | 66 | +| HOOK_ON_DYNOS_PACK_TOGGLED | 66 | +| HOOK_MAX | 67 | - MAX_HOOKED_BEHAVIORS [:arrow_up_small:](#) diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index 07d522650..eca0d222b 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -157,6 +157,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_ON_FIND_WATER_LEVEL | Called after water level detection completes. Return a number to override the water level | `number` x, `number` z, `number` waterLevel | | HOOK_ON_FIND_POISON_GAS_LEVEL | Called after poison gas level detection completes. Return a number to override the gas level | `number` x, `number` z, `number` gasLevel | | HOOK_ON_FIND_SURFACE_ON_RAY | Called after ray-surface intersection completes. Return `surface` to override the hit surface, or `surface, hitPos` to override both | `Vec3f` orig, `Vec3f` dir, [Surface](../structs.md#Surface) hitSurface, `Vec3f` hitPos | +| HOOK_ON_DYNOS_PACK_TOGGLED | Called after a DynOS pack is toggled | `string` dynosPackName, `boolean` enabled | ### Parameters diff --git a/src/pc/djui/djui_panel_dynos.c b/src/pc/djui/djui_panel_dynos.c index aec70cafb..a75f75bfa 100644 --- a/src/pc/djui/djui_panel_dynos.c +++ b/src/pc/djui/djui_panel_dynos.c @@ -8,11 +8,13 @@ #include "djui_panel_main.h" #include "djui_panel_options.h" #include "game/level_update.h" +#include "pc/lua/smlua_hooks.h" void djui_panel_dynos_create(struct DjuiBase* caller); static void djui_panel_dynos_apply(struct DjuiBase* caller) { dynos_pack_set_enabled(caller->tag, caller->bTag); + smlua_call_event_hooks(HOOK_ON_DYNOS_PACK_TOGGLED, dynos_pack_get_name(caller->tag), caller->bTag); } static void djui_panel_dynos_local_player_model_only(UNUSED struct DjuiBase* caller) { diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index b292ae5f3..4fe9867df 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -3556,7 +3556,8 @@ char gSmluaConstants[] = "" "HOOK_ON_FIND_WATER_LEVEL=63\n" "HOOK_ON_FIND_POISON_GAS_LEVEL=64\n" "HOOK_ON_FIND_SURFACE_ON_RAY=65\n" -"HOOK_MAX=66\n" +"HOOK_ON_DYNOS_PACK_TOGGLED=66\n" +"HOOK_MAX=67\n" "MAX_HOOKED_BEHAVIORS=1024\n" "HUD_DISPLAY_LIVES=0\n" "HUD_DISPLAY_COINS=1\n" diff --git a/src/pc/lua/smlua_hook_events.inl b/src/pc/lua/smlua_hook_events.inl index 71f4a915c..7641c516e 100644 --- a/src/pc/lua/smlua_hook_events.inl +++ b/src/pc/lua/smlua_hook_events.inl @@ -64,3 +64,4 @@ SMLUA_EVENT_HOOK(HOOK_ON_FIND_FLOOR, _, f32 posX, f32 posY, f32 posZ, struct Sur SMLUA_EVENT_HOOK(HOOK_ON_FIND_WATER_LEVEL, _, f32 x, f32 z, f32 *waterLevel) // Manually defined hook SMLUA_EVENT_HOOK(HOOK_ON_FIND_POISON_GAS_LEVEL, _, f32 x, f32 z, f32 *gasLevel) // Manually defined hook SMLUA_EVENT_HOOK(HOOK_ON_FIND_SURFACE_ON_RAY, _, Vec3f orig, Vec3f dir, struct Surface **hit_surface, Vec3f hit_pos) // Manually defined hook +SMLUA_EVENT_HOOK(HOOK_ON_DYNOS_PACK_TOGGLED, HOOK_RETURN_NEVER, const char *dynosPackName, bool enabled) diff --git a/src/pc/lua/smlua_hook_events_autogen.inl b/src/pc/lua/smlua_hook_events_autogen.inl index 8468eb4b8..b344200b7 100644 --- a/src/pc/lua/smlua_hook_events_autogen.inl +++ b/src/pc/lua/smlua_hook_events_autogen.inl @@ -1863,3 +1863,33 @@ bool smlua_call_event_hooks_HOOK_ON_PACKET_BYTESTRING_RECEIVE(s32 modIndex, s32 } return hookResult; } + +bool smlua_call_event_hooks_HOOK_ON_DYNOS_PACK_TOGGLED(const char *dynosPackName, bool enabled) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_DYNOS_PACK_TOGGLED]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push dynosPackName + lua_pushstring(L, dynosPackName); + + // push enabled + lua_pushboolean(L, enabled); + + // call the callback + if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i], hook->modFile[i])) { + LOG_LUA("Failed to call the callback for hook %s - '%s/%s'", sLuaHookedEventTypeName[HOOK_ON_DYNOS_PACK_TOGGLED], hook->mod[i]->relativePath, hook->modFile[i]->relativePath); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index c814c73e9..fdf6f8d35 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -82,6 +82,7 @@ enum LuaHookedEventType { HOOK_ON_FIND_WATER_LEVEL, HOOK_ON_FIND_POISON_GAS_LEVEL, HOOK_ON_FIND_SURFACE_ON_RAY, + HOOK_ON_DYNOS_PACK_TOGGLED, HOOK_MAX, };