From 88581420d5ead344a6cda9a4fd6526394e5beec2 Mon Sep 17 00:00:00 2001 From: Misha <106913236+MishaProductions@users.noreply.github.com> Date: Wed, 13 Dec 2023 18:11:07 -0500 Subject: [PATCH] Finish MxRAMStreamProvider and MxRAMStreamController (#328) * Finish MxRAMStreamProvider * Fix formatting * fix naming conventions * use no parameter name for FUN_100c67b0 * fixes * fixes * Update mxramstreamcontroller.h * fix build --- LEGO1/mxdsbuffer.cpp | 8 ++++++ LEGO1/mxdsbuffer.h | 6 ++++- LEGO1/mxdsfile.h | 4 +++ LEGO1/mxramstreamcontroller.cpp | 47 ++++++++++++++++++++++++++++----- LEGO1/mxramstreamcontroller.h | 3 +++ LEGO1/mxramstreamprovider.cpp | 42 +++++++++++++++++++++++++++-- 6 files changed, 101 insertions(+), 9 deletions(-) diff --git a/LEGO1/mxdsbuffer.cpp b/LEGO1/mxdsbuffer.cpp index 47753711..5b308fd2 100644 --- a/LEGO1/mxdsbuffer.cpp +++ b/LEGO1/mxdsbuffer.cpp @@ -1,6 +1,7 @@ #include "mxdsbuffer.h" #include "mxomni.h" +#include "mxstreamcontroller.h" #include "mxstreamer.h" DECOMP_SIZE_ASSERT(MxDSBuffer, 0x34); @@ -118,6 +119,13 @@ MxResult MxDSBuffer::SetBufferPointer(MxU32* p_buffer, MxU32 p_size) return SUCCESS; } +// STUB: LEGO1 0x100c67b0 +MxResult MxDSBuffer::FUN_100c67b0(MxStreamController* p_controller, MxDSAction* p_action, undefined4*) +{ + // TODO STUB + return FAILURE; +} + // FUNCTION: LEGO1 0x100c6f80 void MxDSBuffer::FUN_100c6f80(MxU32 p_writeOffset) { diff --git a/LEGO1/mxdsbuffer.h b/LEGO1/mxdsbuffer.h index 9ceaca3a..aaecd4c0 100644 --- a/LEGO1/mxdsbuffer.h +++ b/LEGO1/mxdsbuffer.h @@ -4,6 +4,9 @@ #include "decomp.h" #include "mxcore.h" +class MxStreamController; +class MxDSAction; + enum MxDSBufferType { MxDSBufferType_Chunk = 0, MxDSBufferType_Allocate = 1, @@ -27,6 +30,7 @@ class MxDSBuffer : public MxCore { MxResult AllocateBuffer(MxU32 p_bufferSize, MxDSBufferType p_mode); MxResult SetBufferPointer(MxU32* p_buffer, MxU32 p_size); + MxResult FUN_100c67b0(MxStreamController* p_controller, MxDSAction* p_action, undefined4*); void FUN_100c6f80(MxU32 p_writeOffset); inline MxU8* GetBuffer() { return m_pBuffer; } @@ -43,7 +47,7 @@ class MxDSBuffer : public MxCore { MxDSBufferType m_mode; MxU32 m_writeOffset; MxU32 m_bytesRemaining; - undefined4 m_unk0x30; + MxDSAction* m_unk0x30; }; #endif // MXDSBUFFER_H diff --git a/LEGO1/mxdsfile.h b/LEGO1/mxdsfile.h index 0cdcdf43..e453cb9a 100644 --- a/LEGO1/mxdsfile.h +++ b/LEGO1/mxdsfile.h @@ -6,6 +6,8 @@ #include "mxstring.h" #include "mxtypes.h" +#include + // VTABLE: LEGO1 0x100dc890 class MxDSFile : public MxDSSource { public: @@ -34,6 +36,8 @@ class MxDSFile : public MxDSSource { inline void SetFileName(const char* p_filename) { m_filename = p_filename; } + inline MxS32 CalcFileSize() { return GetFileSize(m_io.m_info.hmmio, NULL); } + private: MxLong ReadChunks(); struct ChunkHeader { diff --git a/LEGO1/mxramstreamcontroller.cpp b/LEGO1/mxramstreamcontroller.cpp index 887db05a..24c5a79d 100644 --- a/LEGO1/mxramstreamcontroller.cpp +++ b/LEGO1/mxramstreamcontroller.cpp @@ -1,11 +1,12 @@ #include "mxramstreamcontroller.h" #include "mxautolocker.h" +#include "mxdsstreamingaction.h" #include "mxramstreamprovider.h" DECOMP_SIZE_ASSERT(MxRAMStreamController, 0x98); -undefined* __cdecl FUN_100d0d80(MxU32* p_fileSizeBuffer, MxU32 p_fileSize); +undefined* __cdecl ReadData(MxU32* p_fileSizeBuffer, MxU32 p_fileSize); // FUNCTION: LEGO1 0x100c6110 MxResult MxRAMStreamController::Open(const char* p_filename) @@ -21,7 +22,7 @@ MxResult MxRAMStreamController::Open(const char* p_filename) return FAILURE; } - FUN_100d0d80( + ReadData( ((MxRAMStreamProvider*) m_provider)->GetBufferOfFileSize(), ((MxRAMStreamProvider*) m_provider)->GetFileSize() ); @@ -35,11 +36,32 @@ MxResult MxRAMStreamController::Open(const char* p_filename) return FAILURE; } -// STUB: LEGO1 0x100c6210 +// FUNCTION: LEGO1 0x100c6210 MxResult MxRAMStreamController::VTable0x20(MxDSAction* p_action) { - // TODO STUB - return FAILURE; + MxAutoLocker locker(&m_criticalSection); + MxS16 unk0x24 = 0; + MxResult result = FAILURE; + if (p_action->GetUnknown24() == -1) { + p_action->SetUnknown24(-3); + MxDSAction* action = m_unk0x54.Find(p_action, FALSE); + if (action != NULL) { + unk0x24 = action->GetUnknown24() + 1; + } + p_action->SetUnknown24(unk0x24); + } + else { + if (m_unk0x54.Find(p_action, FALSE)) { + return FAILURE; + } + } + + if (MxStreamController::VTable0x20(p_action) == SUCCESS) { + MxDSStreamingAction* action = (MxDSStreamingAction*) m_unk0x3c.Find(p_action, FALSE); + MxDSStreamingAction streamingaction(*action); + result = DeserializeObject(streamingaction); + } + return result; } // FUNCTION: LEGO1 0x100c6320 @@ -57,8 +79,21 @@ MxResult MxRAMStreamController::VTable0x24(MxDSAction* p_action) return SUCCESS; } +// FUNCTION: LEGO1 0x100c63c0 +MxResult MxRAMStreamController::DeserializeObject(MxDSStreamingAction& p_action) +{ + MxAutoLocker locker(&m_criticalSection); + MxResult result; + undefined4 value = 0; + do { + m_buffer.FUN_100c6f80(p_action.GetUnknown94()); + result = m_buffer.FUN_100c67b0(this, &p_action, &value); + } while (m_unk0x3c.Find(&p_action, FALSE) != NULL); + return result; +} + // STUB: LEGO1 0x100d0d80 -undefined* __cdecl FUN_100d0d80(MxU32* p_fileSizeBuffer, MxU32 p_fileSize) +undefined* __cdecl ReadData(MxU32* p_fileSizeBuffer, MxU32 p_fileSize) { return NULL; } diff --git a/LEGO1/mxramstreamcontroller.h b/LEGO1/mxramstreamcontroller.h index 70e69d1b..df7f12a9 100644 --- a/LEGO1/mxramstreamcontroller.h +++ b/LEGO1/mxramstreamcontroller.h @@ -2,6 +2,7 @@ #define MXRAMSTREAMCONTROLLER_H #include "mxdsbuffer.h" +#include "mxdsstreamingaction.h" #include "mxstreamcontroller.h" // VTABLE: LEGO1 0x100dc728 @@ -30,6 +31,8 @@ class MxRAMStreamController : public MxStreamController { private: MxDSBuffer m_buffer; + + MxResult DeserializeObject(MxDSStreamingAction& p_action); }; #endif // MXRAMSTREAMCONTROLLER_H diff --git a/LEGO1/mxramstreamprovider.cpp b/LEGO1/mxramstreamprovider.cpp index 82c498cd..016bcc8d 100644 --- a/LEGO1/mxramstreamprovider.cpp +++ b/LEGO1/mxramstreamprovider.cpp @@ -1,6 +1,8 @@ #include "mxramstreamprovider.h" #include "decomp.h" +#include "mxomni.h" +#include "mxstreamcontroller.h" DECOMP_SIZE_ASSERT(MxRAMStreamProvider, 0x24); @@ -53,8 +55,44 @@ MxRAMStreamProvider::~MxRAMStreamProvider() m_bufferForDWords = NULL; } -// STUB: LEGO1 0x100d0ae0 +// FUNCTION: LEGO1 0x100d0ae0 MxResult MxRAMStreamProvider::SetResourceToGet(MxStreamController* p_resource) { - return FAILURE; + 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_fileSize = m_pFile->CalcFileSize(); + if (m_fileSize != 0) { + m_bufferSize = m_pFile->GetBufferSize(); + m_pBufferOfFileSize = new MxU32[m_fileSize]; + if (m_pBufferOfFileSize != NULL && + m_pFile->Read((unsigned char*) m_pBufferOfFileSize, m_fileSize) == SUCCESS) { + m_lengthInDWords = m_pFile->GetLengthInDWords(); + m_bufferForDWords = new MxU32[m_lengthInDWords * sizeof(MxU32)]; + + if (m_bufferForDWords != NULL) { + memcpy(m_bufferForDWords, m_pFile->GetBuffer(), m_lengthInDWords); + result = SUCCESS; + } + } + } + } + +done: + delete m_pFile; + m_pFile = NULL; + return result; }