Add freqScale to HOOK_ON_PLAY_SOUND
Some checks failed
Build coop / build-linux (push) Has been cancelled
Build coop / build-steamos (push) Has been cancelled
Build coop / build-windows (push) Has been cancelled
Build coop / build-macos-arm (push) Has been cancelled
Build coop / build-macos-intel (push) Has been cancelled

This commit is contained in:
PeachyPeachSM64 2026-06-26 18:51:36 +02:00
parent 63660e52b9
commit 79d6a8bcff
4 changed files with 78 additions and 43 deletions

View file

@ -27,23 +27,30 @@ SMLUA_CALL_EVENT_HOOKS_DEFINE_HOOK_RESULT = """
SMLUA_CALL_EVENT_HOOKS_SET_HOOK_RESULT = """
hookResult = true;"""
SMLUA_CALL_EVENT_HOOKS_DEFINE_OUTPUT_SET = """
bool outputSet = false;"""
SMLUA_CALL_EVENT_HOOKS_CALLBACK = """
// call the callback
if (0 != smlua_call_hook(L, {n_inputs}, {n_outputs}, 0, hook->mod[i], hook->modFile[i])) {{
LOG_LUA("Failed to call the callback for hook %s - '%s/%s'", sLuaHookedEventTypeName[{hook_type}], hook->mod[i]->relativePath, hook->modFile[i]->relativePath);
continue;
}}{set_hook_result}
}}{set_hook_result}{define_output_set}
"""
SMLUA_CALL_EVENT_HOOKS_SET_OUTPUT_SET = """
outputSet = true;"""
SMLUA_CALL_EVENT_HOOKS_RETURN_ON_OUTPUT_SET = """
lua_settop(L, prevTop);
return true;"""
if (outputSet) {
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}
lua_settop(L, prevTop);{return_on_successful_call}{return_on_output_set}
}}
return {hook_result};
}}
@ -60,7 +67,7 @@ SMLUA_INTEGER_TYPES = {
"output": """
// return {name}
if (lua_type(L, -{output_index}) == LUA_TNUMBER) {{
*{name} = smlua_to_integer(L, -{output_index});{return_on_output_set}
*{name} = smlua_to_integer(L, -{output_index});{set_output_set}
}}
"""
}
@ -73,7 +80,7 @@ SMLUA_FLOAT_TYPES = {
"output": """
// return {name}
if (lua_type(L, -{output_index}) == LUA_TNUMBER) {{
*{name} = smlua_to_number(L, -{output_index});{return_on_output_set}
*{name} = smlua_to_number(L, -{output_index});{set_output_set}
}}
"""
}
@ -90,7 +97,7 @@ SMLUA_TYPES = {
// 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}
smlua_get_%s(*{name}, -{output_index});{set_output_set}
}}
""" % (type_name.lower(), type_name, type_name.lower())
}
@ -114,7 +121,7 @@ SMLUA_TYPES = {
"output": """
// return {name}
if (lua_type(L, -{output_index}) == LUA_TBOOLEAN) {{
*{name} = smlua_to_boolean(L, -{output_index});{return_on_output_set}
*{name} = smlua_to_boolean(L, -{output_index});{set_output_set}
}}
"""
},
@ -126,7 +133,7 @@ SMLUA_TYPES = {
"output": """
// return {name}
if (lua_type(L, -{output_index}) == LUA_TSTRING) {{
*{name} = smlua_to_string(L, -{output_index});{return_on_output_set}
*{name} = smlua_to_string(L, -{output_index});{set_output_set}
}}
"""
},
@ -161,7 +168,7 @@ SMLUA_TYPES = {
{name}->nodeId = smlua_to_integer(L, -1);
}}
lua_pop(L, 1);
{return_on_output_set}
{set_output_set}
}}
"""
},
@ -282,6 +289,8 @@ def main():
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 ""
define_output_set = SMLUA_CALL_EVENT_HOOKS_DEFINE_OUTPUT_SET if hook_return == HOOK_RETURN_ON_OUTPUT_SET else ""
set_output_set = SMLUA_CALL_EVENT_HOOKS_SET_OUTPUT_SET if hook_return == HOOK_RETURN_ON_OUTPUT_SET 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"
@ -314,7 +323,8 @@ def main():
n_inputs=len(hook_event["inputs"]) - mod_index_found,
n_outputs=n_outputs,
hook_type=hook_event["type"],
set_hook_result=set_hook_result
set_hook_result=set_hook_result,
define_output_set=define_output_set
)
# Note: relative indexes for return values are reversed in the Lua stack
@ -323,11 +333,12 @@ def main():
generated += SMLUA_TYPES[output["type"]]["output"].format(
name=output["name"],
output_index=n_outputs - i,
return_on_output_set=return_on_output_set
set_output_set=set_output_set
)
generated += SMLUA_CALL_EVENT_HOOKS_END.format(
return_on_successful_call=return_on_successful_call,
return_on_output_set=return_on_output_set,
hook_result=hook_result
)

View file

@ -837,23 +837,14 @@ void create_next_audio_buffer(s16 *samples, u32 num_samples) {
extern f32 *smlua_get_vec3f_for_play_sound(f32 *pos);
void play_sound(s32 soundBits, f32 *pos) {
MUTEX_LOCK(gAudioThread);
pos = smlua_get_vec3f_for_play_sound(pos);
smlua_call_event_hooks(HOOK_ON_PLAY_SOUND, soundBits, pos, &soundBits);
sSoundRequests[sSoundRequestCount].soundBits = soundBits;
sSoundRequests[sSoundRequestCount].position = pos;
sSoundRequests[sSoundRequestCount].customFreqScale = 0;
sSoundRequestCount++;
MUTEX_UNLOCK(gAudioThread);
return play_sound_with_freq_scale(soundBits, pos, 0);
}
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(HOOK_ON_PLAY_SOUND, soundBits, pos, &soundBits);
smlua_call_event_hooks(HOOK_ON_PLAY_SOUND, soundBits, pos, freqScale, &soundBits, &freqScale);
sSoundRequests[sSoundRequestCount].soundBits = soundBits;
sSoundRequests[sSoundRequestCount].position = pos;
sSoundRequests[sSoundRequestCount].customFreqScale = freqScale;

View file

@ -39,7 +39,7 @@ SMLUA_EVENT_HOOK(HOOK_ON_COLLIDE_LEVEL_BOUNDS, HOOK_RETURN_NEVER, struct MarioSt
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_PLAY_SOUND, HOOK_RETURN_ON_OUTPUT_SET, s32 soundBits, Vec3f pos, f32 freqScale, OUTPUT s32 *soundBitsOverride, OUTPUT f32 *freqScaleOverride)
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)

View file

@ -144,15 +144,18 @@ bool smlua_call_event_hooks_HOOK_BEFORE_PHYS_STEP(struct MarioState *m, s32 step
LOG_LUA("Failed to call the callback for hook %s - '%s/%s'", sLuaHookedEventTypeName[HOOK_BEFORE_PHYS_STEP], hook->mod[i]->relativePath, hook->modFile[i]->relativePath);
continue;
}
bool outputSet = false;
// return stepResultOverride
if (lua_type(L, -1) == LUA_TNUMBER) {
*stepResultOverride = smlua_to_integer(L, -1);
lua_settop(L, prevTop);
return true;
outputSet = true;
}
lua_settop(L, prevTop);
if (outputSet) {
return true;
}
}
return false;
}
@ -743,15 +746,18 @@ bool smlua_call_event_hooks_HOOK_USE_ACT_SELECT(s32 levelNum, bool *useActSelect
LOG_LUA("Failed to call the callback for hook %s - '%s/%s'", sLuaHookedEventTypeName[HOOK_USE_ACT_SELECT], hook->mod[i]->relativePath, hook->modFile[i]->relativePath);
continue;
}
bool outputSet = false;
// return useActSelect
if (lua_type(L, -1) == LUA_TBOOLEAN) {
*useActSelect = smlua_to_boolean(L, -1);
lua_settop(L, prevTop);
return true;
outputSet = true;
}
lua_settop(L, prevTop);
if (outputSet) {
return true;
}
}
return false;
}
@ -954,15 +960,18 @@ bool smlua_call_event_hooks_HOOK_CHARACTER_SOUND(struct MarioState *m, enum Char
LOG_LUA("Failed to call the callback for hook %s - '%s/%s'", sLuaHookedEventTypeName[HOOK_CHARACTER_SOUND], hook->mod[i]->relativePath, hook->modFile[i]->relativePath);
continue;
}
bool outputSet = false;
// return soundOverride
if (lua_type(L, -1) == LUA_TNUMBER) {
*soundOverride = smlua_to_integer(L, -1);
lua_settop(L, prevTop);
return true;
outputSet = true;
}
lua_settop(L, prevTop);
if (outputSet) {
return true;
}
}
return false;
}
@ -1139,15 +1148,18 @@ bool smlua_call_event_hooks_HOOK_DIALOG_SOUND(s32 speaker, s32 *speakerOverride)
LOG_LUA("Failed to call the callback for hook %s - '%s/%s'", sLuaHookedEventTypeName[HOOK_DIALOG_SOUND], hook->mod[i]->relativePath, hook->modFile[i]->relativePath);
continue;
}
bool outputSet = false;
// return speakerOverride
if (lua_type(L, -1) == LUA_TNUMBER) {
*speakerOverride = smlua_to_integer(L, -1);
lua_settop(L, prevTop);
return true;
outputSet = true;
}
lua_settop(L, prevTop);
if (outputSet) {
return true;
}
}
return false;
}
@ -1273,7 +1285,7 @@ bool smlua_call_event_hooks_HOOK_ON_OBJECT_LOAD(struct Object *obj) {
return hookResult;
}
bool smlua_call_event_hooks_HOOK_ON_PLAY_SOUND(s32 soundBits, Vec3f pos, s32 *soundBitsOverride) {
bool smlua_call_event_hooks_HOOK_ON_PLAY_SOUND(s32 soundBits, Vec3f pos, f32 freqScale, s32 *soundBitsOverride, f32 *freqScaleOverride) {
lua_State *L = gLuaState;
if (L == NULL) { return false; }
@ -1291,20 +1303,32 @@ bool smlua_call_event_hooks_HOOK_ON_PLAY_SOUND(s32 soundBits, Vec3f pos, s32 *so
extern void smlua_new_vec3f(Vec3f src);
smlua_new_vec3f(pos);
// push freqScale
lua_pushnumber(L, freqScale);
// call the callback
if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i], hook->modFile[i])) {
if (0 != smlua_call_hook(L, 3, 2, 0, hook->mod[i], hook->modFile[i])) {
LOG_LUA("Failed to call the callback for hook %s - '%s/%s'", sLuaHookedEventTypeName[HOOK_ON_PLAY_SOUND], hook->mod[i]->relativePath, hook->modFile[i]->relativePath);
continue;
}
bool outputSet = false;
// return soundBitsOverride
if (lua_type(L, -2) == LUA_TNUMBER) {
*soundBitsOverride = smlua_to_integer(L, -2);
outputSet = true;
}
// return freqScaleOverride
if (lua_type(L, -1) == LUA_TNUMBER) {
*soundBitsOverride = smlua_to_integer(L, -1);
lua_settop(L, prevTop);
return true;
*freqScaleOverride = smlua_to_number(L, -1);
outputSet = true;
}
lua_settop(L, prevTop);
if (outputSet) {
return true;
}
}
return false;
}
@ -1334,15 +1358,18 @@ bool smlua_call_event_hooks_HOOK_ON_SEQ_LOAD(u32 seqPlayer, u32 seqId, s32 loadA
LOG_LUA("Failed to call the callback for hook %s - '%s/%s'", sLuaHookedEventTypeName[HOOK_ON_SEQ_LOAD], hook->mod[i]->relativePath, hook->modFile[i]->relativePath);
continue;
}
bool outputSet = false;
// return seqIdOverride
if (lua_type(L, -1) == LUA_TNUMBER) {
*seqIdOverride = smlua_to_integer(L, -1);
lua_settop(L, prevTop);
return true;
outputSet = true;
}
lua_settop(L, prevTop);
if (outputSet) {
return true;
}
}
return false;
}
@ -1679,6 +1706,7 @@ bool smlua_call_event_hooks_HOOK_BEFORE_WARP(s16 destLevel, s16 destArea, s16 de
LOG_LUA("Failed to call the callback for hook %s - '%s/%s'", sLuaHookedEventTypeName[HOOK_BEFORE_WARP], hook->mod[i]->relativePath, hook->modFile[i]->relativePath);
continue;
}
bool outputSet = false;
// if the hook returns a table, use it to override the warp parameters
if (lua_istable(L, -1)) {
@ -1701,11 +1729,13 @@ bool smlua_call_event_hooks_HOOK_BEFORE_WARP(s16 destLevel, s16 destArea, s16 de
}
lua_pop(L, 1);
lua_settop(L, prevTop);
return true;
outputSet = true;
}
lua_settop(L, prevTop);
if (outputSet) {
return true;
}
}
return false;
}
@ -1769,15 +1799,18 @@ bool smlua_call_event_hooks_HOOK_MARIO_OVERRIDE_FLOOR_CLASS(struct MarioState *m
LOG_LUA("Failed to call the callback for hook %s - '%s/%s'", sLuaHookedEventTypeName[HOOK_MARIO_OVERRIDE_FLOOR_CLASS], hook->mod[i]->relativePath, hook->modFile[i]->relativePath);
continue;
}
bool outputSet = false;
// return floorClassOverride
if (lua_type(L, -1) == LUA_TNUMBER) {
*floorClassOverride = smlua_to_integer(L, -1);
lua_settop(L, prevTop);
return true;
outputSet = true;
}
lua_settop(L, prevTop);
if (outputSet) {
return true;
}
}
return false;
}