From 5617e0e0445b6a52ab887c9105811befae554a0b Mon Sep 17 00:00:00 2001 From: Joshua Peisach Date: Tue, 19 Sep 2023 10:42:39 -0400 Subject: [PATCH] MxAudioManager: Destructor, LockedReinitialize, Reinitialize (#125) * MxAudioManager: Destructor, LockedReinitialize * MxAudioManager::Reinitialize, fix LockedReinitialize logic * MxAudioManager cleanup - fix param in LockedReinitialize, mark that function as private/give it a better param name * Match LockedReinitialize, fix function declarations, add/match InitPresenters --------- Co-authored-by: Christian Semmler --- CMakeLists.txt | 2 +- LEGO1/mxaudiomanager.cpp | 64 +++++++++++++++++++++++++++++++++++++ LEGO1/mxaudiomanager.h | 28 ++++++++++++++++ LEGO1/mxsoundmanager.h | 6 ++-- LEGO1/mxunknown100dc6e0.cpp | 19 ----------- LEGO1/mxunknown100dc6e0.h | 19 ----------- 6 files changed, 96 insertions(+), 42 deletions(-) create mode 100644 LEGO1/mxaudiomanager.cpp create mode 100644 LEGO1/mxaudiomanager.h delete mode 100644 LEGO1/mxunknown100dc6e0.cpp delete mode 100644 LEGO1/mxunknown100dc6e0.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 202e2b7d..3a47fc78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,7 @@ add_library(lego1 SHARED LEGO1/motorcycle.cpp LEGO1/mxatomid.cpp LEGO1/mxatomidcounter.cpp + LEGO1/mxaudiomanager.cpp LEGO1/mxaudiopresenter.cpp LEGO1/mxautolocker.cpp LEGO1/mxbackgroundaudiomanager.cpp @@ -159,7 +160,6 @@ add_library(lego1 SHARED LEGO1/mxticklemanager.cpp LEGO1/mxtimer.cpp LEGO1/mxtransitionmanager.cpp - LEGO1/mxunknown100dc6e0.cpp LEGO1/mxvariable.cpp LEGO1/mxvariabletable.cpp LEGO1/mxvector.cpp diff --git a/LEGO1/mxaudiomanager.cpp b/LEGO1/mxaudiomanager.cpp new file mode 100644 index 00000000..c7ecdc12 --- /dev/null +++ b/LEGO1/mxaudiomanager.cpp @@ -0,0 +1,64 @@ +#include "mxaudiomanager.h" + +DECOMP_SIZE_ASSERT(MxAudioManager, 0x30); + +// GLOBAL: LEGO1 0x10102108 +MxS32 MxAudioManager::g_unkCount = 0; + +// OFFSET: LEGO1 0x100b8d00 +MxAudioManager::MxAudioManager() +{ + Init(); +} + +// OFFSET: LEGO1 0x100b8d90 +MxAudioManager::~MxAudioManager() +{ + LockedReinitialize(TRUE); +} + +// OFFSET: LEGO1 0x100b8df0 +void MxAudioManager::Init() +{ + this->m_unk2c = 100; +} + +// OFFSET: LEGO1 0x100b8e00 +void MxAudioManager::LockedReinitialize(MxBool p_skipDestroy) +{ + this->m_criticalSection.Enter(); + g_unkCount--; + Init(); + this->m_criticalSection.Leave(); + + if (!p_skipDestroy) + MxMediaManager::Destroy(); +} + +// OFFSET: LEGO1 0x100b8e40 +MxResult MxAudioManager::InitPresenters() +{ + MxResult result = FAILURE; + MxBool success = FALSE; + + if (MxMediaManager::InitPresenters() == SUCCESS) { + this->m_criticalSection.Enter(); + success = TRUE; + result = SUCCESS; + g_unkCount++; + } + + if (result) + Destroy(); + + if (success) + this->m_criticalSection.Leave(); + + return result; +} + +// OFFSET: LEGO1 0x100b8e90 +void MxAudioManager::Destroy() +{ + LockedReinitialize(FALSE); +} \ No newline at end of file diff --git a/LEGO1/mxaudiomanager.h b/LEGO1/mxaudiomanager.h new file mode 100644 index 00000000..1403f36d --- /dev/null +++ b/LEGO1/mxaudiomanager.h @@ -0,0 +1,28 @@ +#ifndef MXAUDIOMANAGER_H +#define MXAUDIOMANAGER_H + +#include "decomp.h" +#include "mxmediamanager.h" + +// VTABLE 0x100dc6e0 +class MxAudioManager : public MxMediaManager +{ +public: + MxAudioManager(); + virtual ~MxAudioManager() override; + + virtual MxResult InitPresenters(); // vtable+14 + virtual void Destroy(); // vtable+18 + +private: + void LockedReinitialize(MxBool); + + static MxS32 g_unkCount; + +protected: + void Init(); + + undefined4 m_unk2c; +}; + +#endif // MXAUDIOMANAGER_H diff --git a/LEGO1/mxsoundmanager.h b/LEGO1/mxsoundmanager.h index 4d74fa95..06dc9d5f 100644 --- a/LEGO1/mxsoundmanager.h +++ b/LEGO1/mxsoundmanager.h @@ -1,12 +1,12 @@ #ifndef MXSOUNDMANAGER_H #define MXSOUNDMANAGER_H -#include "mxunknown100dc6e0.h" +#include "mxaudiomanager.h" // VTABLE 0x100dc128 // SIZE 0x3c -// Base vtables are: MxCore -> 0x100dc6b0 -> 0x100dc6e0 -> MxSoundManager -class MxSoundManager : public MxUnknown100dc6e0 +// Base vtables are: MxCore -> 0x100dc6b0 -> MxAudioManager -> MxSoundManager +class MxSoundManager : public MxAudioManager { public: MxSoundManager(); diff --git a/LEGO1/mxunknown100dc6e0.cpp b/LEGO1/mxunknown100dc6e0.cpp deleted file mode 100644 index b896e89b..00000000 --- a/LEGO1/mxunknown100dc6e0.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "mxunknown100dc6e0.h" - -// OFFSET: LEGO1 0x100b8d00 -MxUnknown100dc6e0::MxUnknown100dc6e0() -{ - Init(); -} - -// OFFSET: LEGO1 0x100b8d90 STUB -MxUnknown100dc6e0::~MxUnknown100dc6e0() -{ - // TODO -} - -// OFFSET: LEGO1 0x100b8df0 -void MxUnknown100dc6e0::Init() -{ - this->m_unk2c = 100; -} diff --git a/LEGO1/mxunknown100dc6e0.h b/LEGO1/mxunknown100dc6e0.h deleted file mode 100644 index 056e1fcd..00000000 --- a/LEGO1/mxunknown100dc6e0.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef MXUNKNOWN100DC6E0_H -#define MXUNKNOWN100DC6E0_H - -#include "mxmediamanager.h" - -// VTABLE 0x100dc6e0 -class MxUnknown100dc6e0 : public MxMediaManager -{ -public: - MxUnknown100dc6e0(); - virtual ~MxUnknown100dc6e0() override; - -protected: - void Init(); - - int m_unk2c; -}; - -#endif // MXUNKNOWN100DC6E0_H