smlua event hooks refactor (#826)
Some checks are pending
Build coop / build-linux (push) Waiting to run
Build coop / build-steamos (push) Waiting to run
Build coop / build-windows-opengl (push) Waiting to run
Build coop / build-windows-directx (push) Waiting to run
Build coop / build-macos-arm (push) Waiting to run
Build coop / build-macos-intel (push) Waiting to run

This commit is contained in:
PeachyPeach 2025-06-08 23:40:48 +02:00 committed by GitHub
parent 838fe40d6e
commit 17c311ae7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 2755 additions and 1535 deletions

View file

@ -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

View file

@ -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" ]
}

View file

@ -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():

309
autogen/gen_hooks.py Normal file
View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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:](#)
<br />

View file

@ -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 |

View file

@ -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);

View file

@ -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) {

View file

@ -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);
}
/**

View file

@ -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();

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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) {

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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)) {

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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);
}
}
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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) {

View file

@ -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;

View file

@ -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;

View file

@ -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;
}

View file

@ -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();

View file

@ -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;
}

View file

@ -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;

View file

@ -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"

View file

@ -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]);

View file

@ -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)

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -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);

View file

@ -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;

View file

@ -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));

View file

@ -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
}