HOOK_ON_PLAY_SOUND
This commit is contained in:
parent
c1d3aba94e
commit
d7bad7dcdd
|
@ -395,4 +395,5 @@ COURSE_MIN = 1
|
|||
-----------------
|
||||
-- legacy font --
|
||||
-----------------
|
||||
|
||||
FONT_TINY = -1
|
|
@ -397,6 +397,7 @@ COURSE_MIN = 1
|
|||
-----------------
|
||||
-- legacy font --
|
||||
-----------------
|
||||
|
||||
FONT_TINY = -1
|
||||
|
||||
--- @type integer
|
||||
|
@ -9294,7 +9295,10 @@ HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED = 39
|
|||
HOOK_ON_OBJECT_LOAD = 40
|
||||
|
||||
--- @type LuaHookedEventType
|
||||
HOOK_MAX = 41
|
||||
HOOK_ON_PLAY_SOUND = 41
|
||||
|
||||
--- @type LuaHookedEventType
|
||||
HOOK_MAX = 42
|
||||
|
||||
--- @class HudDisplayFlags
|
||||
|
||||
|
@ -12595,7 +12599,7 @@ MINOR_VERSION_NUMBER = 1
|
|||
PATCH_VERSION_NUMBER = 0
|
||||
|
||||
--- @type string
|
||||
SM64COOPDX_VERSION = "v0.1.3"
|
||||
SM64COOPDX_VERSION = "v0.1.4"
|
||||
|
||||
--- @type integer
|
||||
VERSION_NUMBER = 36
|
||||
|
|
|
@ -3326,7 +3326,8 @@
|
|||
| HOOK_MIRROR_MARIO_RENDER | 38 |
|
||||
| HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED | 39 |
|
||||
| HOOK_ON_OBJECT_LOAD | 40 |
|
||||
| HOOK_MAX | 41 |
|
||||
| HOOK_ON_PLAY_SOUND | 41 |
|
||||
| HOOK_MAX | 42 |
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
|
@ -128,6 +128,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh
|
|||
| HOOK_MIRROR_MARIO_RENDER | Called when a Mirror Mario is rendered | [GraphNodeObject](structs.md#GraphNodeObject) mirrorMario | `integer` mirrorMarioIndex |
|
||||
| HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED | Called when slope defacto speed for walking is being calculated, overrides the floor normal in the equation | [MarioState](structs.md#MarioState) mario |
|
||||
| HOOK_ON_OBJECT_LOAD | Called when an object is spawned in | [Object](structs.md#Object) obj |
|
||||
| HOOK_ON_PLAY_SOUND | Called when a sound is going to play, return a `SOUND_*` constant or `NO_SOUND` to override the sound | `integer` soundBits, `Vec3f` pos |
|
||||
|
||||
### Parameters
|
||||
|
||||
|
|
|
@ -299,7 +299,7 @@ const u8 sBackgroundMusicDefaultVolumeDefault[35] = {
|
|||
};
|
||||
|
||||
// Default volume for background music sequences (playing on player 0).
|
||||
u8 sBackgroundMusicDefaultVolume[64] = {
|
||||
u8 sBackgroundMusicDefaultVolume[MAX_AUDIO_OVERRIDE] = {
|
||||
127, // SEQ_SOUND_PLAYER
|
||||
80, // SEQ_EVENT_CUTSCENE_COLLECT_STAR
|
||||
80, // SEQ_MENU_TITLE_SCREEN
|
||||
|
@ -366,7 +366,7 @@ u8 sBackgroundMusicDefaultVolume[64] = {
|
|||
75, // SEQ_???
|
||||
};
|
||||
|
||||
STATIC_ASSERT(ARRAY_COUNT(sBackgroundMusicDefaultVolume) == 64,
|
||||
STATIC_ASSERT(ARRAY_COUNT(sBackgroundMusicDefaultVolume) == MAX_AUDIO_OVERRIDE,
|
||||
"change this array if you are adding sequences");
|
||||
|
||||
u8 sCurrentBackgroundMusicSeqId = SEQUENCE_NONE;
|
||||
|
@ -836,6 +836,7 @@ extern f32 *smlua_get_vec3f_for_play_sound(f32 *pos);
|
|||
|
||||
void play_sound(s32 soundBits, f32 *pos) {
|
||||
pos = smlua_get_vec3f_for_play_sound(pos);
|
||||
smlua_call_event_hooks_on_play_sound(HOOK_ON_PLAY_SOUND, soundBits, pos, &soundBits);
|
||||
sSoundRequests[sSoundRequestCount].soundBits = soundBits;
|
||||
sSoundRequests[sSoundRequestCount].position = pos;
|
||||
sSoundRequests[sSoundRequestCount].customFreqScale = 0;
|
||||
|
@ -844,6 +845,7 @@ void play_sound(s32 soundBits, f32 *pos) {
|
|||
|
||||
void play_sound_with_freq_scale(s32 soundBits, f32* pos, f32 freqScale) {
|
||||
pos = smlua_get_vec3f_for_play_sound(pos);
|
||||
smlua_call_event_hooks_on_play_sound(HOOK_ON_PLAY_SOUND, soundBits, pos, &soundBits);
|
||||
sSoundRequests[sSoundRequestCount].soundBits = soundBits;
|
||||
sSoundRequests[sSoundRequestCount].position = pos;
|
||||
sSoundRequests[sSoundRequestCount].customFreqScale = freqScale;
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "types.h"
|
||||
|
||||
#include "pc/lua/utils/smlua_audio_utils.h"
|
||||
|
||||
// Sequence arguments, passed to seq_player_play_sequence. seqId may be bit-OR'ed with
|
||||
// SEQ_VARIATION; this will load the same sequence, but set a variation
|
||||
// bit which may be read by the sequence script.
|
||||
|
@ -44,7 +46,7 @@ extern s32 gAudioErrorFlags;
|
|||
extern f32 gGlobalSoundSource[3];
|
||||
|
||||
extern const u8 sBackgroundMusicDefaultVolumeDefault[35];
|
||||
extern u8 sBackgroundMusicDefaultVolume[64];
|
||||
extern u8 sBackgroundMusicDefaultVolume[MAX_AUDIO_OVERRIDE];
|
||||
|
||||
// defined in data.c, used by the game
|
||||
extern u32 gAudioRandom;
|
||||
|
|
|
@ -3297,7 +3297,8 @@ char gSmluaConstants[] = ""
|
|||
"HOOK_MIRROR_MARIO_RENDER = 38\n"
|
||||
"HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED = 39\n"
|
||||
"HOOK_ON_OBJECT_LOAD = 40\n"
|
||||
"HOOK_MAX = 41\n"
|
||||
"HOOK_ON_PLAY_SOUND = 41\n"
|
||||
"HOOK_MAX = 42\n"
|
||||
"ACTION_HOOK_EVERY_FRAME = 0\n"
|
||||
"ACTION_HOOK_GRAVITY = 1\n"
|
||||
"ACTION_HOOK_MAX = 2\n"
|
||||
|
@ -4393,7 +4394,7 @@ char gSmluaConstants[] = ""
|
|||
"COOP_OBJ_FLAG_LUA = (1 << 1)\n"
|
||||
"COOP_OBJ_FLAG_NON_SYNC = (1 << 2)\n"
|
||||
"COOP_OBJ_FLAG_INITIALIZED = (1 << 3)\n"
|
||||
"SM64COOPDX_VERSION = 'v0.1.3'\n"
|
||||
"SM64COOPDX_VERSION = 'v0.1.4'\n"
|
||||
"VERSION_TEXT = 'beta'\n"
|
||||
"VERSION_NUMBER = 36\n"
|
||||
"MINOR_VERSION_NUMBER = 1\n"
|
||||
|
|
|
@ -671,6 +671,52 @@ void smlua_call_event_hooks_value_param(enum LuaHookedEventType hookType, int mo
|
|||
}
|
||||
}
|
||||
|
||||
void smlua_call_event_hooks_on_play_sound(enum LuaHookedEventType hookType, s32 soundBits, f32* pos, s32* returnValue) {
|
||||
lua_State* L = gLuaState;
|
||||
if (L == NULL) { return; }
|
||||
struct LuaHookedEvent* hook = &sHookedEvents[hookType];
|
||||
for (int i = 0; i < hook->count; i++) {
|
||||
s32 prevTop = lua_gettop(L);
|
||||
|
||||
// push the callback onto the stack
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
|
||||
|
||||
// push sound bits
|
||||
lua_pushinteger(L, soundBits);
|
||||
|
||||
// push vec3f
|
||||
lua_newtable(L);
|
||||
int valTableIndex = lua_gettop(L);
|
||||
|
||||
lua_pushstring(L, "x");
|
||||
lua_pushnumber(L, pos[0]);
|
||||
lua_settable(L, valTableIndex);
|
||||
|
||||
lua_pushstring(L, "y");
|
||||
lua_pushnumber(L, pos[1]);
|
||||
lua_settable(L, valTableIndex);
|
||||
|
||||
lua_pushstring(L, "z");
|
||||
lua_pushnumber(L, pos[2]);
|
||||
lua_settable(L, valTableIndex);
|
||||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) {
|
||||
LOG_LUA("Failed to call the callback: %u", hookType);
|
||||
continue;
|
||||
}
|
||||
|
||||
// output the return value
|
||||
if (lua_type(L, -1) == LUA_TNUMBER) {
|
||||
*returnValue = smlua_to_integer(L, -1);
|
||||
lua_settop(L, prevTop);
|
||||
return;
|
||||
} else {
|
||||
lua_settop(L, prevTop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void smlua_call_event_hooks_use_act_select(enum LuaHookedEventType hookType, int value, bool* foundHook, bool* returnValue) {
|
||||
lua_State* L = gLuaState;
|
||||
*foundHook = false;
|
||||
|
|
|
@ -52,6 +52,7 @@ enum LuaHookedEventType {
|
|||
HOOK_MIRROR_MARIO_RENDER,
|
||||
HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED,
|
||||
HOOK_ON_OBJECT_LOAD,
|
||||
HOOK_ON_PLAY_SOUND,
|
||||
HOOK_MAX,
|
||||
};
|
||||
|
||||
|
@ -97,6 +98,7 @@ static const char* LuaHookedEventTypeName[] = {
|
|||
"HOOK_MIRROR_MARIO_RENDER",
|
||||
"HOOK_OVERRIDE_PHYS_STEP_DEFACTO_SPEED",
|
||||
"HOOK_ON_OBJECT_LOAD",
|
||||
"HOOK_ON_PLAY_SOUND",
|
||||
"HOOK_MAX"
|
||||
};
|
||||
|
||||
|
@ -134,6 +136,7 @@ void smlua_call_event_hooks_set_camera_mode_params(enum LuaHookedEventType hookT
|
|||
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_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);
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
#include "bass_audio/bass_audio_helpers.h"
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
#define MAX_AUDIO_OVERRIDE 128
|
||||
|
||||
struct AudioOverride {
|
||||
bool enabled;
|
||||
bool loaded;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef SMLUA_AUDIO_UTILS_H
|
||||
#define SMLUA_AUDIO_UTILS_H
|
||||
|
||||
#define MAX_AUDIO_OVERRIDE 128
|
||||
|
||||
void smlua_audio_utils_reset_all(void);
|
||||
bool smlua_audio_utils_override(u8 sequenceId, s32* bankId, void** seqData);
|
||||
void smlua_audio_utils_replace_sequence(u8 sequenceId, u8 bankId, u8 defaultVolume, const char* m64Name);
|
||||
|
|
Loading…
Reference in New Issue