Beta match MxDSFile (#1098)

This commit is contained in:
MS 2024-09-01 20:08:53 -04:00 committed by GitHub
parent 30be1ed4b8
commit 73938ac2ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 35 deletions

View File

@ -9,6 +9,7 @@
#include <windows.h>
// VTABLE: LEGO1 0x100dc890
// VTABLE: BETA10 0x101c2418
// SIZE 0x7c
class MxDSFile : public MxDSSource {
public:
@ -20,10 +21,12 @@ public:
// We have to explicitly use dllexport, otherwise this function cannot be exported,
// since it is inlined everywhere in LEGO1.DLL
// FUNCTION: LEGO1 0x100bfed0
// FUNCTION: BETA10 0x10148ac0
__declspec(dllexport) ~MxDSFile() override { Close(); }
#endif
// FUNCTION: LEGO1 0x100c0120
// FUNCTION: BETA10 0x10148dc0
const char* ClassName() const override // vtable+0x0c
{
// STRING: LEGO1 0x10102594
@ -31,38 +34,42 @@ public:
}
// FUNCTION: LEGO1 0x100c0130
// FUNCTION: BETA10 0x10148de0
MxBool IsA(const char* p_name) const override // vtable+0x10
{
return !strcmp(p_name, MxDSFile::ClassName()) || MxDSSource::IsA(p_name);
}
MxLong Open(MxULong) override; // vtable+0x14
MxLong Close() override; // vtable+0x18
MxResult Open(MxULong) override; // vtable+0x14
MxResult Close() override; // vtable+0x18
MxResult Read(unsigned char*, MxULong) override; // vtable+0x20
MxLong Seek(MxLong, int) override; // vtable+0x24
MxResult Seek(MxLong, int) override; // vtable+0x24
MxULong GetBufferSize() override; // vtable+0x28
MxULong GetStreamBuffersNum() override; // vtable+0x2c
// FUNCTION: BETA10 0x1015e110
void SetFileName(const char* p_filename) { m_filename = p_filename; }
MxS32 CalcFileSize() { return GetFileSize(m_io.m_info.hmmio, NULL); }
// SYNTHETIC: LEGO1 0x100c01e0
// SYNTHETIC: BETA10 0x10148e40
// MxDSFile::`scalar deleting destructor'
// SIZE 0x0c
struct ChunkHeader {
// FUNCTION: BETA10 0x1015e040
ChunkHeader() : m_majorVersion(0), m_minorVersion(0), m_bufferSize(0), m_streamBuffersNum(0) {}
MxU16 m_majorVersion; // 0x00
MxU16 m_minorVersion; // 0x02
MxS16 m_majorVersion; // 0x00
MxS16 m_minorVersion; // 0x02
MxULong m_bufferSize; // 0x04
MxS16 m_streamBuffersNum; // 0x08
MxS16 m_reserved; // 0x0a
};
private:
MxLong ReadChunks();
MxResult ReadChunks();
MxString m_filename; // 0x14
MXIOINFO m_io; // 0x24

View File

@ -1,6 +1,7 @@
#include "mxdsfile.h"
#include "decomp.h"
#include "mxdebug.h"
#include <stdio.h>
@ -11,42 +12,44 @@ DECOMP_SIZE_ASSERT(MxDSFile::ChunkHeader, 0x0c)
DECOMP_SIZE_ASSERT(MxDSFile, 0x7c)
// FUNCTION: LEGO1 0x100cc4b0
// FUNCTION: BETA10 0x1015db90
MxDSFile::MxDSFile(const char* p_filename, MxULong p_skipReadingChunks)
{
m_filename = p_filename;
SetFileName(p_filename);
m_skipReadingChunks = p_skipReadingChunks;
}
// FUNCTION: LEGO1 0x100cc590
MxLong MxDSFile::Open(MxULong p_uStyle)
// FUNCTION: BETA10 0x1015dc57
MxResult MxDSFile::Open(MxULong p_uStyle)
{
MXIOINFO& io = m_io;
MxLong longResult = 1;
memset(&io, 0, sizeof(MXIOINFO));
MxResult result = -FAILURE; // Non-standard value of 1 here
memset(&m_io, 0, sizeof(MXIOINFO));
if (io.Open(m_filename.GetData(), p_uStyle) != 0) {
if (m_io.Open(m_filename.GetData(), p_uStyle) != 0) {
return -1;
}
io.SetBuffer(NULL, 0, 0);
m_io.SetBuffer(NULL, 0, 0);
m_position = 0;
if (m_skipReadingChunks == 0) {
longResult = ReadChunks();
result = ReadChunks();
}
if (longResult != 0) {
if (result != SUCCESS) {
Close();
}
else {
Seek(0, 0);
}
return longResult;
return result;
}
// FUNCTION: LEGO1 0x100cc620
MxLong MxDSFile::ReadChunks()
// FUNCTION: BETA10 0x1015dd18
MxResult MxDSFile::ReadChunks()
{
_MMCKINFO topChunk;
_MMCKINFO childChunk;
@ -54,33 +57,37 @@ MxLong MxDSFile::ReadChunks()
topChunk.fccType = FOURCC('O', 'M', 'N', 'I');
if (m_io.Descend(&topChunk, NULL, MMIO_FINDRIFF) != 0) {
return -1;
MxTrace("Unable to find Streamer RIFF chunk in file: %s\n", m_filename);
return FAILURE;
}
childChunk.ckid = FOURCC('M', 'x', 'H', 'd');
if (m_io.Descend(&childChunk, &topChunk, 0) != 0) {
return -1;
MxTrace("Unable to find Header chunk in file: %s\n", m_filename);
return FAILURE;
}
m_io.Read(&m_header, 0x0c);
if ((m_header.m_majorVersion == SI_MAJOR_VERSION) && (m_header.m_minorVersion == SI_MINOR_VERSION)) {
childChunk.ckid = FOURCC('M', 'x', 'O', 'f');
if (m_io.Descend(&childChunk, &topChunk, 0) != 0) {
return -1;
}
MxULong* pLengthInDWords = &m_lengthInDWords;
m_io.Read(pLengthInDWords, 4);
m_pBuffer = new MxU32[*pLengthInDWords];
m_io.Read(m_pBuffer, *pLengthInDWords * 4);
return 0;
}
else {
if ((m_header.m_majorVersion != SI_MAJOR_VERSION) || (m_header.m_minorVersion != SI_MINOR_VERSION)) {
sprintf(tempBuffer, "Wrong SI file version. %d.%d expected.", SI_MAJOR_VERSION, SI_MINOR_VERSION);
MessageBoxA(NULL, tempBuffer, NULL, MB_ICONERROR);
return -1;
return FAILURE;
}
childChunk.ckid = FOURCC('M', 'x', 'O', 'f');
if (m_io.Descend(&childChunk, &topChunk, 0) != 0) {
MxTrace("Unable to find Header chunk in file: %s\n", m_filename);
return FAILURE;
}
m_io.Read(&m_lengthInDWords, 4);
m_pBuffer = new MxU32[m_lengthInDWords];
m_io.Read(m_pBuffer, m_lengthInDWords * 4);
return SUCCESS;
}
// FUNCTION: LEGO1 0x100cc740
// FUNCTION: BETA10 0x1015ded2
MxLong MxDSFile::Close()
{
m_io.Close(0);
@ -91,10 +98,12 @@ MxLong MxDSFile::Close()
delete[] m_pBuffer;
m_pBuffer = NULL;
}
return 0;
return SUCCESS;
}
// FUNCTION: LEGO1 0x100cc780
// FUNCTION: BETA10 0x1015df50
MxResult MxDSFile::Read(unsigned char* p_buf, MxULong p_nbytes)
{
if (m_io.Read(p_buf, p_nbytes) != p_nbytes) {
@ -106,18 +115,26 @@ MxResult MxDSFile::Read(unsigned char* p_buf, MxULong p_nbytes)
}
// FUNCTION: LEGO1 0x100cc7b0
MxLong MxDSFile::Seek(MxLong p_lOffset, MxS32 p_iOrigin)
// FUNCTION: BETA10 0x1015dfee
MxResult MxDSFile::Seek(MxLong p_lOffset, MxS32 p_iOrigin)
{
return (m_position = m_io.Seek(p_lOffset, p_iOrigin)) == -1 ? -1 : 0;
m_position = m_io.Seek(p_lOffset, p_iOrigin);
if (m_position == -1) {
return FAILURE;
}
return SUCCESS;
}
// FUNCTION: LEGO1 0x100cc7e0
// FUNCTION: BETA10 0x10148d80
MxULong MxDSFile::GetBufferSize()
{
return m_header.m_bufferSize;
}
// FUNCTION: LEGO1 0x100cc7f0
// FUNCTION: BETA10 0x10148da0
MxULong MxDSFile::GetStreamBuffersNum()
{
return m_header.m_streamBuffersNum;