From 8d72c7eb76701209a2dd8f24457e5099dd900c09 Mon Sep 17 00:00:00 2001 From: MysterD Date: Sun, 26 Nov 2023 13:48:58 -0800 Subject: [PATCH] Remove hook_exclamation_box() --- autogen/lua_definitions/constants.lua | 2 +- autogen/lua_definitions/manual.lua | 6 -- docs/lua/guides/hooks.md | 46 ---------- src/game/behaviors/exclamation_box.inc.c | 8 -- src/pc/lua/smlua_constants_autogen.c | 2 +- src/pc/lua/smlua_hooks.c | 105 ----------------------- src/pc/lua/smlua_hooks.h | 3 - 7 files changed, 2 insertions(+), 170 deletions(-) diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 8d9727c5..489f19ab 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -12412,7 +12412,7 @@ MAX_LOCAL_VERSION_LENGTH = 36 MAX_VERSION_LENGTH = 32 --- @type integer -MINOR_VERSION_NUMBER = 0 +MINOR_VERSION_NUMBER = 1 --- @type integer PATCH_VERSION_NUMBER = 0 diff --git a/autogen/lua_definitions/manual.lua b/autogen/lua_definitions/manual.lua index 11bb0aec..e1b53107 100644 --- a/autogen/lua_definitions/manual.lua +++ b/autogen/lua_definitions/manual.lua @@ -311,10 +311,4 @@ end --- Logs a message to the in-game console function log_to_console(message, level) -- ... -end - ---- @param readFunc (fun(obj:Object):nil)? Called after the exclamation box spawns an object. Use this function to read the contents of the object that spawned. ---- @param writeFunc (fun(box:Object):Object)? Called when the exclamation box is about to spawn an object. Use this function to spawn a different object, and return the object for the read function to use. -function hook_exclamation_box(readFunc, writeFunc) - end \ No newline at end of file diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index 5b4047a3..c42639a7 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -149,52 +149,6 @@ hook_event(HOOK_MARIO_UPDATE, mario_update)
-## [hook_exclamation_box](#hook_exclamation_box) - -Activated when an exclamation box breaks, allowing mods to take control over exclamation boxes. -- `readFunction` is called after the exclamation box breaks, allowing mods to read the object that spawned. - - No return value is necessary. -- `writeFunction` is called when the exclamation box breaks, allowing mods to override the spawned object. - - Returning the spawned object is highly recommended as it prevents spawning both the vanilla and new object at the same time. It also allows `readFunction` to function properly. - -### Parameters - -| Field | Type | -| ----- | ---- | -| readFunction | `Lua Function` ([Object](structs.md#Object)) | -| writeFunction | `Lua Function` ([Object](structs.md#Object)): [Object](structs.md#Object) | - -### Lua Example - -```lua -local objects_to_spawn = { - [0] = {id_bhvGoomba, E_MODEL_GOOMBA}, - [1] = {id_bhvKoopa, E_MODEL_KOOPA_WITH_SHELL}, - [2] = {id_bhvTenCoinsSpawn, E_MODEL_NONE}, - [3] = {id_bhvChainChomp, E_MODEL_CHAIN_CHOMP}, - [4] = {id_bhvHeaveHo, E_MODEL_HEAVE_HO}, - [5] = {id_bhvWingCap, E_MODEL_MARIOS_WING_CAP}, - [6] = {id_bhvKoopaShell, E_MODEL_KOOPA_SHELL}, - [7] = {id_bhvBoo, E_MODEL_BOO}, -} - -local function readFunction(obj) - if obj_has_behavior_id(obj, id_bhvFlame) ~= 0 then - print("FIREEEEEEEEE") - end -end - ----@param box Object -local function writeFunction(box) - local spawn_object = objects_to_spawn[box.oBehParams2ndByte] - return spawn_sync_object(spawn_object[1], spawn_object[2], box.oPosX, box.oPosY, box.oPosZ, nil) -end - -hook_exclamation_box(readFunction, writeFunction) -``` - -
- ## [hook_mario_action](#hook_mario_action) `hook_mario_action()` allows Lua mods to create new actions or override existing ones. diff --git a/src/game/behaviors/exclamation_box.inc.c b/src/game/behaviors/exclamation_box.inc.c index c9a7b8ba..96d939f0 100644 --- a/src/game/behaviors/exclamation_box.inc.c +++ b/src/game/behaviors/exclamation_box.inc.c @@ -131,19 +131,11 @@ void exclamation_box_spawn_contents(struct Struct802C0DF0 *a0, u8 a1) { return; } - 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; - } - while (a0->unk0 != 99) { if (a1 == a0->unk0) { s32 model = exclamation_replace_model(marioState, a0->model); spawnedObject = spawn_object(o, model, a0->behavior); - (void *)smlua_call_exclamation_box_hook(spawnedObject, false); if (spawnedObject != NULL) { spawnedObject->oVelY = 20.0f; spawnedObject->oForwardVel = 3.0f; diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 018e897c..81da2b11 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -4332,7 +4332,7 @@ char gSmluaConstants[] = "" "SM64COOPDX_VERSION = 'v0.1'\n" "VERSION_TEXT = 'beta'\n" "VERSION_NUMBER = 36\n" -"MINOR_VERSION_NUMBER = 0\n" +"MINOR_VERSION_NUMBER = 1\n" "PATCH_VERSION_NUMBER = 0\n" "VERSION_REGION = 'JP'\n" "VERSION_REGION = 'EU'\n" diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index ed7bb3f8..4e289fe9 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -1777,110 +1777,6 @@ int smlua_hook_on_sync_table_change(lua_State* L) { return 1; } - //////////////////////////// - // hooked exclamation box // -//////////////////////////// - -struct LuaHookedExclamationBox { - int readFuncReference; - int writeFuncReference; - struct Mod* mod; -}; - -#define MAX_HOOKED_EXCLAMATION_BOXES 255 // Way more than needed, but better safe than sorry - -static struct LuaHookedExclamationBox sHookedExclamationBoxes[MAX_HOOKED_EXCLAMATION_BOXES] = { 0 }; -static int sHookedExclamationBoxesCount = 0; - -// Bind to lua -int smlua_hook_exclamation_box(lua_State* L) { - if (L == NULL) { return 0; } - if (!smlua_functions_valid_param_count(L, 2)) { return 0; } - - if (gLuaLoadingMod == NULL) { - LOG_LUA_LINE("hook_exclamation_box() can only be called on load."); - return 0; - } - - if (sHookedExclamationBoxesCount > MAX_HOOKED_EXCLAMATION_BOXES) { - LOG_LUA_LINE("hook_exclamation_box() calls exceeded maximum references"); - return 0; - } - - int readReference = 0; - int readReferenceType = lua_type(L, 1); - if (readReferenceType == LUA_TNIL) { - // nothing - } else if (readReferenceType == LUA_TFUNCTION) { - // get reference - lua_pushvalue(L, 1); - readReference = luaL_ref(L, LUA_REGISTRYINDEX); - } else { - LOG_LUA_LINE("Hook exclamation box: tried to reference non-function for read function"); - return 0; - } - - int writeReference = 0; - int writeReferenceType = lua_type(L, 2); - if (writeReferenceType == LUA_TNIL) { - // nothing - } else if (writeReferenceType == LUA_TFUNCTION) { - // get reference - lua_pushvalue(L, 2); - writeReference = luaL_ref(L, LUA_REGISTRYINDEX); - } else { - LOG_LUA_LINE("Hook exclamation box: tried to reference non-function for write function"); - return 0; - } - - struct LuaHookedExclamationBox* hooked = &sHookedExclamationBoxes[sHookedExclamationBoxesCount]; - hooked->readFuncReference = readReference; - hooked->writeFuncReference = writeReference; - hooked->mod = gLuaActiveMod; - - if (!gSmLuaConvertSuccess) { return 0; } - sHookedExclamationBoxesCount++; - return 1; -} - -// Called from the exclamation boxes -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 < sHookedExclamationBoxesCount; i++) { - struct LuaHookedExclamationBox* hook = &sHookedExclamationBoxes[i]; - - // Push 2 potential callbacks - int reference = write ? hook->writeFuncReference : hook->readFuncReference; - lua_rawgeti(L, LUA_REGISTRYINDEX, reference); - - // push object - smlua_push_object(L, LOT_OBJECT, obj); - - // call the callback - if (reference != 0 && 0 != smlua_call_hook(L, 1, 1, 0, hook->mod)) { - LOG_LUA("Failed to call the exclamation box callback: %s", (write ? "writeFunction" : "readFunction")); - continue; - } - - // output the return value - struct Object* returnObject = NULL; - if (write && reference != 0) { - returnObject = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT); - if (lua_type(L, 1) != LUA_TTABLE || !gSmLuaConvertSuccess) { - LOG_LUA("Return value type is invalid for writeFunction: %d", lua_type(L, 1)); - continue; - } - } - lua_pop(L, 1); - - return returnObject; - } - - return NULL; -} - - ////////// // misc // ////////// @@ -1956,5 +1852,4 @@ void smlua_bind_hooks(void) { smlua_bind_function(L, "hook_on_sync_table_change", smlua_hook_on_sync_table_change); smlua_bind_function(L, "hook_behavior", smlua_hook_behavior); smlua_bind_function(L, "update_chat_command_description", smlua_update_chat_command_description); - smlua_bind_function(L, "hook_exclamation_box", smlua_hook_exclamation_box); } diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index 80a1c662..9eb2903a 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -140,9 +140,6 @@ bool smlua_call_event_hooks_mario_param_and_int_ret_int(enum LuaHookedEventType bool smlua_call_event_hooks_mario_param_and_int_and_int_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, u32 args, s32* returnValue); void smlua_call_event_hooks_graph_node_object_and_int_param(enum LuaHookedEventType hookType, struct GraphNodeObject* node, s32 param); -int smlua_hook_exclamation_box(lua_State* L); -struct Object* smlua_call_exclamation_box_hook(struct Object* obj, bool write); - enum BehaviorId smlua_get_original_behavior_id(const BehaviorScript* behavior); const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior); const BehaviorScript* smlua_get_hooked_behavior_from_id(enum BehaviorId id, bool returnOriginal);