From f237fc1781eeb8f15856be266fb27cec71fdde39 Mon Sep 17 00:00:00 2001 From: Sunk <69110309+Sunketchupm@users.noreply.github.com> Date: Fri, 24 Nov 2023 17:57:55 -0500 Subject: [PATCH] Fix exclamation boxes again (#540) Hopefully for the last time for this method --- src/pc/lua/smlua_hooks.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index b145277e..c1e02db1 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -1777,7 +1777,7 @@ int smlua_hook_exclamation_box(lua_State* L) { return 0; } - if (sHookedBehaviorsCount > MAX_HOOKED_EXCLAMATION_BOXES) { + if (sHookedExclamationBoxesCount > MAX_HOOKED_EXCLAMATION_BOXES) { LOG_LUA_LINE("hook_exclamation_box() calls exceeded maximum references"); return 0; } @@ -1814,7 +1814,7 @@ int smlua_hook_exclamation_box(lua_State* L) { hooked->mod = gLuaActiveMod; if (!gSmLuaConvertSuccess) { return 0; } - sHookedBehaviorsCount++; + sHookedExclamationBoxesCount++; return 1; } @@ -1822,7 +1822,7 @@ int smlua_hook_exclamation_box(lua_State* L) { struct Object* smlua_call_exclamation_box_hook(struct Object* obj, bool write) { lua_State* L = gLuaState; if (L == NULL) { return NULL; } - for (int i = 0; i < sHookedBehaviorsCount; i++) { + for (int i = 0; i < sHookedExclamationBoxesCount; i++) { struct LuaHookedExclamationBox* hook = &sHookedExclamationBoxes[i]; // Push 2 potential callbacks @@ -1840,9 +1840,9 @@ struct Object* smlua_call_exclamation_box_hook(struct Object* obj, bool write) { // output the return value struct Object* returnObject = NULL; - if (write) { + if (write && reference != 0) { returnObject = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT); - if (!gSmLuaConvertSuccess || returnObject == NULL) { + if (lua_type(L, 1) != LUA_TTABLE || !gSmLuaConvertSuccess) { LOG_LUA("Return value type is invalid for writeFunction: %d", lua_type(L, 1)); continue; }