diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 7e5419cb..934edf9e 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -7846,7 +7846,10 @@ HOOK_GET_STAR_COLLECTION_DIALOG = 17 HOOK_ON_SET_CAMERA_MODE = 18 --- @type LuaHookedEventType -HOOK_MAX = 19 +HOOK_ON_OBJECT_RENDER = 19 + +--- @type LuaHookedEventType +HOOK_MAX = 20 --- @class ModelExtendedId diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index 111127cf..ac4bd1fb 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -732,6 +732,7 @@ --- @field public hitboxDownOffset number --- @field public hitboxHeight number --- @field public hitboxRadius number +--- @field public hookRender integer --- @field public hurtboxHeight number --- @field public hurtboxRadius number --- @field public numCollidedObjs integer diff --git a/docs/lua/constants.md b/docs/lua/constants.md index e3ba58f6..816ee8a2 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -2753,7 +2753,8 @@ | HOOK_ON_PAUSE_EXIT | 16 | | HOOK_GET_STAR_COLLECTION_DIALOG | 17 | | HOOK_ON_SET_CAMERA_MODE | 18 | -| HOOK_MAX | 19 | +| HOOK_ON_OBJECT_RENDER | 19 | +| HOOK_MAX | 20 | [:arrow_up_small:](#) diff --git a/docs/lua/hooks.md b/docs/lua/hooks.md index 505dda2e..6b8dd65d 100644 --- a/docs/lua/hooks.md +++ b/docs/lua/hooks.md @@ -105,6 +105,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_ON_PAUSE_EXIT | Called when the local player exits through the pause screen, return `false` to prevent the exit | `boolean` usedExitToCastle | | HOOK_GET_STAR_COLLECTION_DIALOG | Called when the local player collects a star, return a [DialogId](constants.md#enum-DialogId) to show a message | None | | HOOK_ON_SET_CAMERA_MODE | Called when the camera mode gets set, return `false` to prevent the camera mode from being set | [Camera](structs.md#Camera), `integer` mode, `integer` frames | +| HOOK_ON_OBJECT_RENDER | Called right before an object is rendered. **Note:** You must set the `hookRender` field of the object to a non-zero value | [Object](structs.md#Object) | ### Parameters diff --git a/docs/lua/structs.md b/docs/lua/structs.md index a225759a..df710091 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -1043,6 +1043,7 @@ | hitboxDownOffset | `number` | | | hitboxHeight | `number` | | | hitboxRadius | `number` | | +| hookRender | `integer` | | | hurtboxHeight | `number` | | | hurtboxRadius | `number` | | | numCollidedObjs | `integer` | | diff --git a/include/types.h b/include/types.h index c327ba0e..26a55cbe 100644 --- a/include/types.h +++ b/include/types.h @@ -219,6 +219,7 @@ struct Object /*?????*/ void (*areaTimerRunOnceCallback)(void); /*?????*/ u8 globalPlayerIndex; /*?????*/ struct Object* usingObj; + /*?????*/ u8 hookRender; }; struct ObjectHitbox diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index 610df36e..8ec082a7 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -11,6 +11,7 @@ #include "shadow.h" #include "sm64.h" #include "game/level_update.h" +#include "pc/lua/smlua_hooks.h" /** * This file contains the code that processes the scene graph for rendering. @@ -1078,7 +1079,11 @@ static void geo_process_object(struct Object *node) { Mat4 mtxf; s32 hasAnimation = (node->header.gfx.node.flags & GRAPH_RENDER_HAS_ANIMATION) != 0; Vec3f scaleInterpolated; - + + if (node->hookRender) { + smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_RENDER, node); + } + if (node->header.gfx.node.flags & GRAPH_RENDER_PLAYER) { gCurGraphNodeMarioState = NULL; for (s32 i = 0; i < MAX_PLAYERS; i++) { diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index e9bb1c86..02732637 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -830,7 +830,7 @@ static struct LuaObjectField sNetworkPlayerFields[LUA_NETWORK_PLAYER_FIELD_COUNT { "type", LVT_U8, offsetof(struct NetworkPlayer, type), true, LOT_NONE }, }; -#define LUA_OBJECT_FIELD_COUNT 752 +#define LUA_OBJECT_FIELD_COUNT 753 static struct LuaObjectField sObjectFields[LUA_OBJECT_FIELD_COUNT] = { { "activeFlags", LVT_S16, offsetof(struct Object, activeFlags), false, LOT_NONE }, { "areaTimer", LVT_U32, offsetof(struct Object, areaTimer), false, LOT_NONE }, @@ -852,6 +852,7 @@ static struct LuaObjectField sObjectFields[LUA_OBJECT_FIELD_COUNT] = { { "hitboxDownOffset", LVT_F32, offsetof(struct Object, hitboxDownOffset), false, LOT_NONE }, { "hitboxHeight", LVT_F32, offsetof(struct Object, hitboxHeight), false, LOT_NONE }, { "hitboxRadius", LVT_F32, offsetof(struct Object, hitboxRadius), false, LOT_NONE }, + { "hookRender", LVT_U8, offsetof(struct Object, hookRender), false, LOT_NONE }, { "hurtboxHeight", LVT_F32, offsetof(struct Object, hurtboxHeight), false, LOT_NONE }, { "hurtboxRadius", LVT_F32, offsetof(struct Object, hurtboxRadius), false, LOT_NONE }, { "numCollidedObjs", LVT_S16, offsetof(struct Object, numCollidedObjs), false, LOT_NONE }, diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index ff95997c..797dec22 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -2796,7 +2796,8 @@ char gSmluaConstants[] = "" "HOOK_ON_PAUSE_EXIT = 16\n" "HOOK_GET_STAR_COLLECTION_DIALOG = 17\n" "HOOK_ON_SET_CAMERA_MODE = 18\n" -"HOOK_MAX = 19\n" +"HOOK_ON_OBJECT_RENDER = 19\n" +"HOOK_MAX = 20\n" "E_MODEL_NONE = 0\n" "E_MODEL_MARIO = 1\n" "E_MODEL_SMOKE = 2\n" diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index 1474cc9f..e6e8d3c7 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -27,6 +27,7 @@ enum LuaHookedEventType { HOOK_ON_PAUSE_EXIT, HOOK_GET_STAR_COLLECTION_DIALOG, HOOK_ON_SET_CAMERA_MODE, + HOOK_ON_OBJECT_RENDER, HOOK_MAX, }; @@ -50,6 +51,7 @@ static char* LuaHookedEventTypeName[] = { "HOOK_ON_PAUSE_EXIT", "HOOK_GET_STAR_COLLECTION_DIALOG", "HOOK_ON_SET_CAMERA_MODE", + "HOOK_ON_OBJECT_RENDER", "HOOK_MAX" };