diff --git a/data/behavior_table.c b/data/behavior_table.c index 896a0f64..28c0ffe9 100644 --- a/data/behavior_table.c +++ b/data/behavior_table.c @@ -526,7 +526,7 @@ enum BehaviorId get_id_from_behavior(const BehaviorScript* behavior) { } const BehaviorScript* get_behavior_from_id(enum BehaviorId id) { - const BehaviorScript* behavior = get_lua_behavior_from_id(id); + const BehaviorScript* behavior = get_lua_behavior_from_id(id, true); if (behavior != NULL) { return behavior; } if (id < 0 || id >= id_bhv_max_count) { diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index ce14315f..d1716cbe 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -324,17 +324,18 @@ const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior) { if (L == NULL) { return behavior; } enum BehaviorId id = get_id_from_behavior(behavior); - const BehaviorScript* luaBehavior = get_lua_behavior_from_id(id); + const BehaviorScript* luaBehavior = get_lua_behavior_from_id(id, false); if (luaBehavior != NULL) { return luaBehavior; } return behavior + *sBehaviorOffset; } -const BehaviorScript* get_lua_behavior_from_id(enum BehaviorId id) { +const BehaviorScript* get_lua_behavior_from_id(enum BehaviorId id, bool returnOriginal) { lua_State* L = gLuaState; if (L == NULL) { return false; } for (int i = 0; i < sHookedBehaviorsCount; i++) { struct LuaHookedBehavior* hooked = &sHookedBehaviors[i]; if (hooked->behaviorId != id && hooked->overrideId != id) { continue; } + if (returnOriginal && !hooked->replace) { return hooked->originalBehavior; } return hooked->behavior; } return NULL; @@ -450,7 +451,7 @@ bool smlua_call_behavior_hook(const BehaviorScript** behavior, struct Object* ob } // retrieve and remember first run - bool firstRun = (object->curBhvCommand == hooked->originalBehavior); + bool firstRun = (object->curBhvCommand == hooked->originalBehavior) || (object->curBhvCommand == hooked->behavior); if (firstRun && hooked->replace) { *behavior = &hooked->behavior[1]; } // get function and null check it diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index a65b7b76..b4282008 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -38,7 +38,7 @@ void smlua_call_event_hooks_mario_params(enum LuaHookedEventType hookType, struc void smlua_call_event_hooks_interact_params(enum LuaHookedEventType hookType, struct MarioState* m, struct Object* obj, u32 interactType, bool interactValue); const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior); -const BehaviorScript* get_lua_behavior_from_id(enum BehaviorId id); +const BehaviorScript* get_lua_behavior_from_id(enum BehaviorId id, bool returnOriginal); bool smlua_call_behavior_hook(const BehaviorScript** behavior, struct Object* object, bool before); bool smlua_call_action_hook(struct MarioState* m, s32* returnValue);