2023-06-29 04:10:08 -04:00
|
|
|
#include "mxstreamer.h"
|
|
|
|
|
2023-09-25 22:30:56 -04:00
|
|
|
#include "legoomni.h"
|
|
|
|
#include "mxdiskstreamcontroller.h"
|
2023-10-07 11:30:04 -04:00
|
|
|
#include "mxnotificationmanager.h"
|
2023-10-24 19:38:27 -04:00
|
|
|
#include "mxramstreamcontroller.h"
|
2023-10-07 11:30:04 -04:00
|
|
|
|
|
|
|
#include <algorithm>
|
2023-09-25 22:30:56 -04:00
|
|
|
|
|
|
|
DECOMP_SIZE_ASSERT(MxStreamer, 0x2c);
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100b8f00
|
|
|
|
MxStreamer::MxStreamer()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
NotificationManager()->Register(this);
|
2023-09-25 22:30:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100b9190
|
2023-10-14 20:49:07 -04:00
|
|
|
MxResult MxStreamer::Create()
|
2023-09-25 22:30:56 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
undefined* b = new undefined[m_subclass1.GetSize() * 0x5800];
|
|
|
|
m_subclass1.SetBuffer(b);
|
|
|
|
if (b) {
|
|
|
|
b = new undefined[m_subclass2.GetSize() * 0x800];
|
|
|
|
m_subclass2.SetBuffer(b);
|
|
|
|
if (b) {
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FAILURE;
|
2023-09-25 22:30:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100b91d0
|
2023-06-29 04:10:08 -04:00
|
|
|
MxStreamer::~MxStreamer()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
while (!m_openStreams.empty()) {
|
|
|
|
MxStreamController* c = m_openStreams.front();
|
|
|
|
m_openStreams.pop_front();
|
|
|
|
delete c;
|
|
|
|
}
|
2023-09-25 22:30:56 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
NotificationManager()->Unregister(this);
|
2023-06-29 04:10:08 -04:00
|
|
|
}
|
|
|
|
|
2023-09-25 22:30:56 -04:00
|
|
|
// OFFSET: LEGO1 0x100b92c0
|
2023-10-24 19:38:27 -04:00
|
|
|
MxStreamController* MxStreamer::Open(const char* p_name, MxU16 p_lookupType)
|
2023-06-30 14:34:39 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
// TODO
|
|
|
|
MxStreamController* stream = NULL;
|
|
|
|
|
|
|
|
if (!GetOpenStream(p_name)) {
|
|
|
|
switch (p_lookupType) {
|
|
|
|
case e_DiskStream:
|
|
|
|
stream = new MxDiskStreamController();
|
|
|
|
break;
|
|
|
|
case e_RAMStream:
|
|
|
|
stream = new MxRAMStreamController();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stream || stream->Open(p_name) != SUCCESS || AddStreamControllerToOpenList(stream) != SUCCESS) {
|
|
|
|
delete stream;
|
|
|
|
stream = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stream;
|
2023-06-30 14:34:39 -04:00
|
|
|
}
|
|
|
|
|
2023-09-25 22:30:56 -04:00
|
|
|
// OFFSET: LEGO1 0x100b9570
|
2023-10-24 19:38:27 -04:00
|
|
|
MxLong MxStreamer::Close(const char* p)
|
2023-06-30 14:34:39 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxDSAction ds;
|
2023-09-25 22:30:56 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
ds.SetUnknown24(-2);
|
2023-09-25 22:30:56 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
for (list<MxStreamController*>::iterator it = m_openStreams.begin(); it != m_openStreams.end(); it++) {
|
|
|
|
MxStreamController* c = *it;
|
2023-09-25 22:30:56 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (!p || !strcmp(p, c->GetAtom().GetInternal())) {
|
|
|
|
m_openStreams.erase(it);
|
2023-09-25 22:30:56 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (!c->FUN_100c20d0(ds)) {
|
|
|
|
MxStreamerNotification notif(MXSTREAMER_DELETE_NOTIFY, NULL, c);
|
2023-09-25 22:30:56 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
NotificationManager()->Send(this, ¬if);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delete c;
|
|
|
|
}
|
2023-09-25 22:30:56 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2023-09-25 22:30:56 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return FAILURE;
|
2023-09-25 22:30:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100b9700
|
2023-10-24 19:38:27 -04:00
|
|
|
MxNotificationParam* MxStreamerNotification::Clone()
|
2023-09-25 22:30:56 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
return new MxStreamerNotification(m_type, m_sender, m_controller);
|
2023-09-25 22:30:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// OFFSET: LEGO1 0x100b9870
|
2023-10-24 19:38:27 -04:00
|
|
|
MxStreamController* MxStreamer::GetOpenStream(const char* p_name)
|
2023-09-25 22:30:56 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
for (list<MxStreamController*>::iterator it = m_openStreams.begin(); it != m_openStreams.end(); it++) {
|
|
|
|
MxStreamController* c = *it;
|
|
|
|
MxAtomId& atom = c->GetAtom();
|
|
|
|
if (p_name) {
|
|
|
|
if (!strcmp(atom.GetInternal(), p_name)) {
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2023-06-30 14:34:39 -04:00
|
|
|
}
|
|
|
|
|
2023-09-25 22:30:56 -04:00
|
|
|
// OFFSET: LEGO1 0x100b9930
|
2023-10-24 19:38:27 -04:00
|
|
|
MxResult MxStreamer::AddStreamControllerToOpenList(MxStreamController* stream)
|
2023-09-25 22:30:56 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (find(m_openStreams.begin(), m_openStreams.end(), stream) == m_openStreams.end()) {
|
|
|
|
m_openStreams.push_back(stream);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2023-09-25 22:30:56 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return FAILURE;
|
2023-09-25 22:30:56 -04:00
|
|
|
}
|
|
|
|
|
2023-10-07 09:05:44 -04:00
|
|
|
// OFFSET: LEGO1 0x100b99b0
|
2023-10-21 17:23:55 -04:00
|
|
|
MxResult MxStreamer::FUN_100b99b0(MxDSAction* p_action)
|
2023-10-07 09:05:44 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxStreamController* controller;
|
|
|
|
if (p_action != NULL && p_action->GetAtomId().GetInternal() != NULL && p_action->GetObjectId() != -1) {
|
|
|
|
controller = GetOpenStream(p_action->GetAtomId().GetInternal());
|
|
|
|
if (controller == NULL) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return controller->vtable0x20(p_action);
|
|
|
|
}
|
|
|
|
return FAILURE;
|
2023-10-07 09:05:44 -04:00
|
|
|
}
|
|
|
|
|
2023-10-21 17:23:55 -04:00
|
|
|
// OFFSET: LEGO1 0x100b9b30
|
2023-10-24 19:38:27 -04:00
|
|
|
MxBool MxStreamer::FUN_100b9b30(MxDSObject& p_dsObject)
|
2023-10-21 17:23:55 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxStreamController* controller = GetOpenStream(p_dsObject.GetAtomId().GetInternal());
|
|
|
|
if (controller)
|
|
|
|
return controller->FUN_100c20d0(p_dsObject);
|
|
|
|
return TRUE;
|
2023-10-21 17:23:55 -04:00
|
|
|
}
|
|
|
|
|
2023-09-25 22:30:56 -04:00
|
|
|
// OFFSET: LEGO1 0x100b9b60
|
2023-10-24 19:38:27 -04:00
|
|
|
MxLong MxStreamer::Notify(MxParam& p)
|
2023-06-29 04:10:08 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (((MxNotificationParam&) p).GetType() == MXSTREAMER_DELETE_NOTIFY) {
|
|
|
|
MxDSAction ds;
|
2023-09-25 22:30:56 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
ds.SetUnknown24(-2);
|
2023-09-25 22:30:56 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
MxStreamController* c = static_cast<MxStreamerNotification&>(p).GetController();
|
2023-09-25 22:30:56 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (!c->FUN_100c20d0(ds)) {
|
|
|
|
MxStreamerNotification notif(MXSTREAMER_DELETE_NOTIFY, NULL, c);
|
|
|
|
NotificationManager()->Send(this, ¬if);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
}
|
2023-06-29 04:10:08 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return 0;
|
2023-06-29 04:10:08 -04:00
|
|
|
}
|
|
|
|
|
2023-09-25 22:30:56 -04:00
|
|
|
// No offset, function is always inlined
|
|
|
|
MxStreamerSubClass1::MxStreamerSubClass1(undefined4 size)
|
2023-06-29 04:10:08 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
m_buffer = NULL;
|
|
|
|
m_size = size;
|
|
|
|
undefined4* ptr = &m_unk08;
|
|
|
|
for (int i = 0; i >= 0; i--) {
|
|
|
|
ptr[i] = 0;
|
|
|
|
}
|
2023-10-25 14:51:59 -04:00
|
|
|
}
|