From 99a17a744d29ceca71fd0a9da591bd436174fbde Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Sun, 29 Oct 2023 09:56:00 -0400 Subject: [PATCH] Match some functions, relocate m_target to `MxThread` --- LEGO1/mxdiskstreamprovider.cpp | 68 +++++++++++++++++---------------- LEGO1/mxdiskstreamprovider.h | 5 +-- LEGO1/mxdsfile.h | 2 +- LEGO1/mxramstreamcontroller.cpp | 16 +++++--- LEGO1/mxthread.cpp | 7 ---- LEGO1/mxthread.h | 11 +++--- 6 files changed, 53 insertions(+), 56 deletions(-) diff --git a/LEGO1/mxdiskstreamprovider.cpp b/LEGO1/mxdiskstreamprovider.cpp index ccd3a09a..b5dabe4a 100644 --- a/LEGO1/mxdiskstreamprovider.cpp +++ b/LEGO1/mxdiskstreamprovider.cpp @@ -10,14 +10,13 @@ DECOMP_SIZE_ASSERT(MxDiskStreamProvider, 0x60); // OFFSET: LEGO1 0x100d0f30 MxResult MxDiskStreamProviderThread::Run() { - if (m_target != NULL) - m_target->WaitForWorkToComplete(); + if (m_target) + ((MxDiskStreamProvider*) m_target)->WaitForWorkToComplete(); MxThread::Run(); // They should probably have writen "return MxThread::Run()" but they didn't. return SUCCESS; } -// Same offset with MxTickleThread::StartWithTarget is intentional // OFFSET: LEGO1 0x100d0f50 MxResult MxDiskStreamProviderThread::StartWithTarget(MxDiskStreamProvider* p_target) { @@ -33,13 +32,44 @@ MxDiskStreamProvider::MxDiskStreamProvider() this->m_unk35 = 0; } -// OFFSET: LEGO1 0x100d1240 +// OFFSET: LEGO1 0x100d1240 STUB MxDiskStreamProvider::~MxDiskStreamProvider() { // TODO } -// Matching but with esi / edi swapped +// OFFSET: LEGO1 0x100d13d0 +MxResult MxDiskStreamProvider::SetResourceToGet(MxStreamController* p_resource) +{ + MxResult result = FAILURE; + MxString path; + m_pLookup = p_resource; + + path = (MxString(MxOmni::GetHD()) + p_resource->GetAtom().GetInternal() + ".si"); + + m_pFile = new MxDSFile(path.GetData(), 0); + if (m_pFile != NULL) { + if (m_pFile->Open(0) != 0) { + path = MxString(MxOmni::GetCD()) + p_resource->GetAtom().GetInternal() + ".si"; + m_pFile->SetFileName(path.GetData()); + + if (m_pFile->Open(0) != 0) + goto done; + } + + m_remainingWork = 1; + MxResult success = m_busySemaphore.Init(0, 100); + m_thread.StartWithTarget(this); + + if (success == SUCCESS && p_resource != NULL) { + result = SUCCESS; + } + } + +done: + return result; +} + // OFFSET: LEGO1 0x100d1750 MxResult MxDiskStreamProvider::WaitForWorkToComplete() { @@ -57,34 +87,6 @@ void MxDiskStreamProvider::PerformWork() // TODO } -// OFFSET: LEGO1 0x100d13d0 -MxResult MxDiskStreamProvider::SetResourceToGet(MxStreamController* p_resource) -{ - m_pLookup = p_resource; - MxString path = MxString(MxOmni::GetHD()) + p_resource->GetAtom().GetInternal() + ".si"; - - MxDSFile* file = new MxDSFile(path.GetData(), 0); - m_pFile = file; - if (file != NULL) { - if (file->Open(0) != 0) { - path = MxString(MxOmni::GetCD()) + p_resource->GetAtom().GetInternal() + ".si"; - file->SetFileName(path); - if (file->Open(0) != 0) { - return FAILURE; - } - } - - m_remainingWork = 1; - MxResult success = m_busySemaphore.Init(0, 100); - m_thread.StartWithTarget(this); - - if (success == SUCCESS && p_resource != NULL) { - return SUCCESS; - } - } - return FAILURE; -} - // OFFSET: LEGO1 0x100d1e90 MxU32 MxDiskStreamProvider::GetFileSize() { diff --git a/LEGO1/mxdiskstreamprovider.h b/LEGO1/mxdiskstreamprovider.h index 26bcc996..9e6e3572 100644 --- a/LEGO1/mxdiskstreamprovider.h +++ b/LEGO1/mxdiskstreamprovider.h @@ -13,14 +13,11 @@ class MxDiskStreamProvider; class MxDiskStreamProviderThread : public MxThread { public: // Only inlined, no offset - inline MxDiskStreamProviderThread() : MxThread(), m_target(NULL) {} + inline MxDiskStreamProviderThread() : MxThread() { m_target = NULL; } MxResult Run() override; MxResult StartWithTarget(MxDiskStreamProvider* p_target); - -private: - MxDiskStreamProvider* m_target; }; // VTABLE 0x100dd138 diff --git a/LEGO1/mxdsfile.h b/LEGO1/mxdsfile.h index 2287be20..477bcf74 100644 --- a/LEGO1/mxdsfile.h +++ b/LEGO1/mxdsfile.h @@ -32,7 +32,7 @@ class MxDSFile : public MxDSSource { __declspec(dllexport) virtual MxULong GetBufferSize(); // vtable+0x28 __declspec(dllexport) virtual MxULong GetStreamBuffersNum(); // vtable+0x2c - inline void SetFileName(MxString p_filename) { m_filename = p_filename; } + inline void SetFileName(const char* p_filename) { m_filename = p_filename; } private: MxLong ReadChunks(); diff --git a/LEGO1/mxramstreamcontroller.cpp b/LEGO1/mxramstreamcontroller.cpp index dee674d7..ae3d9634 100644 --- a/LEGO1/mxramstreamcontroller.cpp +++ b/LEGO1/mxramstreamcontroller.cpp @@ -18,15 +18,21 @@ MxResult MxRAMStreamController::Open(const char* p_filename) if (MxStreamController::Open(p_filename) != SUCCESS) { return FAILURE; } - MxRAMStreamProvider* provider = new MxRAMStreamProvider(); - m_provider = provider; - if (provider != NULL) { + + m_provider = new MxRAMStreamProvider(); + if (((MxRAMStreamProvider*) m_provider) != NULL) { if (m_provider->SetResourceToGet(this) != SUCCESS) { return FAILURE; } - FUN_100d0d80(provider->GetBufferOfFileSize(), provider->GetFileSize()); - m_buffer.FUN_100c6780(provider->GetBufferOfFileSize(), provider->GetFileSize()); + FUN_100d0d80( + ((MxRAMStreamProvider*) m_provider)->GetBufferOfFileSize(), + ((MxRAMStreamProvider*) m_provider)->GetFileSize() + ); + m_buffer.FUN_100c6780( + ((MxRAMStreamProvider*) m_provider)->GetBufferOfFileSize(), + ((MxRAMStreamProvider*) m_provider)->GetFileSize() + ); return SUCCESS; } diff --git a/LEGO1/mxthread.cpp b/LEGO1/mxthread.cpp index fd252799..7e445f7d 100644 --- a/LEGO1/mxthread.cpp +++ b/LEGO1/mxthread.cpp @@ -68,13 +68,6 @@ MxTickleThread::MxTickleThread(MxCore* p_target, int p_frequencyMS) m_frequencyMS = p_frequencyMS; } -// OFFSET: LEGO1 0x100d0f50 -MxResult MxTickleThread::StartWithTarget(MxCore* p_target) -{ - m_target = p_target; - return Start(0x1000, 0); -} - // Match except for register allocation // OFFSET: LEGO1 0x100b8c90 MxResult MxTickleThread::Run() diff --git a/LEGO1/mxthread.h b/LEGO1/mxthread.h index 72a61d95..59b31554 100644 --- a/LEGO1/mxthread.h +++ b/LEGO1/mxthread.h @@ -7,6 +7,7 @@ class MxCore; +// VTABLE 0x100dc860 class MxThread { public: // Note: Comes before virtual destructor @@ -34,24 +35,22 @@ class MxThread { MxU32 m_threadId; MxBool m_running; MxSemaphore m_semaphore; + +protected: + MxCore* m_target; }; +// VTABLE 0x100dc6d8 class MxTickleThread : public MxThread { public: MxTickleThread(MxCore* p_target, int p_frequencyMS); - // Unclear at this time whether this function and the m_target field are - // actually a general "userdata" pointer in the base MxThread, but it seems - // like the only usage is with an MxTickleThread. - MxResult StartWithTarget(MxCore* p_target); - // Only inlined, no offset virtual ~MxTickleThread() {} MxResult Run() override; private: - MxCore* m_target; MxS32 m_frequencyMS; };