From 566e2ba9342ade2060180a2c1bfec0b6bf2351f9 Mon Sep 17 00:00:00 2001 From: Beckowl <68874587+Beckowl@users.noreply.github.com> Date: Tue, 3 Jun 2025 05:12:56 -0300 Subject: [PATCH] Add ``ModelExtendedId`` param to ``HOOK_OBJECT_SET_MODEL`` (#834) --- docs/lua/guides/hooks.md | 2 +- src/game/object_helpers.c | 5 +++-- src/game/object_helpers.h | 1 + src/pc/lua/smlua_hooks.c | 6 ++++-- src/pc/lua/smlua_hooks.h | 3 ++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index 50a3d28e9..59ceb3e61 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -121,7 +121,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_ON_SCREEN_TRANSITION | Called when the game is about to play a transition, return `false` to prevent the transition from playing | `integer` type | | HOOK_ALLOW_HAZARD_SURFACE | Called once per player per frame. Return `false` to prevent the player from being affected by lava, quicksand, or wind | [MarioState](../structs.md#MarioState) mario, `integer` hazardType | | HOOK_ON_CHAT_MESSAGE | Called when a chat message gets sent. Return `false` to prevent the message from being sent | [MarioState](../structs.md#MarioState) messageSender, `string` messageSent | -| HOOK_OBJECT_SET_MODEL | Called when a behavior changes models. Also runs when a behavior spawns | [Object](../structs.md#Object) obj, `integer` modelID | +| HOOK_OBJECT_SET_MODEL | Called when a behavior changes models. Also runs when a behavior spawns | [Object](../structs.md#Object) obj, `integer` modelID, `integer` modelExtendedId| | HOOK_CHARACTER_SOUND | Called when mario retrieves a character sound to play, return a character sound or `0` to override it | [MarioState](../structs.md#MarioState) mario, [enum CharacterSound](../constants.md#enum-CharacterSound) characterSound | | HOOK_BEFORE_SET_MARIO_ACTION | Called before Mario's action changes Return an action to change the incoming action or `1` to cancel the action change | [MarioState](../structs.md#MarioState) mario, `integer` incomingAction, `integer` actionArg | | HOOK_JOINED_GAME | Called when the local player finishes the join process (if the player isn't the host) | None | diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c index e60cde834..a1008cdbe 100644 --- a/src/game/object_helpers.c +++ b/src/game/object_helpers.c @@ -30,6 +30,7 @@ #include "pc/network/network.h" #include "pc/lua/smlua_hooks.h" #include "pc/lua/utils/smlua_camera_utils.h" +#include "pc/lua/utils/smlua_model_utils.h" #include "first_person_cam.h" u8 (*gContinueDialogFunction)(void) = NULL; @@ -696,7 +697,7 @@ struct Object *spawn_object_at_origin(struct Object *parent, UNUSED s32 unusedAr obj->globalPlayerIndex = 0; geo_obj_init((struct GraphNodeObject *) &obj->header.gfx, dynos_model_get_geo(model), gVec3fZero, gVec3sZero); - smlua_call_event_hooks_object_model_param(HOOK_OBJECT_SET_MODEL, obj, model); + smlua_call_event_hooks_object_set_model(HOOK_OBJECT_SET_MODEL, obj, model, smlua_model_util_id_to_ext_id(model)); return obj; } @@ -1453,7 +1454,7 @@ void cur_obj_set_model(s32 modelID) { void obj_set_model(struct Object* obj, s32 modelID) { obj->header.gfx.sharedChild = dynos_model_get_geo(modelID); dynos_actor_override(obj, (void*)&obj->header.gfx.sharedChild); - smlua_call_event_hooks_object_model_param(HOOK_OBJECT_SET_MODEL, obj, modelID); + smlua_call_event_hooks_object_set_model(HOOK_OBJECT_SET_MODEL, obj, modelID, smlua_model_util_id_to_ext_id(modelID)); } void mario_set_flag(s32 flag) { diff --git a/src/game/object_helpers.h b/src/game/object_helpers.h index 170935fb4..6298ad44c 100644 --- a/src/game/object_helpers.h +++ b/src/game/object_helpers.h @@ -5,6 +5,7 @@ #include "macros.h" #include "types.h" +#include "pc/lua/utils/smlua_model_utils.h" // used for chain chomp and wiggler struct ChainSegment diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index 9d6d7c5e3..039bcb0c9 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -19,6 +19,7 @@ #include "pc/djui/djui_panel.h" #include "pc/configfile.h" #include "pc/utils/misc.h" +#include "pc/lua/utils/smlua_model_utils.h" #include "../mods/mods.h" #include "game/print.h" @@ -445,7 +446,7 @@ void smlua_call_event_hooks_object_param(enum LuaHookedEventType hookType, struc } } -void smlua_call_event_hooks_object_model_param(enum LuaHookedEventType hookType, struct Object* obj, s32 modelID) { +void smlua_call_event_hooks_object_set_model(enum LuaHookedEventType hookType, struct Object* obj, s32 modelID, enum ModelExtendedId modelExtendedId) { lua_State* L = gLuaState; if (L == NULL) { return; } struct LuaHookedEvent* hook = &sHookedEvents[hookType]; @@ -456,9 +457,10 @@ void smlua_call_event_hooks_object_model_param(enum LuaHookedEventType hookType, // push params smlua_push_object(L, LOT_OBJECT, obj, NULL); lua_pushinteger(L, modelID); + lua_pushinteger(L, modelExtendedId); // call the callback - if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) { + if (0 != smlua_call_hook(L, 3, 0, 0, hook->mod[i])) { LOG_LUA("Failed to call the callback: %u", hookType); continue; } diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index eb18b5242..3d59f9612 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -6,6 +6,7 @@ #include "smlua.h" #include "pc/mods/mod.h" +#include "pc/lua/utils/smlua_model_utils.h" // forward declare struct Camera; @@ -189,7 +190,7 @@ void smlua_call_event_hooks_interact_params(enum LuaHookedEventType hookType, st void smlua_call_event_hooks_interact_params_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, struct Object* obj, u32 interactType, bool* returnValue); void smlua_call_event_hooks_interact_params_no_ret(enum LuaHookedEventType hookType, struct MarioState* m, struct Object* obj, u32 interactType); void smlua_call_event_hooks_object_param(enum LuaHookedEventType hookType, struct Object* obj); -void smlua_call_event_hooks_object_model_param(enum LuaHookedEventType hookType, struct Object* obj, s32 modelID); +void smlua_call_event_hooks_object_set_model(enum LuaHookedEventType hookType, struct Object* obj, s32 modelID, enum ModelExtendedId modelExtendedId); bool smlua_call_event_hooks_ret_int(enum LuaHookedEventType hookType, s32* returnValue); void smlua_call_event_hooks_set_camera_mode_params(enum LuaHookedEventType hookType, struct Camera *c, s16 mode, s16 frames, bool* returnValue); void smlua_call_event_hooks_int_params_ret_bool(enum LuaHookedEventType hookType, s16 param, bool* returnValue);