From 03e518622a9b10bc45e28170a6b03aba1c09f391 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 6 Jun 2025 14:43:21 +0200 Subject: [PATCH] A bit of dSndSmallEffectMgr_c --- config/SOUE01/splits.txt | 13 +- config/SOUE01/symbols.txt | 24 +-- configure.py | 10 +- include/d/snd/d_snd_3d_actor.h | 18 --- include/d/snd/d_snd_checkers.h | 34 ++++ include/d/snd/d_snd_control_player_mgr.h | 1 + include/d/snd/d_snd_small_effect_mgr.h | 37 ++++- include/d/snd/d_snd_source.h | 3 +- include/nw4r/snd/snd_SoundHandle.h | 5 + include/toBeSorted/music_mgrs.h | 3 + src/d/snd/d_snd_3d_actor.cpp | 1 + src/d/snd/d_snd_small_effect_mgr.cpp | 189 ++++++++++++++++++++++- src/d/snd/d_snd_source.cpp | 22 +++ 13 files changed, 316 insertions(+), 44 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 13bb72e7..ced03afb 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -2419,9 +2419,20 @@ d/snd/d_snd_control_player.cpp: d/snd/d_snd_bgm_mgr.cpp: .text start:0x8036C6B0 end:0x803739CC align:16 + .sbss start:0x80575D80 end:0x80575D88 + .sdata2 start:0x8057D940 end:0x8057D970 + +d/snd/d_snd_bgm_sound_callbacks.cpp: + .text start:0x803739D0 end:0x80378ECC align:16 + .sdata2 start:0x8057D970 end:0x8057DA50 + +d/snd/d_snd_bgm_sound_boss_callbacks.cpp: + .text start:0x80378ED0 end:0x80379D20 align:16 + .sdata2 start:0x8057DA50 end:0x8057DA58 d/snd/d_snd_bgm_sound.cpp: - .text start:0x803739D0 end:0x8037BA68 align:16 + .text start:0x80379D20 end:0x8037BA68 align:16 + .sbss start:0x80575D88 end:0x80575D90 d/snd/d_snd_unk_15.cpp: .text start:0x8037BA70 end:0x8037D800 align:16 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 9c98f249..937bcc97 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -20843,9 +20843,9 @@ fn_8037DC50 = .text:0x8037DC50; // type:function size:0x70 fn_8037DCC0 = .text:0x8037DCC0; // type:function size:0x48 fn_8037DD10 = .text:0x8037DD10; // type:function size:0x1BC playSound__20dSndSmallEffectMgr_cFUl = .text:0x8037DED0; // type:function size:0x2D0 -fn_8037E1A0 = .text:0x8037E1A0; // type:function size:0x90 +playSoundWithPan__20dSndSmallEffectMgr_cFUlf = .text:0x8037E1A0; // type:function size:0x90 fn_8037E230 = .text:0x8037E230; // type:function size:0xEC -fn_8037E320 = .text:0x8037E320; // type:function size:0x78 +playSoundInternal__20dSndSmallEffectMgr_cFUl = .text:0x8037E320; // type:function size:0x78 fn_8037E3A0 = .text:0x8037E3A0; // type:function size:0x158 fn_8037E500 = .text:0x8037E500; // type:function size:0x58 playSoundWithPitch__20dSndSmallEffectMgr_cFUlf = .text:0x8037E560; // type:function size:0xBC @@ -20867,14 +20867,14 @@ fn_8037EC30 = .text:0x8037EC30; // type:function size:0x8 fn_8037EC40 = .text:0x8037EC40; // type:function size:0x3C fn_8037EC80 = .text:0x8037EC80; // type:function size:0xB0 fn_8037ED30 = .text:0x8037ED30; // type:function size:0x68 -fn_8037EDA0 = .text:0x8037EDA0; // type:function size:0xA0 -fn_8037EE40 = .text:0x8037EE40; // type:function size:0x3C -fn_8037EE80 = .text:0x8037EE80; // type:function size:0x64 -playSound = .text:0x8037EEF0; // type:function size:0xAC -fn_8037EFA0 = .text:0x8037EFA0; // type:function size:0x80 +stopSounds__20dSndSmallEffectMgr_cFUlUll = .text:0x8037EDA0; // type:function size:0xA0 +__cl__12SoundStopperFRQ34nw4r3snd11SoundHandle = .text:0x8037EE40; // type:function size:0x3C +stopSounds__20dSndSmallEffectMgr_cFUll = .text:0x8037EE80; // type:function size:0x64 +isPlayingSound__20dSndSmallEffectMgr_cFUlUl = .text:0x8037EEF0; // type:function size:0xAC +isPlayingSound__20dSndSmallEffectMgr_cFUl = .text:0x8037EFA0; // type:function size:0x80 playButtonPressSoundWhenAdvancingTextBoxes__20dSndSmallEffectMgr_cFf = .text:0x8037F020; // type:function size:0xB4 -fn_8037F0E0 = .text:0x8037F0E0; // type:function size:0xC -fn_8037F0F0 = .text:0x8037F0F0; // type:function size:0x60 +resetButtonPressSound__20dSndSmallEffectMgr_cFv = .text:0x8037F0E0; // type:function size:0xC +setButtonPressSound__20dSndSmallEffectMgr_cFP14dSoundSource_c = .text:0x8037F0F0; // type:function size:0x60 fn_8037F150 = .text:0x8037F150; // type:function size:0x6D0 d_s_vt_0x17C__14dSoundSource_cFv = .text:0x8037F820; // type:function size:0x8 vt_0x18__14dSoundSource_cFv = .text:0x8037F830; // type:function size:0x8 @@ -21225,7 +21225,7 @@ vt_0xFC__14dSoundSource_cFv = .text:0x8038BD40; // type:function size:0x20 vt_0x110__14dSoundSource_cFv = .text:0x8038BD60; // type:function size:0xC d_s_vt_0x1E4__14dSoundSource_cFv = .text:0x8038BD70; // type:function size:0x4 fn_8038BD80 = .text:0x8038BD80; // type:function size:0xB8 -fn_8038BE40 = .text:0x8038BE40; // type:function size:0xC4 +getCharacterTalkSoundId__14dSoundSource_cFUlP14dSoundSource_c = .text:0x8038BE40; // type:function size:0xC4 fn_8038BF10 = .text:0x8038BF10; // type:function size:0x104 d_s_vt_0x1E8__14dSoundSource_cFv = .text:0x8038C020; // type:function size:0x8 getRemoConSoundVariant__14dSoundSource_cCFUl = .text:0x8038C030; // type:function size:0x58 @@ -37732,7 +37732,7 @@ lbl_80549178 = .data:0x80549178; // type:object size:0x10 lbl_80549188 = .data:0x80549188; // type:object size:0x10 lbl_80549198 = .data:0x80549198; // type:object size:0x10 lbl_805491A8 = .data:0x805491A8; // type:object size:0x10 -lbl_805491B8 = .data:0x805491B8; // type:object size:0xC +__vt__12SoundStopper = .data:0x805491B8; // type:object size:0xC __vt__38SndMgrDisposer<20dSndSmallEffectMgr_c> = .data:0x805491C4; // type:object size:0xC lbl_805491D0 = .data:0x805491D0; // type:object size:0x10 jumptable_805491E0 = .data:0x805491E0; // type:object size:0x20 scope:local @@ -49197,7 +49197,7 @@ lbl_8057E5BC = .sdata2:0x8057E5BC; // type:object size:0x4 align:4 data:float lbl_8057E5C0 = .sdata2:0x8057E5C0; // type:object size:0x4 data:4byte lbl_8057E5C4 = .sdata2:0x8057E5C4; // type:object size:0x4 align:4 data:float sNumPlayers__22dSndControlPlayerMgr_c = .sdata2:0x8057E5C8; // type:object size:0x4 data:4byte -lbl_8057E5CC = .sdata2:0x8057E5CC; // type:object size:0x4 data:4byte +sPlayerMax__22dSndControlPlayerMgr_c = .sdata2:0x8057E5CC; // type:object size:0x4 data:4byte sEventMuteFlagsMask__15dSndPlayerMgr_c = .sdata2:0x8057E5D0; // type:object size:0x8 data:4byte lbl_8057E5D8 = .sdata2:0x8057E5D8; // type:object size:0x4 align:4 data:float lbl_8057E5DC = .sdata2:0x8057E5DC; // type:object size:0x4 align:4 data:float diff --git a/configure.py b/configure.py index b1193287..0bef48dc 100644 --- a/configure.py +++ b/configure.py @@ -700,8 +700,6 @@ config.libs = [ "progress_category": "game", "host": False, "objects": [ - # These are very low quality splits since nobody has figured - # out enough detail. Need to look into nw4r::snd first Object(NonMatching, "d/snd/d_snd_mgr.cpp"), Object(Matching, "d/snd/d_snd_actor.cpp"), Object(NonMatching, "d/snd/d_snd_3d_actor.cpp"), @@ -710,14 +708,18 @@ config.libs = [ Object(NonMatching, "d/snd/d_snd_player_mgr.cpp"), Object(NonMatching, "d/snd/d_snd_control_player_mgr.cpp"), Object(Matching, "d/snd/d_snd_3d_manager.cpp"), + # this one is a bit weird. it deals with all the stage definitions, + # but it's not actually the bgm manager? Object(NonMatching, "d/snd/d_snd_stage_mgr.cpp"), - Object(NonMatching, "d/snd/d_snd_bgm_mgr.cpp"), - Object(NonMatching, "d/snd/d_snd_bgm_sound.cpp"), Object(NonMatching, "d/snd/d_snd_unk_component_2.cpp"), Object(NonMatching, "d/snd/d_snd_area_sound_effect_mgr.cpp"), Object(NonMatching, "d/snd/d_snd_area_sound.cpp"), Object(Matching, "d/snd/d_snd_control_sound.cpp"), Object(Matching, "d/snd/d_snd_control_player.cpp"), + Object(NonMatching, "d/snd/d_snd_bgm_mgr.cpp"), + Object(NonMatching, "d/snd/d_snd_bgm_sound_callbacks.cpp"), + Object(NonMatching, "d/snd/d_snd_bgm_sound_boss_callbacks.cpp"), + Object(NonMatching, "d/snd/d_snd_bgm_sound.cpp"), Object(NonMatching, "d/snd/d_snd_unk_15.cpp"), Object(NonMatching, "d/snd/d_snd_small_effect_mgr.cpp"), Object(NonMatching, "d/snd/d_snd_harp_mgr.cpp"), diff --git a/include/d/snd/d_snd_3d_actor.h b/include/d/snd/d_snd_3d_actor.h index 5c8642f1..98735baf 100644 --- a/include/d/snd/d_snd_3d_actor.h +++ b/include/d/snd/d_snd_3d_actor.h @@ -4,7 +4,6 @@ #include "common.h" #include "nw4r/math/math_types.h" #include "nw4r/snd/snd_Sound3DActor.h" -#include "nw4r/snd/snd_SoundHandle.h" class dSnd3DActor_c : public nw4r::snd::Sound3DActor { static const u32 NUM_SOUNDS = 4; @@ -90,21 +89,4 @@ protected: /* 0xE0 */ f32 a_field_0xE0; }; -// used at the very least when trying to finish Demise -class IsCurrentSoundIdChecker { -public: - IsCurrentSoundIdChecker(u32 id, bool *pResult) : mSoundId(id), mpResult(pResult) {} - ~IsCurrentSoundIdChecker() {} - - virtual void operator()(nw4r::snd::SoundHandle &pHandle) { - if (mSoundId == pHandle.GetId()) { - *mpResult = true; - } - } - -private: - /* 0x04 */ u32 mSoundId; - /* 0x08 */ bool *mpResult; -}; - #endif diff --git a/include/d/snd/d_snd_checkers.h b/include/d/snd/d_snd_checkers.h index 7a459280..d18c2777 100644 --- a/include/d/snd/d_snd_checkers.h +++ b/include/d/snd/d_snd_checkers.h @@ -70,4 +70,38 @@ private: /* 0x24 */ u32 *mpCounter4; }; + +// used at the very least when trying to finish Demise +class IsCurrentSoundIdChecker { +public: + IsCurrentSoundIdChecker(u32 id, bool *pResult) : mSoundId(id), mpResult(pResult) {} + ~IsCurrentSoundIdChecker() {} + + virtual void operator()(nw4r::snd::SoundHandle &pHandle) { + if (mSoundId == pHandle.GetId()) { + *mpResult = true; + } + } + +private: + /* 0x04 */ u32 mSoundId; + /* 0x08 */ bool *mpResult; +}; + +class SoundStopper { +public: + SoundStopper(u32 id, s32 fadeFrames) : mSoundId(id), mFadeFrames(fadeFrames) {} + ~SoundStopper() {} + + virtual void operator()(nw4r::snd::SoundHandle &pHandle) { + if (mSoundId == pHandle.GetId()) { + pHandle.Stop(mFadeFrames); + } + } + +private: + /* 0x04 */ u32 mSoundId; + /* 0x08 */ s32 mFadeFrames; +}; + #endif diff --git a/include/d/snd/d_snd_control_player_mgr.h b/include/d/snd/d_snd_control_player_mgr.h index d7e3097b..541268fb 100644 --- a/include/d/snd/d_snd_control_player_mgr.h +++ b/include/d/snd/d_snd_control_player_mgr.h @@ -25,6 +25,7 @@ public: void calc(); static const s32 sNumPlayers; + static const s32 sPlayerMax; nw4r::snd::SoundPlayer *getPlayer1(u32) const; nw4r::snd::SoundPlayer *getPlayer2(u32) const; diff --git a/include/d/snd/d_snd_small_effect_mgr.h b/include/d/snd/d_snd_small_effect_mgr.h index 84ebbfb1..6504728a 100644 --- a/include/d/snd/d_snd_small_effect_mgr.h +++ b/include/d/snd/d_snd_small_effect_mgr.h @@ -1,6 +1,7 @@ #ifndef D_SND_SMALL_EFFECT_MGR_H #define D_SND_SMALL_EFFECT_MGR_H +#include "d/snd/d_snd_source.h" #include "d/snd/d_snd_util.h" #include "d/snd/d_snd_wzsound.h" // IWYU pragma: export #include "nw4r/snd/snd_SoundHandle.h" @@ -17,15 +18,39 @@ class dSndSmallEffectMgr_c { public: dSndSmallEffectMgr_c(); - void playSound(u32 soundId); + bool playSound(u32 soundId); + bool playSoundWithPan(u32 soundId, f32 pan); void playSoundWithPitch(u32 soundId, f32 pitch); - void playButtonPressSoundWhenAdvancingTextBoxes(f32); + + + bool playButtonPressSoundWhenAdvancingTextBoxes(f32); + void resetButtonPressSound(); + void setButtonPressSound(dSoundSource_c *source); private: - /* 0x10 */ void *field_0x10; - /* 0x14 */ void *field_0x14; - /* 0x18 */ void *field_0x18; - /* 0x1C */ nw4r::snd::SoundHandle mHandles[3]; + bool playSoundInternal(u32 soundId); + void stopSounds(u32 playerIdx, u32 soundId, s32 fadeFrames); + void stopSounds(u32 soundId, s32 fadeFrames); + bool isPlayingSound(u32 playerIdx, u32 soundId); + bool isPlayingSound(u32 soundId); + + /* 0x10 */ nw4r::snd::SoundHandle mHandle1; + // used for most sounds + /* 0x14 */ nw4r::snd::SoundHandle mNormalSound; + /* 0x18 */ nw4r::snd::SoundHandle mHandle3; + // apparently used for shield gauge sounds, but maybe not given + // that the callers appear unreachable + /* 0x1C */ nw4r::snd::SoundHandle mShieldGaugeHandles[3]; + + /* 0x28 */ s32 field_0x28; + /* 0x2C */ s32 field_0x2C; + /* 0x30 */ s32 field_0x30; + /* 0x34 */ s32 field_0x34; + /* 0x38 */ u32 mTextboxAdvanceSound; + /* 0x3C */ nw4r::snd::SoundHandle mHandle4; + /* 0x40 */ u16 field_0x40; + /* 0x42 */ u16 field_0x42; + /* 0x44 */ s32 field_0x44; }; #endif diff --git a/include/d/snd/d_snd_source.h b/include/d/snd/d_snd_source.h index 1b2ca525..2ae4c739 100644 --- a/include/d/snd/d_snd_source.h +++ b/include/d/snd/d_snd_source.h @@ -12,12 +12,13 @@ public: dSoundSource_c(u8, dAcBase_c *, UNKWORD, UNKWORD); virtual ~dSoundSource_c(); + static u32 getCharacterTalkSoundId(u32 baseSoundId, dSoundSource_c* source); u32 getRemoConSoundVariant(u32 soundId) const; // This is where it gets a bit wild and this class starts mixing in overrides between // new virtual functions, which causes the vtable to list these functions in exactly this // order. - virtual void d_s_vt_0x17C(); + virtual const char *d_s_vt_0x17C() const; virtual void d_s_vt_0x180(); virtual void d_s_vt_0x184(); virtual void d_s_vt_0x188(); diff --git a/include/nw4r/snd/snd_SoundHandle.h b/include/nw4r/snd/snd_SoundHandle.h index bca2c59a..847f7942 100644 --- a/include/nw4r/snd/snd_SoundHandle.h +++ b/include/nw4r/snd/snd_SoundHandle.h @@ -60,6 +60,11 @@ namespace nw4r { namespace snd mSound->Pause(flag, fadeFrames); } + void SetPan(f32 pan) { + if (IsAttachedSound()) + mSound->SetPan(pan); + } + bool IsPause() const { return IsAttachedSound() && mSound->IsPause(); } diff --git a/include/toBeSorted/music_mgrs.h b/include/toBeSorted/music_mgrs.h index 8d255eb8..63c1ceb4 100644 --- a/include/toBeSorted/music_mgrs.h +++ b/include/toBeSorted/music_mgrs.h @@ -26,9 +26,12 @@ extern "C" void fn_80365D20(void *); extern "C" void fn_803624F0(void *); extern "C" void fn_80364FD0(void *, s32); extern "C" bool fn_80364DA0(void *); +extern "C" void fn_80365020(void *); extern "C" void fn_80364D00(void *, s32); // ENEMY_BGM_RELATED_MGR -> dSndSourceMgr_c +// 0x3870 = player sound source +// 0x3874 = Fi extern "C" void *ENEMY_BGM_RELATED_MGR; extern "C" void fn_80384570(void *, bool); extern "C" void fn_803858D0(void *); diff --git a/src/d/snd/d_snd_3d_actor.cpp b/src/d/snd/d_snd_3d_actor.cpp index bf2d7799..41f506aa 100644 --- a/src/d/snd/d_snd_3d_actor.cpp +++ b/src/d/snd/d_snd_3d_actor.cpp @@ -3,6 +3,7 @@ #include "common.h" #include "d/a/d_a_player.h" #include "d/snd/d_snd_3d_manager.h" +#include "d/snd/d_snd_checkers.h" #include "d/snd/d_snd_player_mgr.h" #include "nw4r/math/math_types.h" diff --git a/src/d/snd/d_snd_small_effect_mgr.cpp b/src/d/snd/d_snd_small_effect_mgr.cpp index cab93dd2..24cc3216 100644 --- a/src/d/snd/d_snd_small_effect_mgr.cpp +++ b/src/d/snd/d_snd_small_effect_mgr.cpp @@ -1,8 +1,193 @@ #include "d/snd/d_snd_small_effect_mgr.h" +#include "common.h" +#include "d/snd/d_snd_checkers.h" +#include "d/snd/d_snd_control_player_mgr.h" +#include "d/snd/d_snd_player_mgr.h" +#include "d/snd/d_snd_source.h" +#include "d/snd/d_snd_source_if.h" #include "d/snd/d_snd_util.h" - +#include "d/snd/d_snd_wzsound.h" +#include "nw4r/snd/snd_SeqSoundHandle.h" +#include "rvl/OS/OSFastCast.h" +#include "toBeSorted/music_mgrs.h" SND_DISPOSER_DEFINE(dSndSmallEffectMgr_c) -dSndSmallEffectMgr_c::dSndSmallEffectMgr_c() {} +dSndSmallEffectMgr_c::dSndSmallEffectMgr_c() : mTextboxAdvanceSound(-1), field_0x40(0), field_0x42(0), field_0x44(0) { + // probably arrays + field_0x28 = -1; + field_0x30 = 0; + field_0x2C = -1; + field_0x34 = 0; +} + +bool dSndSmallEffectMgr_c::playSound(u32 soundId) { + if (soundId >= SE_S_BUTTON_CALL_L && soundId <= SE_S_PLAY_GUIDE_BUTTON_BLINK) { + soundId = SE_S_BUTTON_CALL_L; + } else if (soundId >= SE_S_BUTTON_CALL_R && soundId <= SE_S_2_BUTTON_BLINK) { + soundId = SE_S_BUTTON_CALL_R; + } else { + switch (soundId) { + case SE_S_BOSS_KEY_TRANS: { + stopSounds(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_BOSS_KEY_TRANS_OFF, 5); + break; + } + case SE_S_BOSS_KEY_TRANS_OFF: { + stopSounds(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_BOSS_KEY_TRANS, 5); + break; + } + case SE_S_HP_GAUGE_UP: { + if (isPlayingSound(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_HEART_PIECE_GET)) { + return false; + } + break; + } + case SE_S_HEART_PIECE_GET: { + if (isPlayingSound(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_HP_GAUGE_UP)) { + return false; + } + break; + } + case SE_S_MAP_OPEN: + case SE_S_MENU_IN: { + stopSounds(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_HELP_OUT, 1); + break; + } + case SE_S_HELP_OUT: { + if (isPlayingSound(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_MENU_IN) || + isPlayingSound(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_MAP_OPEN)) { + return false; + } + break; + } + case SE_S_MENU_SELECT_TURN_PAGE_LEFT: { + if (isPlayingSound(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_SHOP_STK_STOCK_SELECT_TURN_PAGE_LEFT)) { + return 0; + } + break; + } + case SE_S_MENU_SELECT_TURN_PAGE_RIGHT: { + if (isPlayingSound(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_SHOP_STK_STOCK_SELECT_TURN_PAGE_RIGHT)) { + return 0; + } + break; + } + case SE_S_ITEM_SELECT_START: { + if (isPlayingSound(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_BM_KEEP_ERROR)) { + soundId = SE_S_ITEM_SELECT_START_WAIT; + } + break; + } + case SE_S_SKIP: { + if (fn_80364DA0(ENEMY_SOUND_MGR)) { + fn_80365020(ENEMY_SOUND_MGR); + } + break; + } + case SE_S_WINDOW_PRESS_A: { + if (isPlayingSound(dSndPlayerMgr_c::PLAYER_SMALL_IMPORTANT, SE_S_POINTER_OK)) { + return 0; + } + break; + } + case SE_S_MENU_P1_HOLD_POINTER: { + stopSounds(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_MENU_P1_POINT_ITEM, 0); + break; + } + case SE_S_MENU_P1_POINT_ITEM: { + if (isPlayingSound(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_MENU_P1_HOLD_POINTER)) { + return 0; + } + break; + } + case SE_S_FIRST_PERSON_ON: + case SE_S_FIRST_PERSON_OFF: { + if (!isPlayingSound(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_DOWSING_SELECT_START)) { + playSound(SE_S_DOWSING_SELECT_START); + } + break; + } + case 0x13EF: + if (isPlayingSound(dSndPlayerMgr_c::PLAYER_SMALL_NORMAL, SE_S_FIRST_PERSON_ON)) { + return 0; + } + break; + } + } + + return playSoundInternal(soundId); +} + +bool dSndSmallEffectMgr_c::playSoundWithPan(u32 soundId, f32 pan) { + bool ok = playSoundInternal(soundId); + if (ok) { + if (pan > 1.0f) { + pan = 1.0f; + } else if (pan < -1.0f) { + pan = -1.0f; + } + mNormalSound.SetPan(pan); + } + return ok; +} + +void dSndSmallEffectMgr_c::stopSounds(u32 playerIdx, u32 soundId, s32 fadeFrames) { + SoundStopper stopper(soundId, fadeFrames); + dSndControlPlayerMgr_c::GetInstance()->getPlayer1(playerIdx)->ForEachSound(stopper, false); +} + +void dSndSmallEffectMgr_c::stopSounds(u32 soundId, s32 fadeFrames) { + for (s32 playerId = dSndPlayerMgr_c::PLAYER_SMALL_IMPORTANT; playerId <= dSndControlPlayerMgr_c::sPlayerMax; + playerId++) { + stopSounds(playerId, soundId, fadeFrames); + } +} + +bool dSndSmallEffectMgr_c::isPlayingSound(u32 playerIdx, u32 soundId) { + bool isPlaying = false; + IsCurrentSoundIdChecker check(soundId, &isPlaying); + dSndControlPlayerMgr_c::GetInstance()->getPlayer1(playerIdx)->ForEachSound(check, false); + return isPlaying; +} + +bool dSndSmallEffectMgr_c::isPlayingSound(u32 soundId) { + for (s32 playerId = dSndPlayerMgr_c::PLAYER_SMALL_IMPORTANT; playerId <= dSndControlPlayerMgr_c::sPlayerMax; + playerId++) { + if (isPlayingSound(playerId, soundId)) { + return true; + } + } + return false; +} + +bool dSndSmallEffectMgr_c::playButtonPressSoundWhenAdvancingTextBoxes(f32 ratio) { + if (mTextboxAdvanceSound == -1) { + return false; + } + + bool ok = playSound(mTextboxAdvanceSound); + if (ok) { + s16 varValue; + f32 value = ratio * 100.0f; + OSf32tos16(&value, &varValue); + nw4r::snd::SeqSoundHandle handle(&mNormalSound); + handle.WriteVariable(10, varValue); + } + + return ok; +} + +void dSndSmallEffectMgr_c::resetButtonPressSound() { + mTextboxAdvanceSound = -1; +} + +void dSndSmallEffectMgr_c::setButtonPressSound(dSoundSource_c *source) { + resetButtonPressSound(); + if (source != nullptr) { + mTextboxAdvanceSound = dSoundSource_c::getCharacterTalkSoundId(SE_S_TALK_CHAR, source); + if (mTextboxAdvanceSound == SE_S_TALK_CHAR) { + resetButtonPressSound(); + } + } +} diff --git a/src/d/snd/d_snd_source.cpp b/src/d/snd/d_snd_source.cpp index 11a1589e..96b554a5 100644 --- a/src/d/snd/d_snd_source.cpp +++ b/src/d/snd/d_snd_source.cpp @@ -3,6 +3,8 @@ #include "common.h" #include "d/snd/d_snd_3d_actor.h" #include "d/snd/d_snd_3d_manager.h" +#include "d/snd/d_snd_mgr.h" +#include "d/snd/d_snd_player_mgr.h" #include "nw4r/snd/snd_SoundStartable.h" #include "nw4r/ut/ut_list.h" #include "sized_string.h" @@ -99,6 +101,26 @@ void dSoundSource_c::d_vt_0x5C() { // noop } +u32 dSoundSource_c::getCharacterTalkSoundId(u32 baseSoundId, dSoundSource_c *source) { + if (baseSoundId != -1 && source != nullptr) { + SizedString<64> label; + + // maybe an inline + const char *baseLabel = nullptr; + if (dSndMgr_c::GetInstance()->getArchive() != nullptr) { + baseLabel = dSndMgr_c::GetInstance()->getArchive()->GetSoundLabelString(baseSoundId); + } + + const char *charLabel = source->d_s_vt_0x17C(); + label.sprintf("%s_%s", baseLabel, charLabel); + u32 newLabel = dSndPlayerMgr_c::GetInstance()->convertLabelStringToSoundId(label); + if (newLabel != -1) { + return newLabel; + } + } + return baseSoundId; +} + u32 dSoundSource_c::getRemoConSoundVariant(u32 soundId) const { const char *label = soundIdToSoundLabel(soundId); SizedString<64> str;