From 741d742babf73ee4f09db07819713ddfc26d4a3a Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Thu, 14 Dec 2023 19:33:17 -0500 Subject: [PATCH] Add HOOK_ON_OBJECT_LOAD --- autogen/lua_definitions/constants.lua | 5 ++++- docs/lua/constants.md | 3 ++- docs/lua/guides/hooks.md | 1 + src/game/spawn_object.c | 2 ++ src/pc/lua/smlua_constants_autogen.c | 3 ++- src/pc/lua/smlua_hooks.h | 2 ++ 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 45deb20e..dfd60b69 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -9269,7 +9269,10 @@ HOOK_MIRROR_MARIO_RENDER = 38 HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED = 39 --- @type LuaHookedEventType -HOOK_MAX = 40 +HOOK_ON_OBJECT_LOAD = 40 + +--- @type LuaHookedEventType +HOOK_MAX = 41 --- @class HudDisplayFlags diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 3404fde0..8bad5df0 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -3322,7 +3322,8 @@ | HOOK_ON_COLLIDE_LEVEL_BOUNDS | 37 | | HOOK_MIRROR_MARIO_RENDER | 38 | | HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED | 39 | -| HOOK_MAX | 40 | +| HOOK_ON_OBJECT_LOAD | 40 | +| HOOK_MAX | 41 | [:arrow_up_small:](#) diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index 65a9f2ec..7db8ecf0 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -127,6 +127,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_ON_COLLIDE_LEVEL_BOUNDS | Called when a mario collides with the level boundaries | [MarioState](structs.md#MarioState) mario | | HOOK_MIRROR_MARIO_RENDER | Called when a Mirror Mario is rendered | [GraphNodeObject](structs.md#GraphNodeObject) mirrorMario | `integer` mirrorMarioIndex | | HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED | Called when slope defacto speed for walking is being calculated, overrides the floor normal in the equation | [MarioState](structs.md#MarioState) mario | +| HOOK_ON_OBJECT_LOAD | Called when an object is spawned in | [Object](structs.md#Object) obj | ### Parameters diff --git a/src/game/spawn_object.c b/src/game/spawn_object.c index b0daf2a8..1370fe45 100644 --- a/src/game/spawn_object.c +++ b/src/game/spawn_object.c @@ -401,6 +401,8 @@ struct Object *create_object(const BehaviorScript *bhvScript) { break; } + smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_LOAD, obj); + return obj; } diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index ac78c340..52be5cf1 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -3283,7 +3283,8 @@ char gSmluaConstants[] = "" "HOOK_ON_COLLIDE_LEVEL_BOUNDS = 37\n" "HOOK_MIRROR_MARIO_RENDER = 38\n" "HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED = 39\n" -"HOOK_MAX = 40\n" +"HOOK_ON_OBJECT_LOAD = 40\n" +"HOOK_MAX = 41\n" "ACTION_HOOK_EVERY_FRAME = 0\n" "ACTION_HOOK_GRAVITY = 1\n" "ACTION_HOOK_MAX = 2\n" diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index 7f47cfd1..3debaa49 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -51,6 +51,7 @@ enum LuaHookedEventType { HOOK_ON_COLLIDE_LEVEL_BOUNDS, HOOK_MIRROR_MARIO_RENDER, HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED, + HOOK_ON_OBJECT_LOAD, HOOK_MAX, }; @@ -95,6 +96,7 @@ static const char* LuaHookedEventTypeName[] = { "HOOK_ON_COLLIDE_LEVEL_BOUNDS", "HOOK_MIRROR_MARIO_RENDER", "HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED", + "HOOK_ON_OBJECT_LOAD", "HOOK_MAX" };