From f9f4c619210cc6426e1480b6a541501b658a2b0a Mon Sep 17 00:00:00 2001 From: Sunk <69110309+Sunketchupm@users.noreply.github.com> Date: Wed, 22 Nov 2023 20:01:37 -0500 Subject: [PATCH] Better sanity check exclamation box hook (#536) Also makes the parent object of the spawned object the exclamation box for spawned stars to work properly --- src/game/behaviors/exclamation_box.inc.c | 1 + src/pc/lua/smlua_hooks.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/game/behaviors/exclamation_box.inc.c b/src/game/behaviors/exclamation_box.inc.c index bfc38408..c9a7b8ba 100644 --- a/src/game/behaviors/exclamation_box.inc.c +++ b/src/game/behaviors/exclamation_box.inc.c @@ -133,6 +133,7 @@ void exclamation_box_spawn_contents(struct Struct802C0DF0 *a0, u8 a1) { struct Object* luaSpawnedObject = NULL; if ((luaSpawnedObject = smlua_call_exclamation_box_hook(o, true)) != NULL) { + luaSpawnedObject->parentObj = o; // Allows spawned stars to work like it was a normal exclamation box (void *)smlua_call_exclamation_box_hook(luaSpawnedObject, false); return; } diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index 11b34cd3..b145277e 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -1842,11 +1842,13 @@ struct Object* smlua_call_exclamation_box_hook(struct Object* obj, bool write) { struct Object* returnObject = NULL; if (write) { returnObject = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT); + if (!gSmLuaConvertSuccess || returnObject == NULL) { + LOG_LUA("Return value type is invalid for writeFunction: %d", lua_type(L, 1)); + continue; + } } lua_pop(L, 1); - if (!gSmLuaConvertSuccess) { return NULL; } - return returnObject; }