2023-10-08 16:41:34 -04:00
|
|
|
#include "mxramstreamprovider.h"
|
2023-10-24 19:38:27 -04:00
|
|
|
|
2023-10-08 16:41:34 -04:00
|
|
|
#include "decomp.h"
|
2024-01-10 06:55:25 -05:00
|
|
|
#include "mxdsbuffer.h"
|
2023-12-13 18:11:07 -05:00
|
|
|
#include "mxomni.h"
|
|
|
|
#include "mxstreamcontroller.h"
|
2023-10-08 16:41:34 -04:00
|
|
|
|
|
|
|
DECOMP_SIZE_ASSERT(MxRAMStreamProvider, 0x24);
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100d0730
|
2023-10-08 16:41:34 -04:00
|
|
|
MxRAMStreamProvider::MxRAMStreamProvider()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
m_bufferSize = 0;
|
|
|
|
m_fileSize = 0;
|
|
|
|
m_pBufferOfFileSize = NULL;
|
|
|
|
m_lengthInDWords = 0;
|
|
|
|
m_bufferForDWords = NULL;
|
2023-10-08 16:41:34 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100d0930
|
2023-10-08 16:41:34 -04:00
|
|
|
MxU32 MxRAMStreamProvider::GetFileSize()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
return m_fileSize;
|
2023-10-08 16:41:34 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100d0940
|
2023-12-22 14:03:55 -05:00
|
|
|
MxS32 MxRAMStreamProvider::GetStreamBuffersNum()
|
2023-10-08 16:41:34 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
return 1;
|
2023-10-08 16:41:34 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100d0950
|
2023-10-08 16:41:34 -04:00
|
|
|
MxU32 MxRAMStreamProvider::GetLengthInDWords()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
return m_lengthInDWords;
|
2023-10-08 16:41:34 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100d0960
|
2023-10-10 04:27:00 -04:00
|
|
|
MxU32* MxRAMStreamProvider::GetBufferForDWords()
|
2023-10-08 16:41:34 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
return m_bufferForDWords;
|
2023-10-08 16:41:34 -04:00
|
|
|
}
|
2023-11-21 03:44:45 -05:00
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100d0a50
|
2023-11-21 03:44:45 -05:00
|
|
|
MxRAMStreamProvider::~MxRAMStreamProvider()
|
|
|
|
{
|
|
|
|
m_bufferSize = 0;
|
|
|
|
m_fileSize = 0;
|
|
|
|
|
2024-01-14 16:28:46 -05:00
|
|
|
delete[] m_pBufferOfFileSize;
|
2023-11-21 03:44:45 -05:00
|
|
|
m_pBufferOfFileSize = NULL;
|
|
|
|
|
|
|
|
m_lengthInDWords = 0;
|
|
|
|
|
2024-01-14 16:28:46 -05:00
|
|
|
delete[] m_bufferForDWords;
|
2023-11-21 03:44:45 -05:00
|
|
|
m_bufferForDWords = NULL;
|
|
|
|
}
|
|
|
|
|
2023-12-13 18:11:07 -05:00
|
|
|
// FUNCTION: LEGO1 0x100d0ae0
|
2023-11-21 03:44:45 -05:00
|
|
|
MxResult MxRAMStreamProvider::SetResourceToGet(MxStreamController* p_resource)
|
|
|
|
{
|
2023-12-13 18:11:07 -05:00
|
|
|
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());
|
|
|
|
|
2024-02-01 15:42:10 -05:00
|
|
|
if (m_pFile->Open(0) != 0) {
|
2023-12-13 18:11:07 -05:00
|
|
|
goto done;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
2023-12-13 18:11:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
m_fileSize = m_pFile->CalcFileSize();
|
|
|
|
if (m_fileSize != 0) {
|
|
|
|
m_bufferSize = m_pFile->GetBufferSize();
|
2024-01-10 06:55:25 -05:00
|
|
|
m_pBufferOfFileSize = new MxU8[m_fileSize];
|
2023-12-13 18:11:07 -05:00
|
|
|
if (m_pBufferOfFileSize != NULL &&
|
|
|
|
m_pFile->Read((unsigned char*) m_pBufferOfFileSize, m_fileSize) == SUCCESS) {
|
|
|
|
m_lengthInDWords = m_pFile->GetLengthInDWords();
|
2023-12-29 18:33:30 -05:00
|
|
|
m_bufferForDWords = new MxU32[m_lengthInDWords];
|
2023-12-13 18:11:07 -05:00
|
|
|
|
|
|
|
if (m_bufferForDWords != NULL) {
|
2023-12-29 18:33:30 -05:00
|
|
|
memcpy(m_bufferForDWords, m_pFile->GetBuffer(), m_lengthInDWords * sizeof(MxU32));
|
2023-12-13 18:11:07 -05:00
|
|
|
result = SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
delete m_pFile;
|
|
|
|
m_pFile = NULL;
|
|
|
|
return result;
|
2023-11-21 03:44:45 -05:00
|
|
|
}
|
2024-01-10 06:55:25 -05:00
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x100d0d80
|
|
|
|
MxU32 ReadData(MxU8* p_buffer, MxU32 p_size)
|
|
|
|
{
|
|
|
|
MxU32 id;
|
|
|
|
MxU8* data = p_buffer;
|
|
|
|
MxU8* end = p_buffer + p_size;
|
|
|
|
MxU8* data2;
|
|
|
|
|
|
|
|
if (p_buffer < end) {
|
|
|
|
do {
|
|
|
|
if (*MxDSChunk::IntoType(data) == FOURCC('M', 'x', 'O', 'b')) {
|
|
|
|
data2 = data;
|
|
|
|
data += 8;
|
|
|
|
|
|
|
|
MxDSObject* obj = DeserializeDSObjectDispatch(&data, -1);
|
|
|
|
id = obj->GetObjectId();
|
|
|
|
delete obj;
|
|
|
|
|
|
|
|
data = MxDSChunk::End(data2);
|
|
|
|
while (data < end) {
|
|
|
|
if (*MxDSChunk::IntoType(data) == FOURCC('M', 'x', 'C', 'h')) {
|
|
|
|
MxU8* data3 = data;
|
|
|
|
MxU32* psize = MxDSChunk::IntoLength(data);
|
|
|
|
data += MxDSChunk::Size(*psize);
|
|
|
|
|
|
|
|
if ((*MxDSChunk::IntoType(data2) == FOURCC('M', 'x', 'C', 'h')) &&
|
2024-01-17 11:53:53 -05:00
|
|
|
(*MxStreamChunk::IntoFlags(data2) & MxDSChunk::c_split)) {
|
2024-01-10 06:55:25 -05:00
|
|
|
if (*MxStreamChunk::IntoObjectId(data2) == *MxStreamChunk::IntoObjectId(data3) &&
|
2024-01-17 11:53:53 -05:00
|
|
|
(*MxStreamChunk::IntoFlags(data3) & MxDSChunk::c_split) &&
|
2024-01-10 06:55:25 -05:00
|
|
|
*MxStreamChunk::IntoTime(data2) == *MxStreamChunk::IntoTime(data3)) {
|
|
|
|
MxDSBuffer::Append(data2, data3);
|
|
|
|
continue;
|
|
|
|
}
|
2024-02-01 15:42:10 -05:00
|
|
|
else {
|
2024-01-17 11:53:53 -05:00
|
|
|
*MxStreamChunk::IntoFlags(data2) &= ~MxDSChunk::c_split;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
2024-01-10 06:55:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
data2 += MxDSChunk::Size(*MxDSChunk::IntoLength(data2));
|
|
|
|
memcpy(data2, data3, MxDSChunk::Size(*psize));
|
|
|
|
|
|
|
|
if (*MxStreamChunk::IntoObjectId(data2) == id &&
|
2024-02-01 15:42:10 -05:00
|
|
|
(*MxStreamChunk::IntoFlags(data2) & MxDSChunk::c_end)) {
|
2024-01-10 06:55:25 -05:00
|
|
|
break;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
2024-01-10 06:55:25 -05:00
|
|
|
}
|
2024-02-01 15:42:10 -05:00
|
|
|
else {
|
2024-01-10 06:55:25 -05:00
|
|
|
data++;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
2024-01-10 06:55:25 -05:00
|
|
|
}
|
|
|
|
}
|
2024-02-01 15:42:10 -05:00
|
|
|
else {
|
2024-01-10 06:55:25 -05:00
|
|
|
data++;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
2024-01-10 06:55:25 -05:00
|
|
|
} while (data < end);
|
|
|
|
}
|
|
|
|
|
2024-01-17 11:53:53 -05:00
|
|
|
*MxStreamChunk::IntoFlags(data2) &= ~MxDSChunk::c_split;
|
2024-01-10 06:55:25 -05:00
|
|
|
return MxDSChunk::End(data2) - p_buffer;
|
|
|
|
}
|