more MxDSBuffer functions (#255)

* FUN_100c6f80

* AllocateBuffer

* Update mxdsbuffer.h

* Update mxdsbuffer.cpp

* Update mxdsbuffer.cpp

* Return reference

* Fix delete call

* Fix GetWriteOffset

* Remove cast

---------

Co-authored-by: Christian Semmler <mail@csemmler.com>
This commit is contained in:
Misha 2023-10-30 09:54:00 -04:00 committed by GitHub
parent 787d932825
commit f3b0de0609
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 121 additions and 16 deletions

View file

@ -1,5 +1,8 @@
#include "mxdsbuffer.h" #include "mxdsbuffer.h"
#include "mxomni.h"
#include "mxstreamer.h"
DECOMP_SIZE_ASSERT(MxDSBuffer, 0x34); DECOMP_SIZE_ASSERT(MxDSBuffer, 0x34);
// OFFSET: LEGO1 0x100c6470 // OFFSET: LEGO1 0x100c6470
@ -14,24 +17,112 @@ MxDSBuffer::MxDSBuffer()
m_unk1c = 0; m_unk1c = 0;
m_writeOffset = 0; m_writeOffset = 0;
m_bytesRemaining = 0; m_bytesRemaining = 0;
m_mode = 2; m_mode = MxDSBufferType_Preallocated;
m_unk30 = 0; m_unk30 = 0;
} }
// OFFSET: LEGO1 0x100c6530 // OFFSET: LEGO1 0x100c6530
MxDSBuffer::~MxDSBuffer() MxDSBuffer::~MxDSBuffer()
{ {
if (m_pBuffer != NULL) {
if (m_mode == MxDSBufferType_Chunk) {
// TODO // TODO
}
else if (m_mode == MxDSBufferType_Allocate || m_mode == MxDSBufferType_Unknown) {
delete[] m_pBuffer;
}
}
m_unk14 = 0;
m_unk1c = 0;
}
// OFFSET: LEGO1 0x100c6640
MxResult MxDSBuffer::AllocateBuffer(MxU32 p_bufferSize, MxDSBufferType p_mode)
{
MxResult result = FAILURE;
MxU32 i = 0;
if (p_mode == MxDSBufferType_Allocate) {
m_pBuffer = new MxU8[p_bufferSize];
}
else if (p_mode == MxDSBufferType_Chunk) {
MxStreamer* streamer = Streamer();
// I have no clue as to what this does, or even if its correct. Maybe it's related to storing chunks in
// MxRamStreamController?
if (p_bufferSize >> 10 == 0x40) {
i = 0;
while (i < 22) {
if ((*(MxU32*) ((streamer->GetSubclass1().GetUnk08() + ((i & 0xffffffe7) >> 3)) & 1 << ((MxU8) i & 0x1f)
)) == 0) {
MxU32* ptr = (MxU32*) ((streamer->GetSubclass1().GetUnk08() + ((i & 0xffffffe7) >> 3)) &
1 << ((MxU8) i & 0x1f));
// mark it as used?
*ptr = *ptr ^ 1 << (i & 0x1f);
m_pBuffer =
(MxU8*) (streamer->GetSubclass1().GetSize() * i * 0x400 + streamer->GetSubclass1().GetBuffer());
break;
}
i++;
}
m_pBuffer = NULL;
}
else if (p_bufferSize >> 10 == 0x80) {
i = 0;
// Same thing as above but it uses subclass2
while (i < 22) {
if ((*(MxU32*) ((streamer->GetSubclass2().GetUnk08() + ((i & 0xffffffe7) >> 3)) & 1 << ((MxU8) i & 0x1f)
)) == 0) {
MxU32* ptr = (MxU32*) ((streamer->GetSubclass2().GetUnk08() + ((i & 0xffffffe7) >> 3)) &
1 << ((MxU8) i & 0x1f));
// mark it as used?
*ptr = *ptr ^ 1 << (i & 0x1f);
m_pBuffer =
(MxU8*) (streamer->GetSubclass2().GetSize() * i * 0x400 + streamer->GetSubclass2().GetBuffer());
break;
}
i++;
}
m_pBuffer = NULL;
}
else {
m_pIntoBuffer = NULL;
}
}
m_pIntoBuffer = m_pBuffer;
m_pIntoBuffer2 = m_pBuffer;
if (m_pBuffer != NULL) {
m_mode = p_mode;
m_bytesRemaining = p_bufferSize;
m_writeOffset = p_bufferSize;
result = SUCCESS;
}
return result;
} }
// OFFSET: LEGO1 0x100c6780 // OFFSET: LEGO1 0x100c6780
MxResult MxDSBuffer::FUN_100c6780(void* p_buffer, MxU32 p_size) MxResult MxDSBuffer::SetBufferPointer(MxU32* p_buffer, MxU32 p_size)
{ {
m_pBuffer = p_buffer; m_pBuffer = (MxU8*) p_buffer;
m_pIntoBuffer = p_buffer; m_pIntoBuffer = (MxU8*) p_buffer;
m_pIntoBuffer2 = p_buffer; m_pIntoBuffer2 = (MxU8*) p_buffer;
m_bytesRemaining = p_size; m_bytesRemaining = p_size;
m_writeOffset = p_size; m_writeOffset = p_size;
m_mode = 2; m_mode = MxDSBufferType_Preallocated;
return SUCCESS; return SUCCESS;
} }
// OFFSET: LEGO1 0x100c6f80
void MxDSBuffer::FUN_100c6f80(MxU32 p_unk)
{
if (p_unk < m_writeOffset) {
m_pIntoBuffer2 = m_pBuffer + p_unk;
m_pIntoBuffer = m_pBuffer + p_unk;
}
}

