From 6cc8ca8ebd3f4ea9bea6f8c1dc227aaa131aadba Mon Sep 17 00:00:00 2001 From: robojumper Date: Thu, 10 Jul 2025 14:15:45 +0200 Subject: [PATCH] A bit more --- config/SOUE01/symbols.txt | 46 ++--- include/d/snd/d_snd_area_sound_effect_mgr.h | 3 + include/d/snd/d_snd_bgm_mgr.h | 11 +- include/d/snd/d_snd_checkers.h | 17 ++ include/d/snd/d_snd_event.h | 3 +- include/d/snd/d_snd_source_mgr.h | 2 + include/d/snd/d_snd_state_mgr.h | 46 +++-- include/nw4r/snd/snd_SoundHandle.h | 5 + include/toBeSorted/event_manager.h | 4 + include/toBeSorted/music_mgrs.h | 1 - src/d/snd/d_snd_3d_manager.cpp | 2 +- src/d/snd/d_snd_area_sound_effect_mgr.cpp | 8 + src/d/snd/d_snd_bgm_mgr.cpp | 18 +- src/d/snd/d_snd_control_player_mgr.cpp | 4 +- src/d/snd/d_snd_event_callbacks.cpp | 2 +- src/d/snd/d_snd_event_demo_callbacks.cpp | 1 - src/d/snd/d_snd_mgr.cpp | 4 +- src/d/snd/d_snd_player_mgr.cpp | 3 +- src/d/snd/d_snd_small_effect_mgr.cpp | 7 +- src/d/snd/d_snd_sound_npc_callbacks.cpp | 3 +- src/d/snd/d_snd_source_mgr.cpp | 8 + src/d/snd/d_snd_state_mgr.cpp | 186 +++++++++++++++++++- 22 files changed, 324 insertions(+), 60 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index bc2f3da0..80e00be5 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -20064,7 +20064,7 @@ fn_80362300 = .text:0x80362300; // type:function size:0x84 fn_80362390 = .text:0x80362390; // type:function size:0x6C fn_80362400 = .text:0x80362400; // type:function size:0x10 fn_80362410 = .text:0x80362410; // type:function size:0xC -fn_80362420 = .text:0x80362420; // type:function size:0x18 +checkFlag0x18__14dSndStateMgr_cFUl = .text:0x80362420; // type:function size:0x18 isInStage__14dSndStateMgr_cFPCc = .text:0x80362440; // type:function size:0x34 fn_80362480 = .text:0x80362480; // type:function size:0x6C fn_803624F0 = .text:0x803624F0; // type:function size:0xF4 @@ -20075,7 +20075,7 @@ EnemySoundMgr__update = .text:0x80362CE0; // type:function size:0xFC EnemySoundMgr__enemyMusicRelated = .text:0x80362DE0; // type:function size:0x154 fn_80362F40 = .text:0x80362F40; // type:function size:0x770 initializeEventCallbacks__14dSndStateMgr_cFPCc = .text:0x803636B0; // type:function size:0xCC -fn_80363780 = .text:0x80363780; // type:function size:0xCC +convertSeLabelToSoundId__14dSndStateMgr_cFPCc = .text:0x80363780; // type:function size:0xCC fn_80363850 = .text:0x80363850; // type:function size:0xA8 fn_80363900 = .text:0x80363900; // type:function size:0xA8 fn_803639B0 = .text:0x803639B0; // type:function size:0xA8 @@ -20093,32 +20093,32 @@ fn_80363DD0 = .text:0x80363DD0; // type:function size:0x1AC fn_80363F80 = .text:0x80363F80; // type:function size:0x48 fn_80363FD0 = .text:0x80363FD0; // type:function size:0x24C fn_80364220 = .text:0x80364220; // type:function size:0x9C -fn_803642C0 = .text:0x803642C0; // type:function size:0x84 +playFanOrBgm__14dSndStateMgr_cFUl = .text:0x803642C0; // type:function size:0x84 fn_80364350 = .text:0x80364350; // type:function size:0x48 fn_803643A0 = .text:0x803643A0; // type:function size:0x130 fn_803644D0 = .text:0x803644D0; // type:function size:0x40 fn_80364510 = .text:0x80364510; // type:function size:0x60 -fn_80364570 = .text:0x80364570; // type:function size:0x8 -fn_80364580 = .text:0x80364580; // type:function size:0x1C4 +handleSe__14dSndStateMgr_cFv = .text:0x80364570; // type:function size:0x8 +handleSeLv__14dSndStateMgr_cFv = .text:0x80364580; // type:function size:0x1C4 fn_80364750 = .text:0x80364750; // type:function size:0x84 -fn_803647E0 = .text:0x803647E0; // type:function size:0x8 -fn_803647F0 = .text:0x803647F0; // type:function size:0x44 +getBgmLabelSoundId__14dSndStateMgr_cFv = .text:0x803647E0; // type:function size:0x8 +handleFan__14dSndStateMgr_cFv = .text:0x803647F0; // type:function size:0x44 fn_80364840 = .text:0x80364840; // type:function size:0x60 -fn_803648A0 = .text:0x803648A0; // type:function size:0x8 -fn_803648B0 = .text:0x803648B0; // type:function size:0x190 -fn_80364A40 = .text:0x80364A40; // type:function size:0x9C +handleCmd__14dSndStateMgr_cFv = .text:0x803648A0; // type:function size:0x8 +finalizeEvent__14dSndStateMgr_cFb = .text:0x803648B0; // type:function size:0x190 +__cl__25SoundStopperIfParamFlag20FRQ34nw4r3snd11SoundHandle = .text:0x80364A40; // type:function size:0x9C fn_80364AE0 = .text:0x80364AE0; // type:function size:0x8C fn_80364B70 = .text:0x80364B70; // type:function size:0xD0 -fn_80364C40 = .text:0x80364C40; // type:function size:0xBC +resetEventVars__14dSndStateMgr_cFv = .text:0x80364C40; // type:function size:0xBC fn_80364D00 = .text:0x80364D00; // type:function size:0x94 -fn_80364DA0 = .text:0x80364DA0; // type:function size:0xC +isInEvent__14dSndStateMgr_cCFv = .text:0x80364DA0; // type:function size:0xC isInEvent__14dSndStateMgr_cFPCc = .text:0x80364DB0; // type:function size:0x2C doMsgStart__14dSndStateMgr_cFl = .text:0x80364DE0; // type:function size:0x7C doMsgEnd__14dSndStateMgr_cFv = .text:0x80364E60; // type:function size:0x54 doMsgWaitStart__14dSndStateMgr_cFv = .text:0x80364EC0; // type:function size:0x90 doMsgWaitEnd__14dSndStateMgr_cFv = .text:0x80364F50; // type:function size:0x7C setFlowEvent__14dSndStateMgr_cFUl = .text:0x80364FD0; // type:function size:0x50 -fn_80365020 = .text:0x80365020; // type:function size:0x84 +onSkipEvent__14dSndStateMgr_cCFv = .text:0x80365020; // type:function size:0x84 fn_803650B0 = .text:0x803650B0; // type:function size:0x6C getStageMusicDemoName = .text:0x80365120; // type:function size:0x28 getCurrentStageMusicDemoName__14dSndStateMgr_cCFv = .text:0x80365150; // type:function size:0x8 @@ -20346,8 +20346,8 @@ fn_8036A690 = .text:0x8036A690; // type:function size:0x9C startSound__24dSndAreaSoundEffectMgr_cFUlUl = .text:0x8036A730; // type:function size:0xEC fn_8036A820 = .text:0x8036A820; // type:function size:0x328 fn_8036AB50 = .text:0x8036AB50; // type:function size:0x20 -fn_8036AB70 = .text:0x8036AB70; // type:function size:0x4 -fn_8036AB80 = .text:0x8036AB80; // type:function size:0x4 +onEventStart__24dSndAreaSoundEffectMgr_cFv = .text:0x8036AB70; // type:function size:0x4 +onEventEnd__24dSndAreaSoundEffectMgr_cFv = .text:0x8036AB80; // type:function size:0x4 fn_8036AB90 = .text:0x8036AB90; // type:function size:0xFC stopSounds__24dSndAreaSoundEffectMgr_cFl = .text:0x8036AC90; // type:function size:0x68 fn_8036AD00 = .text:0x8036AD00; // type:function size:0xB0 @@ -20453,7 +20453,7 @@ fn_8036EA60 = .text:0x8036EA60; // type:function size:0xC4 fn_8036EB30 = .text:0x8036EB30; // type:function size:0xC4 checkForPrepareStoppedBgmSound__12dSndBgmMgr_cFUl = .text:0x8036EC00; // type:function size:0x28 fn_8036EC30 = .text:0x8036EC30; // type:function size:0x98 -fn_8036ECD0 = .text:0x8036ECD0; // type:function size:0x64 +prepareBgm__12dSndBgmMgr_cFv = .text:0x8036ECD0; // type:function size:0x64 startAdditionalBgm__12dSndBgmMgr_cFUl = .text:0x8036ED40; // type:function size:0x58 fn_8036EDA0 = .text:0x8036EDA0; // type:function size:0x3F8 fn_8036F1A0 = .text:0x8036F1A0; // type:function size:0x58 @@ -20493,13 +20493,13 @@ calcDelayedSound__12dSndBgmMgr_cFv = .text:0x80370E20; // type:function size:0x2 fn_80370E50 = .text:0x80370E50; // type:function size:0x6C setBgmHandleIdxVolume__12dSndBgmMgr_cFUlfl = .text:0x80370EC0; // type:function size:0x70 fn_80370F30 = .text:0x80370F30; // type:function size:0x6C -fn_80370FA0 = .text:0x80370FA0; // type:function size:0xA0 +onEventStart__12dSndBgmMgr_cFPCcll = .text:0x80370FA0; // type:function size:0xA0 fn_80371040 = .text:0x80371040; // type:function size:0x138 fn_80371180 = .text:0x80371180; // type:function size:0x1A8 fn_80371330 = .text:0x80371330; // type:function size:0x48 fn_80371380 = .text:0x80371380; // type:function size:0x48 -fn_803713D0 = .text:0x803713D0; // type:function size:0x4C -fn_80371420 = .text:0x80371420; // type:function size:0x58 +setBgmToPlayOnEventEnd__12dSndBgmMgr_cFUl = .text:0x803713D0; // type:function size:0x4C +onEventEnd__12dSndBgmMgr_cFv = .text:0x80371420; // type:function size:0x58 fn_80371480 = .text:0x80371480; // type:function size:0x7C fn_80371500 = .text:0x80371500; // type:function size:0x60 fn_80371560 = .text:0x80371560; // type:function size:0x84 @@ -21006,8 +21006,8 @@ fn_803853D0 = .text:0x803853D0; // type:function size:0xA0 stopAllSound__15dSndSourceMgr_cFv = .text:0x80385470; // type:function size:0x78 stopAllNonPlayerSound__15dSndSourceMgr_cFv = .text:0x803854F0; // type:function size:0x94 fn_80385590 = .text:0x80385590; // type:function size:0x74 -fn_80385610 = .text:0x80385610; // type:function size:0x4 -fn_80385620 = .text:0x80385620; // type:function size:0x4 +onEventStart__15dSndSourceMgr_cFv = .text:0x80385610; // type:function size:0x4 +onEventEnd__15dSndSourceMgr_cFv = .text:0x80385620; // type:function size:0x4 fn_80385630 = .text:0x80385630; // type:function size:0x8 fn_80385640 = .text:0x80385640; // type:function size:0x134 getPlayerSourceRoomId__15dSndSourceMgr_cCFv = .text:0x80385780; // type:function size:0x34 @@ -37984,10 +37984,10 @@ lbl_80548998 = .data:0x80548998; // type:object size:0x14 lbl_805489AC = .data:0x805489AC; // type:object size:0x14 data:string lbl_805489C0 = .data:0x805489C0; // type:object size:0x10 data:string lbl_805489D0 = .data:0x805489D0; // type:object size:0xC -lbl_805489DC = .data:0x805489DC; // type:object size:0xC +__vt__25SoundStopperIfParamFlag20 = .data:0x805489DC; // type:object size:0xC lbl_805489E8 = .data:0x805489E8; // type:object size:0xC __vt__32SndMgrDisposer<14dSndStateMgr_c> = .data:0x805489F4; // type:object size:0xC -@STRING@resetStageName__14dSndStateMgr_cFv = .data:0x80548A00; // type:object size:0xB data:string +@STRING@resetEventName__14dSndStateMgr_cFv = .data:0x80548A00; // type:object size:0xB data:string lbl_80548A0C = .data:0x80548A0C; // type:object size:0xC lbl_80548A18 = .data:0x80548A18; // type:object size:0x10 lbl_80548A28 = .data:0x80548A28; // type:object size:0x10 diff --git a/include/d/snd/d_snd_area_sound_effect_mgr.h b/include/d/snd/d_snd_area_sound_effect_mgr.h index 3cda1f9b..2e450743 100644 --- a/include/d/snd/d_snd_area_sound_effect_mgr.h +++ b/include/d/snd/d_snd_area_sound_effect_mgr.h @@ -25,6 +25,9 @@ public: void stopSounds(s32 fadeFrames); void pauseAllSounds(); + void onEventStart(); + void onEventEnd(); + private: bool isPlayingAnySound() const; bool isPlayingSound(u32 soundId) const; diff --git a/include/d/snd/d_snd_bgm_mgr.h b/include/d/snd/d_snd_bgm_mgr.h index aa8654fa..3500283c 100644 --- a/include/d/snd/d_snd_bgm_mgr.h +++ b/include/d/snd/d_snd_bgm_mgr.h @@ -37,6 +37,11 @@ public: void pauseAllBgm(); void stopAllBgm(s32 fadeFrames); + void setBgmToPlayOnEventEnd(u32 soundId); + bool onEventEnd(); + void onEventStart(const char *eventName, s32 soundEventId, s32 unk); + void prepareBgm(); + dSndBgmSound_c *getSoundHandleForBgm(u32 soundId, u32 startOffset); bool isPlayingBgmSound() const; bool isPlayingBgmSoundId(u32 soundId) const; @@ -93,6 +98,10 @@ public: return getActiveBgmSound(); } + void setField_0x306(u8 val) { + field_0x306 = val; + } + private: dSndBgmBattleSound_c *getBgmBattleSound(); @@ -144,7 +153,7 @@ private: /* 0x29C */ UNKWORD field_0x29C; /* 0x2A0 */ dSndActor_c mSoundActor; /* 0x2F4 */ f32 field_0x2F4; - /* 0x2F8 */ s32 field_0x2F8; + /* 0x2F8 */ u32 mBgmToPlayOnEventEnd; /* 0x2FC */ u8 field_0x2FC; /* 0x300 */ s32 field_0x300; /* 0x304 */ u8 field_0x304; diff --git a/include/d/snd/d_snd_checkers.h b/include/d/snd/d_snd_checkers.h index e6bff0de..880d65e3 100644 --- a/include/d/snd/d_snd_checkers.h +++ b/include/d/snd/d_snd_checkers.h @@ -3,6 +3,7 @@ #include "common.h" #include "d/snd/d_snd_bgm_mgr.h" +#include "d/snd/d_snd_player_mgr.h" #include "nw4r/snd/snd_SoundHandle.h" class SoundPropertiesChecker { @@ -108,4 +109,20 @@ private: /* 0x08 */ s32 mFadeFrames; }; +class SoundStopperIfParamFlag20 { +public: + SoundStopperIfParamFlag20() {} + + virtual void operator()(nw4r::snd::SoundHandle &pHandle) { + u32 id = pHandle.GetId(); + u32 param = dSndPlayerMgr_c::GetInstance()->getDemoArchive()->GetSoundUserParam(id); + if ((param & 0x100000) != 0) { + u32 fadeFrames = param & 0xFF; + pHandle.Stop(fadeFrames); + } + } + +private: +}; + #endif diff --git a/include/d/snd/d_snd_event.h b/include/d/snd/d_snd_event.h index dafff2d9..2c394869 100644 --- a/include/d/snd/d_snd_event.h +++ b/include/d/snd/d_snd_event.h @@ -4,13 +4,14 @@ #include "common.h" typedef void (*SndEventCallback)(void); +typedef void (*SndEventFinalizeCallback)(bool skipped); struct SndEventDef { /* 0x00 */ const char *eventName; /* 0x04 */ s32 eventId; /* 0x08 */ SndEventCallback initializeCb; /* 0x0C */ SndEventCallback executeCb; - /* 0x10 */ SndEventCallback finalizeCb; + /* 0x10 */ SndEventFinalizeCallback finalizeCb; /* 0x14 */ u8 _0x14[0x1C - 0x14]; // always zero }; diff --git a/include/d/snd/d_snd_source_mgr.h b/include/d/snd/d_snd_source_mgr.h index e1eb6a28..19f22d85 100644 --- a/include/d/snd/d_snd_source_mgr.h +++ b/include/d/snd/d_snd_source_mgr.h @@ -63,6 +63,8 @@ public: } void setMutedFromFader(bool muteFlag); + void onEventStart(); + void onEventEnd(); private: void calcEnemyObjVolume(); diff --git a/include/d/snd/d_snd_state_mgr.h b/include/d/snd/d_snd_state_mgr.h index 13c3b1df..a164d78c 100644 --- a/include/d/snd/d_snd_state_mgr.h +++ b/include/d/snd/d_snd_state_mgr.h @@ -5,6 +5,7 @@ #include "d/snd/d_snd_event.h" #include "d/snd/d_snd_util.h" #include "nw4r/snd/snd_FxReverbStdDpl2.h" +#include "nw4r/snd/snd_SoundHandle.h" #include "sized_string.h" SND_DISPOSER_FORWARD_DECL(dSndStateMgr_c); @@ -15,6 +16,8 @@ public: SND_DISPOSER_MEMBERS(dSndStateMgr_c); public: + typedef void (*OnEventStartCallback)(s32 soundEventId, u32 flags); + enum StageFlags_e { STAGE_FIELD = 0x1, STAGE_DUNGEON = 0x2, @@ -33,6 +36,7 @@ public: enum EventFlags_e { EVENT_IN_EVENT = 0x1, EVENT_DEMO = 0x2, + EVENT_0x04 = 0x4, EVENT_MUTE_BGM_PARTIAL = 0x8, EVENT_MUTE_BGM_FULL = 0x10, EVENT_MUTE_STAGE_EFFECTS_PARTIAL = 0x20, @@ -41,6 +45,7 @@ public: EVENT_MUTE_ENEMY_FULL = 0x100, EVENT_MUTE_OBJ_PARTIAL = 0x200, EVENT_MUTE_OBJ_FULL = 0x400, + EVENT_0x800 = 0x800, EVENT_0x400000 = 0x400000, }; @@ -76,10 +81,12 @@ public: return field_0x49C; } - void resetStageName() { - field_0x098 = "EVENT_NONE"; + void resetEventName() { + mEventName = "EVENT_NONE"; } + bool checkFlag0x18(u32 mask); + bool checkFlag0x10(u32 mask) const { return field_0x010 & mask; } @@ -92,7 +99,7 @@ public: field_0x010 &= ~mask; } - bool checkEventFlag(u32 mask) const { + bool checkEventFlag(u32 mask) { return mEventFlags & mask; } @@ -111,9 +118,12 @@ public: return getCurrentStageMusicDemoName() != nullptr; } + void setEvent(const char *eventName); // not sure, subtype is unused bool isActiveDemoMaybe(s32 subtype) const; bool isInEvent(const char *eventName); + bool isInEvent() const; + bool onSkipEvent() const; void doMsgStart(s32 idx); void doMsgEnd(); @@ -151,6 +161,20 @@ private: bool handleStageEvent(const char *name); void handleDemoEvent(const char *name); + u32 convertSeLabelToSoundId(const char *label); + u32 convertBgmLabelToSoundId(const char *label); + + u32 getBgmLabelSoundId(); + bool playFanOrBgm(u32 soundId); + + void handleFan(); + void handleSe(); + void handleCmd(); + void handleSeLv(); + bool finalizeEvent(bool skipped); + + void resetEventVars(); + // Callbacks start static void cbUnkNoop(); @@ -173,7 +197,7 @@ private: /* 0x010 */ u32 field_0x010; /* 0x014 */ UNKWORD field_0x014; /* 0x018 */ UNKWORD field_0x018; - /* 0x01C */ SizedString<32> field_0x01C; + /* 0x01C */ SizedString<32> mStageName; /* 0x03C */ UNKWORD field_0x03C; /* 0x040 */ s32 mStageId; /* 0x044 */ UNKWORD field_0x044; @@ -189,9 +213,9 @@ private: /* 0x067 */ u8 field_0x067; /* 0x068 */ UNKWORD field_0x068; /* 0x06C */ UNKWORD field_0x06C; - /* 0x070 */ UNKWORD field_0x070; + /* 0x070 */ void (*mpUnkCallback)(); /* 0x074 */ UNKWORD field_0x074; - /* 0x078 */ UNKWORD field_0x078; + /* 0x078 */ OnEventStartCallback mpOnEventStartCallback; /* 0x07C */ UNKWORD field_0x07C; /* 0x080 */ UNKWORD field_0x080; /* 0x084 */ UNKWORD field_0x084; @@ -199,21 +223,21 @@ private: /* 0x08C */ s32 mSoundEventId; /* 0x090 */ UNKWORD field_0x090; /* 0x094 */ u32 mEventFlags; - /* 0x098 */ SizedString<64> field_0x098; - /* 0x0D8 */ SizedString<64> field_0x0D8; + /* 0x098 */ SizedString<64> mEventName; + /* 0x0D8 */ SizedString<64> mPrevEventName; /* 0x118 */ const char *field_0x118; /* 0x11C */ u32 field_0x11C; /* 0x120 */ UNKWORD field_0x120; /* 0x124 */ UNKWORD field_0x124; - /* 0x128 */ UNKWORD field_0x128; + /* 0x128 */ u32 mSeLvSoundId; /* 0x12C */ SizedString<64> mSeName; /* 0x16C */ SizedString<64> mBgmName; /* 0x1AC */ SizedString<64> mFanName; /* 0x1EC */ SizedString<64> mCmdName; /* 0x22C */ UNKWORD field_0x22C; - /* 0x230 */ UNKWORD field_0x230; + /* 0x230 */ nw4r::snd::SoundHandle mSeLvSoundHandle; /* 0x234 */ const SndEventDef *mpSoundEventDef; - /* 0x238 */ UNKWORD field_0x238; + /* 0x238 */ u32 field_0x238; /* 0x23C */ u8 field_0x23C; /* 0x23D */ u8 field_0x23D; /* 0x240 */ UNKWORD field_0x240; diff --git a/include/nw4r/snd/snd_SoundHandle.h b/include/nw4r/snd/snd_SoundHandle.h index a69b7999..4dd83232 100644 --- a/include/nw4r/snd/snd_SoundHandle.h +++ b/include/nw4r/snd/snd_SoundHandle.h @@ -69,6 +69,11 @@ namespace nw4r { namespace snd mSound->SetPan(pan); } + void SetFxSend(AuxBus bus, f32 send) { + if (IsAttachedSound()) + mSound->SetFxSend(bus, send); + } + void SetLpfFreq(f32 lpfFreq) { if (IsAttachedSound()) mSound->SetLpfFreq(lpfFreq); diff --git a/include/toBeSorted/event_manager.h b/include/toBeSorted/event_manager.h index c248e8b8..561490c8 100644 --- a/include/toBeSorted/event_manager.h +++ b/include/toBeSorted/event_manager.h @@ -37,6 +37,10 @@ public: return isInEvent() ? sInstance->mCurrentEvent.eventName : nullptr; } + static s32 getCurrentEventRoomId() { + return isInEvent() ? sInstance->mCurrentEvent.roomid : -1; + } + static bool isCurrentEvent(const char *name) { return strequals(getCurrentEventName(), name); } diff --git a/include/toBeSorted/music_mgrs.h b/include/toBeSorted/music_mgrs.h index 17821527..ef62b8b2 100644 --- a/include/toBeSorted/music_mgrs.h +++ b/include/toBeSorted/music_mgrs.h @@ -23,7 +23,6 @@ extern "C" void fn_803618F0(dSndStateMgr_c *); extern "C" void fn_80362730(dSndStateMgr_c *); extern "C" void fn_80365D20(dSndStateMgr_c *); extern "C" void fn_803624F0(dSndStateMgr_c *); -extern "C" bool fn_80364DA0(dSndStateMgr_c *); extern "C" void fn_80365020(dSndStateMgr_c *); extern "C" void fn_80364D00(dSndStateMgr_c *, s32); diff --git a/src/d/snd/d_snd_3d_manager.cpp b/src/d/snd/d_snd_3d_manager.cpp index bc204ce8..07a14b51 100644 --- a/src/d/snd/d_snd_3d_manager.cpp +++ b/src/d/snd/d_snd_3d_manager.cpp @@ -75,7 +75,7 @@ void dSnd3DManager_c::updateFromCamera(EGG::LookAtCamera &camera) { } f32 dist = 0.5f; - if (fn_80364DA0(ENEMY_SOUND_MGR)) { + if (dSndStateMgr_c::GetInstance()->isInEvent()) { dist = mCamDistance; f32 prevCameraAtSqVelocity = mCameraAtSqVelocity; f32 prevCameraPosSqVelocity = mCameraPosSqVelocity; diff --git a/src/d/snd/d_snd_area_sound_effect_mgr.cpp b/src/d/snd/d_snd_area_sound_effect_mgr.cpp index c21bdb69..691aa918 100644 --- a/src/d/snd/d_snd_area_sound_effect_mgr.cpp +++ b/src/d/snd/d_snd_area_sound_effect_mgr.cpp @@ -50,6 +50,14 @@ bool dSndAreaSoundEffectMgr_c::startSound(u32 soundId, u32 handleIdx) { return res; } +void dSndAreaSoundEffectMgr_c::onEventStart() { + // no-op +} + +void dSndAreaSoundEffectMgr_c::onEventEnd() { + // no-op +} + void dSndAreaSoundEffectMgr_c::stopSounds(s32 fadeFrames) { for (u32 i = 0; i < 3; i++) { mSounds[i].stop(fadeFrames); diff --git a/src/d/snd/d_snd_bgm_mgr.cpp b/src/d/snd/d_snd_bgm_mgr.cpp index 04e206b2..1563c995 100644 --- a/src/d/snd/d_snd_bgm_mgr.cpp +++ b/src/d/snd/d_snd_bgm_mgr.cpp @@ -35,7 +35,7 @@ dSndBgmMgr_c::dSndBgmMgr_c() field_0x29C(0), mSoundActor(dSndMgr_c::GetInstance()->getPlayer()), field_0x2F4(1.0f), - field_0x2F8(-1), + mBgmToPlayOnEventEnd(-1), field_0x2FC(0), field_0x300(-1), field_0x304(0), @@ -278,6 +278,22 @@ void dSndBgmMgr_c::setBgmHandleIdxVolume(u32 handleIdx, f32 volume, s32 fadeFram } } +void dSndBgmMgr_c::setBgmToPlayOnEventEnd(u32 soundId) { + if (soundId != -1) { + prepareBgm(soundId, 0); + mBgmToPlayOnEventEnd = soundId; + } +} + +bool dSndBgmMgr_c::onEventEnd() { + bool ret = false; + if (mBgmToPlayOnEventEnd != -1) { + ret = playBgm(mBgmToPlayOnEventEnd, 0, false); + mBgmToPlayOnEventEnd = -1; + } + return ret; +} + bool dSndBgmMgr_c::isPlayingBgmSound() const { for (int i = 0; i < 7; i++) { if (mBgmSounds[i]->isPlaying()) { diff --git a/src/d/snd/d_snd_control_player_mgr.cpp b/src/d/snd/d_snd_control_player_mgr.cpp index 88e45102..5503760a 100644 --- a/src/d/snd/d_snd_control_player_mgr.cpp +++ b/src/d/snd/d_snd_control_player_mgr.cpp @@ -5,9 +5,9 @@ #include "d/snd/d_snd_control_player.h" #include "d/snd/d_snd_mgr.h" #include "d/snd/d_snd_player_mgr.h" +#include "d/snd/d_snd_state_mgr.h" #include "nw4r/snd/snd_SoundHandle.h" #include "nw4r/ut/ut_list.h" -#include "toBeSorted/music_mgrs.h" struct FanfareMuteFlagsApplier { ~FanfareMuteFlagsApplier() {} @@ -24,7 +24,7 @@ struct FanfareMuteFlagsApplier { dSndControlPlayerMgr_c::GetInstance()->setBgmVolumeDecreaseSpeed(0.2f); } - if (fn_80364DA0(ENEMY_SOUND_MGR)) { + if (dSndStateMgr_c::GetInstance()->isInEvent()) { if (!(userParam & dSndPlayerMgr_c::FANFARE_UNMUTE_STAGE_EFFECTS)) { dSndControlPlayerMgr_c::GetInstance()->setGroupVolumeFlag( dSndControlPlayerMgr_c::CTRL_GROUP_STAGE_EFFECTS, dSndControlPlayerMgr_c::MUTE_FULL diff --git a/src/d/snd/d_snd_event_callbacks.cpp b/src/d/snd/d_snd_event_callbacks.cpp index ef47659d..9e05cc71 100644 --- a/src/d/snd/d_snd_event_callbacks.cpp +++ b/src/d/snd/d_snd_event_callbacks.cpp @@ -5,7 +5,7 @@ void todoInititalizeSndEvent(); void todoExecuteSndEvent(); -void todoFinalizeSndEvent(); +void todoFinalizeSndEvent(bool skipped); #pragma push #pragma readonly_strings on diff --git a/src/d/snd/d_snd_event_demo_callbacks.cpp b/src/d/snd/d_snd_event_demo_callbacks.cpp index d7e71ae7..8d806c06 100644 --- a/src/d/snd/d_snd_event_demo_callbacks.cpp +++ b/src/d/snd/d_snd_event_demo_callbacks.cpp @@ -4,7 +4,6 @@ void todoInititalizeSndEvent(); void todoExecuteSndEvent(); -void todoFinalizeSndEvent(); // clang-format off diff --git a/src/d/snd/d_snd_mgr.cpp b/src/d/snd/d_snd_mgr.cpp index 4b8eadb2..bfa6be62 100644 --- a/src/d/snd/d_snd_mgr.cpp +++ b/src/d/snd/d_snd_mgr.cpp @@ -3,6 +3,7 @@ #include "d/snd/d_snd_3d_manager.h" #include "d/snd/d_snd_area_sound_effect_mgr.h" #include "d/snd/d_snd_bgm_mgr.h" +#include "d/snd/d_snd_bgm_seq_data_mgr.h" #include "d/snd/d_snd_control_player_mgr.h" #include "d/snd/d_snd_distant_sound_actor_pool.h" #include "d/snd/d_snd_player_mgr.h" @@ -14,7 +15,6 @@ #include "egg/audio/eggAudioRmtSpeakerMgr.h" #include "egg/audio/eggAudioUtility.h" -extern "C" void initSomeUnusedSoundMgr(); extern "C" void fn_8037F940(); extern "C" void fn_80399600(); @@ -27,7 +27,7 @@ dSndMgr_c::dSndMgr_c() : field_0x6CC(0) { dSndStateMgr_c::create(); dSnd3DManager_c::create(); dSndBgmMgr_c::create(); - initSomeUnusedSoundMgr(); + dSndBgmSeqDataMgr_c::create(); dSndSmallEffectMgr_c::create(); dSndAreaSoundEffectMgr_c::create(); dSndSourceMgr_c::create(); diff --git a/src/d/snd/d_snd_player_mgr.cpp b/src/d/snd/d_snd_player_mgr.cpp index 3663b779..741690e1 100644 --- a/src/d/snd/d_snd_player_mgr.cpp +++ b/src/d/snd/d_snd_player_mgr.cpp @@ -20,7 +20,6 @@ #include "nw4r/snd/snd_SoundHandle.h" #include "nw4r/snd/snd_SoundStartable.h" #include "sized_string.h" -#include "toBeSorted/music_mgrs.h" const char *dSndPlayerMgr_c::getSoundArchivePath() { return "Sound/WZSound.brsar"; @@ -168,7 +167,7 @@ void dSndPlayerMgr_c::enterCaution() { } s32 frames = 9; - if (fn_80364DA0(ENEMY_SOUND_MGR)) { + if (dSndStateMgr_c::GetInstance()->isInEvent()) { frames = 0; } diff --git a/src/d/snd/d_snd_small_effect_mgr.cpp b/src/d/snd/d_snd_small_effect_mgr.cpp index eaf02c1b..41c89b8e 100644 --- a/src/d/snd/d_snd_small_effect_mgr.cpp +++ b/src/d/snd/d_snd_small_effect_mgr.cpp @@ -21,7 +21,6 @@ #include "nw4r/snd/snd_SoundStartable.h" #include "nw4r/snd/snd_global.h" #include "rvl/OS/OSFastCast.h" -#include "toBeSorted/music_mgrs.h" SND_DISPOSER_DEFINE(dSndSmallEffectMgr_c) @@ -175,8 +174,8 @@ bool dSndSmallEffectMgr_c::playSound(u32 soundId) { break; } case SE_S_SKIP: { - if (fn_80364DA0(ENEMY_SOUND_MGR)) { - fn_80365020(ENEMY_SOUND_MGR); + if (dSndStateMgr_c::GetInstance()->isInEvent()) { + dSndStateMgr_c::GetInstance()->onSkipEvent(); } break; } @@ -349,7 +348,7 @@ bool dSndSmallEffectMgr_c::holdBowChargeSound(f32 remainingChargeAmount) { } bool dSndSmallEffectMgr_c::holdFinisherPromptSound(const nw4r::math::VEC3 *position) { - if (fn_80364DA0(ENEMY_SOUND_MGR)) { + if (dSndStateMgr_c::GetInstance()->isInEvent()) { return false; } return dSndDistantSoundActorPool_c::GetInstance()->holdSound(SE_S_FOCUS_FINISHER_LV, position); diff --git a/src/d/snd/d_snd_sound_npc_callbacks.cpp b/src/d/snd/d_snd_sound_npc_callbacks.cpp index e809927f..94054d87 100644 --- a/src/d/snd/d_snd_sound_npc_callbacks.cpp +++ b/src/d/snd/d_snd_sound_npc_callbacks.cpp @@ -4,11 +4,10 @@ #include "d/snd/d_snd_state_mgr.h" #include "d/snd/d_snd_wzsound.h" #include "nw4r/snd/snd_SeqSoundHandle.h" -#include "toBeSorted/music_mgrs.h" void dSndSourcePyBird_c::cbPyBirdGlide(dSndSeSound_c *sound, dSoundSource_c *source, nw4r::snd::SoundHandle &handle) { s32 var = 0; - if (!fn_80364DA0(dSndStateMgr_c::GetInstance())) { + if (!dSndStateMgr_c::GetInstance()->isInEvent()) { var = static_cast(source)->mSeqVarValue; } nw4r::snd::SeqSoundHandle seqHandle(&handle); diff --git a/src/d/snd/d_snd_source_mgr.cpp b/src/d/snd/d_snd_source_mgr.cpp index 9a391372..85e196d4 100644 --- a/src/d/snd/d_snd_source_mgr.cpp +++ b/src/d/snd/d_snd_source_mgr.cpp @@ -580,6 +580,14 @@ void dSndSourceMgr_c::clearSourceList(nw4r::ut::List *list) { } } +void dSndSourceMgr_c::onEventStart() { + // no-op +} + +void dSndSourceMgr_c::onEventEnd() { + // no-op +} + s32 dSndSourceMgr_c::getPlayerSourceRoomId() const { if (mpPlayerSource == nullptr) { return -1; diff --git a/src/d/snd/d_snd_state_mgr.cpp b/src/d/snd/d_snd_state_mgr.cpp index 86100d36..8dd9ff4d 100644 --- a/src/d/snd/d_snd_state_mgr.cpp +++ b/src/d/snd/d_snd_state_mgr.cpp @@ -2,13 +2,22 @@ #include "common.h" #include "d/d_sc_game.h" +#include "d/snd/d_snd_area_sound_effect_mgr.h" +#include "d/snd/d_snd_bgm_mgr.h" +#include "d/snd/d_snd_checkers.h" +#include "d/snd/d_snd_control_player_mgr.h" #include "d/snd/d_snd_event.h" +#include "d/snd/d_snd_mgr.h" #include "d/snd/d_snd_player_mgr.h" +#include "d/snd/d_snd_source_mgr.h" #include "d/snd/d_snd_stage_data.h" #include "d/snd/d_snd_util.h" #include "egg/core/eggHeap.h" #include "nw4r/snd/snd_FxReverbStdDpl2.h" +#include "nw4r/snd/snd_SoundPlayer.h" +#include "nw4r/snd/snd_global.h" #include "sized_string.h" +#include "toBeSorted/event_manager.h" #include @@ -32,9 +41,9 @@ dSndStateMgr_c::dSndStateMgr_c() field_0x067(0), field_0x068(-1), field_0x06C(-1), - field_0x070(0), + mpUnkCallback(nullptr), field_0x074(0), - field_0x078(0), + mpOnEventStartCallback(nullptr), field_0x07C(0), field_0x080(0), field_0x084(0), @@ -46,9 +55,8 @@ dSndStateMgr_c::dSndStateMgr_c() field_0x11C(0), field_0x120(0), field_0x124(0), - field_0x128(-1), + mSeLvSoundId(-1), field_0x22C(0), - field_0x230(0), mpSoundEventDef(nullptr), field_0x238(-1), field_0x23C(0), @@ -85,7 +93,7 @@ void dSndStateMgr_c::setup(EGG::Heap *pHeap) { } void *mem = pHeap->alloc(max, 4); mFx.AssignWorkBuffer(mem, max); - resetStageName(); + resetEventName(); } void dSndStateMgr_c::onStageOrLayerUpdate() { @@ -98,9 +106,9 @@ void dSndStateMgr_c::onStageOrLayerUpdate() { onFlag0x10(0x2); field_0x064 = 0; - if (!streq(field_0x098, dScGame_c::currentSpawnInfo.getStageName())) { + if (!streq(mStageName, dScGame_c::currentSpawnInfo.getStageName())) { needsGroupsReload = true; - field_0x01C = dScGame_c::currentSpawnInfo.getStageName(); + mStageName = dScGame_c::currentSpawnInfo.getStageName(); } if (!needsGroupsReload && dScGame_c::currentSpawnInfo.layer != mLayer) { @@ -197,6 +205,130 @@ bool dSndStateMgr_c::isSeekerStoneStage(const char *stageName, s32 layer) { return false; } +void dSndStateMgr_c::setEvent(const char *eventName) { + if (eventName == nullptr) { + return; + } + + if (dSndPlayerMgr_c::GetInstance()->checkFlag(dSndPlayerMgr_c::MGR_CAUTION)) { + dSndPlayerMgr_c::GetInstance()->leaveCaution(); + } + + if (field_0x064 == 0) { + if (streq(mEventName, "DefaultSkip")) { + onSkipEvent(); + mPrevEventName = mEventName; + return; + } + + if (!checkFlag0x18(0x20) || !checkFlag0x10(0x04)) { + SizedString<64> prevEvent = mEventName; + if (isInEvent()) { + field_0x23C = 1; + finalizeEvent(false); + } else { + field_0x23C = 0; + } + + // TODO - constness or direct access + if (checkEventFlag(EVENT_0x04)) { + offEventFlag(EVENT_0x04); + } + mEventName = eventName; + mPrevEventName = prevEvent; + resetEventVars(); + field_0x23D = 0; + field_0x238 = -1; + + if (streq(mEventName, "STB")) { + if (field_0x118 != nullptr) { + mEventName = field_0x118; + } + onEventFlag(EVENT_DEMO); + } else { + field_0x118 = nullptr; + } + + if (!checkFlag0x10(0x04)) { + if (mpUnkCallback != nullptr) { + mpUnkCallback(); + } + field_0x23D = 1; + dSndBgmMgr_c::GetInstance()->setField_0x306(1); + dSndBgmMgr_c::GetInstance()->prepareBgm(); + onEventFlag(EVENT_0x04); + onFlag0x10(0x04); + dSndControlPlayerMgr_c::GetInstance()->unmuteScenePlayers(30); + } + bool b2 = checkEventFlag(EVENT_0x800) && dSndBgmMgr_c::GetInstance()->isPlayingBgmSound(); + if (checkEventFlag(EVENT_0x800) && field_0x064 == 0) { + // TODO - constness or direct access + offEventFlag(0x800); + } + + mSoundEventId = SND_EVENT_0x89; + initializeEventCallbacks(mEventName); + s32 i3 = 0; + SizedString<64> eventLabel; + if (mSoundEventId == SND_EVENT_JMAP) { + s32 roomId = EventManager::getCurrentEventRoomId(); + // UB: Cannot pass object of non-POD type 'SizedString<32>' through variadic method + eventLabel.sprintf("%s_R%d_JMAP_%d", mStageName, mLayer, roomId); + } else if (mSoundEventId == SND_EVENT_JMAPAllMove) { + s32 roomId = EventManager::getCurrentEventRoomId(); + // UB: Cannot pass object of non-POD type 'SizedString<32>' through variadic method + eventLabel.sprintf("%s_R%d_JMAPAllMove_%d", mStageName, mLayer, roomId); + } else { + eventLabel.sprintf("%s", &mEventName); + } + + if (checkEventFlag(EVENT_DEMO)) { + mBgmName.sprintf("BGM_%s", &eventLabel); + mFanName.sprintf("FAN_%s", &eventLabel); + mSeName.sprintf("SE_%s", &eventLabel); + mCmdName.sprintf("CMD_%s", &eventLabel); + } else { + mBgmName.sprintf("BGM_EVENT_%s", &eventLabel); + mFanName.sprintf("FAN_EVENT_%s", &eventLabel); + mSeName.sprintf("SE_EVENT_%s", &eventLabel); + mCmdName.sprintf("CMD_EVENT_%s", &eventLabel); + } + + if (checkEventFlag(EVENT_0x04)) { + field_0x238 = getBgmLabelSoundId(); + if (b2 && field_0x238 == -1) { + field_0x23D = 0; + } + } else { + i3 = playFanOrBgm(getBgmLabelSoundId()); + if (i3) { + field_0x23D = 0; + } + } + + handleFan(); + handleSe(); + handleSeLv(); + handleCmd(); + + if (mSoundEventId != SND_EVENT_0x89) { + onEventFlag(EVENT_IN_EVENT); + field_0x11C = 0; + field_0x120 = 0; + field_0x124 = 0; + if (mpOnEventStartCallback != nullptr) { + (mpOnEventStartCallback)(mSoundEventId, mEventFlags); + } + if (field_0x238 == -1) { + dSndBgmMgr_c::GetInstance()->onEventStart(mEventName, mSoundEventId, i3); + } + dSndAreaSoundEffectMgr_c::GetInstance()->onEventStart(); + dSndSourceMgr_c::GetInstance()->onEventStart(); + } + } + } +} + bool dSndStateMgr_c::isInStage(const char *stageName) { return !std::strcmp(dScGame_c::currentSpawnInfo.getStageName(), stageName); } @@ -233,6 +365,46 @@ void dSndStateMgr_c::initializeEventCallbacks(const char *name) { } } +void dSndStateMgr_c::handleSeLv() { + SizedString<0x40> name = mSeName; + name += "_LV"; + u32 soundId = convertSeLabelToSoundId(name); + if (soundId != -1) { + mSeLvSoundId = soundId; + if (dSndMgr_c::GetInstance()->holdSound(&mSeLvSoundHandle, soundId)) { + u32 id = dSndPlayerMgr_c::GetInstance()->getDemoArchive()->GetSoundUserParam(soundId); + if ((dSndPlayerMgr_c::sEventMuteFlagsMask & id & 0x2000000) == 0) { + mSeLvSoundHandle.SetFxSend(nw4r::snd::AUX_A, field_0x49C); + } + } + } else { + mSeLvSoundId = -1; + } +} + +bool dSndStateMgr_c::finalizeEvent(bool skipped) { + dSndPlayerMgr_c *mgr = dSndPlayerMgr_c::GetInstance(); + if (mgr->checkFlag(dSndPlayerMgr_c::MGR_CAUTION)) { + mgr->leaveCaution(); + } + if (!isInEvent()) { + return false; + } + + if (mpSoundEventDef != nullptr && mpSoundEventDef->finalizeCb) { + mpSoundEventDef->finalizeCb(skipped); + } + + if (!isInDemo()) { + nw4r::snd::SoundPlayer *p = dSndControlPlayerMgr_c::GetInstance()->getPlayer1(dSndPlayerMgr_c::PLAYER_EVENT); + SoundStopperIfParamFlag20 stopper; + p->ForEachSound(stopper, false); + } + // TODO ... + + return false; +} + const char *dSndStateMgr_c::getStageName(s32 id) { if (id >= SND_STAGE_MAX) { return "NULL";