diff --git a/LEGO1/mxbackgroundaudiomanager.cpp b/LEGO1/mxbackgroundaudiomanager.cpp index e9106177..cba68627 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" @@ -47,6 +51,32 @@ void MxBackgroundAudioManager::Stop() m_unk13c = 0; } +// OFFSET: LEGO1 0x1007f570 +void MxBackgroundAudioManager::FUN_1007f570() +{ + if (m_unk148 == 0) { + if (m_unk13c == 0) { + m_unk13c = 2; + } + m_unk140 = 20; + } + m_unk148++; +} + +// OFFSET: LEGO1 0x1007f5b0 +void MxBackgroundAudioManager::FUN_1007f5b0() +{ + 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,56 @@ void MxBackgroundAudioManager::DestroyMusic() m_musicEnabled = FALSE; } } + +// OFFSET: LEGO1 0x1007f170 +MxResult MxBackgroundAudioManager::Notify(MxParam& p) +{ + if (((MxNotificationParam&) p).GetNotification() == c_notificationStartAction) { + StartAction(p); + return 1; + } + + if (((MxNotificationParam&) p).GetNotification() != c_notificationEndAction) { + return 0; + } + StopAction(p); + return 1; +} + +// Matches but register allocation is is different. +// OFFSET: LEGO1 0x1007f1b0 +void MxBackgroundAudioManager::StartAction(MxParam& p) +{ + // TODO: the sender is most likely a MxCompositePresenter? + m_unk138 = (MxCompositePresenter*) ((MxNotificationParam&) p).GetSender(); + m_action2.SetAtomId(m_unk138->GetAction()->GetAtomId()); + m_action2.SetObjectId(m_unk138->GetAction()->GetObjectId()); + m_unk144 = ((MxDSSound*)(m_unk138->GetAction()))->GetVolume(); + m_unk138->VTable0x60(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 0x1007ee40 STUB +MxResult MxBackgroundAudioManager::Tickle() +{ + // TODO + return FAILURE; +} diff --git a/LEGO1/mxbackgroundaudiomanager.h b/LEGO1/mxbackgroundaudiomanager.h index a306ef2a..97aade9c 100644 --- a/LEGO1/mxbackgroundaudiomanager.h +++ b/LEGO1/mxbackgroundaudiomanager.h @@ -1,9 +1,11 @@ #ifndef MXBACKGROUNDAUDIOMANAGER_H #define MXBACKGROUNDAUDIOMANAGER_H +#include "mxcompositepresenter.h" #include "mxcore.h" #include "mxdsaction.h" #include "mxnotificationmanager.h" +#include "mxpresenter.h" #include "mxtypes.h" // VTABLE 0x100d9fe8 @@ -26,10 +28,18 @@ class MxBackgroundAudioManager : public MxCore { return !strcmp(name, MxBackgroundAudioManager::ClassName()) || MxCore::IsA(name); } + virtual MxResult Notify(MxParam& p) override; + + void StartAction(MxParam& p); + void StopAction(MxParam& p); + virtual MxResult Tickle() override; + __declspec(dllexport) void Enable(unsigned char p); virtual MxResult Create(MxAtomId& p_script, MxU32 p_frequencyMS); void Stop(); + void FUN_1007f570(); + void FUN_1007f5b0(); private: void Init(); @@ -38,9 +48,9 @@ class MxBackgroundAudioManager : public MxCore { MxBool m_musicEnabled; // 0x8 MxDSAction m_action1; // 0xc - MxS32 m_unka0; + MxCore* m_unka0; MxDSAction m_action2; // 0xa4 - MxS32 m_unk138; + MxCompositePresenter* m_unk138; MxS32 m_unk13c; MxS32 m_unk140; MxS32 m_unk144; 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/mxdssound.h b/LEGO1/mxdssound.h index d56a4471..2a56baad 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; + virtual 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..c74ee937 100644 --- a/LEGO1/mxnotificationparam.h +++ b/LEGO1/mxnotificationparam.h @@ -9,7 +9,7 @@ class MxCore; enum MxParamType { PARAM_NONE = 0, - PAINT = 1, // 100dc210:100d8350 + c_notificationStartAction = 1, // 100dc210:100d8350 c_notificationEndAction = 2, // 100d8358:100d8350 TYPE4 = 4, // 100dc208:100d8350 MXPRESENTER_NOTIFICATION = 5, 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;