View file

@ -4,6 +4,13 @@
#include "decomp.h" #include "decomp.h"
#include "mxcore.h" #include "mxcore.h"
enum MxDSBufferType {
MxDSBufferType_Chunk = 0,
MxDSBufferType_Allocate = 1,
MxDSBufferType_Preallocated = 2,
MxDSBufferType_Unknown = 3,
};
// VTABLE 0x100dcca0 // VTABLE 0x100dcca0
// SIZE 0x34 // SIZE 0x34
class MxDSBuffer : public MxCore { class MxDSBuffer : public MxCore {
@ -18,20 +25,22 @@ class MxDSBuffer : public MxCore {
return "MxDSBuffer"; return "MxDSBuffer";
} }
MxResult FUN_100c6780(void* p_buffer, MxU32 p_size); MxResult AllocateBuffer(MxU32 p_bufferSize, MxDSBufferType p_mode);
MxResult SetBufferPointer(MxU32* p_buffer, MxU32 p_size);
void FUN_100c6f80(MxU32 p_unk);
inline void* GetBuffer() { return m_pBuffer; } inline MxU8* GetBuffer() { return m_pBuffer; }
inline MxU32 GetWriteOffset() { return m_writeOffset; } inline MxU32 GetWriteOffset() { return m_writeOffset; }
private: private:
void* m_pBuffer; MxU8* m_pBuffer;
void* m_pIntoBuffer; MxU8* m_pIntoBuffer;
void* m_pIntoBuffer2; MxU8* m_pIntoBuffer2;
undefined4 m_unk14; undefined4 m_unk14;
undefined4 m_unk18; undefined4 m_unk18;
undefined4 m_unk1c; undefined4 m_unk1c;
undefined2 m_unk20; undefined2 m_unk20;
undefined4 m_mode; MxDSBufferType m_mode;
MxU32 m_writeOffset; MxU32 m_writeOffset;
MxU32 m_bytesRemaining; MxU32 m_bytesRemaining;
undefined4 m_unk30; undefined4 m_unk30;

View file

@ -5,7 +5,7 @@
// OFFSET: LEGO1 0x100bffd0 // OFFSET: LEGO1 0x100bffd0
void MxDSSource::ReadToBuffer(MxDSBuffer* p_buffer) void MxDSSource::ReadToBuffer(MxDSBuffer* p_buffer)
{ {
Read((unsigned char*) p_buffer->GetBuffer(), p_buffer->GetWriteOffset()); Read(p_buffer->GetBuffer(), p_buffer->GetWriteOffset());
} }
// OFFSET: LEGO1 0x100bfff0 // OFFSET: LEGO1 0x100bfff0

View file

@ -29,7 +29,7 @@ MxResult MxRAMStreamController::Open(const char* p_filename)
((MxRAMStreamProvider*) m_provider)->GetBufferOfFileSize(), ((MxRAMStreamProvider*) m_provider)->GetBufferOfFileSize(),
((MxRAMStreamProvider*) m_provider)->GetFileSize() ((MxRAMStreamProvider*) m_provider)->GetFileSize()
); );
m_buffer.FUN_100c6780( m_buffer.SetBufferPointer(
((MxRAMStreamProvider*) m_provider)->GetBufferOfFileSize(), ((MxRAMStreamProvider*) m_provider)->GetBufferOfFileSize(),
((MxRAMStreamProvider*) m_provider)->GetFileSize() ((MxRAMStreamProvider*) m_provider)->GetFileSize()
); );

View file

@ -18,9 +18,11 @@ class MxStreamerSubClass1 {
~MxStreamerSubClass1() { delete[] m_buffer; } ~MxStreamerSubClass1() { delete[] m_buffer; }
undefined4 GetSize() { return m_size; } undefined4 GetSize() const { return m_size; }
void SetBuffer(undefined* p_buf) { m_buffer = p_buf; } void SetBuffer(undefined* p_buf) { m_buffer = p_buf; }
inline undefined* GetBuffer() const { return m_buffer; }
inline undefined4 GetUnk08() const { return m_unk08; }
private: private:
undefined* m_buffer; undefined* m_buffer;
@ -93,6 +95,9 @@ class MxStreamer : public MxCore {
MxResult AddStreamControllerToOpenList(MxStreamController* p_stream); MxResult AddStreamControllerToOpenList(MxStreamController* p_stream);
MxResult FUN_100b99b0(MxDSAction* p_action); MxResult FUN_100b99b0(MxDSAction* p_action);
inline const MxStreamerSubClass2& GetSubclass1() { return m_subclass1; }
inline const MxStreamerSubClass3& GetSubclass2() { return m_subclass2; }
private: private:
list<MxStreamController*> m_openStreams; // 0x8 list<MxStreamController*> m_openStreams; // 0x8
MxStreamerSubClass2 m_subclass1; // 0x14 MxStreamerSubClass2 m_subclass1; // 0x14