diff --git a/LEGO1/legoomni.cpp b/LEGO1/legoomni.cpp index a37d9776..a6c1461d 100644 --- a/LEGO1/legoomni.cpp +++ b/LEGO1/legoomni.cpp @@ -212,12 +212,29 @@ GifManager* GetGifManager() return LegoOmni::GetInstance()->GetGifManager(); } +// OFFSET: LEGO1 0x100158e0 +MxDSAction& GetCurrentAction() +{ + return LegoOmni::GetInstance()->GetCurrentAction(); +} + // OFFSET: LEGO1 0x10015900 MxTransitionManager* TransitionManager() { return LegoOmni::GetInstance()->GetTransitionManager(); } +// OFFSET: LEGO1 0x10015910 +void PlayMusic(MxU32 p_index) +{ + // index is the entityid of the music in jukebox.si + MxDSAction action; + action.SetAtomId(*g_jukeboxScript); + action.SetObjectId(p_index); + + LegoOmni::GetInstance()->GetBackgroundAudioManager()->PlayMusic(action, 5, 4); +} + // OFFSET: LEGO1 0x100c0280 MxDSObject* CreateStreamObject(MxDSFile* p_file, MxS16 p_ofs) { diff --git a/LEGO1/legoomni.h b/LEGO1/legoomni.h index b8b9c1d5..469fd8cb 100644 --- a/LEGO1/legoomni.h +++ b/LEGO1/legoomni.h @@ -79,6 +79,7 @@ class LegoOmni : public MxOmni { LegoGameState* GetGameState() { return m_gameState; } MxBackgroundAudioManager* GetBackgroundAudioManager() { return m_bkgAudioManager; } MxTransitionManager* GetTransitionManager() { return m_transitionManager; } + MxDSAction& GetCurrentAction() { return m_action; } private: undefined4 m_unk68; @@ -124,5 +125,6 @@ LegoPlantManager* PlantManager(); MxBool KeyValueStringParse(char*, const char*, const char*); LegoWorld* GetCurrentWorld(); GifManager* GetGifManager(); +MxDSAction& GetCurrentAction(); #endif // LEGOOMNI_H diff --git a/LEGO1/mxbackgroundaudiomanager.cpp b/LEGO1/mxbackgroundaudiomanager.cpp index e9106177..26d399f7 100644 --- a/LEGO1/mxbackgroundaudiomanager.cpp +++ b/LEGO1/mxbackgroundaudiomanager.cpp @@ -1,6 +1,10 @@ #include "mxbackgroundaudiomanager.h" +#include "legoomni.h" +#include "mxcompositepresenter.h" +#include "mxdssound.h" #include "mxomni.h" +#include "mxpresenter.h" #include "mxstreamer.h" #include "mxticklemanager.h" @@ -14,7 +18,7 @@ MxBackgroundAudioManager::MxBackgroundAudioManager() m_unk138 = 0; m_unk13c = 0; m_unk140 = 0; - m_unk144 = 0; + m_targetVolume = 0; m_unk148 = 0; m_musicEnabled = FALSE; } @@ -47,6 +51,32 @@ void MxBackgroundAudioManager::Stop() m_unk13c = 0; } +// OFFSET: LEGO1 0x1007f570 +void MxBackgroundAudioManager::LowerVolume() +{ + if (m_unk148 == 0) { + if (m_unk13c == 0) { + m_unk13c = 2; + } + m_unk140 = 20; + } + m_unk148++; +} + +// OFFSET: LEGO1 0x1007f5b0 +void MxBackgroundAudioManager::RaiseVolume() +{ + if (m_unk148 != 0) { + m_unk148--; + if (m_unk148 == 0) { + if (m_unk13c == 0) { + m_unk13c = 2; + } + m_unk140 = 10; + } + } +} + // OFFSET: LEGO1 0x1007f5f0 void MxBackgroundAudioManager::Enable(MxBool p) { @@ -106,3 +136,191 @@ void MxBackgroundAudioManager::DestroyMusic() m_musicEnabled = FALSE; } } + +// OFFSET: LEGO1 0x1007f170 +MxLong MxBackgroundAudioManager::Notify(MxParam& p) +{ + switch (((MxNotificationParam&) p).GetNotification()) { + case c_notificationStartAction: + StartAction(p); + return 1; + case c_notificationEndAction: + StopAction(p); + return 1; + } + return 0; +} + +// OFFSET: LEGO1 0x1007f1b0 +void MxBackgroundAudioManager::StartAction(MxParam& p) +{ + // TODO: the sender is most likely a MxAudioPresenter? + m_unk138 = (MxAudioPresenter*) ((MxNotificationParam&) p).GetSender(); + m_action2.SetAtomId(m_unk138->GetAction()->GetAtomId()); + m_action2.SetObjectId(m_unk138->GetAction()->GetObjectId()); + m_targetVolume = ((MxDSSound*) (m_unk138->GetAction()))->GetVolume(); + m_unk138->vtable60(0); +} + +// OFFSET: LEGO1 0x1007f200 +void MxBackgroundAudioManager::StopAction(MxParam& p) +{ + if (((MxNotificationParam&) p).GetSender() == m_unka0) { + m_unka0 = NULL; + m_action1.SetAtomId(MxAtomId()); + m_action1.SetObjectId(-1); + } + else if (((MxNotificationParam&) p).GetSender() == m_unk138) { + m_unk138 = NULL; + m_action2.SetAtomId(MxAtomId()); + m_action2.SetObjectId(-1); + } + + Lego()->HandleNotificationType2(p); +} + +// OFFSET: LEGO1 0x1007f2f0 +MxResult MxBackgroundAudioManager::PlayMusic(MxDSAction& p_action, undefined4 p_unknown, undefined4 p_unknown2) +{ + if (!m_musicEnabled) { + return SUCCESS; + } + if (m_action2.GetObjectId() == -1 && m_action1.GetObjectId() != p_action.GetObjectId()) { + MxDSAction action; + action.SetAtomId(GetCurrentAction().GetAtomId()); + action.SetObjectId(GetCurrentAction().GetObjectId()); + action.SetUnknown24(GetCurrentAction().GetUnknown24()); + + m_action2.SetAtomId(p_action.GetAtomId()); + m_action2.SetObjectId(p_action.GetObjectId()); + m_action2.SetUnknown84(this); + m_action2.SetUnknown8c(this); + + MxResult result = Start(&m_action2); + + GetCurrentAction().SetAtomId(action.GetAtomId()); + GetCurrentAction().SetObjectId(action.GetObjectId()); + GetCurrentAction().SetUnknown24(action.GetUnknown24()); + + if (result == SUCCESS) { + m_unk13c = p_unknown2; + m_unk140 = p_unknown; + } + return result; + } + return FAILURE; +} + +// OFFSET: LEGO1 0x1007ee40 +MxResult MxBackgroundAudioManager::Tickle() +{ + switch (m_unk13c) { + case MxPresenter::TickleState_Starting: + FadeInOrFadeOut(); + return SUCCESS; + case MxPresenter::TickleState_Streaming: + FUN_1007ee70(); + return SUCCESS; + case MxPresenter::TickleState_Repeating: + FUN_1007ef40(); + return SUCCESS; + default: + return SUCCESS; + } +} + +// OFFSET: LEGO1 0x1007ee70 +void MxBackgroundAudioManager::FUN_1007ee70() +{ + if (m_unka0 && m_unka0->GetAction()) { + DeleteObject(*m_unk138->GetAction()); + } + + if (m_unk138) { + m_unka0 = m_unk138; + m_action1 = m_action2; + m_unk138 = NULL; + m_action2.SetObjectId(-1); + m_action2.SetAtomId(MxAtomId()); + m_unk13c = NULL; + } +} + +// OFFSET: LEGO1 0x1007ef40 +void MxBackgroundAudioManager::FUN_1007ef40() +{ + MxU32 compare; + MxU32 volume; + if (m_unka0 == NULL) { + if (m_unk138) { + compare = 30; + if (m_unk148 == 0) { + compare = m_unk148; + } + volume = m_unk138->vtable5c(); + if (volume < compare) { + if (m_unk140 + m_unk138->vtable5c() <= compare) { + compare = m_unk140 + compare; + } + m_unk138->vtable60(compare); + } + else { + m_unk138->vtable60(compare); + m_unka0 = m_unk138; + m_action1 = m_action2; + m_unk138 = NULL; + m_action2.SetObjectId(-1); + m_action2.SetAtomId(MxAtomId()); + m_unk13c = NULL; + } + } + } + else if (m_unka0->GetAction() != NULL) { + if (m_unka0->vtable5c() == 0) { + DeleteObject(*m_unka0->GetAction()); + } + else { + compare = m_unka0->vtable5c(); + volume = 0; + if (compare != m_unk140 && -1 < compare - m_unk140) { + volume = m_unka0->vtable5c() - m_unk140; + } + m_unk138->vtable60(volume); + } + } +} + +// OFFSET: LEGO1 0x1007f0e0 +void MxBackgroundAudioManager::FadeInOrFadeOut() +{ + // This function probably is the fade in/out routine + if (m_unka0 != NULL) { + undefined4 volume = m_unka0->vtable5c(); + MxU32 compare = 30; + if (m_unk148 == 0) { + compare = m_targetVolume; + } + + if (volume < compare) { + volume = m_unk140 + volume; + if (compare <= volume) { + volume = compare; + } + m_unka0->vtable60(volume); + } + else if (compare < volume) { + volume = volume - m_unk140; + if (volume <= compare) { + volume = compare; + } + m_unka0->vtable60(volume); + } + else { + m_unka0->vtable60(volume); + m_unk13c = 0; + } + } + else { + m_unk13c = 0; + } +} diff --git a/LEGO1/mxbackgroundaudiomanager.h b/LEGO1/mxbackgroundaudiomanager.h index a306ef2a..6ff05bb3 100644 --- a/LEGO1/mxbackgroundaudiomanager.h +++ b/LEGO1/mxbackgroundaudiomanager.h @@ -1,9 +1,11 @@ #ifndef MXBACKGROUNDAUDIOMANAGER_H #define MXBACKGROUNDAUDIOMANAGER_H +#include "mxaudiopresenter.h" #include "mxcore.h" #include "mxdsaction.h" #include "mxnotificationmanager.h" +#include "mxpresenter.h" #include "mxtypes.h" // VTABLE 0x100d9fe8 @@ -13,6 +15,9 @@ class MxBackgroundAudioManager : public MxCore { MxBackgroundAudioManager(); virtual ~MxBackgroundAudioManager() override; + virtual MxLong Notify(MxParam& p) override; // vtable+0x04 + virtual MxResult Tickle() override; // vtable+0x08 + // OFFSET: LEGO1 0x1007eb70 inline virtual const char* ClassName() const override // vtable+0x0c { @@ -26,10 +31,20 @@ class MxBackgroundAudioManager : public MxCore { return !strcmp(name, MxBackgroundAudioManager::ClassName()) || MxCore::IsA(name); } + void StartAction(MxParam& p); + void StopAction(MxParam& p); + MxResult PlayMusic(MxDSAction& p_action, undefined4 p_unknown, undefined4 p_unknown2); + + void FUN_1007ee70(); + void FUN_1007ef40(); + void FadeInOrFadeOut(); + __declspec(dllexport) void Enable(unsigned char p); virtual MxResult Create(MxAtomId& p_script, MxU32 p_frequencyMS); void Stop(); + void LowerVolume(); + void RaiseVolume(); private: void Init(); @@ -38,12 +53,12 @@ class MxBackgroundAudioManager : public MxCore { MxBool m_musicEnabled; // 0x8 MxDSAction m_action1; // 0xc - MxS32 m_unka0; + MxAudioPresenter* m_unka0; MxDSAction m_action2; // 0xa4 - MxS32 m_unk138; + MxAudioPresenter* m_unk138; MxS32 m_unk13c; MxS32 m_unk140; - MxS32 m_unk144; + MxS32 m_targetVolume; MxS16 m_unk148; MxAtomId m_script; }; diff --git a/LEGO1/mxcompositepresenter.cpp b/LEGO1/mxcompositepresenter.cpp index b6a38fa7..25a290a4 100644 --- a/LEGO1/mxcompositepresenter.cpp +++ b/LEGO1/mxcompositepresenter.cpp @@ -30,7 +30,7 @@ void MxCompositePresenter::VTable0x5c() } // OFFSET: LEGO1 0x100b6b40 STUB -void MxCompositePresenter::VTable0x60() +void MxCompositePresenter::VTable0x60(undefined4 p_unknown) { // TODO } diff --git a/LEGO1/mxcompositepresenter.h b/LEGO1/mxcompositepresenter.h index c41f4a0c..7def4ded 100644 --- a/LEGO1/mxcompositepresenter.h +++ b/LEGO1/mxcompositepresenter.h @@ -26,7 +26,7 @@ class MxCompositePresenter : public MxPresenter { virtual void VTable0x58(); virtual void VTable0x5c(); - virtual void VTable0x60(); + virtual void VTable0x60(undefined4 p_unknown); virtual void VTable0x64(); private: diff --git a/LEGO1/mxcore.h b/LEGO1/mxcore.h index 1ca8a906..899e3371 100644 --- a/LEGO1/mxcore.h +++ b/LEGO1/mxcore.h @@ -13,9 +13,9 @@ class MxParam; class MxCore { public: __declspec(dllexport) MxCore(); - __declspec(dllexport) virtual ~MxCore(); // vtable+00 - __declspec(dllexport) virtual MxResult Notify(MxParam& p); // vtable+04 - virtual MxResult Tickle(); // vtable+08 + __declspec(dllexport) virtual ~MxCore(); // vtable+00 + __declspec(dllexport) virtual MxLong Notify(MxParam& p); // vtable+04 + virtual MxResult Tickle(); // vtable+08 // OFFSET: LEGO1 0x100144c0 inline virtual const char* ClassName() const // vtable+0c diff --git a/LEGO1/mxdsaction.cpp b/LEGO1/mxdsaction.cpp index 6dc334ec..91db4e57 100644 --- a/LEGO1/mxdsaction.cpp +++ b/LEGO1/mxdsaction.cpp @@ -28,7 +28,7 @@ MxDSAction::MxDSAction() this->m_up.Fill(FLT_MAX); this->m_unk84 = NULL; this->m_unk88 = 0; - this->m_omni = NULL; + this->m_unk8c = NULL; this->m_unkTimingField = INT_MIN; } @@ -54,7 +54,7 @@ void MxDSAction::CopyFrom(MxDSAction& p_dsAction) AppendData(p_dsAction.m_extraLength, p_dsAction.m_extraData); this->m_unk84 = p_dsAction.m_unk84; this->m_unk88 = p_dsAction.m_unk88; - this->m_omni = p_dsAction.m_omni; + this->m_unk8c = p_dsAction.m_unk8c; this->m_unkTimingField = p_dsAction.m_unkTimingField; } diff --git a/LEGO1/mxdsaction.h b/LEGO1/mxdsaction.h index 72d7afac..c56a71e4 100644 --- a/LEGO1/mxdsaction.h +++ b/LEGO1/mxdsaction.h @@ -63,7 +63,7 @@ class MxDSAction : public MxDSObject { inline void SetLoopCount(MxS32 p_loopCount) { m_loopCount = p_loopCount; } inline const MxVector3Data& GetLocation() const { return m_location; } inline void SetUnknown84(MxCore* p_unk84) { m_unk84 = p_unk84; } - inline void SetOmni(MxOmni* p_omni) { m_omni = p_omni; } + inline void SetUnknown8c(MxCore* p_unk8c) { m_unk8c = p_unk8c; } inline MxBool IsLooping() const { return m_flags & Flag_Looping; } inline MxBool IsBit3() const { return m_flags & Flag_Bit3; } @@ -85,7 +85,7 @@ class MxDSAction : public MxDSObject { MxU16 m_extraLength; MxCore* m_unk84; undefined4 m_unk88; - MxOmni* m_omni; // 0x8c + MxCore* m_unk8c; protected: MxLong m_unkTimingField; // 0x90 diff --git a/LEGO1/mxdssound.h b/LEGO1/mxdssound.h index d56a4471..63a1d5ab 100644 --- a/LEGO1/mxdssound.h +++ b/LEGO1/mxdssound.h @@ -30,6 +30,8 @@ class MxDSSound : public MxDSMediaAction { virtual void Deserialize(char** p_source, MxS16 p_unk24) override; // vtable+1c; virtual MxDSAction* Clone() override; // vtable+2c; + inline MxS32 GetVolume() const { return m_volume; } + private: MxU32 m_sizeOnDisk; MxS32 m_volume; // 0xbc diff --git a/LEGO1/mxnotificationparam.h b/LEGO1/mxnotificationparam.h index e5654243..36c21b24 100644 --- a/LEGO1/mxnotificationparam.h +++ b/LEGO1/mxnotificationparam.h @@ -9,9 +9,9 @@ class MxCore; enum MxParamType { PARAM_NONE = 0, - PAINT = 1, // 100dc210:100d8350 - c_notificationEndAction = 2, // 100d8358:100d8350 - TYPE4 = 4, // 100dc208:100d8350 + c_notificationStartAction = 1, // 100dc210:100d8350 + c_notificationEndAction = 2, // 100d8358:100d8350 + TYPE4 = 4, // 100dc208:100d8350 MXPRESENTER_NOTIFICATION = 5, MXSTREAMER_DELETE_NOTIFY = 6, // 100dc760 c_notificationKeyPress = 7, // 100d6aa0 diff --git a/LEGO1/mxpresenter.cpp b/LEGO1/mxpresenter.cpp index 13df6a60..89dfddc8 100644 --- a/LEGO1/mxpresenter.cpp +++ b/LEGO1/mxpresenter.cpp @@ -65,7 +65,7 @@ void MxPresenter::SendTo_unkPresenter(MxOmni* p_omni) NotificationManager()->Send(m_unkPresenter, &MxNotificationParam(MXPRESENTER_NOTIFICATION, this)); - m_action->SetOmni(p_omni ? p_omni : MxOmni::GetInstance()); + m_action->SetUnknown8c(p_omni ? p_omni : MxOmni::GetInstance()); m_unkPresenter = NULL; } } diff --git a/LEGO1/score.cpp b/LEGO1/score.cpp index c071f404..3339ac61 100644 --- a/LEGO1/score.cpp +++ b/LEGO1/score.cpp @@ -41,7 +41,7 @@ MxLong Score::Notify(MxParam& p) LegoWorld::Notify(p); if (m_unkf6) { switch (((MxNotificationParam&) p).GetNotification()) { - case PAINT: + case c_notificationStartAction: ret = 1; Paint(); break;