From 17c311ae7d957534e677faa98fe11942da5280bc Mon Sep 17 00:00:00 2001 From: PeachyPeach <72323920+PeachyPeachSM64@users.noreply.github.com> Date: Sun, 8 Jun 2025 23:40:48 +0200 Subject: [PATCH] smlua event hooks refactor (#826) --- autogen/autogen.sh | 1 + autogen/convert_constants.py | 2 +- autogen/convert_functions.py | 15 +- autogen/gen_hooks.py | 309 ++++ autogen/lua_definitions/constants.lua | 24 - data/dynos_warps.cpp | 4 +- docs/lua/constants.md | 18 +- docs/lua/guides/hooks.md | 4 +- src/audio/external.c | 6 +- src/audio/load.c | 8 +- src/engine/surface_load.c | 2 +- src/game/area.c | 8 +- src/game/camera.c | 16 +- src/game/characters.c | 6 +- src/game/ingame_menu.c | 13 +- src/game/interaction.c | 40 +- src/game/level_update.c | 21 +- src/game/mario.c | 21 +- src/game/mario_actions_airborne.c | 28 +- src/game/mario_actions_automatic.c | 12 +- src/game/mario_actions_cutscene.c | 10 +- src/game/mario_actions_moving.c | 6 +- src/game/mario_actions_object.c | 6 +- src/game/mario_actions_stationary.c | 6 +- src/game/mario_actions_submerged.c | 65 +- src/game/mario_misc.c | 2 +- src/game/mario_step.c | 56 +- src/game/object_helpers.c | 4 +- src/game/object_list_processor.c | 4 +- src/game/rendering_graph_node.c | 12 +- src/game/spawn_object.c | 6 +- src/pc/djui/djui.c | 2 +- src/pc/djui/djui_chat_message.c | 6 +- src/pc/djui/djui_panel_language.c | 2 +- src/pc/lua/smlua_constants_autogen.c | 9 - src/pc/lua/smlua_functions_autogen.c | 248 ++- src/pc/lua/smlua_hook_events.inl | 59 + src/pc/lua/smlua_hook_events_autogen.inl | 1839 ++++++++++++++++++++ src/pc/lua/smlua_hooks.c | 1256 +------------ src/pc/lua/smlua_hooks.h | 115 +- src/pc/nametags.c | 13 +- src/pc/network/network_player.c | 4 +- src/pc/network/packets/packet_lua_custom.c | 2 +- 43 files changed, 2755 insertions(+), 1535 deletions(-) create mode 100644 autogen/gen_hooks.py create mode 100644 src/pc/lua/smlua_hook_events.inl create mode 100644 src/pc/lua/smlua_hook_events_autogen.inl diff --git a/autogen/autogen.sh b/autogen/autogen.sh index a96262584..9459f4d61 100755 --- a/autogen/autogen.sh +++ b/autogen/autogen.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash python3 ./autogen/gen_math.py $1 python3 ./autogen/convert_structs.py $1 +python3 ./autogen/gen_hooks.py $1 python3 ./autogen/convert_functions.py $1 python3 ./autogen/convert_constants.py $1 python3 ./autogen/extract_display_lists.py $1 diff --git a/autogen/convert_constants.py b/autogen/convert_constants.py index d4ee7a80e..565cc4efb 100644 --- a/autogen/convert_constants.py +++ b/autogen/convert_constants.py @@ -62,7 +62,7 @@ exclude_constants = { "src/game/save_file.h": [ "EEPROM_SIZE" ], "src/game/obj_behaviors.c": [ "^o$" ], "src/pc/djui/djui_console.h": [ "CONSOLE_MAX_TMP_BUFFER" ], - "src/pc/lua/smlua_hooks.h": [ "MAX_HOOKED_MOD_MENU_ELEMENTS" ], + "src/pc/lua/smlua_hooks.h": [ "MAX_HOOKED_MOD_MENU_ELEMENTS", "^HOOK_RETURN_.*", "^ACTION_HOOK_.*", "^MOD_MENU_ELEMENT_.*" ], "src/pc/djui/djui_panel_menu.h": [ "RAINBOW_TEXT_LEN" ] } diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py index 04c1cd120..d1f698fde 100644 --- a/autogen/convert_functions.py +++ b/autogen/convert_functions.py @@ -754,14 +754,25 @@ def build_vec_types(): s = gen_comment_header("vec types") for type_name, vec_type in VEC_TYPES.items(): + # New + s += "void smlua_new_%s(%s src) {\n" % (type_name.lower(), type_name) + s += " struct lua_State *L = gLuaState;\n" + s += " lua_newtable(L);\n" + s += " int tableIndex = lua_gettop(L);\n" + for lua_field, c_field in vec_type["fields_mapping"].items(): + s += " lua_pushstring(L, \"%s\");\n" % (lua_field) + s += " lua_push%s(L, src%s);\n" % (vec_type["field_lua_type"], c_field) + s += " lua_settable(L, tableIndex);\n" + s += "}\n\n" + # Get - s += "static void smlua_get_%s(%s dest, int index) {\n" % (type_name.lower(), type_name) + s += "void smlua_get_%s(%s dest, int index) {\n" % (type_name.lower(), type_name) for lua_field, c_field in vec_type["fields_mapping"].items(): s += " dest%s = smlua_get_%s_field(index, \"%s\");\n" % (c_field, vec_type["field_lua_type"], lua_field) s += "}\n\n" # Push - s += "static void smlua_push_%s(%s src, int index) {\n" % (type_name.lower(), type_name) + s += "void smlua_push_%s(%s src, int index) {\n" % (type_name.lower(), type_name) for lua_field, c_field in vec_type["fields_mapping"].items(): s += " smlua_push_%s_field(index, \"%s\", src%s);\n" % (vec_type["field_lua_type"], lua_field, c_field) for lua_field, c_field in vec_type.get('optional_fields_mapping', {}).items(): diff --git a/autogen/gen_hooks.py b/autogen/gen_hooks.py new file mode 100644 index 000000000..fd76b5534 --- /dev/null +++ b/autogen/gen_hooks.py @@ -0,0 +1,309 @@ +import sys +import re +from vec_types import * + + +HOOK_RETURN_NEVER = "HOOK_RETURN_NEVER" +HOOK_RETURN_ON_SUCCESSFUL_CALL = "HOOK_RETURN_ON_SUCCESSFUL_CALL" +HOOK_RETURN_ON_OUTPUT_SET = "HOOK_RETURN_ON_OUTPUT_SET" + + +SMLUA_CALL_EVENT_HOOKS_BEGIN = """ +bool smlua_call_event_hooks_{hook_type}({parameters}) {{ + lua_State *L = gLuaState; + if (L == NULL) {{ return false; }}{define_hook_result} + + struct LuaHookedEvent *hook = &sHookedEvents[{hook_type}]; + for (int i = 0; i < hook->count; i++) {{ + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); +""" + +SMLUA_CALL_EVENT_HOOKS_DEFINE_HOOK_RESULT = """ + bool hookResult = false;""" + +SMLUA_CALL_EVENT_HOOKS_SET_HOOK_RESULT = """ + hookResult = true;""" + +SMLUA_CALL_EVENT_HOOKS_CALLBACK = """ + // call the callback + if (0 != smlua_call_hook(L, {n_inputs}, {n_outputs}, 0, hook->mod[i])) {{ + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[{hook_type}]); + continue; + }}{set_hook_result} +""" + +SMLUA_CALL_EVENT_HOOKS_RETURN_ON_OUTPUT_SET = """ + lua_settop(L, prevTop); + return true;""" + +SMLUA_CALL_EVENT_HOOKS_RETURN_ON_SUCCESSFUL_CALL = """ + return true;""" + +SMLUA_CALL_EVENT_HOOKS_END = """ + lua_settop(L, prevTop);{return_on_successful_call} + }} + return {hook_result}; +}} +""" + +SMLUA_INTEGER_TYPES = { +"input": """ + // push {name} + lua_pushinteger(L, {name}); +""", +"output": """ + // return {name} + if (lua_type(L, -{output_index}) == LUA_TNUMBER) {{ + *{name} = smlua_to_integer(L, -{output_index});{return_on_output_set} + }} +""" +} + +SMLUA_FLOAT_TYPES = { +"input": """ + // push {name} + lua_pushnumber(L, {name}); +""", +"output": """ + // return {name} + if (lua_type(L, -{output_index}) == LUA_TNUMBER) {{ + *{name} = smlua_to_number(L, -{output_index});{return_on_output_set} + }} +""" +} + +SMLUA_TYPES = { + **{ + type_name: { +"input": """ + // push {name} + extern void smlua_new_%s(%s src); + smlua_new_%s({name}); +""" % (type_name.lower(), type_name, type_name.lower()), +"output": """ + // return {name} + if (lua_type(L, -{output_index}) == LUA_TTABLE) {{ + extern void smlua_get_%s(%s dest, int index); + smlua_get_%s(*{name}, -{output_index});{return_on_output_set} + }} +""" % (type_name.lower(), type_name, type_name.lower()) + } + for type_name in VEC_TYPES + }, + "u8": SMLUA_INTEGER_TYPES, + "u16": SMLUA_INTEGER_TYPES, + "u32": SMLUA_INTEGER_TYPES, + "u64": SMLUA_INTEGER_TYPES, + "s8": SMLUA_INTEGER_TYPES, + "s16": SMLUA_INTEGER_TYPES, + "s32": SMLUA_INTEGER_TYPES, + "s64": SMLUA_INTEGER_TYPES, + "f32": SMLUA_FLOAT_TYPES, + "f64": SMLUA_FLOAT_TYPES, + "bool": { +"input": """ + // push {name} + lua_pushboolean(L, {name}); +""", +"output": """ + // return {name} + if (lua_type(L, -{output_index}) == LUA_TBOOLEAN) {{ + *{name} = smlua_to_boolean(L, -{output_index});{return_on_output_set} + }} +""" + }, + "constchar*": { +"input": """ + // push {name} + lua_pushstring(L, {name}); +""", +"output": """ + // return {name} + if (lua_type(L, -{output_index}) == LUA_TSTRING) {{ + *{name} = smlua_to_string(L, -{output_index});{return_on_output_set} + }} +""" + }, + "structMarioState*": { +"input": """ + // push {name} + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, {name}->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); +""" + }, + "structWarpDest": { +"output": """ + // if the hook returns a table, use it to override the warp parameters + if (lua_istable(L, -1)) {{ + + lua_getfield(L, -1, "destLevel"); + if (lua_isnumber(L, -1)) {{ + {name}->levelNum = smlua_to_integer(L, -1); + }} + lua_pop(L, 1); + + lua_getfield(L, -1, "destArea"); + if (lua_isnumber(L, -1)) {{ + {name}->areaIdx = smlua_to_integer(L, -1); + }} + lua_pop(L, 1); + + lua_getfield(L, -1, "destWarpNode"); + if (lua_isnumber(L, -1)) {{ + {name}->nodeId = smlua_to_integer(L, -1); + }} + lua_pop(L, 1); +{return_on_output_set} + }} +""" + }, +} + + +def init(): + + # HACK: build LOT types from smlua_cobject_autogen.c + with open('src/pc/lua/smlua_cobject_autogen.c') as f: + file = f.read() + begin = file.find("const char *sLuaLotNames[] = {") + len("const char *sLuaLotNames[] = {") + end = file.find("};", begin) + types = [list(filter(None, re.split(r'\W+', line.strip()))) for line in file[begin:end].split('\n') if line.strip()] + + for lot, name in types: + typename = f"struct{name}*" + if typename not in SMLUA_TYPES: + SMLUA_TYPES[typename] = { +"input": """ + // push {name} + smlua_push_object(L, %s, {name}, NULL); +""" % (lot) + } + + +def extract_hook_event(line: str): + if line.startswith("//"): + return None + if not line.startswith("SMLUA_EVENT_HOOK"): + return None + + tokens = [token.strip() for token in line.replace('(', ',').replace(')', ',').split(',') if token.strip()] + if len(tokens) < 3: + return None + + hook_event_type = tokens[1] + if not hook_event_type.startswith("HOOK_"): + return None + + hook_event_return = tokens[2] + if not hook_event_return.startswith("HOOK_RETURN_"): + return None + + parameters = ", ".join(token.replace("OUTPUT ", "") for token in tokens[3:]) + inputs = [] + outputs = [] + for token in tokens[3:]: + param = [x.strip() for x in token.split() if x.strip()] + if len(param) < 2: + continue + + is_output = param[0] == "OUTPUT" + if is_output: + param = param[1:] + if len(param) < 2: + continue + + param_type = " ".join(param[:-1]) if param[0] != "enum" else "s32" + param_name = param[-1] + stars = param_name.count('*') + param_name = param_name[stars:] + param_type += "*" * stars + param_type = "".join(param_type.split()) + + if is_output: + outputs.append({ + "type": param_type[:-1], + "name": param_name + }) + else: + inputs.append({ + "type": param_type, + "name": param_name + }) + + return { + "type": hook_event_type, + "return": hook_event_return, + "parameters": parameters, + "inputs": inputs, + "outputs": outputs + } + + +def main(): + verbose = len(sys.argv) > 1 and (sys.argv[1] == "-v" or sys.argv[1] == "--verbose") + with open("src/pc/lua/smlua_hook_events.inl", "r") as f: + lines = f.readlines() + + hook_events = [] + for line in lines: + hook_event = extract_hook_event(line) + if hook_event: + if verbose: + print(hook_event) + hook_events.append(hook_event) + + generated = ( + "/* THIS FILE IS AUTO-GENERATED */\n" + + "/* DO NOT EDIT IT MANUALLY */\n\n" + ) + + for hook_event in hook_events: + hook_return = hook_event["return"] + define_hook_result = SMLUA_CALL_EVENT_HOOKS_DEFINE_HOOK_RESULT if hook_return == HOOK_RETURN_NEVER else "" + set_hook_result = SMLUA_CALL_EVENT_HOOKS_SET_HOOK_RESULT if hook_return == HOOK_RETURN_NEVER else "" + return_on_successful_call = SMLUA_CALL_EVENT_HOOKS_RETURN_ON_SUCCESSFUL_CALL if hook_return == HOOK_RETURN_ON_SUCCESSFUL_CALL else "" + return_on_output_set = SMLUA_CALL_EVENT_HOOKS_RETURN_ON_OUTPUT_SET if hook_return == HOOK_RETURN_ON_OUTPUT_SET else "" + hook_result = "hookResult" if hook_return == HOOK_RETURN_NEVER else "false" + + generated += SMLUA_CALL_EVENT_HOOKS_BEGIN.format( + hook_type=hook_event["type"], + parameters=hook_event["parameters"], + define_hook_result=define_hook_result + ) + + for input in hook_event["inputs"]: + generated += SMLUA_TYPES[input["type"]]["input"].format( + name=input["name"] + ) + + generated += SMLUA_CALL_EVENT_HOOKS_CALLBACK.format( + n_inputs=len(hook_event["inputs"]), + n_outputs=len(hook_event["outputs"]), + hook_type=hook_event["type"], + set_hook_result=set_hook_result + ) + + for i, output in enumerate(hook_event["outputs"]): + generated += SMLUA_TYPES[output["type"]]["output"].format( + name=output["name"], + output_index=i+1, + return_on_output_set=return_on_output_set + ) + + generated += SMLUA_CALL_EVENT_HOOKS_END.format( + return_on_successful_call=return_on_successful_call, + hook_result=hook_result + ) + + with open("src/pc/lua/smlua_hook_events_autogen.inl", "w", encoding="utf-8", newline="\n") as f: + f.write(generated) + + +if __name__ == "__main__": + init() + main() diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 29b751d6b..2492ea46d 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -7888,30 +7888,6 @@ HOOK_MAX = 59 --- @type LuaHookedEventType --- | `HOOK_ON_CLEAR_AREAS` --- | `HOOK_MAX` -ACTION_HOOK_EVERY_FRAME = 0 --- @type LuaActionHookType -ACTION_HOOK_GRAVITY = 1 --- @type LuaActionHookType -ACTION_HOOK_MAX = 2 --- @type LuaActionHookType - ---- @alias LuaActionHookType ---- | `ACTION_HOOK_EVERY_FRAME` ---- | `ACTION_HOOK_GRAVITY` ---- | `ACTION_HOOK_MAX` - -MOD_MENU_ELEMENT_TEXT = 0 --- @type LuaModMenuElementType -MOD_MENU_ELEMENT_BUTTON = 1 --- @type LuaModMenuElementType -MOD_MENU_ELEMENT_CHECKBOX = 2 --- @type LuaModMenuElementType -MOD_MENU_ELEMENT_SLIDER = 3 --- @type LuaModMenuElementType -MOD_MENU_ELEMENT_INPUTBOX = 4 --- @type LuaModMenuElementType -MOD_MENU_ELEMENT_MAX = 5 --- @type LuaModMenuElementType - ---- @alias LuaModMenuElementType ---- | `MOD_MENU_ELEMENT_TEXT` ---- | `MOD_MENU_ELEMENT_BUTTON` ---- | `MOD_MENU_ELEMENT_CHECKBOX` ---- | `MOD_MENU_ELEMENT_SLIDER` ---- | `MOD_MENU_ELEMENT_INPUTBOX` ---- | `MOD_MENU_ELEMENT_MAX` - HUD_DISPLAY_LIVES = 0 --- @type HudDisplayValue HUD_DISPLAY_COINS = 1 --- @type HudDisplayValue HUD_DISPLAY_STARS = 2 --- @type HudDisplayValue diff --git a/data/dynos_warps.cpp b/data/dynos_warps.cpp index 569c6a28f..e9d1c6fd9 100644 --- a/data/dynos_warps.cpp +++ b/data/dynos_warps.cpp @@ -264,7 +264,7 @@ static void *DynOS_Warp_UpdateWarp(void *aCmd, bool aIsLevelInitDone) { } // lua hooks - smlua_call_event_hooks_warp_params(HOOK_ON_WARP, sBackupWarpDest.type, sDynosWarpLevelNum, sDynosWarpAreaNum, sDynosWarpNodeNum, sBackupWarpDest.arg); + smlua_call_event_hooks(HOOK_ON_WARP, sBackupWarpDest.type, sDynosWarpLevelNum, sDynosWarpAreaNum, sDynosWarpNodeNum, sBackupWarpDest.arg); // Reset values sDynosWarpTargetArea = -1; @@ -412,7 +412,7 @@ static void *DynOS_Warp_UpdateExit(void *aCmd, bool aIsLevelInitDone) { sDynosExitTargetWarp = NULL; // lua hooks - smlua_call_event_hooks_warp_params(HOOK_ON_WARP, sBackupWarpDest.type, sDynosWarpLevelNum, sDynosWarpAreaNum, sDynosWarpNodeNum, sBackupWarpDest.arg); + smlua_call_event_hooks(HOOK_ON_WARP, sBackupWarpDest.type, sDynosWarpLevelNum, sDynosWarpAreaNum, sDynosWarpNodeNum, sBackupWarpDest.arg); } // Phase 4 - Unlock Mario as soon as the second transition is ended diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 401591833..5c3b1385e 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -72,6 +72,7 @@ - [sm64.h](#sm64h) - [smlua_hooks.h](#smlua_hooksh) - [enum LuaHookedEventType](#enum-LuaHookedEventType) + - [enum LuaHookedEventReturn](#enum-LuaHookedEventReturn) - [enum LuaActionHookType](#enum-LuaActionHookType) - [enum LuaModMenuElementType](#enum-LuaModMenuElementType) - [smlua_misc_utils.h](#smlua_misc_utilsh) @@ -3443,23 +3444,6 @@ | HOOK_ON_CLEAR_AREAS | 58 | | HOOK_MAX | 59 | -### [enum LuaActionHookType](#LuaActionHookType) -| Identifier | Value | -| :--------- | :---- | -| ACTION_HOOK_EVERY_FRAME | 0 | -| ACTION_HOOK_GRAVITY | 1 | -| ACTION_HOOK_MAX | 2 | - -### [enum LuaModMenuElementType](#LuaModMenuElementType) -| Identifier | Value | -| :--------- | :---- | -| MOD_MENU_ELEMENT_TEXT | 0 | -| MOD_MENU_ELEMENT_BUTTON | 1 | -| MOD_MENU_ELEMENT_CHECKBOX | 2 | -| MOD_MENU_ELEMENT_SLIDER | 3 | -| MOD_MENU_ELEMENT_INPUTBOX | 4 | -| MOD_MENU_ELEMENT_MAX | 5 | - [:arrow_up_small:](#)
diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index ba9f59f8c..af1226bae 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -121,7 +121,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_ON_SCREEN_TRANSITION | Called when the game is about to play a transition, return `false` to prevent the transition from playing | `integer` type | | HOOK_ALLOW_HAZARD_SURFACE | Called once per player per frame. Return `false` to prevent the player from being affected by lava, quicksand, or wind | [MarioState](../structs.md#MarioState) mario, `integer` hazardType | | HOOK_ON_CHAT_MESSAGE | Called when a chat message gets sent. Return `false` to prevent the message from being sent | [MarioState](../structs.md#MarioState) messageSender, `string` messageSent | -| HOOK_OBJECT_SET_MODEL | Called when a behavior changes models. Also runs when a behavior spawns | [Object](../structs.md#Object) obj, `integer` modelID, `integer` modelExtendedId| +| HOOK_OBJECT_SET_MODEL | Called when a behavior changes models. Also runs when a behavior spawns | [Object](../structs.md#Object) obj, `integer` modelID, `integer` modelExtendedId | | HOOK_CHARACTER_SOUND | Called when mario retrieves a character sound to play, return a character sound or `0` to override it | [MarioState](../structs.md#MarioState) mario, [enum CharacterSound](../constants.md#enum-CharacterSound) characterSound | | HOOK_BEFORE_SET_MARIO_ACTION | Called before Mario's action changes Return an action to change the incoming action or `1` to cancel the action change | [MarioState](../structs.md#MarioState) mario, `integer` incomingAction, `integer` actionArg | | HOOK_JOINED_GAME | Called when the local player finishes the join process (if the player isn't the host) | None | @@ -138,7 +138,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_ON_ATTACK_OBJECT | Called when a player attacks an object. May be double-fired in some cases, you'll need to write special code for this | [MarioState](../structs.md#MarioState) attacker, [Object](../structs.md#Object) victim, `integer` interactionId | | HOOK_ON_LANGUAGE_CHANGED | Called when the language is changed | `string` language | | HOOK_ON_MODS_LOADED | Called directly after every mod file is loaded in by smlua | None | -| HOOK_ON_NAMETAGS_RENDER | Called when nametags are rendered. Return a `string` to change what renders on the nametag, return an empty `string` to render nothing. | `string` playerIndex | +| HOOK_ON_NAMETAGS_RENDER | Called when nametags are rendered. Return a table with `name` and/or `pos` to override the nametag text and/or position. | `string` playerIndex, `Vec3f` pos | | HOOK_ON_DJUI_THEME_CHANGED | Called when the DJUI theme is changed. Run `djui_menu_get_theme()` to get the new theme. | None | | HOOK_ON_GEO_PROCESS | Called when a GeoLayout is processed **Note:** You must set the `hookProcess` field of the graph node to a non-zero value | [GraphNode](../structs.md#GraphNode) graphNode, `integer` matStackIndex | | HOOK_BEFORE_GEO_PROCESS | Called before a GeoLayout is processed **Note:** You must set the `hookProcess` field of the graph node to a non-zero value | [GraphNode](../structs.md#GraphNode) graphNode, `integer` matStackIndex | diff --git a/src/audio/external.c b/src/audio/external.c index 056e858b4..1d778db59 100644 --- a/src/audio/external.c +++ b/src/audio/external.c @@ -838,7 +838,7 @@ void play_sound(s32 soundBits, f32 *pos) { MUTEX_LOCK(gAudioThread); pos = smlua_get_vec3f_for_play_sound(pos); - smlua_call_event_hooks_on_play_sound(HOOK_ON_PLAY_SOUND, soundBits, pos, &soundBits); + smlua_call_event_hooks(HOOK_ON_PLAY_SOUND, soundBits, pos, &soundBits); sSoundRequests[sSoundRequestCount].soundBits = soundBits; sSoundRequests[sSoundRequestCount].position = pos; sSoundRequests[sSoundRequestCount].customFreqScale = 0; @@ -851,7 +851,7 @@ void play_sound_with_freq_scale(s32 soundBits, f32* pos, f32 freqScale) { MUTEX_LOCK(gAudioThread); pos = smlua_get_vec3f_for_play_sound(pos); - smlua_call_event_hooks_on_play_sound(HOOK_ON_PLAY_SOUND, soundBits, pos, &soundBits); + smlua_call_event_hooks(HOOK_ON_PLAY_SOUND, soundBits, pos, &soundBits); sSoundRequests[sSoundRequestCount].soundBits = soundBits; sSoundRequests[sSoundRequestCount].position = pos; sSoundRequests[sSoundRequestCount].customFreqScale = freqScale; @@ -2463,7 +2463,7 @@ void play_dialog_sound(u8 dialogID) { } speaker = sDialogSpeaker[dialogID]; - smlua_call_event_hooks_int_params_ret_int(HOOK_DIALOG_SOUND, speaker, &speaker); + smlua_call_event_hooks(HOOK_DIALOG_SOUND, speaker, &speaker); if (speaker < DS_MAX && speaker != 0xff) { play_sound(sDialogSpeakerVoice[speaker], gGlobalSoundSource); diff --git a/src/audio/load.c b/src/audio/load.c index 281dbe445..14498b196 100644 --- a/src/audio/load.c +++ b/src/audio/load.c @@ -1553,11 +1553,9 @@ void preload_sequence(u32 seqId, u8 preloadMask) { void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync); void load_sequence(u32 player, u32 seqId, s32 loadAsync) { - s16 returnValue = -1; - - smlua_call_event_hooks_on_seq_load(HOOK_ON_SEQ_LOAD, player, seqId, loadAsync, &returnValue); - if (returnValue > -1) { - seqId = returnValue; + u32 seqIdOverride = 0; + if (smlua_call_event_hooks(HOOK_ON_SEQ_LOAD, player, seqId, loadAsync, &seqIdOverride)) { + seqId = seqIdOverride; } if (!loadAsync) { diff --git a/src/engine/surface_load.c b/src/engine/surface_load.c index d667f5ba1..9e9c8b866 100644 --- a/src/engine/surface_load.c +++ b/src/engine/surface_load.c @@ -246,7 +246,7 @@ static void add_surface(struct Surface *surface, s32 dynamic) { } } - smlua_call_event_on_add_surface(surface, dynamic); + smlua_call_event_hooks(HOOK_ON_ADD_SURFACE, surface, dynamic); } /** diff --git a/src/game/area.c b/src/game/area.c index 91a9b52bb..ab30a154f 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -375,9 +375,9 @@ void area_update_objects(void) { */ void play_transition(s16 transType, s16 time, u8 red, u8 green, u8 blue) { reset_screen_transition_timers(); - bool returnValue = true; - smlua_call_event_hooks_int_params_ret_bool(HOOK_ON_SCREEN_TRANSITION, transType, &returnValue); - if (!returnValue) { return; } + bool allowPlayTransition = true; + smlua_call_event_hooks(HOOK_ON_SCREEN_TRANSITION, transType, &allowPlayTransition); + if (!allowPlayTransition) { return; } gWarpTransition.isActive = TRUE; gWarpTransition.type = transType; @@ -458,7 +458,7 @@ void render_game(void) { if (gServerSettings.nametags && !gDjuiInMainMenu) { nametags_render(); } - smlua_call_event_on_hud_render_behind(djui_reset_hud_params); + smlua_call_event_hooks(HOOK_ON_HUD_RENDER_BEHIND, djui_reset_hud_params); djui_gfx_displaylist_end(); } render_hud(); diff --git a/src/game/camera.c b/src/game/camera.c index 525d62f6e..53de82b30 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -2973,9 +2973,9 @@ void set_camera_mode(struct Camera *c, s16 mode, s16 frames) { if (c->mode == CAMERA_MODE_ROM_HACK && allow_romhack_camera_override_mode(mode)) { return; } - bool returnValue = true; - smlua_call_event_hooks_set_camera_mode_params(HOOK_ON_SET_CAMERA_MODE, c, mode, frames, &returnValue); - if (!returnValue) { + bool allowSetCameraMode = true; + smlua_call_event_hooks(HOOK_ON_SET_CAMERA_MODE, c, mode, frames, &allowSetCameraMode); + if (!allowSetCameraMode) { return; } @@ -3186,15 +3186,15 @@ void update_camera(struct Camera *c) { // Only process R_TRIG if 'fixed' is not selected in the menu if (cam_select_alt_mode(0) == CAM_SELECTION_MARIO && c->mode != CAMERA_MODE_NEWCAM) { if ((sCurrPlayMode != PLAY_MODE_PAUSED) && gPlayer1Controller->buttonPressed & R_TRIG) { - bool returnValue = true; + bool allowSetCamAngle = true; if (set_cam_angle(0) == CAM_ANGLE_LAKITU) { - smlua_call_event_hooks_int_params_ret_bool(HOOK_ON_CHANGE_CAMERA_ANGLE, CAM_ANGLE_MARIO, &returnValue); - if (returnValue) { + smlua_call_event_hooks(HOOK_ON_CHANGE_CAMERA_ANGLE, CAM_ANGLE_MARIO, &allowSetCamAngle); + if (allowSetCamAngle) { set_cam_angle(CAM_ANGLE_MARIO); } } else { - smlua_call_event_hooks_int_params_ret_bool(HOOK_ON_CHANGE_CAMERA_ANGLE, CAM_ANGLE_LAKITU, &returnValue); - if (returnValue) { + smlua_call_event_hooks(HOOK_ON_CHANGE_CAMERA_ANGLE, CAM_ANGLE_LAKITU, &allowSetCamAngle); + if (allowSetCamAngle) { set_cam_angle(CAM_ANGLE_LAKITU); } } diff --git a/src/game/characters.c b/src/game/characters.c index 662ff5265..4c0fce483 100644 --- a/src/game/characters.c +++ b/src/game/characters.c @@ -425,9 +425,9 @@ struct Character* get_character(struct MarioState* m) { static s32 get_character_sound(struct MarioState* m, enum CharacterSound characterSound) { if (m == NULL || m->marioObj == NULL) { return 0; } - s32 override = 0; - if (smlua_call_event_hooks_mario_character_sound_param_ret_int(HOOK_CHARACTER_SOUND, m, characterSound, &override)) { - return override; + s32 soundOverride = 0; + if (smlua_call_event_hooks(HOOK_CHARACTER_SOUND, m, characterSound, &soundOverride)) { + return soundOverride; } struct Character* character = ((m == NULL || m->character == NULL) ? &gCharacters[CT_MARIO] : m->character); diff --git a/src/game/ingame_menu.c b/src/game/ingame_menu.c index e4d4646b9..709e3d253 100644 --- a/src/game/ingame_menu.c +++ b/src/game/ingame_menu.c @@ -1160,14 +1160,15 @@ static u8 sHookString[255]; static bool sOverrideDialogString = false; void convert_string_ascii_to_sm64(u8 *str64, const char *strAscii, bool menu); bool handle_dialog_hook(s16 dialogId) { - bool open = false; - const char *str = smlua_call_event_hooks_int_ret_bool_and_string(HOOK_ON_DIALOG, dialogId, &open); - if (!open) { + bool openDialogBox = true; + const char *dialogTextOverride = NULL; + smlua_call_event_hooks(HOOK_ON_DIALOG, dialogId, &openDialogBox, &dialogTextOverride); + if (!openDialogBox) { if (gCamera->cutscene == CUTSCENE_READ_MESSAGE) { gCamera->cutscene = 0; } return false; } - sOverrideDialogString = str != NULL; - if (sOverrideDialogString) { convert_string_ascii_to_sm64(sHookString, str, false); } + sOverrideDialogString = dialogTextOverride != NULL; + if (sOverrideDialogString) { convert_string_ascii_to_sm64(sHookString, dialogTextOverride, false); } return true; } @@ -3107,7 +3108,7 @@ s16 render_pause_courses_and_castle(void) { { bool allowExit = true; if (gDialogLineNum == 2 || gDialogLineNum == 3) { - smlua_call_event_hooks_bool_param_ret_bool(HOOK_ON_PAUSE_EXIT, (gDialogLineNum == 3), &allowExit); + smlua_call_event_hooks(HOOK_ON_PAUSE_EXIT, gDialogLineNum == 3, &allowExit); } if (allowExit) { level_set_transition(0, NULL); diff --git a/src/game/interaction.c b/src/game/interaction.c index e182a2d80..e80de6200 100644 --- a/src/game/interaction.c +++ b/src/game/interaction.c @@ -300,7 +300,7 @@ u32 attack_object(struct MarioState* m, struct Object *o, s32 interaction) { o->oInteractStatus = attackType + (INT_STATUS_INTERACTED | INT_STATUS_WAS_ATTACKED); - smlua_call_event_hooks_interact_params_no_ret(HOOK_ON_ATTACK_OBJECT, m, o, interaction); + smlua_call_event_hooks(HOOK_ON_ATTACK_OBJECT, m, o, interaction); return attackType; } @@ -1515,9 +1515,9 @@ u32 interact_player_pvp(struct MarioState* attacker, struct MarioState* victim) } // call the Lua hook - bool allow = true; - smlua_call_event_hooks_mario_params_ret_bool(HOOK_ALLOW_PVP_ATTACK, attacker, cVictim, interaction, &allow); - if (!allow) { + bool allowAttack = true; + smlua_call_event_hooks(HOOK_ALLOW_PVP_ATTACK, attacker, cVictim, interaction, &allowAttack); + if (!allowAttack) { // Lua blocked the interaction return FALSE; } @@ -1591,7 +1591,7 @@ u32 interact_player_pvp(struct MarioState* attacker, struct MarioState* victim) } victim->interactObj = NULL; - smlua_call_event_hooks_mario_params(HOOK_ON_PVP_ATTACK, attacker, victim, interaction); + smlua_call_event_hooks(HOOK_ON_PVP_ATTACK, attacker, victim, interaction); return FALSE; } @@ -2339,14 +2339,14 @@ void check_kick_or_punch_wall(struct MarioState *m) { // Intended for interactions triggered by mods u32 process_interaction(struct MarioState *m, u32 interactType, struct Object *o, u32 (*interact_function)(struct MarioState *, u32 interactType, struct Object *)) { if (!m || !o) { return FALSE; } - bool allow = true; - smlua_call_event_hooks_interact_params_ret_bool(HOOK_ALLOW_INTERACT, m, o, interactType, &allow); - if (allow) { + bool allowInteract = true; + smlua_call_event_hooks(HOOK_ALLOW_INTERACT, m, o, interactType, &allowInteract); + if (allowInteract) { if (interact_function(m, interactType, o)) { - smlua_call_event_hooks_interact_params(HOOK_ON_INTERACT, m, o, interactType, true); + smlua_call_event_hooks(HOOK_ON_INTERACT, m, o, interactType, true); return TRUE; } else { - smlua_call_event_hooks_interact_params(HOOK_ON_INTERACT, m, o, interactType, false); + smlua_call_event_hooks(HOOK_ON_INTERACT, m, o, interactType, false); } } return FALSE; @@ -2377,14 +2377,14 @@ void mario_process_interactions(struct MarioState *m) { m->collidedObjInteractTypes &= ~interactType; if (object && !(object->oInteractStatus & INT_STATUS_INTERACTED)) { - bool allow = true; - smlua_call_event_hooks_interact_params_ret_bool(HOOK_ALLOW_INTERACT, m, object, interactType, &allow); - if (allow) { + bool allowInteract = true; + smlua_call_event_hooks(HOOK_ALLOW_INTERACT, m, object, interactType, &allowInteract); + if (allowInteract) { if (sInteractionHandlers[i].handler(m, interactType, object)) { - smlua_call_event_hooks_interact_params(HOOK_ON_INTERACT, m, object, interactType, true); + smlua_call_event_hooks(HOOK_ON_INTERACT, m, object, interactType, true); break; } else { - smlua_call_event_hooks_interact_params(HOOK_ON_INTERACT, m, object, interactType, false); + smlua_call_event_hooks(HOOK_ON_INTERACT, m, object, interactType, false); } } } @@ -2405,7 +2405,7 @@ void mario_process_interactions(struct MarioState *m) { m->invincTimer -= 1; } - smlua_call_event_hooks_mario_param(HOOK_ON_INTERACTIONS, m); + smlua_call_event_hooks(HOOK_ON_INTERACTIONS, m); //! If the kick/punch flags are set and an object collision changes Mario's // action, he will get the kick/punch wall speed anyway. @@ -2428,7 +2428,7 @@ void check_death_barrier(struct MarioState *m) { if (m->pos[1] < m->floorHeight + 2048.0f) { bool allowDeath = true; - smlua_call_event_hooks_mario_param_ret_bool(HOOK_ON_DEATH, m, &allowDeath); + smlua_call_event_hooks(HOOK_ON_DEATH, m, &allowDeath); if (!allowDeath) { return; } if (mario_can_bubble(m)) { @@ -2460,9 +2460,9 @@ void check_death_barrier(struct MarioState *m) { void check_lava_boost(struct MarioState *m) { if (!m) { return; } - bool allow = true; - smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_LAVA_FLOOR, &allow); - if (m->action == ACT_BUBBLED || (!allow)) { return; } + bool allowHazard = true; + smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_LAVA_FLOOR, &allowHazard); + if (m->action == ACT_BUBBLED || (!allowHazard)) { return; } if (!(m->action & ACT_FLAG_RIDING_SHELL) && m->pos[1] < m->floorHeight + 10.0f) { if (!(m->flags & MARIO_METAL_CAP)) { m->hurtCounter += (m->flags & MARIO_CAP_ON_HEAD) ? 12 : 18; diff --git a/src/game/level_update.c b/src/game/level_update.c index 65969f8d9..bccfeefaf 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -548,7 +548,7 @@ void init_mario_after_warp(void) { gMarioState->skipWarpInteractionsTimer = 30; } - smlua_call_event_hooks_warp_params(HOOK_ON_WARP, warpType, sWarpDest.levelNum, sWarpDest.areaIdx, sWarpDest.nodeId, sWarpDest.arg); + smlua_call_event_hooks(HOOK_ON_WARP, warpType, sWarpDest.levelNum, sWarpDest.areaIdx, sWarpDest.nodeId, sWarpDest.arg); } // used for warps inside one level @@ -686,7 +686,7 @@ void check_instant_warp(void) { skip_camera_interpolation(); gMarioStates[0].area->camera->yaw = cameraAngle; - smlua_call_event_hooks_instant_warp_params(HOOK_ON_INSTANT_WARP, warp->area, warp->id, warp->displacement); + smlua_call_event_hooks(HOOK_ON_INSTANT_WARP, warp->area, warp->id, warp->displacement); return; } @@ -749,8 +749,16 @@ s16 music_changed_through_warp(s16 arg) { * Set the current warp type and destination level/area/node. */ void initiate_warp(s16 destLevel, s16 destArea, s16 destWarpNode, s32 arg) { - - smlua_call_event_hooks_before_warp(HOOK_BEFORE_WARP, &destLevel, &destArea, &destWarpNode, &arg); + struct WarpDest warpDestOverride = { + .levelNum = destLevel, + .areaIdx = destArea, + .nodeId = destWarpNode, + }; + if (smlua_call_event_hooks(HOOK_BEFORE_WARP, destLevel, destArea, destWarpNode, arg, &warpDestOverride)) { + destLevel = warpDestOverride.levelNum; + destArea = warpDestOverride.areaIdx; + destWarpNode = warpDestOverride.nodeId; + } if (destWarpNode >= WARP_NODE_CREDITS_MIN) { sWarpDest.type = WARP_TYPE_CHANGE_LEVEL; @@ -1844,7 +1852,7 @@ s32 init_level(void) { if (gNetworkPlayerLocal != NULL) { network_player_update_course_level(gNetworkPlayerLocal, gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex); } - smlua_call_event_hooks_warp_params(HOOK_ON_LEVEL_INIT, sWarpDest.type, sWarpDest.levelNum, sWarpDest.areaIdx, sWarpDest.nodeId, sWarpDest.arg); + smlua_call_event_hooks(HOOK_ON_LEVEL_INIT, sWarpDest.type, sWarpDest.levelNum, sWarpDest.areaIdx, sWarpDest.nodeId, sWarpDest.arg); // clear texture 1 on level init -- can linger and corrupt textures otherwise extern u8 gGfxPcResetTex1; @@ -1926,9 +1934,8 @@ s32 lvl_set_current_level(s16 param, s16 levelNum) { gCurrLevelNum = level; gCurrCourseNum = get_level_course_num(level); - bool foundHook = false; bool hookUseActSelect = false; - smlua_call_event_hooks_use_act_select(HOOK_USE_ACT_SELECT, level, &foundHook, &hookUseActSelect); + bool foundHook = smlua_call_event_hooks(HOOK_USE_ACT_SELECT, level, &hookUseActSelect); if (!foundHook || !hookUseActSelect) { if (gCurrDemoInput != NULL || gCurrCreditsEntry != NULL || gCurrCourseNum == COURSE_NONE) { diff --git a/src/game/mario.c b/src/game/mario.c index 9c42ffc36..8858ae372 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -524,8 +524,10 @@ s32 mario_get_floor_class(struct MarioState *m) { floorClass = SURFACE_CLASS_NOT_SLIPPERY; } - s32 returnValue = 0; - if (smlua_call_event_hooks_mario_param_and_int_ret_int(HOOK_MARIO_OVERRIDE_FLOOR_CLASS, m, floorClass, &returnValue)) return returnValue; + s32 floorClassOverride = 0; + if (smlua_call_event_hooks(HOOK_MARIO_OVERRIDE_FLOOR_CLASS, m, floorClass, &floorClassOverride)) { + return floorClassOverride; + } return floorClass; } @@ -1140,9 +1142,10 @@ static u32 set_mario_action_cutscene(struct MarioState *m, u32 action, UNUSED u3 */ u32 set_mario_action(struct MarioState *m, u32 action, u32 actionArg) { if (!m) { return FALSE; } - u32 returnValue = 0; - smlua_call_event_hooks_mario_action_and_arg_ret_int(HOOK_BEFORE_SET_MARIO_ACTION, m, action, actionArg, &returnValue); - if (returnValue == 1) { return TRUE; } else if (returnValue) { action = returnValue; } + u32 actionOverride = 0; + smlua_call_event_hooks(HOOK_BEFORE_SET_MARIO_ACTION, m, action, actionArg, &actionOverride); + if (actionOverride == 1) { return TRUE; } + if (actionOverride != 0) { action = actionOverride; } switch (action & ACT_GROUP_MASK) { case ACT_GROUP_MOVING: @@ -1176,7 +1179,7 @@ u32 set_mario_action(struct MarioState *m, u32 action, u32 actionArg) { m->actionState = 0; m->actionTimer = 0; - smlua_call_event_hooks_mario_param(HOOK_ON_SET_MARIO_ACTION, m); + smlua_call_event_hooks(HOOK_ON_SET_MARIO_ACTION, m); return TRUE; } @@ -1519,9 +1522,9 @@ resetGoto:; f32 gasLevel; f32 ceilToFloorDist; - bool allow = true; - smlua_call_event_hooks_mario_param_ret_bool(HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS, m, &allow); - if (!allow) { return; } + bool allowUpdateGeometryInputs = true; + smlua_call_event_hooks(HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS, m, &allowUpdateGeometryInputs); + if (!allowUpdateGeometryInputs) { return; } f32_find_wall_collision(&m->pos[0], &m->pos[1], &m->pos[2], 60.0f, 50.0f); f32_find_wall_collision(&m->pos[0], &m->pos[1], &m->pos[2], 30.0f, 24.0f); diff --git a/src/game/mario_actions_airborne.c b/src/game/mario_actions_airborne.c index a9594baef..1865d465c 100644 --- a/src/game/mario_actions_airborne.c +++ b/src/game/mario_actions_airborne.c @@ -72,9 +72,9 @@ Useful for handling collisions with lava walls, giving Mario a strong upward/for |descriptionEnd| */ s32 lava_boost_on_wall(struct MarioState *m) { if (!m) { return 0; } - bool allow = true; - smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_LAVA_WALL, &allow); - if ((!allow) || gDjuiInMainMenu) { return FALSE; } + bool allowHazard = true; + smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_LAVA_WALL, &allowHazard); + if ((!allowHazard) || gDjuiInMainMenu) { return FALSE; } m->faceAngle[1] = atan2s(m->wallNormal[2], m->wallNormal[0]); if (m->forwardVel < 24.0f) { @@ -206,9 +206,9 @@ s32 check_horizontal_wind(struct MarioState *m) { struct Surface *floor; f32 speed; s16 pushAngle; - bool allow = true; - smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_HORIZONTAL_WIND, &allow); - if (!allow) { + bool allowHazard = true; + smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_HORIZONTAL_WIND, &allowHazard); + if (!allowHazard) { return FALSE; } @@ -1733,7 +1733,7 @@ s32 act_lava_boost(struct MarioState *m) { m->health = 0x100; } else { bool allowDeath = true; - smlua_call_event_hooks_mario_param_ret_bool(HOOK_ON_DEATH, m, &allowDeath); + smlua_call_event_hooks(HOOK_ON_DEATH, m, &allowDeath); if (!allowDeath) { reset_rumble_timers(m); return FALSE; @@ -2297,23 +2297,23 @@ if on certain wind surfaces. Also resets `m.quicksandDepth` |descriptionEnd| */ s32 check_common_airborne_cancels(struct MarioState *m) { if (!m) { return 0; } - bool allow = true; + if (m->pos[1] < m->waterLevel - 100) { - smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow); - if (allow) { + bool allowForceAction = true; + smlua_call_event_hooks(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allowForceAction); + if (allowForceAction) { return set_water_plunge_action(m); } } - allow = true; if (m->input & INPUT_SQUISHED) { return drop_and_set_mario_action(m, ACT_SQUISHED, 0); } - if (m->floor && m->floor->type == SURFACE_VERTICAL_WIND && (m->action & ACT_FLAG_ALLOW_VERTICAL_WIND_ACTION)) { - smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_VERTICAL_WIND, &allow); - if (allow) { + bool allowHazard = true; + smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_VERTICAL_WIND, &allowHazard); + if (allowHazard) { return drop_and_set_mario_action(m, ACT_VERTICAL_WIND, 0); } } diff --git a/src/game/mario_actions_automatic.c b/src/game/mario_actions_automatic.c index 64a1566d3..535d94110 100644 --- a/src/game/mario_actions_automatic.c +++ b/src/game/mario_actions_automatic.c @@ -353,8 +353,10 @@ s32 perform_hanging_step(struct MarioState *m, OUT Vec3f nextPos) { f32 floorHeight; f32 ceilOffset; - s32 returnValue = 0; - if (smlua_call_event_hooks_mario_param_and_int_ret_int(HOOK_BEFORE_PHYS_STEP, m, STEP_TYPE_HANG, &returnValue)) return returnValue; + s32 stepResultOverride = 0; + if (smlua_call_event_hooks(HOOK_BEFORE_PHYS_STEP, m, STEP_TYPE_HANG, 0, &stepResultOverride)) { + return stepResultOverride; + } struct WallCollisionData wcd = { 0 }; resolve_and_return_wall_collisions_data(nextPos, 50.0f, 50.0f, &wcd); @@ -1170,9 +1172,9 @@ Checks if Mario should cancel his current automatic action, primarily by detecti s32 check_common_automatic_cancels(struct MarioState *m) { if (!m) { return 0; } if (m->pos[1] < m->waterLevel - 100) { - bool allow = true; - smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow); - if (allow) { + bool allowForceAction = true; + smlua_call_event_hooks(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allowForceAction); + if (allowForceAction) { return set_water_plunge_action(m); } } diff --git a/src/game/mario_actions_cutscene.c b/src/game/mario_actions_cutscene.c index 8f9090441..55296f7b8 100644 --- a/src/game/mario_actions_cutscene.c +++ b/src/game/mario_actions_cutscene.c @@ -257,7 +257,7 @@ s32 get_star_collection_dialog(struct MarioState *m) { if (!m) { return 0; } s32 dialogID = 0; - if (smlua_call_event_hooks_ret_int(HOOK_GET_STAR_COLLECTION_DIALOG, &dialogID)) { + if (smlua_call_event_hooks(HOOK_GET_STAR_COLLECTION_DIALOG, &dialogID)) { m->prevNumStarsForDialog = m->numStars; return dialogID; } @@ -849,7 +849,7 @@ s32 common_death_handler(struct MarioState *m, s32 animation, s32 frameToDeathWa // do nothing } else { bool allowDeath = true; - smlua_call_event_hooks_mario_param_ret_bool(HOOK_ON_DEATH, m, &allowDeath); + smlua_call_event_hooks(HOOK_ON_DEATH, m, &allowDeath); if (!allowDeath) { return animFrame; } if (mario_can_bubble(m)) { @@ -923,7 +923,7 @@ s32 act_quicksand_death(struct MarioState *m) { } else { m->actionState = 2; bool allowDeath = true; - smlua_call_event_hooks_mario_param_ret_bool(HOOK_ON_DEATH, m, &allowDeath); + smlua_call_event_hooks(HOOK_ON_DEATH, m, &allowDeath); if (!allowDeath) { return FALSE; } if (mario_can_bubble(m)) { @@ -947,7 +947,7 @@ s32 act_eaten_by_bubba(struct MarioState *m) { if (m->actionTimer++ == 60) { if (m->playerIndex == 0) { bool allowDeath = true; - smlua_call_event_hooks_mario_param_ret_bool(HOOK_ON_DEATH, m, &allowDeath); + smlua_call_event_hooks(HOOK_ON_DEATH, m, &allowDeath); if (!allowDeath) { return FALSE; } if (mario_can_bubble(m)) { @@ -1874,7 +1874,7 @@ s32 act_squished(struct MarioState *m) { m->health = 0x100; } else { bool allowDeath = true; - smlua_call_event_hooks_mario_param_ret_bool(HOOK_ON_DEATH, m, &allowDeath); + smlua_call_event_hooks(HOOK_ON_DEATH, m, &allowDeath); if (!allowDeath) { return FALSE; } if (mario_can_bubble(m)) { diff --git a/src/game/mario_actions_moving.c b/src/game/mario_actions_moving.c index 1e68b2b91..c22f2a631 100644 --- a/src/game/mario_actions_moving.c +++ b/src/game/mario_actions_moving.c @@ -2181,9 +2181,9 @@ Performs common checks when Mario is in a moving state, transitions to water plu s32 check_common_moving_cancels(struct MarioState *m) { if (!m) { return FALSE; } if (m->pos[1] < m->waterLevel - 100) { - bool allow = true; - smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow); - if (allow) { + bool allowForceAction = true; + smlua_call_event_hooks(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allowForceAction); + if (allowForceAction) { return set_water_plunge_action(m); } } diff --git a/src/game/mario_actions_object.c b/src/game/mario_actions_object.c index 6c890ebbe..ca66da1db 100644 --- a/src/game/mario_actions_object.c +++ b/src/game/mario_actions_object.c @@ -486,9 +486,9 @@ s32 check_common_object_cancels(struct MarioState *m) { if (m->playerIndex != 0) { return FALSE; } if (m->pos[1] < m->waterLevel - 100) { - bool allow = true; - smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow); - if (allow) { + bool allowForceAction = true; + smlua_call_event_hooks(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allowForceAction); + if (allowForceAction) { return set_water_plunge_action(m); } } diff --git a/src/game/mario_actions_stationary.c b/src/game/mario_actions_stationary.c index 547fbd315..a5228c3cb 100644 --- a/src/game/mario_actions_stationary.c +++ b/src/game/mario_actions_stationary.c @@ -1167,9 +1167,9 @@ s32 check_common_stationary_cancels(struct MarioState *m) { if (!m) { return 0; } if (m->playerIndex != 0) { return FALSE; } if (m->pos[1] < m->waterLevel - 100) { - bool allow = true; - smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow); - if (allow) { + bool allowForceAction = true; + smlua_call_event_hooks(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allowForceAction); + if (allowForceAction) { if (m->action == ACT_SPAWN_SPIN_LANDING) { if (m == &gMarioStates[0]) { load_level_init_text(0); diff --git a/src/game/mario_actions_submerged.c b/src/game/mario_actions_submerged.c index dfe323559..e573613c1 100644 --- a/src/game/mario_actions_submerged.c +++ b/src/game/mario_actions_submerged.c @@ -195,8 +195,10 @@ u32 perform_water_step(struct MarioState *m) { Vec3f step; struct Object *marioObj = m->marioObj; - s32 returnValue = 0; - if (smlua_call_event_hooks_mario_param_and_int_ret_int(HOOK_BEFORE_PHYS_STEP, m, STEP_TYPE_WATER, &returnValue)) return (u32) returnValue; + s32 stepResultOverride = 0; + if (smlua_call_event_hooks(HOOK_BEFORE_PHYS_STEP, m, STEP_TYPE_WATER, 0, &stepResultOverride)) { + return (u32) stepResultOverride; + } vec3f_copy(step, m->vel); @@ -209,11 +211,11 @@ u32 perform_water_step(struct MarioState *m) { nextPos[2] = m->pos[2] + step[2]; if (nextPos[1] > m->waterLevel - 80) { - bool allow = true; - smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, true, &allow); - if (allow) { - nextPos[1] = m->waterLevel - 80; - m->vel[1] = 0.0f; + bool allowForceAction = true; + smlua_call_event_hooks(HOOK_ALLOW_FORCE_WATER_ACTION, m, true, &allowForceAction); + if (allowForceAction) { + nextPos[1] = m->waterLevel - 80; + m->vel[1] = 0.0f; } } @@ -538,9 +540,10 @@ static s32 check_water_jump(struct MarioState *m) { if (m->input & INPUT_A_PRESSED) { if (probe >= m->waterLevel - 80 && m->faceAngle[0] >= 0 && m->controller->stickY < -60.0f) { - bool allow = true; - smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, true, &allow); - if (!allow) { return FALSE; } + bool allowForceAction = true; + smlua_call_event_hooks(HOOK_ALLOW_FORCE_WATER_ACTION, m, true, &allowForceAction); + if (!allowForceAction) { return FALSE; } + vec3s_set(m->angleVel, 0, 0, 0); m->vel[1] = 62.0f; @@ -997,7 +1000,7 @@ static s32 act_drowning(struct MarioState *m) { // do nothing } else { bool allowDeath = true; - smlua_call_event_hooks_mario_param_ret_bool(HOOK_ON_DEATH, m, &allowDeath); + smlua_call_event_hooks(HOOK_ON_DEATH, m, &allowDeath); if (!allowDeath) { return FALSE; } if (mario_can_bubble(m)) { @@ -1032,7 +1035,7 @@ static s32 act_water_death(struct MarioState *m) { // do nothing } else { bool allowDeath = true; - smlua_call_event_hooks_mario_param_ret_bool(HOOK_ON_DEATH, m, &allowDeath); + smlua_call_event_hooks(HOOK_ON_DEATH, m, &allowDeath); if (!allowDeath) { return FALSE; } if (mario_can_bubble(m)) { @@ -1158,7 +1161,7 @@ static s32 act_caught_in_whirlpool(struct MarioState *m) { // do nothing } else { bool allowDeath = true; - smlua_call_event_hooks_mario_param_ret_bool(HOOK_ON_DEATH, m, &allowDeath); + smlua_call_event_hooks(HOOK_ON_DEATH, m, &allowDeath); if (!allowDeath) { reset_rumble_timers(m); return FALSE; } if (mario_can_bubble(m)) { @@ -1626,24 +1629,24 @@ static s32 act_hold_metal_water_fall_land(struct MarioState *m) { static s32 check_common_submerged_cancels(struct MarioState *m) { if (!m) { return 0; } if (m->pos[1] > m->waterLevel - 80) { - bool allow = true; - smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, true, &allow); - if (allow) { - if (m->waterLevel - 80 > m->floorHeight) { - m->pos[1] = m->waterLevel - 80; - } else { - //! If you press B to throw the shell, there is a ~5 frame window - // where your held object is the shell, but you are not in the - // water shell swimming action. This allows you to hold the water - // shell on land (used for cloning in DDD). - if (m->action == ACT_WATER_SHELL_SWIMMING && m->heldObj != NULL && m->playerIndex == 0) { - m->heldObj->oInteractStatus = INT_STATUS_STOP_RIDING; - m->heldObj = NULL; - stop_shell_music(); - } - - return transition_submerged_to_walking(m); - } + bool allowForceAction = true; + smlua_call_event_hooks(HOOK_ALLOW_FORCE_WATER_ACTION, m, true, &allowForceAction); + if (allowForceAction) { + if (m->waterLevel - 80 > m->floorHeight) { + m->pos[1] = m->waterLevel - 80; + } else { + //! If you press B to throw the shell, there is a ~5 frame window + // where your held object is the shell, but you are not in the + // water shell swimming action. This allows you to hold the water + // shell on land (used for cloning in DDD). + if (m->action == ACT_WATER_SHELL_SWIMMING && m->heldObj != NULL && m->playerIndex == 0) { + m->heldObj->oInteractStatus = INT_STATUS_STOP_RIDING; + m->heldObj = NULL; + stop_shell_music(); + } + + return transition_submerged_to_walking(m); + } } } diff --git a/src/game/mario_misc.c b/src/game/mario_misc.c index fb76332dd..8e4e62f26 100644 --- a/src/game/mario_misc.c +++ b/src/game/mario_misc.c @@ -725,7 +725,7 @@ Gfx* geo_render_mirror_mario(s32 callContext, struct GraphNode* node, UNUSED Mat gMirrorMario[i].scale[0] *= -1.0f; gMirrorMario[i].node.flags |= GRAPH_RENDER_ACTIVE; - smlua_call_event_hooks_graph_node_object_and_int_param(HOOK_MIRROR_MARIO_RENDER, &gMirrorMario[i], i); + smlua_call_event_hooks(HOOK_MIRROR_MARIO_RENDER, &gMirrorMario[i], i); } else { gMirrorMario[i].node.flags &= ~GRAPH_RENDER_ACTIVE; } diff --git a/src/game/mario_step.c b/src/game/mario_step.c index 969162df5..16be3e767 100644 --- a/src/game/mario_step.c +++ b/src/game/mario_step.c @@ -123,10 +123,10 @@ void mario_bonk_reflection(struct MarioState *m, u8 negateSpeed) { u32 mario_update_quicksand(struct MarioState *m, f32 sinkingSpeed) { if (!m) { return 0; } - bool allow = true; - smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_QUICKSAND, &allow); + bool allowHazard = true; + smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_QUICKSAND, &allowHazard); extern bool gDjuiInMainMenu; - if (m->action & ACT_FLAG_RIDING_SHELL || (!allow) || gDjuiInMainMenu) { + if (m->action & ACT_FLAG_RIDING_SHELL || (!allowHazard) || gDjuiInMainMenu) { m->quicksandDepth = 0.0f; } else { if (m->quicksandDepth < 1.1f) { @@ -217,9 +217,9 @@ u32 mario_update_windy_ground(struct MarioState *m) { if (!m) { return 0; } struct Surface *floor = m->floor; if (!floor) { return 0; } - bool allow = true; - smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_HORIZONTAL_WIND, &allow); - if (!allow) { + bool allowHazard = true; + smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_HORIZONTAL_WIND, &allowHazard); + if (!allowHazard) { return FALSE; } @@ -316,14 +316,14 @@ static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) { m->faceAngle[1] += 0x8000; mario_set_forward_vel(m, gServerSettings.bouncyLevelBounds == BOUNCY_LEVEL_BOUNDS_ON_CAP ? clamp(1.5f * m->forwardVel, -500, 500) : 1.5f * m->forwardVel); } - smlua_call_event_hooks_mario_param(HOOK_ON_COLLIDE_LEVEL_BOUNDS, m); + smlua_call_event_hooks(HOOK_ON_COLLIDE_LEVEL_BOUNDS, m); return GROUND_STEP_HIT_WALL_STOP_QSTEPS; } if ((m->action & ACT_FLAG_RIDING_SHELL) && floorHeight < waterLevel) { - bool allow = true; - smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow); - if (allow) { + bool allowForceAction = true; + smlua_call_event_hooks(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allowForceAction); + if (allowForceAction) { floorHeight = waterLevel; floor = &gWaterSurfacePseudoFloor; floor->originOffset = floorHeight; //! Wrong origin offset (no effect) @@ -376,18 +376,18 @@ s32 perform_ground_step(struct MarioState *m) { u32 stepResult; Vec3f intendedPos; - s32 returnValue = 0; - if (smlua_call_event_hooks_mario_param_and_int_ret_int(HOOK_BEFORE_PHYS_STEP, m, STEP_TYPE_GROUND, &returnValue)) return returnValue; + s32 stepResultOverride = 0; + if (smlua_call_event_hooks(HOOK_BEFORE_PHYS_STEP, m, STEP_TYPE_GROUND, 0, &stepResultOverride)) { + return stepResultOverride; + } for (i = 0; i < 4; i++) { Vec3f step = { 0 }; if (m->floor) { - f32 floorNormal; - if (!smlua_call_event_hooks_mario_param_ret_float(HOOK_MARIO_OVERRIDE_PHYS_STEP_DEFACTO_SPEED, m, &floorNormal)) { - floorNormal = m->floor->normal.y; - } - step[0] = floorNormal * (m->vel[0] / 4.0f); - step[2] = floorNormal * (m->vel[2] / 4.0f); + f32 floorNormalY = m->floor->normal.y; + smlua_call_event_hooks(HOOK_MARIO_OVERRIDE_PHYS_STEP_DEFACTO_SPEED, m, &floorNormalY); + step[0] = floorNormalY * (m->vel[0] / 4.0f); + step[2] = floorNormalY * (m->vel[2] / 4.0f); } intendedPos[0] = m->pos[0] + step[0]; @@ -505,14 +505,14 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr m->faceAngle[1] += 0x8000; mario_set_forward_vel(m, gServerSettings.bouncyLevelBounds == BOUNCY_LEVEL_BOUNDS_ON_CAP ? clamp(1.5f * m->forwardVel, -500, 500) : 1.5f * m->forwardVel); } - smlua_call_event_hooks_mario_param(HOOK_ON_COLLIDE_LEVEL_BOUNDS, m); + smlua_call_event_hooks(HOOK_ON_COLLIDE_LEVEL_BOUNDS, m); return AIR_STEP_HIT_WALL; } if ((m->action & ACT_FLAG_RIDING_SHELL) && floorHeight < waterLevel) { - bool allow = true; - smlua_call_event_hooks_mario_param_and_bool_ret_bool(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allow); - if (allow) { + bool allowForceAction = true; + smlua_call_event_hooks(HOOK_ALLOW_FORCE_WATER_ACTION, m, false, &allowForceAction); + if (allowForceAction) { floorHeight = waterLevel; floor = &gWaterSurfacePseudoFloor; floor->originOffset = floorHeight; //! Incorrect origin offset (no effect) @@ -721,9 +721,9 @@ void apply_vertical_wind(struct MarioState *m) { if (!m) { return; } f32 maxVelY; f32 offsetY; - bool allow = true; - smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_VERTICAL_WIND, &allow); - if (m->action != ACT_GROUND_POUND && allow) { + bool allowHazard = true; + smlua_call_event_hooks(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_VERTICAL_WIND, &allowHazard); + if (m->action != ACT_GROUND_POUND && allowHazard) { offsetY = m->pos[1] - -1500.0f; if (m->floor && m->floor->type == SURFACE_VERTICAL_WIND && -3000.0f < offsetY && offsetY < 2000.0f) { @@ -753,8 +753,10 @@ s32 perform_air_step(struct MarioState *m, u32 stepArg) { s32 quarterStepResult; s32 stepResult = AIR_STEP_NONE; - s32 returnValue = 0; - if (smlua_call_event_hooks_mario_param_and_int_and_int_ret_int(HOOK_BEFORE_PHYS_STEP, m, STEP_TYPE_AIR, stepArg, &returnValue)) return returnValue; + s32 stepResultOverride = 0; + if (smlua_call_event_hooks(HOOK_BEFORE_PHYS_STEP, m, STEP_TYPE_AIR, stepArg, &stepResultOverride)) { + return stepResultOverride; + } m->wall = NULL; diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c index f95018748..10ea9cdc9 100644 --- a/src/game/object_helpers.c +++ b/src/game/object_helpers.c @@ -697,7 +697,7 @@ struct Object *spawn_object_at_origin(struct Object *parent, UNUSED s32 unusedAr obj->globalPlayerIndex = 0; geo_obj_init((struct GraphNodeObject *) &obj->header.gfx, dynos_model_get_geo(model), gVec3fZero, gVec3sZero); - smlua_call_event_hooks_object_set_model(HOOK_OBJECT_SET_MODEL, obj, model, smlua_model_util_id_to_ext_id(model)); + smlua_call_event_hooks(HOOK_OBJECT_SET_MODEL, obj, model, smlua_model_util_id_to_ext_id(model)); return obj; } @@ -1454,7 +1454,7 @@ void cur_obj_set_model(s32 modelID) { void obj_set_model(struct Object* obj, s32 modelID) { obj->header.gfx.sharedChild = dynos_model_get_geo(modelID); dynos_actor_override(obj, (void*)&obj->header.gfx.sharedChild); - smlua_call_event_hooks_object_set_model(HOOK_OBJECT_SET_MODEL, obj, modelID, smlua_model_util_id_to_ext_id(modelID)); + smlua_call_event_hooks(HOOK_OBJECT_SET_MODEL, obj, modelID, smlua_model_util_id_to_ext_id(modelID)); } void mario_set_flag(s32 flag) { diff --git a/src/game/object_list_processor.c b/src/game/object_list_processor.c index d707ab8e7..ec0534d05 100644 --- a/src/game/object_list_processor.c +++ b/src/game/object_list_processor.c @@ -285,10 +285,10 @@ void bhv_mario_update(void) { gMarioState->particleFlags = 0; } - smlua_call_event_hooks_mario_param(HOOK_BEFORE_MARIO_UPDATE, gMarioState); + smlua_call_event_hooks(HOOK_BEFORE_MARIO_UPDATE, gMarioState); u32 particleFlags = execute_mario_action(gCurrentObject); - smlua_call_event_hooks_mario_param(HOOK_MARIO_UPDATE, gMarioState); + smlua_call_event_hooks(HOOK_MARIO_UPDATE, gMarioState); particleFlags |= gMarioState->particleFlags; gCurrentObject->oMarioParticleFlags = particleFlags; diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index 687e5340f..e4699d835 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -1258,7 +1258,7 @@ static void geo_process_object(struct Object *node) { } if (node->hookRender) { - smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_RENDER, node); + smlua_call_event_hooks(HOOK_ON_OBJECT_RENDER, node); } if (node->header.gfx.node.flags & GRAPH_RENDER_PLAYER) { @@ -1376,7 +1376,7 @@ static void geo_process_object(struct Object *node) { if (node->header.gfx.animInfo.curAnim != NULL) { dynos_gfx_swap_animations(node); geo_set_animation_globals(&node->header.gfx.animInfo, hasAnimation); - if (node->hookRender) smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_ANIM_UPDATE, node); + if (node->hookRender) smlua_call_event_hooks(HOOK_ON_OBJECT_ANIM_UPDATE, node); dynos_gfx_swap_animations(node); } if (obj_is_in_view(&node->header.gfx, gMatStack[gMatStackIndex])) { @@ -1505,7 +1505,7 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { if (node->objNode->header.gfx.animInfo.curAnim != NULL) { dynos_gfx_swap_animations(node->objNode); geo_set_animation_globals(&node->objNode->header.gfx.animInfo, hasAnimation); - if (node->objNode->hookRender) smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_ANIM_UPDATE, node->objNode); + if (node->objNode->hookRender) smlua_call_event_hooks(HOOK_ON_OBJECT_ANIM_UPDATE, node->objNode); dynos_gfx_swap_animations(node->objNode); } @@ -1555,7 +1555,7 @@ void geo_process_node_and_siblings(struct GraphNode *firstNode) { if (parent != NULL) { iterateChildren = (parent->type != GRAPH_NODE_TYPE_SWITCH_CASE); - if (parent->hookProcess) smlua_call_event_hooks_graph_node_and_int_param(HOOK_ON_GEO_PROCESS_CHILDREN, parent, gMatStackIndex); + if (parent->hookProcess) smlua_call_event_hooks(HOOK_ON_GEO_PROCESS_CHILDREN, parent, gMatStackIndex); } do { @@ -1584,7 +1584,7 @@ void geo_process_node_and_siblings(struct GraphNode *firstNode) { } if (curGraphNode->flags & GRAPH_RENDER_ACTIVE) { - if (curGraphNode->hookProcess) smlua_call_event_hooks_graph_node_and_int_param(HOOK_BEFORE_GEO_PROCESS, curGraphNode, gMatStackIndex); + if (curGraphNode->hookProcess) smlua_call_event_hooks(HOOK_BEFORE_GEO_PROCESS, curGraphNode, gMatStackIndex); if (curGraphNode->flags & GRAPH_RENDER_CHILDREN_FIRST) { geo_try_process_children(curGraphNode); } else { @@ -1652,7 +1652,7 @@ void geo_process_node_and_siblings(struct GraphNode *firstNode) { break; } } - if (curGraphNode->hookProcess) smlua_call_event_hooks_graph_node_and_int_param(HOOK_ON_GEO_PROCESS, curGraphNode, gMatStackIndex + 1); + if (curGraphNode->hookProcess) smlua_call_event_hooks(HOOK_ON_GEO_PROCESS, curGraphNode, gMatStackIndex + 1); } else { if (curGraphNode && curGraphNode->type == GRAPH_NODE_TYPE_OBJECT) { ((struct GraphNodeObject *) curGraphNode)->throwMatrix = NULL; diff --git a/src/game/spawn_object.c b/src/game/spawn_object.c index 438e1e6e1..c0e6f40a3 100644 --- a/src/game/spawn_object.c +++ b/src/game/spawn_object.c @@ -239,13 +239,13 @@ void unload_object(struct Object *obj) { sync_object_forget(so->id); } - smlua_call_event_hooks_object_param(HOOK_ON_SYNC_OBJECT_UNLOAD, obj); + smlua_call_event_hooks(HOOK_ON_SYNC_OBJECT_UNLOAD, obj); } obj->firstSurface = 0; obj->numSurfaces = 0; - smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_UNLOAD, obj); + smlua_call_event_hooks(HOOK_ON_OBJECT_UNLOAD, obj); deallocate_object(&gFreeObjectList, &obj->header); } @@ -411,7 +411,7 @@ struct Object *create_object(const BehaviorScript *bhvScript) { break; } - smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_LOAD, obj); + smlua_call_event_hooks(HOOK_ON_OBJECT_LOAD, obj); return obj; } diff --git a/src/pc/djui/djui.c b/src/pc/djui/djui.c index 405f51afc..bee49721c 100644 --- a/src/pc/djui/djui.c +++ b/src/pc/djui/djui.c @@ -163,7 +163,7 @@ void djui_render(void) { djui_base_render(&sDjuiRootBehind->base); } - smlua_call_event_on_hud_render(djui_reset_hud_params); + smlua_call_event_hooks(HOOK_ON_HUD_RENDER, djui_reset_hud_params); djui_panel_update(); djui_popup_update(); diff --git a/src/pc/djui/djui_chat_message.c b/src/pc/djui/djui_chat_message.c index 17ebe564d..6bb9028a4 100644 --- a/src/pc/djui/djui_chat_message.c +++ b/src/pc/djui/djui_chat_message.c @@ -55,9 +55,9 @@ void djui_chat_message_create_from(u8 globalIndex, const char* message) { return; } - bool returnValue = true; - smlua_call_event_hooks_on_chat_message(HOOK_ON_CHAT_MESSAGE, &gMarioStates[np->localIndex], message, &returnValue); - if (!returnValue) { + bool allowMessage = true; + smlua_call_event_hooks(HOOK_ON_CHAT_MESSAGE, &gMarioStates[np->localIndex], message, &allowMessage); + if (!allowMessage) { return; } diff --git a/src/pc/djui/djui_panel_language.c b/src/pc/djui/djui_panel_language.c index b70a56c3e..b286a3a5e 100644 --- a/src/pc/djui/djui_panel_language.c +++ b/src/pc/djui/djui_panel_language.c @@ -41,7 +41,7 @@ static void select_language(struct DjuiBase* caller) { if (strcmp(configLanguage, langName)) { snprintf(configLanguage, MAX_CONFIG_STRING, "%s", langName); sLanguageChanged = true; - smlua_call_event_hooks_string_param(HOOK_ON_LANGUAGE_CHANGED, configLanguage); + smlua_call_event_hooks(HOOK_ON_LANGUAGE_CHANGED, configLanguage); } checkbox->value = &sTrue; diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 86aaeea9b..3e7fe0b8f 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -3257,15 +3257,6 @@ char gSmluaConstants[] = "" "HOOK_ON_ADD_SURFACE=57\n" "HOOK_ON_CLEAR_AREAS=58\n" "HOOK_MAX=59\n" -"ACTION_HOOK_EVERY_FRAME=0\n" -"ACTION_HOOK_GRAVITY=1\n" -"ACTION_HOOK_MAX=2\n" -"MOD_MENU_ELEMENT_TEXT=0\n" -"MOD_MENU_ELEMENT_BUTTON=1\n" -"MOD_MENU_ELEMENT_CHECKBOX=2\n" -"MOD_MENU_ELEMENT_SLIDER=3\n" -"MOD_MENU_ELEMENT_INPUTBOX=4\n" -"MOD_MENU_ELEMENT_MAX=5\n" "HUD_DISPLAY_LIVES=0\n" "HUD_DISPLAY_COINS=1\n" "HUD_DISPLAY_STARS=2\n" diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 5b9edfe53..1f7fce0ed 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -59,115 +59,304 @@ // vec types // /////////////// -static void smlua_get_vec2f(Vec2f dest, int index) { +void smlua_new_vec2f(Vec2f src) { + struct lua_State *L = gLuaState; + lua_newtable(L); + int tableIndex = lua_gettop(L); + lua_pushstring(L, "x"); + lua_pushnumber(L, src[0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "y"); + lua_pushnumber(L, src[1]); + lua_settable(L, tableIndex); +} + +void smlua_get_vec2f(Vec2f dest, int index) { dest[0] = smlua_get_number_field(index, "x"); dest[1] = smlua_get_number_field(index, "y"); } -static void smlua_push_vec2f(Vec2f src, int index) { +void smlua_push_vec2f(Vec2f src, int index) { smlua_push_number_field(index, "x", src[0]); smlua_push_number_field(index, "y", src[1]); } -static void smlua_get_vec3f(Vec3f dest, int index) { +void smlua_new_vec3f(Vec3f src) { + struct lua_State *L = gLuaState; + lua_newtable(L); + int tableIndex = lua_gettop(L); + lua_pushstring(L, "x"); + lua_pushnumber(L, src[0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "y"); + lua_pushnumber(L, src[1]); + lua_settable(L, tableIndex); + lua_pushstring(L, "z"); + lua_pushnumber(L, src[2]); + lua_settable(L, tableIndex); +} + +void smlua_get_vec3f(Vec3f dest, int index) { dest[0] = smlua_get_number_field(index, "x"); dest[1] = smlua_get_number_field(index, "y"); dest[2] = smlua_get_number_field(index, "z"); } -static void smlua_push_vec3f(Vec3f src, int index) { +void smlua_push_vec3f(Vec3f src, int index) { smlua_push_number_field(index, "x", src[0]); smlua_push_number_field(index, "y", src[1]); smlua_push_number_field(index, "z", src[2]); } -static void smlua_get_vec4f(Vec4f dest, int index) { +void smlua_new_vec4f(Vec4f src) { + struct lua_State *L = gLuaState; + lua_newtable(L); + int tableIndex = lua_gettop(L); + lua_pushstring(L, "x"); + lua_pushnumber(L, src[0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "y"); + lua_pushnumber(L, src[1]); + lua_settable(L, tableIndex); + lua_pushstring(L, "z"); + lua_pushnumber(L, src[2]); + lua_settable(L, tableIndex); + lua_pushstring(L, "w"); + lua_pushnumber(L, src[3]); + lua_settable(L, tableIndex); +} + +void smlua_get_vec4f(Vec4f dest, int index) { dest[0] = smlua_get_number_field(index, "x"); dest[1] = smlua_get_number_field(index, "y"); dest[2] = smlua_get_number_field(index, "z"); dest[3] = smlua_get_number_field(index, "w"); } -static void smlua_push_vec4f(Vec4f src, int index) { +void smlua_push_vec4f(Vec4f src, int index) { smlua_push_number_field(index, "x", src[0]); smlua_push_number_field(index, "y", src[1]); smlua_push_number_field(index, "z", src[2]); smlua_push_number_field(index, "w", src[3]); } -static void smlua_get_vec2i(Vec2i dest, int index) { +void smlua_new_vec2i(Vec2i src) { + struct lua_State *L = gLuaState; + lua_newtable(L); + int tableIndex = lua_gettop(L); + lua_pushstring(L, "x"); + lua_pushinteger(L, src[0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "y"); + lua_pushinteger(L, src[1]); + lua_settable(L, tableIndex); +} + +void smlua_get_vec2i(Vec2i dest, int index) { dest[0] = smlua_get_integer_field(index, "x"); dest[1] = smlua_get_integer_field(index, "y"); } -static void smlua_push_vec2i(Vec2i src, int index) { +void smlua_push_vec2i(Vec2i src, int index) { smlua_push_integer_field(index, "x", src[0]); smlua_push_integer_field(index, "y", src[1]); } -static void smlua_get_vec3i(Vec3i dest, int index) { +void smlua_new_vec3i(Vec3i src) { + struct lua_State *L = gLuaState; + lua_newtable(L); + int tableIndex = lua_gettop(L); + lua_pushstring(L, "x"); + lua_pushinteger(L, src[0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "y"); + lua_pushinteger(L, src[1]); + lua_settable(L, tableIndex); + lua_pushstring(L, "z"); + lua_pushinteger(L, src[2]); + lua_settable(L, tableIndex); +} + +void smlua_get_vec3i(Vec3i dest, int index) { dest[0] = smlua_get_integer_field(index, "x"); dest[1] = smlua_get_integer_field(index, "y"); dest[2] = smlua_get_integer_field(index, "z"); } -static void smlua_push_vec3i(Vec3i src, int index) { +void smlua_push_vec3i(Vec3i src, int index) { smlua_push_integer_field(index, "x", src[0]); smlua_push_integer_field(index, "y", src[1]); smlua_push_integer_field(index, "z", src[2]); } -static void smlua_get_vec4i(Vec4i dest, int index) { +void smlua_new_vec4i(Vec4i src) { + struct lua_State *L = gLuaState; + lua_newtable(L); + int tableIndex = lua_gettop(L); + lua_pushstring(L, "x"); + lua_pushinteger(L, src[0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "y"); + lua_pushinteger(L, src[1]); + lua_settable(L, tableIndex); + lua_pushstring(L, "z"); + lua_pushinteger(L, src[2]); + lua_settable(L, tableIndex); + lua_pushstring(L, "w"); + lua_pushinteger(L, src[3]); + lua_settable(L, tableIndex); +} + +void smlua_get_vec4i(Vec4i dest, int index) { dest[0] = smlua_get_integer_field(index, "x"); dest[1] = smlua_get_integer_field(index, "y"); dest[2] = smlua_get_integer_field(index, "z"); dest[3] = smlua_get_integer_field(index, "w"); } -static void smlua_push_vec4i(Vec4i src, int index) { +void smlua_push_vec4i(Vec4i src, int index) { smlua_push_integer_field(index, "x", src[0]); smlua_push_integer_field(index, "y", src[1]); smlua_push_integer_field(index, "z", src[2]); smlua_push_integer_field(index, "w", src[3]); } -static void smlua_get_vec2s(Vec2s dest, int index) { +void smlua_new_vec2s(Vec2s src) { + struct lua_State *L = gLuaState; + lua_newtable(L); + int tableIndex = lua_gettop(L); + lua_pushstring(L, "x"); + lua_pushinteger(L, src[0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "y"); + lua_pushinteger(L, src[1]); + lua_settable(L, tableIndex); +} + +void smlua_get_vec2s(Vec2s dest, int index) { dest[0] = smlua_get_integer_field(index, "x"); dest[1] = smlua_get_integer_field(index, "y"); } -static void smlua_push_vec2s(Vec2s src, int index) { +void smlua_push_vec2s(Vec2s src, int index) { smlua_push_integer_field(index, "x", src[0]); smlua_push_integer_field(index, "y", src[1]); } -static void smlua_get_vec3s(Vec3s dest, int index) { +void smlua_new_vec3s(Vec3s src) { + struct lua_State *L = gLuaState; + lua_newtable(L); + int tableIndex = lua_gettop(L); + lua_pushstring(L, "x"); + lua_pushinteger(L, src[0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "y"); + lua_pushinteger(L, src[1]); + lua_settable(L, tableIndex); + lua_pushstring(L, "z"); + lua_pushinteger(L, src[2]); + lua_settable(L, tableIndex); +} + +void smlua_get_vec3s(Vec3s dest, int index) { dest[0] = smlua_get_integer_field(index, "x"); dest[1] = smlua_get_integer_field(index, "y"); dest[2] = smlua_get_integer_field(index, "z"); } -static void smlua_push_vec3s(Vec3s src, int index) { +void smlua_push_vec3s(Vec3s src, int index) { smlua_push_integer_field(index, "x", src[0]); smlua_push_integer_field(index, "y", src[1]); smlua_push_integer_field(index, "z", src[2]); } -static void smlua_get_vec4s(Vec4s dest, int index) { +void smlua_new_vec4s(Vec4s src) { + struct lua_State *L = gLuaState; + lua_newtable(L); + int tableIndex = lua_gettop(L); + lua_pushstring(L, "x"); + lua_pushinteger(L, src[0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "y"); + lua_pushinteger(L, src[1]); + lua_settable(L, tableIndex); + lua_pushstring(L, "z"); + lua_pushinteger(L, src[2]); + lua_settable(L, tableIndex); + lua_pushstring(L, "w"); + lua_pushinteger(L, src[3]); + lua_settable(L, tableIndex); +} + +void smlua_get_vec4s(Vec4s dest, int index) { dest[0] = smlua_get_integer_field(index, "x"); dest[1] = smlua_get_integer_field(index, "y"); dest[2] = smlua_get_integer_field(index, "z"); dest[3] = smlua_get_integer_field(index, "w"); } -static void smlua_push_vec4s(Vec4s src, int index) { +void smlua_push_vec4s(Vec4s src, int index) { smlua_push_integer_field(index, "x", src[0]); smlua_push_integer_field(index, "y", src[1]); smlua_push_integer_field(index, "z", src[2]); smlua_push_integer_field(index, "w", src[3]); } -static void smlua_get_mat4(Mat4 dest, int index) { +void smlua_new_mat4(Mat4 src) { + struct lua_State *L = gLuaState; + lua_newtable(L); + int tableIndex = lua_gettop(L); + lua_pushstring(L, "m00"); + lua_pushnumber(L, src[0][0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m01"); + lua_pushnumber(L, src[0][1]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m02"); + lua_pushnumber(L, src[0][2]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m03"); + lua_pushnumber(L, src[0][3]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m10"); + lua_pushnumber(L, src[1][0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m11"); + lua_pushnumber(L, src[1][1]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m12"); + lua_pushnumber(L, src[1][2]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m13"); + lua_pushnumber(L, src[1][3]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m20"); + lua_pushnumber(L, src[2][0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m21"); + lua_pushnumber(L, src[2][1]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m22"); + lua_pushnumber(L, src[2][2]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m23"); + lua_pushnumber(L, src[2][3]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m30"); + lua_pushnumber(L, src[3][0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m31"); + lua_pushnumber(L, src[3][1]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m32"); + lua_pushnumber(L, src[3][2]); + lua_settable(L, tableIndex); + lua_pushstring(L, "m33"); + lua_pushnumber(L, src[3][3]); + lua_settable(L, tableIndex); +} + +void smlua_get_mat4(Mat4 dest, int index) { dest[0][0] = smlua_get_number_field(index, "m00"); dest[0][1] = smlua_get_number_field(index, "m01"); dest[0][2] = smlua_get_number_field(index, "m02"); @@ -186,7 +375,7 @@ static void smlua_get_mat4(Mat4 dest, int index) { dest[3][3] = smlua_get_number_field(index, "m33"); } -static void smlua_push_mat4(Mat4 src, int index) { +void smlua_push_mat4(Mat4 src, int index) { smlua_push_number_field(index, "m00", src[0][0]); smlua_push_number_field(index, "m01", src[0][1]); smlua_push_number_field(index, "m02", src[0][2]); @@ -221,13 +410,28 @@ static void smlua_push_mat4(Mat4 src, int index) { smlua_push_number_field(index, "p", src[3][3]); } -static void smlua_get_color(Color dest, int index) { +void smlua_new_color(Color src) { + struct lua_State *L = gLuaState; + lua_newtable(L); + int tableIndex = lua_gettop(L); + lua_pushstring(L, "r"); + lua_pushinteger(L, src[0]); + lua_settable(L, tableIndex); + lua_pushstring(L, "g"); + lua_pushinteger(L, src[1]); + lua_settable(L, tableIndex); + lua_pushstring(L, "b"); + lua_pushinteger(L, src[2]); + lua_settable(L, tableIndex); +} + +void smlua_get_color(Color dest, int index) { dest[0] = smlua_get_integer_field(index, "r"); dest[1] = smlua_get_integer_field(index, "g"); dest[2] = smlua_get_integer_field(index, "b"); } -static void smlua_push_color(Color src, int index) { +void smlua_push_color(Color src, int index) { smlua_push_integer_field(index, "r", src[0]); smlua_push_integer_field(index, "g", src[1]); smlua_push_integer_field(index, "b", src[2]); diff --git a/src/pc/lua/smlua_hook_events.inl b/src/pc/lua/smlua_hook_events.inl new file mode 100644 index 000000000..ec7c9a07c --- /dev/null +++ b/src/pc/lua/smlua_hook_events.inl @@ -0,0 +1,59 @@ +SMLUA_EVENT_HOOK(HOOK_UPDATE, HOOK_RETURN_NEVER) +SMLUA_EVENT_HOOK(HOOK_MARIO_UPDATE, HOOK_RETURN_NEVER, struct MarioState *m) +SMLUA_EVENT_HOOK(HOOK_BEFORE_MARIO_UPDATE, HOOK_RETURN_NEVER, struct MarioState *m) +SMLUA_EVENT_HOOK(HOOK_ON_SET_MARIO_ACTION, HOOK_RETURN_NEVER, struct MarioState *m) +SMLUA_EVENT_HOOK(HOOK_BEFORE_PHYS_STEP, HOOK_RETURN_ON_OUTPUT_SET, struct MarioState *m, s32 stepType, u32 stepArg, OUTPUT s32 *stepResultOverride) +SMLUA_EVENT_HOOK(HOOK_ALLOW_PVP_ATTACK, HOOK_RETURN_NEVER, struct MarioState *attacker, struct MarioState *victim, u32 interaction, OUTPUT bool *allowAttack) +SMLUA_EVENT_HOOK(HOOK_ON_PVP_ATTACK, HOOK_RETURN_NEVER, struct MarioState *attacker, struct MarioState *victim, u32 interaction) +SMLUA_EVENT_HOOK(HOOK_ON_PLAYER_CONNECTED, HOOK_RETURN_NEVER, struct MarioState *m) +SMLUA_EVENT_HOOK(HOOK_ON_PLAYER_DISCONNECTED, HOOK_RETURN_NEVER, struct MarioState *m) +SMLUA_EVENT_HOOK(HOOK_ON_HUD_RENDER, _, void (*resetFunc)(void)) // Manually defined hook +SMLUA_EVENT_HOOK(HOOK_ALLOW_INTERACT, HOOK_RETURN_NEVER, struct MarioState *m, struct Object *obj, u32 interactType, OUTPUT bool *allowInteract) +SMLUA_EVENT_HOOK(HOOK_ON_INTERACT, HOOK_RETURN_NEVER, struct MarioState *m, struct Object *obj, u32 interactType, bool interactValue) +SMLUA_EVENT_HOOK(HOOK_ON_LEVEL_INIT, HOOK_RETURN_NEVER, u8 warpType, s16 levelNum, u8 areaIdx, u8 nodeId, u32 warpArg) +SMLUA_EVENT_HOOK(HOOK_ON_WARP, HOOK_RETURN_NEVER, u8 warpType, s16 levelNum, u8 areaIdx, u8 nodeId, u32 warpArg) +SMLUA_EVENT_HOOK(HOOK_ON_SYNC_VALID, HOOK_RETURN_NEVER) +SMLUA_EVENT_HOOK(HOOK_ON_OBJECT_UNLOAD, HOOK_RETURN_NEVER, struct Object *obj) +SMLUA_EVENT_HOOK(HOOK_ON_SYNC_OBJECT_UNLOAD, HOOK_RETURN_NEVER, struct Object *obj) +SMLUA_EVENT_HOOK(HOOK_ON_PAUSE_EXIT, HOOK_RETURN_NEVER, bool usedExitToCastle, OUTPUT bool *allowExit) +SMLUA_EVENT_HOOK(HOOK_GET_STAR_COLLECTION_DIALOG, HOOK_RETURN_ON_SUCCESSFUL_CALL, OUTPUT s32 *dialogID) +SMLUA_EVENT_HOOK(HOOK_ON_SET_CAMERA_MODE, HOOK_RETURN_NEVER, struct Camera *c, s16 mode, s16 frames, OUTPUT bool *allowSetCameraMode) +SMLUA_EVENT_HOOK(HOOK_ON_OBJECT_RENDER, HOOK_RETURN_NEVER, struct Object *obj) +SMLUA_EVENT_HOOK(HOOK_ON_DEATH, HOOK_RETURN_NEVER, struct MarioState *m, OUTPUT bool *allowDeath) +SMLUA_EVENT_HOOK(HOOK_ON_PACKET_RECEIVE, HOOK_RETURN_NEVER, s32 modIndex, s32 valueIndex) +SMLUA_EVENT_HOOK(HOOK_USE_ACT_SELECT, HOOK_RETURN_ON_OUTPUT_SET, s32 levelNum, OUTPUT bool *useActSelect) +SMLUA_EVENT_HOOK(HOOK_ON_CHANGE_CAMERA_ANGLE, HOOK_RETURN_NEVER, s32 camAngleType, OUTPUT bool *allowSetCamAngle) +SMLUA_EVENT_HOOK(HOOK_ON_SCREEN_TRANSITION, HOOK_RETURN_NEVER, s32 transitionType, OUTPUT bool *allowPlayTransition) +SMLUA_EVENT_HOOK(HOOK_ALLOW_HAZARD_SURFACE, HOOK_RETURN_NEVER, struct MarioState *m, s32 hazardType, OUTPUT bool *allowHazard) +SMLUA_EVENT_HOOK(HOOK_ON_CHAT_MESSAGE, HOOK_RETURN_NEVER, struct MarioState *m, const char *message, OUTPUT bool *allowMessage) +SMLUA_EVENT_HOOK(HOOK_OBJECT_SET_MODEL, HOOK_RETURN_NEVER, struct Object *obj, s32 modelID, enum ModelExtendedId modelExtendedId) +SMLUA_EVENT_HOOK(HOOK_CHARACTER_SOUND, HOOK_RETURN_ON_OUTPUT_SET, struct MarioState *m, enum CharacterSound characterSound, OUTPUT s32 *soundOverride) +SMLUA_EVENT_HOOK(HOOK_BEFORE_SET_MARIO_ACTION, HOOK_RETURN_NEVER, struct MarioState *m, u32 action, u32 actionArg, OUTPUT u32 *actionOverride) +SMLUA_EVENT_HOOK(HOOK_JOINED_GAME, HOOK_RETURN_NEVER) +SMLUA_EVENT_HOOK(HOOK_ON_OBJECT_ANIM_UPDATE, HOOK_RETURN_NEVER, struct Object *obj) +SMLUA_EVENT_HOOK(HOOK_ON_DIALOG, HOOK_RETURN_NEVER, s32 dialogID, OUTPUT bool *openDialogBox, OUTPUT const char **dialogTextOverride) +SMLUA_EVENT_HOOK(HOOK_ON_EXIT, HOOK_RETURN_NEVER) +SMLUA_EVENT_HOOK(HOOK_DIALOG_SOUND, HOOK_RETURN_ON_OUTPUT_SET, s32 speaker, OUTPUT s32 *speakerOverride) +SMLUA_EVENT_HOOK(HOOK_ON_HUD_RENDER_BEHIND, _, void (*resetFunc)(void)) // Manually defined hook +SMLUA_EVENT_HOOK(HOOK_ON_COLLIDE_LEVEL_BOUNDS, HOOK_RETURN_NEVER, struct MarioState *m) +SMLUA_EVENT_HOOK(HOOK_MIRROR_MARIO_RENDER, HOOK_RETURN_NEVER, struct GraphNodeObject *mirrorMario, s32 playerIndex) +SMLUA_EVENT_HOOK(HOOK_MARIO_OVERRIDE_PHYS_STEP_DEFACTO_SPEED, HOOK_RETURN_ON_SUCCESSFUL_CALL, struct MarioState *m, OUTPUT f32 *floorNormalY) +SMLUA_EVENT_HOOK(HOOK_ON_OBJECT_LOAD, HOOK_RETURN_NEVER, struct Object *obj) +SMLUA_EVENT_HOOK(HOOK_ON_PLAY_SOUND, HOOK_RETURN_ON_OUTPUT_SET, s32 soundBits, Vec3f pos, OUTPUT s32 *soundBitsOverride) +SMLUA_EVENT_HOOK(HOOK_ON_SEQ_LOAD, HOOK_RETURN_ON_OUTPUT_SET, u32 seqPlayer, u32 seqId, s32 loadAsync, OUTPUT u32 *seqIdOverride) +SMLUA_EVENT_HOOK(HOOK_ON_ATTACK_OBJECT, HOOK_RETURN_NEVER, struct MarioState *m, struct Object *obj, s32 interaction) +SMLUA_EVENT_HOOK(HOOK_ON_LANGUAGE_CHANGED, HOOK_RETURN_NEVER, const char *langName) +SMLUA_EVENT_HOOK(HOOK_ON_MODS_LOADED, HOOK_RETURN_NEVER) +SMLUA_EVENT_HOOK(HOOK_ON_NAMETAGS_RENDER, _, s32 playerIndex, Vec3f pos, OUTPUT const char **playerNameOverride) // Manually defined hook +SMLUA_EVENT_HOOK(HOOK_ON_DJUI_THEME_CHANGED, HOOK_RETURN_NEVER) +SMLUA_EVENT_HOOK(HOOK_ON_GEO_PROCESS, HOOK_RETURN_NEVER, struct GraphNode *node, s32 matStackIndex) +SMLUA_EVENT_HOOK(HOOK_BEFORE_GEO_PROCESS, HOOK_RETURN_NEVER, struct GraphNode *node, s32 matStackIndex) +SMLUA_EVENT_HOOK(HOOK_ON_GEO_PROCESS_CHILDREN, HOOK_RETURN_NEVER, struct GraphNode *parent, s32 matStackIndex) +SMLUA_EVENT_HOOK(HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS, HOOK_RETURN_NEVER, struct MarioState *m, OUTPUT bool *allowUpdateGeometryInputs) +SMLUA_EVENT_HOOK(HOOK_ON_INTERACTIONS, HOOK_RETURN_NEVER, struct MarioState *m) +SMLUA_EVENT_HOOK(HOOK_ALLOW_FORCE_WATER_ACTION, HOOK_RETURN_NEVER, struct MarioState *m, bool isInWaterAction, OUTPUT bool *allowForceAction) +SMLUA_EVENT_HOOK(HOOK_BEFORE_WARP, HOOK_RETURN_ON_OUTPUT_SET, s16 destLevel, s16 destArea, s16 destWarpNode, s32 arg, OUTPUT struct WarpDest *warpDestOverride) +SMLUA_EVENT_HOOK(HOOK_ON_INSTANT_WARP, HOOK_RETURN_NEVER, u8 areaIdx, u8 nodeId, Vec3s displacement) +SMLUA_EVENT_HOOK(HOOK_MARIO_OVERRIDE_FLOOR_CLASS, HOOK_RETURN_ON_OUTPUT_SET, struct MarioState *m, s32 floorClass, OUTPUT s32 *floorClassOverride) +SMLUA_EVENT_HOOK(HOOK_ON_ADD_SURFACE, HOOK_RETURN_NEVER, struct Surface *surface, bool dynamic) +SMLUA_EVENT_HOOK(HOOK_ON_CLEAR_AREAS, HOOK_RETURN_NEVER) diff --git a/src/pc/lua/smlua_hook_events_autogen.inl b/src/pc/lua/smlua_hook_events_autogen.inl new file mode 100644 index 000000000..3c9ac1386 --- /dev/null +++ b/src/pc/lua/smlua_hook_events_autogen.inl @@ -0,0 +1,1839 @@ +/* THIS FILE IS AUTO-GENERATED */ +/* DO NOT EDIT IT MANUALLY */ + + +bool smlua_call_event_hooks_HOOK_UPDATE() { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_UPDATE]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // call the callback + if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_UPDATE]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_MARIO_UPDATE(struct MarioState *m) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_MARIO_UPDATE]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // call the callback + if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_MARIO_UPDATE]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_BEFORE_MARIO_UPDATE(struct MarioState *m) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_BEFORE_MARIO_UPDATE]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // call the callback + if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_BEFORE_MARIO_UPDATE]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_SET_MARIO_ACTION(struct MarioState *m) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_SET_MARIO_ACTION]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // call the callback + if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_SET_MARIO_ACTION]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_BEFORE_PHYS_STEP(struct MarioState *m, s32 stepType, u32 stepArg, s32 *stepResultOverride) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_BEFORE_PHYS_STEP]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push stepType + lua_pushinteger(L, stepType); + + // push stepArg + lua_pushinteger(L, stepArg); + + // call the callback + if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_BEFORE_PHYS_STEP]); + continue; + } + + // return stepResultOverride + if (lua_type(L, -1) == LUA_TNUMBER) { + *stepResultOverride = smlua_to_integer(L, -1); + lua_settop(L, prevTop); + return true; + } + + lua_settop(L, prevTop); + } + return false; +} + +bool smlua_call_event_hooks_HOOK_ALLOW_PVP_ATTACK(struct MarioState *attacker, struct MarioState *victim, u32 interaction, bool *allowAttack) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ALLOW_PVP_ATTACK]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push attacker + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, attacker->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push victim + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, victim->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push interaction + lua_pushinteger(L, interaction); + + // call the callback + if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ALLOW_PVP_ATTACK]); + continue; + } + hookResult = true; + + // return allowAttack + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *allowAttack = smlua_to_boolean(L, -1); + } + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_PVP_ATTACK(struct MarioState *attacker, struct MarioState *victim, u32 interaction) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_PVP_ATTACK]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push attacker + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, attacker->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push victim + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, victim->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push interaction + lua_pushinteger(L, interaction); + + // call the callback + if (0 != smlua_call_hook(L, 3, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_PVP_ATTACK]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_PLAYER_CONNECTED(struct MarioState *m) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_PLAYER_CONNECTED]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // call the callback + if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_PLAYER_CONNECTED]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_PLAYER_DISCONNECTED(struct MarioState *m) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_PLAYER_DISCONNECTED]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // call the callback + if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_PLAYER_DISCONNECTED]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ALLOW_INTERACT(struct MarioState *m, struct Object *obj, u32 interactType, bool *allowInteract) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ALLOW_INTERACT]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push obj + smlua_push_object(L, LOT_OBJECT, obj, NULL); + + // push interactType + lua_pushinteger(L, interactType); + + // call the callback + if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ALLOW_INTERACT]); + continue; + } + hookResult = true; + + // return allowInteract + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *allowInteract = smlua_to_boolean(L, -1); + } + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_INTERACT(struct MarioState *m, struct Object *obj, u32 interactType, bool interactValue) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_INTERACT]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push obj + smlua_push_object(L, LOT_OBJECT, obj, NULL); + + // push interactType + lua_pushinteger(L, interactType); + + // push interactValue + lua_pushboolean(L, interactValue); + + // call the callback + if (0 != smlua_call_hook(L, 4, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_INTERACT]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_LEVEL_INIT(u8 warpType, s16 levelNum, u8 areaIdx, u8 nodeId, u32 warpArg) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_LEVEL_INIT]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push warpType + lua_pushinteger(L, warpType); + + // push levelNum + lua_pushinteger(L, levelNum); + + // push areaIdx + lua_pushinteger(L, areaIdx); + + // push nodeId + lua_pushinteger(L, nodeId); + + // push warpArg + lua_pushinteger(L, warpArg); + + // call the callback + if (0 != smlua_call_hook(L, 5, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_LEVEL_INIT]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_WARP(u8 warpType, s16 levelNum, u8 areaIdx, u8 nodeId, u32 warpArg) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_WARP]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push warpType + lua_pushinteger(L, warpType); + + // push levelNum + lua_pushinteger(L, levelNum); + + // push areaIdx + lua_pushinteger(L, areaIdx); + + // push nodeId + lua_pushinteger(L, nodeId); + + // push warpArg + lua_pushinteger(L, warpArg); + + // call the callback + if (0 != smlua_call_hook(L, 5, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_WARP]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_SYNC_VALID() { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_SYNC_VALID]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // call the callback + if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_SYNC_VALID]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_OBJECT_UNLOAD(struct Object *obj) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_OBJECT_UNLOAD]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push obj + smlua_push_object(L, LOT_OBJECT, obj, NULL); + + // call the callback + if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_OBJECT_UNLOAD]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_SYNC_OBJECT_UNLOAD(struct Object *obj) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_SYNC_OBJECT_UNLOAD]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push obj + smlua_push_object(L, LOT_OBJECT, obj, NULL); + + // call the callback + if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_SYNC_OBJECT_UNLOAD]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_PAUSE_EXIT(bool usedExitToCastle, bool *allowExit) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_PAUSE_EXIT]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push usedExitToCastle + lua_pushboolean(L, usedExitToCastle); + + // call the callback + if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_PAUSE_EXIT]); + continue; + } + hookResult = true; + + // return allowExit + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *allowExit = smlua_to_boolean(L, -1); + } + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_GET_STAR_COLLECTION_DIALOG(s32 *dialogID) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_GET_STAR_COLLECTION_DIALOG]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // call the callback + if (0 != smlua_call_hook(L, 0, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_GET_STAR_COLLECTION_DIALOG]); + continue; + } + + // return dialogID + if (lua_type(L, -1) == LUA_TNUMBER) { + *dialogID = smlua_to_integer(L, -1); + } + + lua_settop(L, prevTop); + return true; + } + return false; +} + +bool smlua_call_event_hooks_HOOK_ON_SET_CAMERA_MODE(struct Camera *c, s16 mode, s16 frames, bool *allowSetCameraMode) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_SET_CAMERA_MODE]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push c + smlua_push_object(L, LOT_CAMERA, c, NULL); + + // push mode + lua_pushinteger(L, mode); + + // push frames + lua_pushinteger(L, frames); + + // call the callback + if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_SET_CAMERA_MODE]); + continue; + } + hookResult = true; + + // return allowSetCameraMode + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *allowSetCameraMode = smlua_to_boolean(L, -1); + } + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_OBJECT_RENDER(struct Object *obj) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_OBJECT_RENDER]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push obj + smlua_push_object(L, LOT_OBJECT, obj, NULL); + + // call the callback + if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_OBJECT_RENDER]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_DEATH(struct MarioState *m, bool *allowDeath) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_DEATH]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // call the callback + if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_DEATH]); + continue; + } + hookResult = true; + + // return allowDeath + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *allowDeath = smlua_to_boolean(L, -1); + } + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_PACKET_RECEIVE(s32 modIndex, s32 valueIndex) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_PACKET_RECEIVE]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push modIndex + lua_pushinteger(L, modIndex); + + // push valueIndex + lua_pushinteger(L, valueIndex); + + // call the callback + if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_PACKET_RECEIVE]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_USE_ACT_SELECT(s32 levelNum, bool *useActSelect) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_USE_ACT_SELECT]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push levelNum + lua_pushinteger(L, levelNum); + + // call the callback + if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_USE_ACT_SELECT]); + continue; + } + + // return useActSelect + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *useActSelect = smlua_to_boolean(L, -1); + lua_settop(L, prevTop); + return true; + } + + lua_settop(L, prevTop); + } + return false; +} + +bool smlua_call_event_hooks_HOOK_ON_CHANGE_CAMERA_ANGLE(s32 camAngleType, bool *allowSetCamAngle) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_CHANGE_CAMERA_ANGLE]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push camAngleType + lua_pushinteger(L, camAngleType); + + // call the callback + if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_CHANGE_CAMERA_ANGLE]); + continue; + } + hookResult = true; + + // return allowSetCamAngle + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *allowSetCamAngle = smlua_to_boolean(L, -1); + } + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_SCREEN_TRANSITION(s32 transitionType, bool *allowPlayTransition) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_SCREEN_TRANSITION]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push transitionType + lua_pushinteger(L, transitionType); + + // call the callback + if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_SCREEN_TRANSITION]); + continue; + } + hookResult = true; + + // return allowPlayTransition + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *allowPlayTransition = smlua_to_boolean(L, -1); + } + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ALLOW_HAZARD_SURFACE(struct MarioState *m, s32 hazardType, bool *allowHazard) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ALLOW_HAZARD_SURFACE]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push hazardType + lua_pushinteger(L, hazardType); + + // call the callback + if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ALLOW_HAZARD_SURFACE]); + continue; + } + hookResult = true; + + // return allowHazard + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *allowHazard = smlua_to_boolean(L, -1); + } + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_CHAT_MESSAGE(struct MarioState *m, const char *message, bool *allowMessage) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_CHAT_MESSAGE]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push message + lua_pushstring(L, message); + + // call the callback + if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_CHAT_MESSAGE]); + continue; + } + hookResult = true; + + // return allowMessage + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *allowMessage = smlua_to_boolean(L, -1); + } + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_OBJECT_SET_MODEL(struct Object *obj, s32 modelID, enum ModelExtendedId modelExtendedId) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_OBJECT_SET_MODEL]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push obj + smlua_push_object(L, LOT_OBJECT, obj, NULL); + + // push modelID + lua_pushinteger(L, modelID); + + // push modelExtendedId + lua_pushinteger(L, modelExtendedId); + + // call the callback + if (0 != smlua_call_hook(L, 3, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_OBJECT_SET_MODEL]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_CHARACTER_SOUND(struct MarioState *m, enum CharacterSound characterSound, s32 *soundOverride) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_CHARACTER_SOUND]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push characterSound + lua_pushinteger(L, characterSound); + + // call the callback + if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_CHARACTER_SOUND]); + continue; + } + + // return soundOverride + if (lua_type(L, -1) == LUA_TNUMBER) { + *soundOverride = smlua_to_integer(L, -1); + lua_settop(L, prevTop); + return true; + } + + lua_settop(L, prevTop); + } + return false; +} + +bool smlua_call_event_hooks_HOOK_BEFORE_SET_MARIO_ACTION(struct MarioState *m, u32 action, u32 actionArg, u32 *actionOverride) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_BEFORE_SET_MARIO_ACTION]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push action + lua_pushinteger(L, action); + + // push actionArg + lua_pushinteger(L, actionArg); + + // call the callback + if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_BEFORE_SET_MARIO_ACTION]); + continue; + } + hookResult = true; + + // return actionOverride + if (lua_type(L, -1) == LUA_TNUMBER) { + *actionOverride = smlua_to_integer(L, -1); + } + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_JOINED_GAME() { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_JOINED_GAME]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // call the callback + if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_JOINED_GAME]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_OBJECT_ANIM_UPDATE(struct Object *obj) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_OBJECT_ANIM_UPDATE]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push obj + smlua_push_object(L, LOT_OBJECT, obj, NULL); + + // call the callback + if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_OBJECT_ANIM_UPDATE]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_DIALOG(s32 dialogID, bool *openDialogBox, const char **dialogTextOverride) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_DIALOG]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push dialogID + lua_pushinteger(L, dialogID); + + // call the callback + if (0 != smlua_call_hook(L, 1, 2, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_DIALOG]); + continue; + } + hookResult = true; + + // return openDialogBox + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *openDialogBox = smlua_to_boolean(L, -1); + } + + // return dialogTextOverride + if (lua_type(L, -2) == LUA_TSTRING) { + *dialogTextOverride = smlua_to_string(L, -2); + } + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_EXIT() { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_EXIT]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // call the callback + if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_EXIT]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_DIALOG_SOUND(s32 speaker, s32 *speakerOverride) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_DIALOG_SOUND]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push speaker + lua_pushinteger(L, speaker); + + // call the callback + if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_DIALOG_SOUND]); + continue; + } + + // return speakerOverride + if (lua_type(L, -1) == LUA_TNUMBER) { + *speakerOverride = smlua_to_integer(L, -1); + lua_settop(L, prevTop); + return true; + } + + lua_settop(L, prevTop); + } + return false; +} + +bool smlua_call_event_hooks_HOOK_ON_COLLIDE_LEVEL_BOUNDS(struct MarioState *m) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_COLLIDE_LEVEL_BOUNDS]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // call the callback + if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_COLLIDE_LEVEL_BOUNDS]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_MIRROR_MARIO_RENDER(struct GraphNodeObject *mirrorMario, s32 playerIndex) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_MIRROR_MARIO_RENDER]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push mirrorMario + smlua_push_object(L, LOT_GRAPHNODEOBJECT, mirrorMario, NULL); + + // push playerIndex + lua_pushinteger(L, playerIndex); + + // call the callback + if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_MIRROR_MARIO_RENDER]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_MARIO_OVERRIDE_PHYS_STEP_DEFACTO_SPEED(struct MarioState *m, f32 *floorNormalY) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_MARIO_OVERRIDE_PHYS_STEP_DEFACTO_SPEED]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // call the callback + if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_MARIO_OVERRIDE_PHYS_STEP_DEFACTO_SPEED]); + continue; + } + + // return floorNormalY + if (lua_type(L, -1) == LUA_TNUMBER) { + *floorNormalY = smlua_to_number(L, -1); + } + + lua_settop(L, prevTop); + return true; + } + return false; +} + +bool smlua_call_event_hooks_HOOK_ON_OBJECT_LOAD(struct Object *obj) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_OBJECT_LOAD]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push obj + smlua_push_object(L, LOT_OBJECT, obj, NULL); + + // call the callback + if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_OBJECT_LOAD]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_PLAY_SOUND(s32 soundBits, Vec3f pos, s32 *soundBitsOverride) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_PLAY_SOUND]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push soundBits + lua_pushinteger(L, soundBits); + + // push pos + extern void smlua_new_vec3f(Vec3f src); + smlua_new_vec3f(pos); + + // call the callback + if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_PLAY_SOUND]); + continue; + } + + // return soundBitsOverride + if (lua_type(L, -1) == LUA_TNUMBER) { + *soundBitsOverride = smlua_to_integer(L, -1); + lua_settop(L, prevTop); + return true; + } + + lua_settop(L, prevTop); + } + return false; +} + +bool smlua_call_event_hooks_HOOK_ON_SEQ_LOAD(u32 seqPlayer, u32 seqId, s32 loadAsync, u32 *seqIdOverride) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_SEQ_LOAD]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push seqPlayer + lua_pushinteger(L, seqPlayer); + + // push seqId + lua_pushinteger(L, seqId); + + // push loadAsync + lua_pushinteger(L, loadAsync); + + // call the callback + if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_SEQ_LOAD]); + continue; + } + + // return seqIdOverride + if (lua_type(L, -1) == LUA_TNUMBER) { + *seqIdOverride = smlua_to_integer(L, -1); + lua_settop(L, prevTop); + return true; + } + + lua_settop(L, prevTop); + } + return false; +} + +bool smlua_call_event_hooks_HOOK_ON_ATTACK_OBJECT(struct MarioState *m, struct Object *obj, s32 interaction) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_ATTACK_OBJECT]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push obj + smlua_push_object(L, LOT_OBJECT, obj, NULL); + + // push interaction + lua_pushinteger(L, interaction); + + // call the callback + if (0 != smlua_call_hook(L, 3, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_ATTACK_OBJECT]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_LANGUAGE_CHANGED(const char *langName) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_LANGUAGE_CHANGED]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push langName + lua_pushstring(L, langName); + + // call the callback + if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_LANGUAGE_CHANGED]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_MODS_LOADED() { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_MODS_LOADED]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // call the callback + if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_MODS_LOADED]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_DJUI_THEME_CHANGED() { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_DJUI_THEME_CHANGED]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // call the callback + if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_DJUI_THEME_CHANGED]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_GEO_PROCESS(struct GraphNode *node, s32 matStackIndex) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_GEO_PROCESS]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push node + smlua_push_object(L, LOT_GRAPHNODE, node, NULL); + + // push matStackIndex + lua_pushinteger(L, matStackIndex); + + // call the callback + if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_GEO_PROCESS]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_BEFORE_GEO_PROCESS(struct GraphNode *node, s32 matStackIndex) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_BEFORE_GEO_PROCESS]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push node + smlua_push_object(L, LOT_GRAPHNODE, node, NULL); + + // push matStackIndex + lua_pushinteger(L, matStackIndex); + + // call the callback + if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_BEFORE_GEO_PROCESS]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_GEO_PROCESS_CHILDREN(struct GraphNode *parent, s32 matStackIndex) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_GEO_PROCESS_CHILDREN]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push parent + smlua_push_object(L, LOT_GRAPHNODE, parent, NULL); + + // push matStackIndex + lua_pushinteger(L, matStackIndex); + + // call the callback + if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_GEO_PROCESS_CHILDREN]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS(struct MarioState *m, bool *allowUpdateGeometryInputs) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // call the callback + if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS]); + continue; + } + hookResult = true; + + // return allowUpdateGeometryInputs + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *allowUpdateGeometryInputs = smlua_to_boolean(L, -1); + } + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_INTERACTIONS(struct MarioState *m) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_INTERACTIONS]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // call the callback + if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_INTERACTIONS]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ALLOW_FORCE_WATER_ACTION(struct MarioState *m, bool isInWaterAction, bool *allowForceAction) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ALLOW_FORCE_WATER_ACTION]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push isInWaterAction + lua_pushboolean(L, isInWaterAction); + + // call the callback + if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ALLOW_FORCE_WATER_ACTION]); + continue; + } + hookResult = true; + + // return allowForceAction + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *allowForceAction = smlua_to_boolean(L, -1); + } + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_BEFORE_WARP(s16 destLevel, s16 destArea, s16 destWarpNode, s32 arg, struct WarpDest *warpDestOverride) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_BEFORE_WARP]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push destLevel + lua_pushinteger(L, destLevel); + + // push destArea + lua_pushinteger(L, destArea); + + // push destWarpNode + lua_pushinteger(L, destWarpNode); + + // push arg + lua_pushinteger(L, arg); + + // call the callback + if (0 != smlua_call_hook(L, 4, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_BEFORE_WARP]); + continue; + } + + // if the hook returns a table, use it to override the warp parameters + if (lua_istable(L, -1)) { + + lua_getfield(L, -1, "destLevel"); + if (lua_isnumber(L, -1)) { + warpDestOverride->levelNum = smlua_to_integer(L, -1); + } + lua_pop(L, 1); + + lua_getfield(L, -1, "destArea"); + if (lua_isnumber(L, -1)) { + warpDestOverride->areaIdx = smlua_to_integer(L, -1); + } + lua_pop(L, 1); + + lua_getfield(L, -1, "destWarpNode"); + if (lua_isnumber(L, -1)) { + warpDestOverride->nodeId = smlua_to_integer(L, -1); + } + lua_pop(L, 1); + + lua_settop(L, prevTop); + return true; + } + + lua_settop(L, prevTop); + } + return false; +} + +bool smlua_call_event_hooks_HOOK_ON_INSTANT_WARP(u8 areaIdx, u8 nodeId, Vec3s displacement) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_INSTANT_WARP]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push areaIdx + lua_pushinteger(L, areaIdx); + + // push nodeId + lua_pushinteger(L, nodeId); + + // push displacement + extern void smlua_new_vec3s(Vec3s src); + smlua_new_vec3s(displacement); + + // call the callback + if (0 != smlua_call_hook(L, 3, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_INSTANT_WARP]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_MARIO_OVERRIDE_FLOOR_CLASS(struct MarioState *m, s32 floorClass, s32 *floorClassOverride) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_MARIO_OVERRIDE_FLOOR_CLASS]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push m + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push floorClass + lua_pushinteger(L, floorClass); + + // call the callback + if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_MARIO_OVERRIDE_FLOOR_CLASS]); + continue; + } + + // return floorClassOverride + if (lua_type(L, -1) == LUA_TNUMBER) { + *floorClassOverride = smlua_to_integer(L, -1); + lua_settop(L, prevTop); + return true; + } + + lua_settop(L, prevTop); + } + return false; +} + +bool smlua_call_event_hooks_HOOK_ON_ADD_SURFACE(struct Surface *surface, bool dynamic) { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_ADD_SURFACE]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push surface + smlua_push_object(L, LOT_SURFACE, surface, NULL); + + // push dynamic + lua_pushboolean(L, dynamic); + + // call the callback + if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_ADD_SURFACE]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} + +bool smlua_call_event_hooks_HOOK_ON_CLEAR_AREAS() { + lua_State *L = gLuaState; + if (L == NULL) { return false; } + bool hookResult = false; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_CLEAR_AREAS]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // call the callback + if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_CLEAR_AREAS]); + continue; + } + hookResult = true; + + lua_settop(L, prevTop); + } + return hookResult; +} diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index fc14780e6..e0cf01b9b 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -9,6 +9,7 @@ #include "pc/djui/djui_chat_message.h" #include "pc/crash_handler.h" #include "game/hud.h" +#include "game/level_update.h" #include "pc/debug_context.h" #include "pc/network/network.h" #include "pc/network/network_player.h" @@ -38,6 +39,13 @@ struct LuaHookedEvent { static struct LuaHookedEvent sHookedEvents[HOOK_MAX] = { 0 }; +static const char* sLuaHookedEventTypeName[] = { +#define SMLUA_EVENT_HOOK(hookEventType, ...) #hookEventType, +#include "smlua_hook_events.inl" +#undef SMLUA_EVENT_HOOK + "HOOK_MAX" +}; + int smlua_call_hook(lua_State* L, int nargs, int nresults, int errfunc, struct Mod* activeMod) { if (!gGameInited) { return 0; } // Don't call hooks while the game is booting @@ -75,13 +83,13 @@ int smlua_hook_event(lua_State* L) { struct LuaHookedEvent* hook = &sHookedEvents[hookType]; if (hook->count >= MAX_HOOKED_REFERENCES) { - LOG_LUA_LINE("Hook Type: %s exceeded maximum references!", LuaHookedEventTypeName[hookType]); + LOG_LUA_LINE("Hook Type: %s exceeded maximum references!", sLuaHookedEventTypeName[hookType]); return 0; } int ref = luaL_ref(L, LUA_REGISTRYINDEX); if (ref == -1) { - LOG_LUA_LINE("Tried to hook undefined function to '%s'", LuaHookedEventTypeName[hookType]); + LOG_LUA_LINE("Tried to hook undefined function to '%s'", sLuaHookedEventTypeName[hookType]); return 0; } @@ -92,1212 +100,118 @@ int smlua_hook_event(lua_State* L) { return 1; } -void smlua_call_event_hooks(enum LuaHookedEventType hookType) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + /////////////////// + // hooked events // +/////////////////// - // call the callback - if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the event_hook callback: %u", hookType); - continue; - } - } -} +#include "smlua_hook_events_autogen.inl" -void smlua_call_event_on_hud_render(void (*resetFunc)(void)) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - if (resetFunc) { resetFunc(); } - - struct LuaHookedEvent* hook = &sHookedEvents[HOOK_ON_HUD_RENDER]; - for (int i = 0; i < hook->count; i++) { - // support deprecated render behind hud - if (hook->mod[i]->renderBehindHud) { continue; } - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // call the callback - if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the event_hook callback: %u", HOOK_ON_HUD_RENDER); - } - if (resetFunc) { resetFunc(); } - } -} - -void smlua_call_event_on_hud_render_behind(void (*resetFunc)(void)) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - if (resetFunc) { resetFunc(); } - - struct LuaHookedEvent* hook = &sHookedEvents[HOOK_ON_HUD_RENDER_BEHIND]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // call the callback - if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the event_hook callback: %u", HOOK_ON_HUD_RENDER_BEHIND); - } - if (resetFunc) { resetFunc(); } - } - - // support deprecated render behind hud - hook = &sHookedEvents[HOOK_ON_HUD_RENDER]; - for (int i = 0; i < hook->count; i++) { - // support deprecated render behind hud - if (!hook->mod[i]->renderBehindHud) { continue; } - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // call the callback - if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the event_hook callback: %u", HOOK_ON_HUD_RENDER); - } - if (resetFunc) { resetFunc(); } - } - -} - -void smlua_call_event_on_add_surface(struct Surface* surface, bool dynamic) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - - struct LuaHookedEvent* hook = &sHookedEvents[HOOK_ON_ADD_SURFACE]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push surface and dynamic - smlua_push_object(L, LOT_SURFACE, surface, NULL); - lua_pushboolean(L, dynamic); - - // call the callback - if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the event_hook callback: %u", HOOK_ON_ADD_SURFACE); - } - } -} - -void smlua_call_event_hooks_bool_param(enum LuaHookedEventType hookType, bool value) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push value - lua_pushboolean(L, value); - - // call the callback - if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - } -} - -void smlua_call_event_hooks_bool_param_ret_bool(enum LuaHookedEventType hookType, bool value, bool* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push value - lua_pushboolean(L, value); - - // call the callback - if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TBOOLEAN) { - *returnValue = smlua_to_boolean(L, -1); - } - lua_settop(L, prevTop); - } -} - -void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct MarioState* m) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // call the callback - if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - } -} - -void smlua_call_event_hooks_mario_param_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, bool* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // call the callback - if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TBOOLEAN) { - *returnValue = smlua_to_boolean(L, -1); - } - lua_settop(L, prevTop); - } -} - -void smlua_call_event_hooks_mario_params(enum LuaHookedEventType hookType, struct MarioState* m1, struct MarioState* m2, u32 interaction) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m1->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m2->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // push interaction - lua_pushinteger(L, interaction); - - // call the callback - if (0 != smlua_call_hook(L, 3, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - } -} - -void smlua_call_event_hooks_mario_params_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m1, struct MarioState* m2, u32 interaction, bool* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m1->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m2->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // push interaction - lua_pushinteger(L, interaction); - - // call the callback - if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TBOOLEAN) { - *returnValue = smlua_to_boolean(L, -1); - } - lua_settop(L, prevTop); - } -} - -void smlua_call_event_hooks_interact_params(enum LuaHookedEventType hookType, struct MarioState* m, struct Object* obj, u32 interactType, bool interactValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // push object - smlua_push_object(L, LOT_OBJECT, obj, NULL); - - // push interact type - lua_pushinteger(L, interactType); - - // push interact value - lua_pushboolean(L, interactValue); - - // call the callback - if (0 != smlua_call_hook(L, 4, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - } -} - -void smlua_call_event_hooks_interact_params_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, struct Object* obj, u32 interactType, bool* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // push object - smlua_push_object(L, LOT_OBJECT, obj, NULL); - - // push interact type - lua_pushinteger(L, interactType); - - // call the callback - if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TBOOLEAN) { - *returnValue = smlua_to_boolean(L, -1); - } - lua_settop(L, prevTop); - } -} - -void smlua_call_event_hooks_interact_params_no_ret(enum LuaHookedEventType hookType, struct MarioState* m, struct Object* obj, u32 interactType) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // push object - smlua_push_object(L, LOT_OBJECT, obj, NULL); - - // push interact type - lua_pushinteger(L, interactType); - - // call the callback - if (0 != smlua_call_hook(L, 3, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - } -} - -void smlua_call_event_hooks_object_param(enum LuaHookedEventType hookType, struct Object* obj) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push object - smlua_push_object(L, LOT_OBJECT, obj, NULL); - - // call the callback - if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - } -} - -void smlua_call_event_hooks_object_set_model(enum LuaHookedEventType hookType, struct Object* obj, s32 modelID, enum ModelExtendedId modelExtendedId) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push params - smlua_push_object(L, LOT_OBJECT, obj, NULL); - lua_pushinteger(L, modelID); - lua_pushinteger(L, modelExtendedId); - - // call the callback - if (0 != smlua_call_hook(L, 3, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - } -} - -bool smlua_call_event_hooks_ret_int(enum LuaHookedEventType hookType, s32* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return false; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // call the callback - if (0 != smlua_call_hook(L, 0, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TNUMBER) { - *returnValue = smlua_to_integer(L, -1); - } - lua_settop(L, prevTop); - return true; - } - return false; -} - -void smlua_call_event_hooks_ret_bool(enum LuaHookedEventType hookType, bool* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - *returnValue = true; - - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // call the callback - if (0 != smlua_call_hook(L, 0, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TBOOLEAN && *returnValue) { - *returnValue = smlua_to_boolean(L, -1); - } - lua_settop(L, prevTop); - } -} - -void smlua_call_event_hooks_network_player_param(enum LuaHookedEventType hookType, struct NetworkPlayer* np) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gNetworkPlayers"); - lua_pushinteger(L, np->localIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // call the callback - if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - } -} - -void smlua_call_event_hooks_set_camera_mode_params(enum LuaHookedEventType hookType, struct Camera *c, s16 mode, s16 frames, bool* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - *returnValue = true; - - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push params - smlua_push_object(L, LOT_CAMERA, c, NULL); - lua_pushinteger(L, mode); - lua_pushinteger(L, frames); - - // call the callback - if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TBOOLEAN && *returnValue) { - *returnValue = smlua_to_boolean(L, -1); - } - lua_settop(L, prevTop); - } -} - -void smlua_call_event_hooks_int_params_ret_bool(enum LuaHookedEventType hookType, s16 param, bool* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - *returnValue = true; - - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push params - lua_pushinteger(L, param); - - // call the callback - if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TBOOLEAN) { - *returnValue = smlua_to_boolean(L, -1); - } - lua_settop(L, prevTop); - } -} - -void smlua_call_event_hooks_int_params_ret_int(enum LuaHookedEventType hookType, s32 param, s32* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push params - lua_pushinteger(L, param); - - // call the callback - if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TNUMBER) { - *returnValue = smlua_to_integer(L, -1); - lua_settop(L, prevTop); - return; - } else { - lua_settop(L, prevTop); - } - } -} - -void smlua_call_event_hooks_warp_params(enum LuaHookedEventType hookType, u8 type, s16 levelNum, u8 areaIdx, u8 nodeId, u32 arg) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push params - lua_pushinteger(L, type); - lua_pushinteger(L, levelNum); - lua_pushinteger(L, areaIdx); - lua_pushinteger(L, nodeId); - lua_pushinteger(L, arg); - - // call the callback - if (0 != smlua_call_hook(L, 5, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - lua_settop(L, prevTop); - } -} - -void smlua_call_event_hooks_instant_warp_params(enum LuaHookedEventType hookType, u8 area, u8 warpId, Vec3s displacement) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push params - lua_pushinteger(L, area); - lua_pushinteger(L, warpId); - - lua_newtable(L); - int tbl = lua_gettop(L); - - lua_pushstring(L, "x"); - lua_pushinteger(L, displacement[0]); - lua_settable(L, tbl); - - lua_pushstring(L, "y"); - lua_pushinteger(L, displacement[1]); - lua_settable(L, tbl); - - lua_pushstring(L, "z"); - lua_pushinteger(L, displacement[2]); - lua_settable(L, tbl); - - // call the callback - if (0 != smlua_call_hook(L, 3, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - lua_settop(L, prevTop); - } -} - -void smlua_call_event_hooks_int_params_ret_string(enum LuaHookedEventType hookType, s32 param, char** returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push params - lua_pushinteger(L, param); - - // call the callback - if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TSTRING) { - *returnValue = (char *)smlua_to_string(L, -1); - lua_settop(L, prevTop); - return; - } else { - lua_settop(L, prevTop); - } - } -} - -void smlua_call_event_hooks_value_param(enum LuaHookedEventType hookType, int modIndex, int valueIndex) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - if (hook->mod[i]->index != modIndex) { continue; } - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push value - lua_pushvalue(L, valueIndex); - - // call the callback - if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - } -} - -void smlua_call_event_hooks_on_play_sound(enum LuaHookedEventType hookType, s32 soundBits, f32* pos, s32* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push sound bits - lua_pushinteger(L, soundBits); - - // push vec3f - lua_newtable(L); - int valTableIndex = lua_gettop(L); - - lua_pushstring(L, "x"); - lua_pushnumber(L, pos[0]); - lua_settable(L, valTableIndex); - - lua_pushstring(L, "y"); - lua_pushnumber(L, pos[1]); - lua_settable(L, valTableIndex); - - lua_pushstring(L, "z"); - lua_pushnumber(L, pos[2]); - lua_settable(L, valTableIndex); - - // call the callback - if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TNUMBER) { - *returnValue = smlua_to_integer(L, -1); - lua_settop(L, prevTop); - return; - } else { - lua_settop(L, prevTop); - } - } -} - -void smlua_call_event_hooks_before_warp(enum LuaHookedEventType hookType, s16 *destLevel, s16 *destArea, s16 *destWarpNode, s32 *arg) { +static bool smlua_call_event_hooks_on_hud_render(void (*resetFunc)(void), bool renderBehind) { lua_State *L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - int prevTop = lua_gettop(L); + if (L == NULL) { return false; } + bool hookResult = false; - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + if (resetFunc) { resetFunc(); } - lua_pushinteger(L, *destLevel); - lua_pushinteger(L, *destArea); - lua_pushinteger(L, *destWarpNode); - lua_pushinteger(L, *arg); + const enum LuaHookedEventType renderHudHookTypes[] = { + HOOK_ON_HUD_RENDER_BEHIND, + HOOK_ON_HUD_RENDER, + }; + for (s32 k = renderBehind ? 0 : 1; k != 2; ++k) { + enum LuaHookedEventType hookType = renderHudHookTypes[k]; + struct LuaHookedEvent *hook = &sHookedEvents[hookType]; + for (int i = 0; i < hook->count; i++) { - if (smlua_call_hook(L, 4, 1, 0, hook->mod[i]) != 0) { - LOG_LUA("Failed to call the callback: %u", hookType); - lua_settop(L, prevTop); - continue; - } - - // if the hook returns a table, use it to override the warp parameters - if (lua_istable(L, -1)) { - - lua_getfield(L, -1, "destLevel"); - if (lua_isnumber(L, -1)) { - *destLevel = (s16)lua_tointeger(L, -1); + // support deprecated render behind hud + if (hookType == HOOK_ON_HUD_RENDER && hook->mod[i]->renderBehindHud != renderBehind) { + continue; } - lua_pop(L, 1); - lua_getfield(L, -1, "destArea"); - if (lua_isnumber(L, -1)) { - *destArea = (s16)lua_tointeger(L, -1); + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // call the callback + if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[hookType]); + } else { + hookResult = true; } - lua_pop(L, 1); - lua_getfield(L, -1, "destWarpNode"); - if (lua_isnumber(L, -1)) { - *destWarpNode = (s16)lua_tointeger(L, -1); - } - lua_pop(L, 1); - - lua_settop(L, prevTop); - return; - } - lua_settop(L, prevTop); - } -} - -void smlua_call_event_hooks_on_seq_load(enum LuaHookedEventType hookType, u32 player, u32 seqId, s32 loadAsync, s16* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - lua_pushinteger(L, player); - lua_pushinteger(L, seqId); - lua_pushinteger(L, loadAsync); - - // Call the callback - if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // Output the return value - if (lua_type(L, -1) == LUA_TNUMBER) { - *returnValue = smlua_to_integer(L, -1); - lua_settop(L, prevTop); - return; - } else { - lua_settop(L, prevTop); + if (resetFunc) { resetFunc(); } } } + return hookResult; } -void smlua_call_event_hooks_use_act_select(enum LuaHookedEventType hookType, int value, bool* foundHook, bool* returnValue) { - lua_State* L = gLuaState; - *foundHook = false; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push value - lua_pushinteger(L, value); - - // call the callback - if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TBOOLEAN) { - *foundHook = true; - *returnValue = smlua_to_boolean(L, -1); - } - lua_settop(L, prevTop); - } +bool smlua_call_event_hooks_HOOK_ON_HUD_RENDER(void (*resetFunc)(void)) { + return smlua_call_event_hooks_on_hud_render(resetFunc, false); } -void smlua_call_event_hooks_on_chat_message(enum LuaHookedEventType hookType, struct MarioState* m, const char* message, bool* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // push the string - lua_pushstring(L, message); - - // call the callback - if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TBOOLEAN) { - *returnValue = smlua_to_boolean(L, -1); - } - lua_settop(L, prevTop); - } +bool smlua_call_event_hooks_HOOK_ON_HUD_RENDER_BEHIND(void (*resetFunc)(void)) { + return smlua_call_event_hooks_on_hud_render(resetFunc, true); } -bool smlua_call_event_hooks_mario_character_sound_param_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, enum CharacterSound characterSound, s32* returnValue) { - lua_State* L = gLuaState; +bool smlua_call_event_hooks_HOOK_ON_NAMETAGS_RENDER(s32 playerIndex, Vec3f pos, const char **playerNameOverride) { + lua_State *L = gLuaState; if (L == NULL) { return false; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; + + struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_NAMETAGS_RENDER]; for (int i = 0; i < hook->count; i++) { s32 prevTop = lua_gettop(L); // push the callback onto the stack lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); + // push playerIndex + lua_pushinteger(L, playerIndex); - // push character sound - lua_pushinteger(L, characterSound); + // push pos + extern void smlua_new_vec3f(Vec3f src); + smlua_new_vec3f(pos); // call the callback if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); + LOG_LUA("Failed to call the callback for hook %s", sLuaHookedEventTypeName[HOOK_ON_NAMETAGS_RENDER]); continue; } - // output the return value - if (lua_type(L, -1) == LUA_TNUMBER) { - *returnValue = smlua_to_integer(L, -1); - lua_settop(L, prevTop); - return true; - } else { - lua_settop(L, prevTop); - } - } - return false; -} - -void smlua_call_event_hooks_mario_action_and_arg_ret_int(enum LuaHookedEventType hookType, struct MarioState *m, u32 action, u32 arg, u32* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // push action - lua_pushinteger(L, action); - - // push arg - lua_pushinteger(L, arg); - - // call the callback - if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TNUMBER) { - *returnValue = smlua_to_integer(L, -1); - } - lua_settop(L, prevTop); - } -} - -void smlua_call_event_hooks_mario_param_and_int_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, bool* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // push param - lua_pushinteger(L, param); - - // call the callback - if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TBOOLEAN) { - *returnValue = smlua_to_boolean(L, -1); - } - lua_settop(L, prevTop); - } -} - -bool smlua_call_event_hooks_mario_param_and_int_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, s32* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return false; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // push param - lua_pushinteger(L, param); - - // call the callback - if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TNUMBER) { - *returnValue = smlua_to_integer(L, -1); - lua_settop(L, prevTop); - return true; - } - lua_settop(L, prevTop); - } - return false; -} - -void smlua_call_event_hooks_mario_param_and_bool_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, bool param, bool* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // push param - lua_pushboolean(L, param); - - // call the callback - if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TBOOLEAN) { - *returnValue = smlua_to_boolean(L, -1); - } - lua_settop(L, prevTop); - } -} - -bool smlua_call_event_hooks_mario_param_ret_float(enum LuaHookedEventType hookType, struct MarioState* m, f32* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return false; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // call the callback - if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TNUMBER) { - *returnValue = smlua_to_number(L, -1); - } - lua_settop(L, prevTop); - - return true; - } - - return false; -} - -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) { - lua_State* L = gLuaState; - if (L == NULL) { return false; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push mario state - lua_getglobal(L, "gMarioStates"); - lua_pushinteger(L, m->playerIndex); - lua_gettable(L, -2); - lua_remove(L, -2); - - // push param - lua_pushinteger(L, param); - - // push args - lua_pushinteger(L, args); - - // call the callback - if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return value - if (lua_type(L, -1) == LUA_TNUMBER) { - *returnValue = smlua_to_integer(L, -1); - lua_settop(L, prevTop); - return true; - } - lua_settop(L, prevTop); - } - return false; -} - -void smlua_call_event_hooks_graph_node_object_and_int_param(enum LuaHookedEventType hookType, struct GraphNodeObject* node, s32 param) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push graph node object - smlua_push_object(L, LOT_GRAPHNODEOBJECT, node, NULL); - - // push param - lua_pushinteger(L, param); - - // call the callback - if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - } -} - -void smlua_call_event_hooks_graph_node_and_int_param(enum LuaHookedEventType hookType, struct GraphNode* node, s16 matIndex) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push graph node - smlua_push_object(L, LOT_GRAPHNODE, node, NULL); - - // push mat index - lua_pushinteger(L, matIndex); - - // call the callback - if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - } -} - -const char *smlua_call_event_hooks_int_ret_bool_and_string(enum LuaHookedEventType hookType, s32 param, bool* returnValue) { - lua_State* L = gLuaState; - if (L == NULL) { return NULL; } - *returnValue = true; - const char *retString = NULL; - - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - s32 prevTop = lua_gettop(L); - - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push param - lua_pushinteger(L, param); - - // call the callback - if (0 != smlua_call_hook(L, 1, 2, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - - // output the return values - if (lua_type(L, -2) == LUA_TBOOLEAN) { - *returnValue = smlua_to_boolean(L, -2); - } + // return playerNameOverride if (lua_type(L, -1) == LUA_TSTRING) { - retString = smlua_to_string(L, -1); + *playerNameOverride = smlua_to_string(L, -1); lua_settop(L, prevTop); - return retString; + return true; } + + // if it's a table, override name, pos or both + if (lua_type(L, -1) == LUA_TTABLE) { + bool override = false; + + // name + lua_getfield(L, -1, "name"); + if (lua_type(L, -1) == LUA_TSTRING) { + *playerNameOverride = smlua_to_string(L, -1); + override = true; + } + lua_pop(L, 1); + + // pos + lua_getfield(L, -1, "pos"); + if (lua_type(L, -1) == LUA_TTABLE) { + extern void smlua_get_vec3f(Vec3f dest, int index); + smlua_get_vec3f(pos, -1); + override = true; + } + lua_pop(L, 1); + + lua_settop(L, prevTop); + if (override) { + return true; + } + } + lua_settop(L, prevTop); } - return NULL; -} - -void smlua_call_event_hooks_string_param(enum LuaHookedEventType hookType, const char* string) { - lua_State* L = gLuaState; - if (L == NULL) { return; } - struct LuaHookedEvent* hook = &sHookedEvents[hookType]; - for (int i = 0; i < hook->count; i++) { - // push the callback onto the stack - lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - - // push string - lua_pushstring(L, string); - - // call the callback - if (0 != smlua_call_hook(L, 1, 0, 0, hook->mod[i])) { - LOG_LUA("Failed to call the callback: %u", hookType); - continue; - } - } + return false; } //////////////////// diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index a7a9d222f..b81841e4b 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -10,6 +10,7 @@ // forward declare struct Camera; +struct WarpDest; // ! Hooks must be added at the end enum LuaHookedEventType { @@ -75,65 +76,10 @@ enum LuaHookedEventType { HOOK_MAX, }; -static const char* LuaHookedEventTypeName[] = { - "HOOK_UPDATE", - "HOOK_MARIO_UPDATE", - "HOOK_BEFORE_MARIO_UPDATE", - "HOOK_ON_SET_MARIO_ACTION", - "HOOK_BEFORE_PHYS_STEP", - "HOOK_ALLOW_PVP_ATTACK", - "HOOK_ON_PVP_ATTACK", - "HOOK_ON_PLAYER_CONNECTED", - "HOOK_ON_PLAYER_DISCONNECTED", - "HOOK_ON_HUD_RENDER", - "HOOK_ALLOW_INTERACT", - "HOOK_ON_INTERACT", - "HOOK_ON_LEVEL_INIT", - "HOOK_ON_WARP", - "HOOK_ON_SYNC_VALID", - "HOOK_ON_OBJECT_UNLOAD", - "HOOK_ON_SYNC_OBJECT_UNLOAD", - "HOOK_ON_PAUSE_EXIT", - "HOOK_GET_STAR_COLLECTION_DIALOG", - "HOOK_ON_SET_CAMERA_MODE", - "HOOK_ON_OBJECT_RENDER", - "HOOK_ON_DEATH", - "HOOK_ON_PACKET_RECEIVE", - "HOOK_USE_ACT_SELECT", - "HOOK_ON_CHANGE_CAMERA_ANGLE", - "HOOK_ON_SCREEN_TRANSITION", - "HOOK_ALLOW_HAZARD_SURFACE", - "HOOK_ON_CHAT_MESSAGE", - "HOOK_OBJECT_SET_MODEL", - "HOOK_CHARACTER_SOUND", - "HOOK_BEFORE_SET_MARIO_ACTION", - "HOOK_JOINED_GAME", - "HOOK_ON_OBJECT_ANIM_UPDATE", - "HOOK_ON_DIALOG", - "HOOK_ON_EXIT", - "HOOK_DIALOG_SOUND", - "HOOK_ON_HUD_RENDER_BEHIND", - "HOOK_ON_COLLIDE_LEVEL_BOUNDS", - "HOOK_MIRROR_MARIO_RENDER", - "HOOK_MARIO_OVERRIDE_PHYS_STEP_DEFACTO_SPEED", - "HOOK_ON_OBJECT_LOAD", - "HOOK_ON_PLAY_SOUND", - "HOOK_ON_SEQ_LOAD", - "HOOK_ON_ATTACK_OBJECT", - "HOOK_ON_LANGUAGE_CHANGED", - "HOOK_ON_MODS_LOADED", - "HOOK_ON_NAMETAGS_RENDER", - "HOOK_ON_DJUI_THEME_CHANGED", - "HOOK_ON_GEO_PROCESS", - "HOOK_BEFORE_GEO_PROCESS", - "HOOK_ON_GEO_PROCESS_CHILDREN", - "HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS", - "HOOK_ON_INTERACTIONS", - "HOOK_ALLOW_FORCE_WATER_ACTION", - "HOOK_BEFORE_WARP", - "HOOK_ON_INSTANT_WARP", - "HOOK_MARIO_OVERRIDE_FLOOR_CLASS", - "HOOK_MAX" +enum LuaHookedEventReturn { + HOOK_RETURN_NEVER, // Never returns before calling all hooks for a given event, returns true if there is at least one successful callback call + HOOK_RETURN_ON_SUCCESSFUL_CALL, // Returns true on first successful callback call, skipping next hooks for a given event + HOOK_RETURN_ON_OUTPUT_SET, // Returns true on output set after a successful call, skipping next hooks for a given event }; enum LuaActionHookType { @@ -177,49 +123,16 @@ extern u32 gLuaMarioActionIndex[]; extern struct LuaHookedModMenuElement gHookedModMenuElements[]; extern int gHookedModMenuElementsCount; +#define OUTPUT +#define SMLUA_EVENT_HOOK(hookEventType, hookReturn, ...) bool smlua_call_event_hooks_##hookEventType(__VA_ARGS__); +#include "smlua_hook_events.inl" +#undef OUTPUT +#undef SMLUA_EVENT_HOOK + +#define smlua_call_event_hooks(hookEventType, ...) \ + smlua_call_event_hooks_##hookEventType(__VA_ARGS__) + int smlua_hook_custom_bhv(BehaviorScript *bhvScript, const char *bhvName); - -void smlua_call_event_hooks(enum LuaHookedEventType hookType); -void smlua_call_event_on_hud_render(void (*resetFunc)(void)); -void smlua_call_event_on_hud_render_behind(void (*resetFunc)(void)); -void smlua_call_event_on_add_surface(struct Surface* surface, bool dynamic); -void smlua_call_event_hooks_bool_param(enum LuaHookedEventType hookType, bool value); -void smlua_call_event_hooks_bool_param_ret_bool(enum LuaHookedEventType hookType, bool value, bool* returnValue); -void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct MarioState* m); -void smlua_call_event_hooks_mario_param_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, bool* returnValue); -void smlua_call_event_hooks_mario_params(enum LuaHookedEventType hookType, struct MarioState* m1, struct MarioState* m2, u32 interaction); -void smlua_call_event_hooks_mario_params_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m1, struct MarioState* m2, u32 interaction, bool* returnValue); -void smlua_call_event_hooks_interact_params(enum LuaHookedEventType hookType, struct MarioState* m, struct Object* obj, u32 interactType, bool interactValue); -void smlua_call_event_hooks_interact_params_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, struct Object* obj, u32 interactType, bool* returnValue); -void smlua_call_event_hooks_interact_params_no_ret(enum LuaHookedEventType hookType, struct MarioState* m, struct Object* obj, u32 interactType); -void smlua_call_event_hooks_object_param(enum LuaHookedEventType hookType, struct Object* obj); -void smlua_call_event_hooks_object_set_model(enum LuaHookedEventType hookType, struct Object* obj, s32 modelID, enum ModelExtendedId modelExtendedId); -bool smlua_call_event_hooks_ret_int(enum LuaHookedEventType hookType, s32* returnValue); -void smlua_call_event_hooks_set_camera_mode_params(enum LuaHookedEventType hookType, struct Camera *c, s16 mode, s16 frames, bool* returnValue); -void smlua_call_event_hooks_int_params_ret_bool(enum LuaHookedEventType hookType, s16 param, bool* returnValue); -void smlua_call_event_hooks_int_params_ret_int(enum LuaHookedEventType hookType, s32 param, s32* returnValue); -void smlua_call_event_hooks_int_params_ret_string(enum LuaHookedEventType hookType, s32 param, char** returnValue); -void smlua_call_event_hooks_value_param(enum LuaHookedEventType hookType, int modIndex, int valueIndex); -void smlua_call_event_hooks_on_play_sound(enum LuaHookedEventType hookType, s32 soundBits, f32* pos, s32* returnValue); -void smlua_call_event_hooks_use_act_select(enum LuaHookedEventType hookType, int value, bool* foundHook, bool* returnValue); -void smlua_call_event_hooks_ret_bool(enum LuaHookedEventType hookType, bool* returnValue); -void smlua_call_event_hooks_on_chat_message(enum LuaHookedEventType hookType, struct MarioState* m, const char* message, bool* returnValue); -bool smlua_call_event_hooks_mario_character_sound_param_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, enum CharacterSound characterSound, s32* returnValue); -void smlua_call_event_hooks_mario_action_and_arg_ret_int(enum LuaHookedEventType hookType, struct MarioState *m, u32 action, u32 arg, u32* returnValue); -void smlua_call_event_hooks_mario_param_and_int_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, bool* returnValue); -bool smlua_call_event_hooks_mario_param_and_int_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, s32* returnValue); -void smlua_call_event_hooks_mario_param_and_bool_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, bool param, bool* returnValue); -bool smlua_call_event_hooks_mario_param_ret_float(enum LuaHookedEventType hookType, struct MarioState* m, f32* returnValue); -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); -void smlua_call_event_hooks_graph_node_and_int_param(enum LuaHookedEventType hookType, struct GraphNode* node, s16 matIndex); -void smlua_call_event_hooks_on_seq_load(enum LuaHookedEventType hookType, u32 player, u32 seqId, s32 loadAsync, s16* returnValue); -void smlua_call_event_hooks_before_warp(enum LuaHookedEventType hookType, s16 *destLevel, s16 *destArea, s16 *destWarpNode, s32 *arg); -void smlua_call_event_hooks_warp_params(enum LuaHookedEventType hookType, u8 type, s16 levelNum, u8 areaIdx, u8 nodeId, u32 arg); -void smlua_call_event_hooks_instant_warp_params(enum LuaHookedEventType hookType, u8 area, u8 warpId, Vec3s displacement); -const char *smlua_call_event_hooks_int_ret_bool_and_string(enum LuaHookedEventType hookType, s32 param, bool* returnValue); -void smlua_call_event_hooks_string_param(enum LuaHookedEventType hookType, const char* string); - 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); diff --git a/src/pc/nametags.c b/src/pc/nametags.c index 258466f69..927a3df12 100644 --- a/src/pc/nametags.c +++ b/src/pc/nametags.c @@ -84,21 +84,24 @@ void nametags_render(void) { vec3f_copy(pos, m->marioBodyState->headPos); pos[1] += 100; - if (djui_hud_world_pos_to_screen_pos(pos, out) && - (i != 0 || (i == 0 && m->action != ACT_FIRST_PERSON))) { - f32 scale = -300 / out[2] * djui_hud_get_fov_coeff(); + if ((i != 0 || (i == 0 && m->action != ACT_FIRST_PERSON)) && + djui_hud_world_pos_to_screen_pos(pos, out)) { char name[MAX_CONFIG_STRING]; - char* hookedString = NULL; - smlua_call_event_hooks_int_params_ret_string(HOOK_ON_NAMETAGS_RENDER, i, &hookedString); + const char* hookedString = NULL; + smlua_call_event_hooks(HOOK_ON_NAMETAGS_RENDER, i, pos, &hookedString); if (hookedString) { snprintf(name, MAX_CONFIG_STRING, "%s", hookedString); } else { snprintf(name, MAX_CONFIG_STRING, "%s", np->name); name_without_hex(name); } + if (!djui_hud_world_pos_to_screen_pos(pos, out)) { + continue; + } u8* color = network_get_player_text_color(m->playerIndex); + f32 scale = -300 / out[2] * djui_hud_get_fov_coeff(); f32 measure = djui_hud_measure_text(name) * scale * 0.5f; out[1] -= 16 * scale; diff --git a/src/pc/network/network_player.c b/src/pc/network/network_player.c index c581e79d8..7b5294b5a 100644 --- a/src/pc/network/network_player.c +++ b/src/pc/network/network_player.c @@ -356,7 +356,7 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode } LOG_INFO("player connected, local %d, global %d", localIndex, np->globalIndex); - smlua_call_event_hooks_mario_param(HOOK_ON_PLAYER_CONNECTED, &gMarioStates[localIndex]); + smlua_call_event_hooks(HOOK_ON_PLAYER_CONNECTED, &gMarioStates[localIndex]); #ifdef DISCORD_SDK if (gDiscordInitialized) { @@ -408,7 +408,7 @@ u8 network_player_disconnected(u8 globalIndex) { packet_ordered_clear(globalIndex); - smlua_call_event_hooks_mario_param(HOOK_ON_PLAYER_DISCONNECTED, &gMarioStates[i]); + smlua_call_event_hooks(HOOK_ON_PLAYER_DISCONNECTED, &gMarioStates[i]); memset(np, 0, sizeof(struct NetworkPlayer)); diff --git a/src/pc/network/packets/packet_lua_custom.c b/src/pc/network/packets/packet_lua_custom.c index ef392d872..bdeea5fcd 100644 --- a/src/pc/network/packets/packet_lua_custom.c +++ b/src/pc/network/packets/packet_lua_custom.c @@ -129,6 +129,6 @@ void network_receive_lua_custom(struct Packet* p) { lua_settable(L, -3); } - smlua_call_event_hooks_value_param(HOOK_ON_PACKET_RECEIVE, modIndex, tableIndex); + smlua_call_event_hooks(HOOK_ON_PACKET_RECEIVE, modIndex, tableIndex); lua_pop(L, 1); // pop table }