diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 24cca8d9..1b25e5af 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -2646,14 +2646,14 @@ d/snd/d_snd_event_callbacks.cpp: .rodata start:0x804F2308 end:0x804F3678 .data start:0x80548A48 end:0x80548A58 .sdata start:0x805741A0 end:0x805741F8 - .sdata2 start:0x8057D808 end:0x8057D8A4 + .sdata2 start:0x8057D808 end:0x8057D8A0 d/snd/d_snd_event_demo_callbacks.cpp: .text start:0x80369900 end:0x8036A3A4 align:16 .rodata start:0x804F3678 end:0x804F37E8 .data start:0x80548A58 end:0x80548B08 .sdata start:0x805741F8 end:0x80574200 - .sdata2 start:0x8057D8A4 end:0x8057D8B0 + .sdata2 start:0x8057D8A0 end:0x8057D8B0 d/snd/d_snd_area_sound_effect_mgr.cpp: .text start:0x8036A3B0 end:0x8036B8D0 align:16 @@ -2890,8 +2890,13 @@ d/snd/d_snd_rng_mgr.cpp: .sbss start:0x80575DE8 end:0x80575DF0 d/snd/d_snd_mgr_unk_11.cpp: - .text start:0x80399D60 end:0x8039A848 align:16 + .text start:0x80399D60 end:0x8039A344 align:16 + +d/snd/d_snd_file_mgr.cpp: + .text start:0x8039A350 end:0x8039A848 align:16 .ctors start:0x804DB934 end:0x804DB938 + .data start:0x8054D7E0 end:0x8054D810 + .bss start:0x805D1030 end:0x805D1050 d/snd/d_snd_calc_pitch.cpp: .text start:0x8039A850 end:0x8039A960 align:16 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 2c03b0b7..64edd0d1 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -19952,14 +19952,14 @@ enterMap__15dSndPlayerMgr_cFv = .text:0x8035E4A0; // type:function size:0x44 leaveMap__15dSndPlayerMgr_cFv = .text:0x8035E4F0; // type:function size:0x44 enterHelp__15dSndPlayerMgr_cFv = .text:0x8035E540; // type:function size:0x18 leaveHelp__15dSndPlayerMgr_cFv = .text:0x8035E560; // type:function size:0x18 -fn_8035E580 = .text:0x8035E580; // type:function size:0x50 -fn_8035E5D0 = .text:0x8035E5D0; // type:function size:0x44 -fn_8035E620__15dSndPlayerMgr_cFv = .text:0x8035E620; // type:function size:0xB4 -fn_8035E6E0__15dSndPlayerMgr_cFv = .text:0x8035E6E0; // type:function size:0xA4 -fn_8035E790 = .text:0x8035E790; // type:function size:0x84 -fn_8035E820 = .text:0x8035E820; // type:function size:0x38 -fn_8035E860 = .text:0x8035E860; // type:function size:0x14 -fn_8035E880 = .text:0x8035E880; // type:function size:0x14 +enterSystemMenu__15dSndPlayerMgr_cFv = .text:0x8035E580; // type:function size:0x50 +leaveSystemMenu__15dSndPlayerMgr_cFv = .text:0x8035E5D0; // type:function size:0x44 +enterCaution__15dSndPlayerMgr_cFv = .text:0x8035E620; // type:function size:0xB4 +leaveCaution__15dSndPlayerMgr_cFv = .text:0x8035E6E0; // type:function size:0xA4 +setMsgActor__15dSndPlayerMgr_cFlP9dAcBase_c = .text:0x8035E790; // type:function size:0x84 +unsetMsgActor__15dSndPlayerMgr_cFv = .text:0x8035E820; // type:function size:0x38 +enterMsgWait__15dSndPlayerMgr_cFv = .text:0x8035E860; // type:function size:0x14 +leaveMsgWait__15dSndPlayerMgr_cFv = .text:0x8035E880; // type:function size:0x14 setup__15dSndPlayerMgr_cFl = .text:0x8035E8A0; // type:function size:0xC shutdown__15dSndPlayerMgr_cFl = .text:0x8035E8B0; // type:function size:0xC startSound__15dSndPlayerMgr_cFPQ34nw4r3snd11SoundHandleUlPCQ44nw4r3snd14SoundStartable9StartInfo = .text:0x8035E8C0; // type:function size:0x90 @@ -19973,11 +19973,11 @@ fn_8035EB00 = .text:0x8035EB00; // type:function size:0x3C fn_8035EB40 = .text:0x8035EB40; // type:function size:0xC fn_8035EB50 = .text:0x8035EB50; // type:function size:0x3C getSomeUserParam__15dSndPlayerMgr_cCFUl = .text:0x8035EB90; // type:function size:0x80 -fn_8035EC10 = .text:0x8035EC10; // type:function size:0x5C -fn_8035EC70 = .text:0x8035EC70; // type:function size:0x84 +getRemoConSoundVariant__15dSndPlayerMgr_cCFUl = .text:0x8035EC10; // type:function size:0x5C +getRemoConSoundVariantDemo__15dSndPlayerMgr_cCFUl = .text:0x8035EC70; // type:function size:0x84 convertLabelStringToSoundId__15dSndPlayerMgr_cCFPCc = .text:0x8035ED00; // type:function size:0x3C getSoundArchivePlayerForType__15dSndPlayerMgr_cFl = .text:0x8035ED40; // type:function size:0x44 -canUseThisPlayer__15dSndPlayerMgr_cCFl = .text:0x8035ED90; // type:function size:0x5C +shouldUseDemoPlayer__15dSndPlayerMgr_cCFl = .text:0x8035ED90; // type:function size:0x5C loadDemoArchive__15dSndPlayerMgr_cFPCc = .text:0x8035EDF0; // type:function size:0x198 shutdown__15dSndPlayerMgr_cFv = .text:0x8035EF90; // type:function size:0x38 calc__15dSndPlayerMgr_cFv = .text:0x8035EFD0; // type:function size:0x40 @@ -20074,7 +20074,7 @@ fn_80362740 = .text:0x80362740; // type:function size:0x59C EnemySoundMgr__update = .text:0x80362CE0; // type:function size:0xFC EnemySoundMgr__enemyMusicRelated = .text:0x80362DE0; // type:function size:0x154 fn_80362F40 = .text:0x80362F40; // type:function size:0x770 -fn_803636B0 = .text:0x803636B0; // type:function size:0xCC +initializeEventCallbacks__14dSndStateMgr_cFPCc = .text:0x803636B0; // type:function size:0xCC fn_80363780 = .text:0x80363780; // type:function size:0xCC fn_80363850 = .text:0x80363850; // type:function size:0xA8 fn_80363900 = .text:0x80363900; // type:function size:0xA8 @@ -20113,10 +20113,10 @@ fn_80364C40 = .text:0x80364C40; // type:function size:0xBC fn_80364D00 = .text:0x80364D00; // type:function size:0x94 fn_80364DA0 = .text:0x80364DA0; // type:function size:0xC isInEvent__14dSndStateMgr_cFPCc = .text:0x80364DB0; // type:function size:0x2C -fn_80364DE0 = .text:0x80364DE0; // type:function size:0x7C -fn_80364E60 = .text:0x80364E60; // type:function size:0x54 -fn_80364EC0 = .text:0x80364EC0; // type:function size:0x90 -fn_80364F50 = .text:0x80364F50; // type:function size:0x7C +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 fn_803650B0 = .text:0x803650B0; // type:function size:0x6C @@ -20179,7 +20179,7 @@ fn_80366F00 = .text:0x80366F00; // type:function size:0x5C fn_80366F60 = .text:0x80366F60; // type:function size:0x30C fn_80367270 = .text:0x80367270; // type:function size:0xC fn_80367280 = .text:0x80367280; // type:function size:0x18C -fn_80367410 = .text:0x80367410; // type:function size:0x4 +cbUnkNoop__14dSndStateMgr_cFv = .text:0x80367410; // type:function size:0x4 fn_80367420 = .text:0x80367420; // type:function size:0x24 fn_80367450 = .text:0x80367450; // type:function size:0x14 fn_80367470 = .text:0x80367470; // type:function size:0x64 @@ -20334,7 +20334,7 @@ fn_8036A110 = .text:0x8036A110; // type:function size:0x108 fn_8036A220 = .text:0x8036A220; // type:function size:0x3C fn_8036A260 = .text:0x8036A260; // type:function size:0x6C handleDemoEvent__14dSndStateMgr_cFPCc = .text:0x8036A2D0; // type:function size:0xB8 -fn_8036A390 = .text:0x8036A390; // type:function size:0x14 +resetOverrides__14dSndStateMgr_cFv = .text:0x8036A390; // type:function size:0x14 __dt__42SndMgrDisposer<24dSndAreaSoundEffectMgr_c>Fv = .text:0x8036A3B0; // type:function size:0x78 create__42SndMgrDisposer<24dSndAreaSoundEffectMgr_c>Fv = .text:0x8036A430; // type:function size:0x48 remove__42SndMgrDisposer<24dSndAreaSoundEffectMgr_c>Fv = .text:0x8036A480; // type:function size:0x10 @@ -20360,7 +20360,7 @@ fn_8036B170 = .text:0x8036B170; // type:function size:0x200 fn_8036B370 = .text:0x8036B370; // type:function size:0x6C fn_8036B3E0 = .text:0x8036B3E0; // type:function size:0xA4 fn_8036B490 = .text:0x8036B490; // type:function size:0x124 -fn_8036B5C0 = .text:0x8036B5C0; // type:function size:0x6C +pauseAllSounds__24dSndAreaSoundEffectMgr_cFv = .text:0x8036B5C0; // type:function size:0x6C fn_8036B630 = .text:0x8036B630; // type:function size:0x170 fn_8036B7A0 = .text:0x8036B7A0; // type:function size:0x110 fn_8036B8B0 = .text:0x8036B8B0; // type:function size:0x20 @@ -20441,7 +20441,7 @@ fn_8036E290 = .text:0x8036E290; // type:function size:0xC0 fn_8036E350 = .text:0x8036E350; // type:function size:0x9C fn_8036E3F0 = .text:0x8036E3F0; // type:function size:0x90 fn_8036E480 = .text:0x8036E480; // type:function size:0x94 -fn_8036E520 = .text:0x8036E520; // type:function size:0x6C +pauseAllBgm__12dSndBgmMgr_cFv = .text:0x8036E520; // type:function size:0x6C fn_8036E590 = .text:0x8036E590; // type:function size:0x68 fn_8036E600 = .text:0x8036E600; // type:function size:0x18 fn_8036E620 = .text:0x8036E620; // type:function size:0x68 @@ -20512,7 +20512,7 @@ fn_80371A60 = .text:0x80371A60; // type:function size:0x88 fn_80371AF0 = .text:0x80371AF0; // type:function size:0x58 fn_80371B50 = .text:0x80371B50; // type:function size:0x58 fn_80371BB0 = .text:0x80371BB0; // type:function size:0x58 -fn_80371C10 = .text:0x80371C10; // type:function size:0x58 +isPlayingBgmSound__12dSndBgmMgr_cCFv = .text:0x80371C10; // type:function size:0x58 isPlayingBgmSoundId__12dSndBgmMgr_cCFUl = .text:0x80371C70; // type:function size:0x70 fn_80371CE0 = .text:0x80371CE0; // type:function size:0x64 isBgmHandleIdxPlayingSoundId__12dSndBgmMgr_cFUlUl = .text:0x80371D50; // type:function size:0x84 @@ -21001,7 +21001,7 @@ fn_803851C0 = .text:0x803851C0; // type:function size:0x74 clearSourceList__15dSndSourceMgr_cFPQ34nw4r2ut4List = .text:0x80385240; // type:function size:0x64 fn_803852B0 = .text:0x803852B0; // type:function size:0x3C fn_803852F0 = .text:0x803852F0; // type:function size:0x3C -fn_80385330 = .text:0x80385330; // type:function size:0x94 +pauseAllSound__15dSndSourceMgr_cFv = .text:0x80385330; // type:function size:0x94 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 @@ -21641,21 +21641,21 @@ fn_8039A210 = .text:0x8039A210; // type:function size:0x44 fn_8039A260 = .text:0x8039A260; // type:function size:0x44 fn_8039A2B0 = .text:0x8039A2B0; // type:function size:0x44 fn_8039A300 = .text:0x8039A300; // type:function size:0x44 -fn_8039A350 = .text:0x8039A350; // type:function size:0x40 -fn_8039A390 = .text:0x8039A390; // type:function size:0xB0 -fn_8039A440 = .text:0x8039A440; // type:function size:0x40 -fn_8039A480 = .text:0x8039A480; // type:function size:0xCC -fn_8039A550 = .text:0x8039A550; // type:function size:0x6C -fn_8039A5C0 = .text:0x8039A5C0; // type:function size:0x88 -fn_8039A650 = .text:0x8039A650; // type:function size:0x88 -fn_8039A6E0 = .text:0x8039A6E0; // type:function size:0x4C -fn_8039A730 = .text:0x8039A730; // type:function size:0x4C -fn_8039A780 = .text:0x8039A780; // type:function size:0x28 -fn_8039A7B0 = .text:0x8039A7B0; // type:function size:0x28 -fn_8039A7E0 = .text:0x8039A7E0; // type:function size:0x38 -fn_8039A820 = .text:0x8039A820; // type:function size:0x8 -fn_8039A830 = .text:0x8039A830; // type:function size:0x8 -fn_8039A840 = .text:0x8039A840; // type:function size:0x8 +__dt__15dSndFileManagerFv = .text:0x8039A350; // type:function size:0x40 scope:weak +create__15dSndFileManagerFPQ34nw4r3snd12SoundArchivePQ34nw4r3snd9SoundHeap = .text:0x8039A390; // type:function size:0xB0 +clearGlob__15dSndFileManagerFv = .text:0x8039A440; // type:function size:0x40 +loadFileForSound__15dSndFileManagerFRCQ34nw4r3snd12SoundArchiveUlPQ34nw4r3snd9SoundHeap = .text:0x8039A480; // type:function size:0xCC +isLoadedFileForSound__15dSndFileManagerFPQ34nw4r3snd18SoundArchivePlayerUl = .text:0x8039A550; // type:function size:0x6C +isLoadedFileAndWaveForBank__15dSndFileManagerFPQ34nw4r3snd18SoundArchivePlayerUl = .text:0x8039A5C0; // type:function size:0x88 +isLoadedFileAndWaveForSound__15dSndFileManagerFPQ34nw4r3snd18SoundArchivePlayerUl = .text:0x8039A650; // type:function size:0x88 +InvalidateData__15dSndFileManagerFPCvPCv = .text:0x8039A6E0; // type:function size:0x4C +InvalidateWaveData__15dSndFileManagerFPCvPCv = .text:0x8039A730; // type:function size:0x4C +GetFileWaveDataAddress__15dSndFileManagerFUl = .text:0x8039A780; // type:function size:0x28 +GetFileAddress__15dSndFileManagerFUl = .text:0x8039A7B0; // type:function size:0x28 +__sinit_\d_snd_file_mgr_cpp = .text:0x8039A7E0; // type:function size:0x38 scope:local +@4@InvalidateWaveData__15dSndFileManagerFPCvPCv = .text:0x8039A820; // type:function size:0x8 scope:weak +@4@InvalidateData__15dSndFileManagerFPCvPCv = .text:0x8039A830; // type:function size:0x8 scope:weak +@4@__dt__15dSndFileManagerFv = .text:0x8039A840; // type:function size:0x8 scope:weak pitchScaleForPitchIdx__Fl = .text:0x8039A850; // type:function size:0x2C pitchScaleForPitchIdxTenths__Ff = .text:0x8039A880; // type:function size:0x58 pitchIdxTenthsForPitchScale__Ff = .text:0x8039A8E0; // type:function size:0x80 @@ -38125,7 +38125,7 @@ __vt__9dSndRng_c = .data:0x8054D7A8; // type:object size:0x10 __vt__12dSndRngMgr_c = .data:0x8054D7B8; // type:object size:0xC scope:weak __vt__30SndMgrDisposer<12dSndRngMgr_c> = .data:0x8054D7C4; // type:object size:0xC scope:weak lbl_8054D7D0 = .data:0x8054D7D0; // type:object size:0x10 -lbl_8054D7E0 = .data:0x8054D7E0; // type:object size:0x30 +__vt__15dSndFileManager = .data:0x8054D7E0; // type:object size:0x30 lbl_8054D810 = .data:0x8054D810; // type:object size:0x48 lbl_8054D858 = .data:0x8054D858; // type:object size:0xA data:string lbl_8054D864 = .data:0x8054D864; // type:object size:0x15 data:string @@ -52209,8 +52209,8 @@ lbl_805D0FB8 = .bss:0x805D0FB8; // type:object size:0x30 align:4 data:float lbl_805D0FF8 = .bss:0x805D0FF8; // type:object size:0x10 align:4 data:float lbl_805D1008 = .bss:0x805D1008; // type:object size:0x10 align:4 data:float sParam__27dSndDistantSoundActorPool_c = .bss:0x805D1018; // type:object size:0x14 align:4 data:float -lbl_805D1030 = .bss:0x805D1030; // type:object size:0xC data:4byte -lbl_805D103C = .bss:0x805D103C; // type:object size:0x14 data:4byte +sGlob__15dSndFileManager = .bss:0x805D1030; // type:object size:0xC data:4byte +sFileManager = .bss:0x805D103C; // type:object size:0x14 scope:local data:4byte lbl_805D1050 = .bss:0x805D1050; // type:object size:0x80 data:4byte lbl_805D10D0 = .bss:0x805D10D0; // type:object size:0x80 data:4byte lbl_805D1160 = .bss:0x805D1160; // type:object size:0x1200 align:32 data:4byte diff --git a/configure.py b/configure.py index 03daa257..e6a72f2c 100644 --- a/configure.py +++ b/configure.py @@ -799,6 +799,7 @@ config.libs = [ Object(Matching, "d/snd/d_snd_rng_mgr.cpp"), # more rng related Object(NonMatching, "d/snd/d_snd_mgr_unk_11.cpp"), + Object(Matching, "d/snd/d_snd_file_mgr.cpp"), Object(NonMatching, "d/snd/d_snd_calc_pitch.cpp"), ], }, diff --git a/include/d/snd/d_snd_3d_actor.h b/include/d/snd/d_snd_3d_actor.h index 58c21675..2228f7d5 100644 --- a/include/d/snd/d_snd_3d_actor.h +++ b/include/d/snd/d_snd_3d_actor.h @@ -111,7 +111,7 @@ protected: // a_ prefix to prevent multiple inheritance clashes /* 0x7D */ u8 a_field_0x7D; /* 0x7E */ bool mIsDisabled; - /* 0x7F */ u8 a_field_0x7F; + /* 0x7F */ bool mIsDemoActor; /* 0x80 */ bool mIsPaused; /* 0x84 */ f32 a_field_0x84; /* 0x88 */ f32 a_field_0x88; 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 aa4f7f72..3cda1f9b 100644 --- a/include/d/snd/d_snd_area_sound_effect_mgr.h +++ b/include/d/snd/d_snd_area_sound_effect_mgr.h @@ -23,6 +23,7 @@ public: bool startSound(u32 soundId, u32 handleIdx); void calc(); void stopSounds(s32 fadeFrames); + void pauseAllSounds(); private: bool isPlayingAnySound() const; diff --git a/include/d/snd/d_snd_bgm_mgr.h b/include/d/snd/d_snd_bgm_mgr.h index b42d6182..4b5d01f8 100644 --- a/include/d/snd/d_snd_bgm_mgr.h +++ b/include/d/snd/d_snd_bgm_mgr.h @@ -31,9 +31,11 @@ public: bool playBgm(u32 soundId, s32 fadeFrames, bool paused); bool prepareBgm(u32 soundId, u32 startOffset); + void pauseAllBgm(); void stopAllBgm(s32 fadeFrames); dSndBgmSound_c *getSoundHandleForBgm(u32 soundId, u32 startOffset); + bool isPlayingBgmSound() const; bool isPlayingBgmSoundId(u32 soundId) const; bool isPreparingBgmSoundId(u32 soundId) const; diff --git a/include/d/snd/d_snd_control_player_mgr.h b/include/d/snd/d_snd_control_player_mgr.h index 72eef912..bf28f647 100644 --- a/include/d/snd/d_snd_control_player_mgr.h +++ b/include/d/snd/d_snd_control_player_mgr.h @@ -22,6 +22,10 @@ public: dSndControlPlayerMgr_c(); + void setupPlayerControlsGlobal(); + void setupPlayerControlsStage(); + void setupPlayerControlsStageBgm(); + void calc(); static const s32 sNumPlayers; diff --git a/include/d/snd/d_snd_event.h b/include/d/snd/d_snd_event.h index 3094e47a..dafff2d9 100644 --- a/include/d/snd/d_snd_event.h +++ b/include/d/snd/d_snd_event.h @@ -148,9 +148,10 @@ enum SndEvent_e { /* 0x84 */ SND_EVENT_Demo77_01 = 0x84, /* 0x85 */ SND_EVENT_Demo79_01 = 0x85, + /* 0x86 */ SND_EVENT_0x86 = 0x86, /* 0x87 */ SND_EVENT_0x87 = 0x87, - - /* 0x89 */ SND_EVENT_0x98 = 0x89, + /* 0x88 */ SND_EVENT_0x88 = 0x88, + /* 0x89 */ SND_EVENT_0x89 = 0x89, }; #endif diff --git a/include/d/snd/d_snd_file_mgr.h b/include/d/snd/d_snd_file_mgr.h new file mode 100644 index 00000000..dce7d67d --- /dev/null +++ b/include/d/snd/d_snd_file_mgr.h @@ -0,0 +1,44 @@ +#ifndef D_SND_FILE_MGR_H +#define D_SND_FILE_MGR_H + +#include "nw4r/snd/snd_DisposeCallbackManager.h" +#include "nw4r/snd/snd_SoundArchive.h" +#include "nw4r/snd/snd_SoundArchivePlayer.h" +#include "nw4r/snd/snd_SoundHeap.h" + +class dSndFileManager : public nw4r::snd::SoundArchivePlayer_FileManager, public nw4r::snd::detail::DisposeCallback { +private: + struct dSndFileManagerGlob { + u32 numFiles; + const void **pData; + const void **pWaveData; + }; + + static dSndFileManagerGlob sGlob; + +public: + dSndFileManager() { + mpGlob = &sGlob; + } + static dSndFileManager *create(nw4r::snd::SoundArchive *pArchive, nw4r::snd::SoundHeap *pHeap); + + virtual void const *GetFileAddress(u32) override; + virtual void const *GetFileWaveDataAddress(u32) override; + + virtual void InvalidateData(void const *pStart, void const *pEnd) override; + virtual void InvalidateWaveData(void const *pStart, void const *pEnd) override; + + virtual ~dSndFileManager() {} + + static bool loadFileForSound(const nw4r::snd::SoundArchive &pArchive, u32 soundId, nw4r::snd::SoundHeap *pHeap); + static bool isLoadedFileForSound(nw4r::snd::SoundArchivePlayer *pPlayer, u32 soundId); + static bool isLoadedFileAndWaveForBank(nw4r::snd::SoundArchivePlayer *pPlayer, u32 soundId); + static bool isLoadedFileAndWaveForSound(nw4r::snd::SoundArchivePlayer *pPlayer, u32 soundId); + +private: + static void clearGlob(); + + /* 0x10 */ dSndFileManagerGlob *mpGlob; +}; + +#endif diff --git a/include/d/snd/d_snd_player_mgr.h b/include/d/snd/d_snd_player_mgr.h index 4a6796ee..f5c9a9ee 100644 --- a/include/d/snd/d_snd_player_mgr.h +++ b/include/d/snd/d_snd_player_mgr.h @@ -8,6 +8,8 @@ #include "nw4r/snd/snd_SoundHandle.h" #include "nw4r/snd/snd_SoundStartable.h" +class dAcBase_c; + SND_DISPOSER_FORWARD_DECL(dSndPlayerMgr_c); /** @@ -44,8 +46,17 @@ public: void fn_8035E250(u16); bool fn_8035E2E0(); void fn_8035E310(); - void fn_8035E620(); - void fn_8035E6E0(); + void enterSystemMenu(); + void leaveSystemMenu(); + + void enterCaution(); + void leaveCaution(); + + void setMsgActor(s32 msgIdx, dAcBase_c *actor); + void unsetMsgActor(); + + void enterMsgWait(); + void leaveMsgWait(); u32 getFreeSize(); bool loadDemoArchive(const char *demoArchiveName); @@ -55,9 +66,10 @@ public: u32 getSomeUserParam(u32 soundId) const; nw4r::snd::SoundArchivePlayer &getSoundArchivePlayerForType(s32 sourceType); - bool canUseThisPlayer(s32 sourceType) const; + bool shouldUseDemoPlayer(s32 sourceType) const; - void stopAllSound(); + u32 getRemoConSoundVariantDemo(u32 soundId) const; + u32 getRemoConSoundVariant(u32 soundId) const; enum PlayerMgrFlag_e { MGR_HBM = 0x1, @@ -65,8 +77,10 @@ public: MGR_PAUSE = 0x4, MGR_MAP = 0x8, MGR_HELP = 0x10, + MGR_SYSTEM = 0x20, + MGR_MSG_WAIT = 0x40, - MGR_UNK_0x80 = 0x80, + MGR_CAUTION = 0x80, }; bool checkFlag(u32 mask) const { @@ -81,14 +95,16 @@ public: mFlags &= ~mask; } - u32 getEventMuteMask(u32 id) { - nw4r::snd::SoundArchive *archive; - if (mSoundArchivePlayer.IsAvailable()) { - archive = &mSoundArchive; + const nw4r::snd::SoundArchive *getDemoArchive() const { + if (mDemoSoundArchivePlayer.IsAvailable()) { + return &mDemoSoundArchive; } else { - archive = dSndMgr_c::GetInstance()->getArchive(); + return dSndMgr_c::GetInstance()->getArchive(); } - return archive->GetSoundUserParam(id) & sEventMuteFlagsMask; + } + + u32 getEventMuteMask(u32 id) { + return getDemoArchive()->GetSoundUserParam(id) & sEventMuteFlagsMask; } enum FanfareUnmuteParam_e { @@ -179,8 +195,8 @@ private: nw4r::snd::SoundHandle *pHandle, const char *soundLabel, const nw4r::snd::SoundStartable::StartInfo *pStartInfo ); - /* 0x028 */ nw4r::snd::MemorySoundArchive mSoundArchive; - /* 0x178 */ nw4r::snd::SoundArchivePlayer mSoundArchivePlayer; + /* 0x028 */ nw4r::snd::MemorySoundArchive mDemoSoundArchive; + /* 0x178 */ nw4r::snd::SoundArchivePlayer mDemoSoundArchivePlayer; }; #endif diff --git a/include/d/snd/d_snd_source_mgr.h b/include/d/snd/d_snd_source_mgr.h index ca631a2e..41503455 100644 --- a/include/d/snd/d_snd_source_mgr.h +++ b/include/d/snd/d_snd_source_mgr.h @@ -38,6 +38,10 @@ public: return GetInstance()->mpBoomerangSource; } + void setMsgSource(dSoundSource_c *source) { + mpMsgSource = source; + } + u8 getField_0x0012() const { return field_0x0012; } @@ -48,6 +52,7 @@ public: void stopAllSound(); void stopAllNonPlayerSound(); + void pauseAllSound(); void incrementEnemyCount() { field_0x3868++; @@ -102,7 +107,7 @@ private: /* 0x3878 */ dSoundSource_c *mpBoomerangSource; /* 0x387C */ dSoundSource_c *mpTBoatSource; /* 0x3880 */ dSoundSource_c *field_0x3880; // fi singing related? - /* 0x3884 */ dSoundSource_c *field_0x3884; + /* 0x3884 */ dSoundSource_c *mpMsgSource; }; #endif diff --git a/include/d/snd/d_snd_stage_data.h b/include/d/snd/d_snd_stage_data.h index 96dce3d4..ada97ea3 100644 --- a/include/d/snd/d_snd_stage_data.h +++ b/include/d/snd/d_snd_stage_data.h @@ -12,7 +12,6 @@ struct dSndStageInfo { /* 0x14 */ u32 unk4; /* 0x18 */ const char *demoName; - static const s32 sNumStageInfos; static const dSndStageInfo sInfos[]; }; @@ -35,7 +34,7 @@ enum SndStage_e { /* 0x0E */ SND_STAGE_F300_4_L13, /* 0x0F */ SND_STAGE_F300_4, /* 0x10 */ SND_STAGE_F301, - /* 0x11 */ SND_STAGE_F301_1, + /* 0x11 */ SND_STAGE_F301_1, /* 0x12 */ SND_STAGE_F301_2, /* 0x13 */ SND_STAGE_F301_3, /* 0x14 */ SND_STAGE_F301_4_L2, diff --git a/include/d/snd/d_snd_state_mgr.h b/include/d/snd/d_snd_state_mgr.h index e61e961a..36bff333 100644 --- a/include/d/snd/d_snd_state_mgr.h +++ b/include/d/snd/d_snd_state_mgr.h @@ -104,11 +104,24 @@ public: bool isActiveDemoMaybe(s32 subtype) const; bool isInEvent(const char *eventName); + void doMsgStart(s32 idx); + void doMsgEnd(); + + void doMsgWaitStart(); + void doMsgWaitEnd(); + private: + void resetOverrides(); + void initializeEventCallbacks(const char *name); bool handleGlobalEvent(const char *name); bool handleStageEvent(const char *name); void handleDemoEvent(const char *name); + // Callbacks start + static void cbUnkNoop(); + + // Callbacks end + u32 getStageTypeFlags(const char *stageName) const; // ET, FS, or corresponding Sky Keep rooms static bool isVolcanicDungeon(u32 stageId); @@ -121,7 +134,6 @@ private: u32 getStageId(const char *name, s32 layer); static u32 getStageUnk2(u32 stageId); - static SndEventCallback sEventExecuteCallback; /* 0x010 */ u32 field_0x010; @@ -150,7 +162,7 @@ private: /* 0x080 */ UNKWORD field_0x080; /* 0x084 */ UNKWORD field_0x084; /* 0x088 */ UNKWORD field_0x088; - /* 0x08C */ UNKWORD field_0x08C; + /* 0x08C */ s32 mSoundEventId; /* 0x090 */ UNKWORD field_0x090; /* 0x094 */ u32 field_0x094; /* 0x098 */ SizedString<64> field_0x098; @@ -160,13 +172,13 @@ private: /* 0x120 */ UNKWORD field_0x120; /* 0x124 */ UNKWORD field_0x124; /* 0x128 */ UNKWORD field_0x128; - /* 0x12C */ SizedString<64> field_0x12C; - /* 0x16C */ SizedString<64> field_0x16C; - /* 0x1AC */ SizedString<64> field_0x1AC; - /* 0x1EC */ SizedString<64> field_0x1EC; + /* 0x12C */ SizedString<64> mSeName; + /* 0x16C */ SizedString<64> mBgmName; + /* 0x1AC */ SizedString<64> mFanName; + /* 0x1EC */ SizedString<64> mCmdName; /* 0x22C */ UNKWORD field_0x22C; /* 0x230 */ UNKWORD field_0x230; - /* 0x234 */ const SndEventDef *field_0x234; + /* 0x234 */ const SndEventDef *mpSoundEventDef; /* 0x238 */ UNKWORD field_0x238; /* 0x23C */ u8 field_0x23C; /* 0x23D */ u8 field_0x23D; diff --git a/include/toBeSorted/music_mgrs.h b/include/toBeSorted/music_mgrs.h index fb5e5397..b11174bc 100644 --- a/include/toBeSorted/music_mgrs.h +++ b/include/toBeSorted/music_mgrs.h @@ -16,7 +16,6 @@ extern "C" void fn_8035E000(); extern "C" void fn_8035E860(dSndPlayerMgr_c *); extern "C" void fn_8035E820(dSndPlayerMgr_c *); extern "C" void fn_8035E880(dSndPlayerMgr_c *); -extern "C" void fn_8035E790(dSndPlayerMgr_c *, UNKWORD, void *); #define ENEMY_SOUND_MGR (dSndStateMgr_c::GetInstance()) extern "C" void fn_80362150(dSndStateMgr_c *, u16); diff --git a/src/d/a/obj/d_a_obj_boomerang.cpp b/src/d/a/obj/d_a_obj_boomerang.cpp index eb771ff3..4f5dade2 100644 --- a/src/d/a/obj/d_a_obj_boomerang.cpp +++ b/src/d/a/obj/d_a_obj_boomerang.cpp @@ -251,7 +251,7 @@ void dAcBoomerang_c::retrieve() { if (mFader.isStatus(mFaderBase_c::FADED_OUT)) { mFader.setFrame(5); mFader.fadeIn(); - playSound(SE_BE_COME_BACK); + startSound(SE_BE_COME_BACK); } mFader.calc(); } @@ -391,7 +391,7 @@ void dAcBoomerang_c::executeState_ReturnWait() { forwardSpeed = 0.f; placeOnArm(); if (mAnmChr[BOOMERANG_ANIM_PINCERS].isStop() || !dAcPy_c::GetLink2()->checkActionFlagsCont(0x10)) { - playSound(SE_BE_CATCH); + startSound(SE_BE_CATCH); mStateMgr.changeState(StateID_Wait); } } @@ -439,7 +439,7 @@ void dAcBoomerang_c::initializeState_Move() { field_0x8E4.fromXY(angle.x, angle.y, forwardSpeed); - playSound(SE_BE_THROW); + startSound(SE_BE_THROW); dJEffManager_c::spawnUIEffect(PARTICLE_RESOURCE_ID_MAPPING_3_, mVec3_c::Zero, nullptr, nullptr, nullptr, nullptr); field_0x8F0 = mVec3_c::Zero; field_0x8D4 = 0.0f; @@ -484,7 +484,7 @@ void dAcBoomerang_c::executeTimeWarning() { flashClr.r = (1.f / (r - 6)) * MAX(0, (mFlashTimer % r) - 5) * 255.f; if (flashClr.r == 0xFF && !mStateMgr.isState(StateID_MoveCancelWait)) { - playSound(SE_BE_WARNING); + startSound(SE_BE_WARNING); } } @@ -554,7 +554,7 @@ int dAcBoomerang_c::actorExecute() { if (checkField_0x8CC(FLAG_0x20) && !checkField_0x8CC(FLAG_CANCEL)) { if (mStateMgr.isState(StateID_Move) || mStateMgr.isState(StateID_MoveCancelWait)) { mEff3.createContinuousEffect(PARTICLE_RESOURCE_ID_MAPPING_7_, mWorldMtx, nullptr, nullptr); - playSoundEffect1(SE_BE_HIT_LEAVES_LV); + holdSound(SE_BE_HIT_LEAVES_LV); } } diff --git a/src/d/d_dvd_unk.cpp b/src/d/d_dvd_unk.cpp index 60a344f3..2e34c1fc 100644 --- a/src/d/d_dvd_unk.cpp +++ b/src/d/d_dvd_unk.cpp @@ -120,7 +120,7 @@ void dDvdUnk::FontUnk::fn_80052A20() { if (checkFlag(FLAG_ERROR_STATE)) { dGfx_c::GetInstance()->releaseTextureBuffer(); - dSndPlayerMgr_c::GetInstance()->fn_8035E6E0(); + dSndPlayerMgr_c::GetInstance()->leaveCaution(); } if (dLytSystemWindow_c::GetInstance() != nullptr && dLytSystemWindow_c::GetInstance()->fn_80152F80()) { @@ -169,11 +169,11 @@ void FontUnk::preExecute() { if (prevError && !isAnyError()) { dGfx_c::GetInstance()->releaseTextureBuffer(); offFlag(FLAG_ERROR_STATE); - dSndPlayerMgr_c::GetInstance()->fn_8035E6E0(); + dSndPlayerMgr_c::GetInstance()->leaveCaution(); } if (field_0x2C == true && !prevError && isAnyError()) { - dSndPlayerMgr_c::GetInstance()->fn_8035E620(); + dSndPlayerMgr_c::GetInstance()->enterCaution(); } } } @@ -222,7 +222,7 @@ void FontUnk::fn_80052D50() { if (checkFlag(FLAG_ERROR_STATE)) { dGfx_c::GetInstance()->releaseTextureBuffer(); mFlags = 0; - dSndPlayerMgr_c::GetInstance()->fn_8035E6E0(); + dSndPlayerMgr_c::GetInstance()->leaveCaution(); } dPadManager_c::GetInstance()->init(); } diff --git a/src/d/d_reset.cpp b/src/d/d_reset.cpp index e548d9eb..457b8ac1 100644 --- a/src/d/d_reset.cpp +++ b/src/d/d_reset.cpp @@ -338,7 +338,7 @@ void Manage_c::ModeProc_SoftReset() { dScBoot_c::GetInstance()->setField_0x5E3(true); dDvdUnk::FontUnk::GetInstance()->fn_800529B0(); - dSndPlayerMgr_c::GetInstance()->fn_8035E6E0(); + dSndPlayerMgr_c::GetInstance()->leaveCaution(); if (dDvdUnk::FontUnk::GetInstance()->isNandError() || dDvdUnk::FontUnk::GetInstance()->getNandError() != NandResultTracker::ERR_CAT_NONE || diff --git a/src/d/d_tag_processor.cpp b/src/d/d_tag_processor.cpp index fa1cb4e6..bad5969e 100644 --- a/src/d/d_tag_processor.cpp +++ b/src/d/d_tag_processor.cpp @@ -9,6 +9,7 @@ #include "d/lyt/d_lyt_util_items.h" #include "d/lyt/d_textbox.h" #include "d/lyt/msg_window/d_lyt_msg_window.h" +#include "d/snd/d_snd_player_mgr.h" #include "f/f_base.h" #include "f/f_manager.h" #include "f/f_profile_name.h" @@ -1572,12 +1573,12 @@ void dTagProcessor_c::somethingWithScrapperAndMusic(wchar_t *src) { if ((ac->profile_name >= fProfile::NPC_SLFB && ac->profile_name <= fProfile::NPC_SLFL) || (ac->profile_name >= fProfile::NPC_SLB && ac->profile_name <= fProfile::FLY_SLB) || ac->profile_name == fProfile::NPC_SLB2 || ac->profile_name == fProfile::NPC_DRBC) { - fn_8035E790(BGM_MGR, dLytMsgWindow_c::getInstance()->getField_0x784(), ac); + dSndPlayerMgr_c::GetInstance()->setMsgActor(dLytMsgWindow_c::getInstance()->getField_0x784(), ac); return; } } } else if (field_0x824 == 101) { - fn_8035E790(BGM_MGR, dLytMsgWindow_c::getInstance()->getField_0x784(), nullptr); + dSndPlayerMgr_c::GetInstance()->setMsgActor(dLytMsgWindow_c::getInstance()->getField_0x784(), nullptr); } } diff --git a/src/d/snd/d_snd_3d_actor.cpp b/src/d/snd/d_snd_3d_actor.cpp index b3aa0761..409bcd07 100644 --- a/src/d/snd/d_snd_3d_actor.cpp +++ b/src/d/snd/d_snd_3d_actor.cpp @@ -17,7 +17,7 @@ dSnd3DActor_c::dSnd3DActor_c(dSndSourceParam *pSourceParam, s32 sourceType) ), a_field_0x7D(0), mIsDisabled(false), - a_field_0x7F(0), + mIsDemoActor(false), mIsPaused(false), a_field_0x84(0.0f), a_field_0x88(0.0f), @@ -33,8 +33,8 @@ dSnd3DActor_c::dSnd3DActor_c(dSndSourceParam *pSourceParam, s32 sourceType) resetCachedRelativePositions(); // Portability hazard SetUserParam(reinterpret_cast(this)); - if (dSndPlayerMgr_c::GetInstance()->canUseThisPlayer(sourceType)) { - a_field_0x7F = 1; + if (dSndPlayerMgr_c::GetInstance()->shouldUseDemoPlayer(sourceType)) { + mIsDemoActor = true; } } diff --git a/src/d/snd/d_snd_bgm_mgr.cpp b/src/d/snd/d_snd_bgm_mgr.cpp index d592e925..84608cfa 100644 --- a/src/d/snd/d_snd_bgm_mgr.cpp +++ b/src/d/snd/d_snd_bgm_mgr.cpp @@ -255,6 +255,15 @@ void dSndBgmMgr_c::setBgmHandleIdxVolume(u32 handleIdx, f32 volume, s32 fadeFram } } +bool dSndBgmMgr_c::isPlayingBgmSound() const { + for (int i = 0; i < 7; i++) { + if (mBgmSounds[i]->isPlaying()) { + return true; + } + } + return false; +} + bool dSndBgmMgr_c::isPlayingBgmSoundId(u32 soundId) const { for (int i = 0; i < 7; i++) { if (mBgmSounds[i]->isPlayingSoundId(soundId)) { diff --git a/src/d/snd/d_snd_event_callbacks.cpp b/src/d/snd/d_snd_event_callbacks.cpp index 9c0d7f3a..ef47659d 100644 --- a/src/d/snd/d_snd_event_callbacks.cpp +++ b/src/d/snd/d_snd_event_callbacks.cpp @@ -172,7 +172,7 @@ static const SndEventDef sSndEventDefs_D003_1[] = { #pragma pop bool dSndStateMgr_c::handleStageEvent(const char *name) { - if (field_0x08C != SND_EVENT_0x87) { + if (mSoundEventId != SND_EVENT_0x87) { const SndEventDef *def = nullptr; s32 defCount = 0; @@ -226,8 +226,8 @@ bool dSndStateMgr_c::handleStageEvent(const char *name) { if (def != nullptr && defCount > 0) { for (s32 i = 0; i < defCount; def++, i++) { if (streq(name, def->eventName)) { - field_0x08C = def->eventId; - field_0x234 = def; + mSoundEventId = def->eventId; + mpSoundEventDef = def; sEventExecuteCallback = def->executeCb; if (def->initializeCb != nullptr) { (def->initializeCb)(); @@ -241,12 +241,12 @@ bool dSndStateMgr_c::handleStageEvent(const char *name) { } bool dSndStateMgr_c::handleGlobalEvent(const char *name) { - if (field_0x08C != SND_EVENT_0x87) { + if (mSoundEventId != SND_EVENT_0x87) { for (const SndEventDef *def = sSndEventDefs_GLOBAL; def < sSndEventDefs_GLOBAL + ARRAY_LENGTH(sSndEventDefs_GLOBAL); def++) { if (streq(name, def->eventName)) { - field_0x08C = def->eventId; - field_0x234 = def; + mSoundEventId = def->eventId; + mpSoundEventDef = def; sEventExecuteCallback = def->executeCb; if (def->initializeCb != nullptr) { (def->initializeCb)(); diff --git a/src/d/snd/d_snd_event_demo_callbacks.cpp b/src/d/snd/d_snd_event_demo_callbacks.cpp index c6f6df6d..d7e71ae7 100644 --- a/src/d/snd/d_snd_event_demo_callbacks.cpp +++ b/src/d/snd/d_snd_event_demo_callbacks.cpp @@ -30,8 +30,8 @@ void dSndStateMgr_c::handleDemoEvent(const char *name) { for (const SndEventDef *def = sSndEventDefs_DEMO; def < sSndEventDefs_DEMO + ARRAY_LENGTH(sSndEventDefs_DEMO); def++) { if (streq(name, def->eventName)) { - field_0x08C = def->eventId; - field_0x234 = def; + mSoundEventId = def->eventId; + mpSoundEventDef = def; sEventExecuteCallback = def->executeCb; if (def->initializeCb != nullptr) { (def->initializeCb)(); @@ -40,8 +40,8 @@ void dSndStateMgr_c::handleDemoEvent(const char *name) { } } - if (field_0x08C == SND_EVENT_0x98) { - field_0x08C = SND_EVENT_0x78; + if (mSoundEventId == SND_EVENT_0x89) { + mSoundEventId = SND_EVENT_0x78; } return; diff --git a/src/d/snd/d_snd_file_mgr.cpp b/src/d/snd/d_snd_file_mgr.cpp new file mode 100644 index 00000000..fdbd560b --- /dev/null +++ b/src/d/snd/d_snd_file_mgr.cpp @@ -0,0 +1,127 @@ +#include "d/snd/d_snd_file_mgr.h" + +#include "common.h" +#include "nw4r/snd/snd_DisposeCallbackManager.h" +#include "nw4r/snd/snd_SoundArchive.h" +#include "nw4r/snd/snd_SoundArchiveLoader.h" +#include "nw4r/snd/snd_SoundArchivePlayer.h" + +dSndFileManager::dSndFileManagerGlob dSndFileManager::sGlob; + +static dSndFileManager sFileManager; + +dSndFileManager *dSndFileManager::create(nw4r::snd::SoundArchive *pArchive, nw4r::snd::SoundHeap *pHeap) { + sGlob.numFiles = pArchive->detail_GetFileCount(); + sGlob.pData = (const void **)pHeap->Alloc(sGlob.numFiles * sizeof(const void *)); + sGlob.pWaveData = (const void **)pHeap->Alloc(sGlob.numFiles * sizeof(const void *)); + clearGlob(); + nw4r::snd::detail::DisposeCallbackManager::GetInstance().RegisterDisposeCallback(&sFileManager); + return &sFileManager; +} + +void dSndFileManager::clearGlob() { + for (u32 i = 0; i < sGlob.numFiles; i++) { + sGlob.pData[i] = nullptr; + sGlob.pWaveData[i] = nullptr; + } +} + +bool dSndFileManager::loadFileForSound(const nw4r::snd::SoundArchive &pArchive, u32 soundId, nw4r::snd::SoundHeap *pHeap) { + nw4r::snd::SoundArchive::SoundInfo info; + if (!pArchive.ReadSoundInfo(soundId, &info)) { + return false; + } + + if (sGlob.pData[info.fileId] == nullptr) { + nw4r::snd::detail::SoundArchiveLoader loader(pArchive); + const void *data = loader.LoadFile(info.fileId, pHeap); + if (data == nullptr) { + return false; + } + sGlob.pData[info.fileId] = data; + } + return true; +} + +bool dSndFileManager::isLoadedFileForSound(nw4r::snd::SoundArchivePlayer *pPlayer, u32 soundId) { + const nw4r::snd::SoundArchive &pArchive = pPlayer->GetSoundArchive(); + nw4r::snd::SoundArchive::SoundInfo info; + if (!pArchive.ReadSoundInfo(soundId, &info)) { + return false; + } + + if (pPlayer->detail_GetFileAddress(info.fileId) == nullptr) { + return false; + } + + return true; +} + +bool dSndFileManager::isLoadedFileAndWaveForBank(nw4r::snd::SoundArchivePlayer *pPlayer, u32 soundId) { + const nw4r::snd::SoundArchive &pArchive = pPlayer->GetSoundArchive(); + nw4r::snd::SoundArchive::BankInfo info; + if (!pArchive.ReadBankInfo(soundId, &info)) { + return false; + } + + if (pPlayer->detail_GetFileAddress(info.fileId) == nullptr) { + return false; + } + + if (pPlayer->detail_GetFileWaveDataAddress(info.fileId) == nullptr) { + return false; + } + + return true; +} + +bool dSndFileManager::isLoadedFileAndWaveForSound(nw4r::snd::SoundArchivePlayer *pPlayer, u32 soundId) { + const nw4r::snd::SoundArchive &pArchive = pPlayer->GetSoundArchive(); + nw4r::snd::SoundArchive::SoundInfo info; + if (!pArchive.ReadSoundInfo(soundId, &info)) { + return false; + } + + if (pPlayer->detail_GetFileAddress(info.fileId) == nullptr) { + return false; + } + + if (pPlayer->detail_GetFileWaveDataAddress(info.fileId) == nullptr) { + return false; + } + + return true; +} + + +void dSndFileManager::InvalidateData(void const *pStart, void const *pEnd) { + for (u32 i = 0; i < sGlob.numFiles; i++) { + if (pStart <= sGlob.pData[i] && sGlob.pData[i] <= pEnd) { + sGlob.pData[i] = nullptr; + } + } +} + +void dSndFileManager::InvalidateWaveData(void const *pStart, void const *pEnd) { + for (u32 i = 0; i < sGlob.numFiles; i++) { + if (pStart <= sGlob.pWaveData[i] && sGlob.pWaveData[i] <= pEnd) { + sGlob.pWaveData[i] = nullptr; + } + } +} + +// These two might be inline given that the order is reversed + +void const *dSndFileManager::GetFileWaveDataAddress(u32 id) { + if (id >= mpGlob->numFiles) { + return nullptr; + } + return mpGlob->pWaveData[id]; +} + +void const *dSndFileManager::GetFileAddress(u32 id) { + if (id >= mpGlob->numFiles) { + return nullptr; + } + return mpGlob->pData[id]; +} diff --git a/src/d/snd/d_snd_player_mgr.cpp b/src/d/snd/d_snd_player_mgr.cpp index e3d79001..26027e7f 100644 --- a/src/d/snd/d_snd_player_mgr.cpp +++ b/src/d/snd/d_snd_player_mgr.cpp @@ -2,16 +2,23 @@ #include "d/snd/d_snd_player_mgr.h" #include "common.h" +#include "d/a/d_a_base.h" +#include "d/snd/d_snd_area_sound_effect_mgr.h" +#include "d/snd/d_snd_bgm_mgr.h" #include "d/snd/d_snd_control_player_mgr.h" #include "d/snd/d_snd_mgr.h" #include "d/snd/d_snd_small_effect_mgr.h" +#include "d/snd/d_snd_source.h" #include "d/snd/d_snd_source_enums.h" +#include "d/snd/d_snd_source_mgr.h" +#include "d/snd/d_snd_state_mgr.h" #include "d/snd/d_snd_wzsound.h" #include "egg/audio/eggAudioRmtSpeakerMgr.h" #include "egg/core/eggDvdRipper.h" #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"; @@ -81,6 +88,92 @@ void dSndPlayerMgr_c::shutdown(s32 channel) { EGG::AudioRmtSpeakerMgr::shutdown(channel, nullptr); } +void dSndPlayerMgr_c::enterSystemMenu() { + if (checkFlag(MGR_CAUTION)) { + return; + } + enterPauseState(); + onFlag(MGR_SYSTEM); + dSndSmallEffectMgr_c::GetInstance()->playSound(SE_S_MENU_IN); +} + +void dSndPlayerMgr_c::leaveSystemMenu() { + if (checkFlag(MGR_CAUTION)) { + return; + } + leavePauseState(); + offFlag(MGR_SYSTEM); +} + +void dSndPlayerMgr_c::enterCaution() { + if (checkFlag(MGR_CAUTION)) { + return; + } + + s32 frames = 9; + if (fn_80364DA0(ENEMY_SOUND_MGR)) { + frames = 0; + } + + for (int i = 0; i < dSndControlPlayerMgr_c::sNumPlayers; i++) { + if ((u32)i != PLAYER_SMALL_IMPORTANT) { + dSndControlPlayerMgr_c::GetInstance()->getPlayer1(i)->PauseAllSound(true, frames); + } + } + + onFlag(MGR_CAUTION); + dSndSmallEffectMgr_c::GetInstance()->playSound(SE_S_CAUTION_IN); +} + +void dSndPlayerMgr_c::leaveCaution() { + if (!checkFlag(MGR_CAUTION)) { + return; + } + + EGG::AudioRmtSpeakerMgr::connectAllByForce(); + offFlag(MGR_CAUTION); + for (int i = 0; i < dSndControlPlayerMgr_c::sNumPlayers; i++) { + if ((u32)i != PLAYER_SMALL_IMPORTANT) { + dSndControlPlayerMgr_c::GetInstance()->getPlayer1(i)->PauseAllSound(false, 9); + } + } + + dSndBgmMgr_c::GetInstance()->pauseAllBgm(); + dSndAreaSoundEffectMgr_c::GetInstance()->pauseAllSounds(); + dSndSourceMgr_c::GetInstance()->pauseAllSound(); +} + +void dSndPlayerMgr_c::setMsgActor(s32 msgIdx, dAcBase_c *actor) { + if (actor != nullptr) { + dSoundSource_c *source = static_cast(actor->getSoundSource()); + if (source != nullptr) { + dSndSmallEffectMgr_c::GetInstance()->setButtonPressSound(source); + dSndSourceMgr_c::GetInstance()->setMsgSource(source); + } else { + dSndSmallEffectMgr_c::GetInstance()->resetButtonPressSound(); + } + } else { + dSndSmallEffectMgr_c::GetInstance()->resetButtonPressSound(); + } + dSndStateMgr_c::GetInstance()->doMsgStart(msgIdx); +} + +void dSndPlayerMgr_c::unsetMsgActor() { + dSndStateMgr_c::GetInstance()->doMsgEnd(); + dSndSmallEffectMgr_c::GetInstance()->resetButtonPressSound(); + dSndSourceMgr_c::GetInstance()->setMsgSource(nullptr); +} + +void dSndPlayerMgr_c::enterMsgWait() { + onFlag(MGR_MSG_WAIT); + dSndStateMgr_c::GetInstance()->doMsgWaitStart(); +} + +void dSndPlayerMgr_c::leaveMsgWait() { + offFlag(MGR_MSG_WAIT); + dSndStateMgr_c::GetInstance()->doMsgWaitEnd(); +} + nw4r::snd::SoundStartable::StartResult dSndPlayerMgr_c::startSound( nw4r::snd::SoundHandle *pHandle, u32 soundId, const nw4r::snd::SoundStartable::StartInfo *pStartInfo ) { @@ -108,19 +201,33 @@ nw4r::snd::SoundStartable::StartResult dSndPlayerMgr_c::startSound( return startSound(pHandle, id, pStartInfo); } +u32 dSndPlayerMgr_c::getRemoConSoundVariant(u32 soundId) const { + const char *label = dSndMgr_c::getSoundLabelString(soundId); + SizedString<64> variant; + variant.sprintf("%s_RC", label); + return sInstance->convertLabelStringToSoundId(variant); +} + +u32 dSndPlayerMgr_c::getRemoConSoundVariantDemo(u32 soundId) const { + const char *label = getDemoArchive()->GetSoundLabelString(soundId); + SizedString<64> variant; + variant.sprintf("%s_RC", label); + return sInstance->convertLabelStringToSoundId(variant); +} + u32 dSndPlayerMgr_c::convertLabelStringToSoundId(const char *label) const { return dSndMgr_c::GetInstance()->changeNameToId(label); } nw4r::snd::SoundArchivePlayer &dSndPlayerMgr_c::getSoundArchivePlayerForType(s32 sourceType) { - if (canUseThisPlayer(sourceType)) { - return mSoundArchivePlayer; + if (shouldUseDemoPlayer(sourceType)) { + return mDemoSoundArchivePlayer; } return dSndMgr_c::getPlayer(); } -bool dSndPlayerMgr_c::canUseThisPlayer(s32 sourceType) const { - if (!mSoundArchivePlayer.IsAvailable()) { +bool dSndPlayerMgr_c::shouldUseDemoPlayer(s32 sourceType) const { + if (!mDemoSoundArchivePlayer.IsAvailable()) { return false; } @@ -150,12 +257,12 @@ bool dSndPlayerMgr_c::loadDemoArchive(const char *demoArchiveName) { EGG::DvdRipper::Arg arg(path, (u8 *)buf, nullptr, EGG::DvdRipper::ALLOC_DIR_TOP, 0, &amountRead, &fileSize); void *ptr = EGG::DvdRipper::loadToMainRAM(arg); if (ptr != nullptr) { - ok = mSoundArchive.Setup(ptr); + ok = mDemoSoundArchive.Setup(ptr); if (ok) { - u32 size = mSoundArchivePlayer.GetRequiredMemSize(&mSoundArchive); + u32 size = mDemoSoundArchivePlayer.GetRequiredMemSize(&mDemoSoundArchive); void *buf2 = dSndMgr_c::GetInstance()->getSoundHeap()->Alloc(size); if (buf2 != nullptr) { - ok = mSoundArchivePlayer.Setup(&mSoundArchive, buf2, size, nullptr, 0); + ok = mDemoSoundArchivePlayer.Setup(&mDemoSoundArchive, buf2, size, nullptr, 0); } } } @@ -166,13 +273,13 @@ bool dSndPlayerMgr_c::loadDemoArchive(const char *demoArchiveName) { } void dSndPlayerMgr_c::shutdown() { - mSoundArchivePlayer.Shutdown(); - mSoundArchive.Shutdown(); + mDemoSoundArchivePlayer.Shutdown(); + mDemoSoundArchive.Shutdown(); } void dSndPlayerMgr_c::calc() { - if (mSoundArchivePlayer.IsAvailable()) { - mSoundArchivePlayer.Update(); + if (mDemoSoundArchivePlayer.IsAvailable()) { + mDemoSoundArchivePlayer.Update(); } } diff --git a/src/d/snd/d_snd_source_mgr.cpp b/src/d/snd/d_snd_source_mgr.cpp index 486c27a0..b587d07f 100644 --- a/src/d/snd/d_snd_source_mgr.cpp +++ b/src/d/snd/d_snd_source_mgr.cpp @@ -227,7 +227,7 @@ dSoundSourceIf_c *dSndSourceMgr_c::createSource(s32 sourceType, dAcBase_c *actor dSoundSourceIf_c *newSource = nullptr; bool isAnimSource = isAnimSoundSource(sourceType, actualName); bool isMultiSource = isMultiSoundSource(sourceType, actualName); - bool isDemo = dSndPlayerMgr_c::GetInstance()->canUseThisPlayer(sourceType); + bool isDemo = dSndPlayerMgr_c::GetInstance()->shouldUseDemoPlayer(sourceType); if (isDemo) { newSource = new dSndSourceDemo_c(sourceType, actor, actualName, group); @@ -368,7 +368,7 @@ dSndSourceMgr_c::dSndSourceMgr_c() mpBoomerangSource(nullptr), mpTBoatSource(nullptr), field_0x3880(nullptr), - field_0x3884(nullptr) { + mpMsgSource(nullptr) { // TODO offsetof nw4r::ut::List_Init(&mGroup1List, 0); nw4r::ut::List_Init(&mGroup2List, 0); diff --git a/src/d/snd/d_snd_state_mgr.cpp b/src/d/snd/d_snd_state_mgr.cpp index 0331c350..c7de7301 100644 --- a/src/d/snd/d_snd_state_mgr.cpp +++ b/src/d/snd/d_snd_state_mgr.cpp @@ -2,6 +2,7 @@ #include "common.h" #include "d/d_sc_game.h" +#include "d/snd/d_snd_event.h" #include "d/snd/d_snd_player_mgr.h" #include "d/snd/d_snd_stage_data.h" #include "egg/core/eggHeap.h" @@ -9,6 +10,7 @@ #include +SndEventCallback dSndStateMgr_c::sEventExecuteCallback; SND_DISPOSER_DEFINE(dSndStateMgr_c); dSndStateMgr_c::dSndStateMgr_c() @@ -35,7 +37,7 @@ dSndStateMgr_c::dSndStateMgr_c() field_0x080(0), field_0x084(0), field_0x088(0), - field_0x08C(0x89), + mSoundEventId(SND_EVENT_0x89), field_0x090(0), field_0x094(0), field_0x118(nullptr), @@ -45,7 +47,7 @@ dSndStateMgr_c::dSndStateMgr_c() field_0x128(-1), field_0x22C(0), field_0x230(0), - field_0x234(nullptr), + mpSoundEventDef(nullptr), field_0x238(-1), field_0x23C(0), field_0x23D(0), @@ -85,8 +87,8 @@ void dSndStateMgr_c::setup(EGG::Heap *pHeap) { } void dSndStateMgr_c::onStageOrLayerUpdate() { - if (dSndPlayerMgr_c::GetInstance()->checkFlag(dSndPlayerMgr_c::MGR_UNK_0x80)) { - dSndPlayerMgr_c::GetInstance()->stopAllSound(); + if (dSndPlayerMgr_c::GetInstance()->checkFlag(dSndPlayerMgr_c::MGR_CAUTION)) { + dSndPlayerMgr_c::GetInstance()->leaveCaution(); } bool unk_0x065 = field_0x065; @@ -198,3 +200,35 @@ bool dSndStateMgr_c::isSeekerStoneStage(const char *stageName, s32 layer) { bool dSndStateMgr_c::isInStage(const char *stageName) { return !std::strcmp(dScGame_c::currentSpawnInfo.getStageName(), stageName); } + +void dSndStateMgr_c::initializeEventCallbacks(const char *name) { + if (name == nullptr) { + return; + } + + mpSoundEventDef = nullptr; + sEventExecuteCallback = nullptr; + resetOverrides(); + + if (checkFlag0x94(0x2)) { + handleDemoEvent(name); + return; + } + + if (mSoundEventId == SND_EVENT_0x87) { + return; + } + + if (!handleStageEvent(name)) { + handleGlobalEvent(name); + } + + if (mSoundEventId == SND_EVENT_0x89) { + if (strstr(name, "Intro")) { + mSoundEventId = SND_EVENT_0x88; + } else { + mSoundEventId = SND_EVENT_0x86; + cbUnkNoop(); + } + } +}