From 7f5ad98749ce4244946ab8022849d1d0429fd025 Mon Sep 17 00:00:00 2001 From: Misha <106913236+MishaProductions@users.noreply.github.com> Date: Sun, 3 Mar 2024 17:15:24 -0500 Subject: [PATCH] implement ModelDbPart::Read & ModelDbModel::Read (#620) * implement ModelDbPart::Read & ModelDbModel::Read * Update modeldb.cpp * Minor style fixes * Add comment about buffer overrun * Use sizeof on var --------- Co-authored-by: Christian Semmler --- LEGO1/modeldb/modeldb.cpp | 62 ++++++++++++++++++++++++++++++++++++--- LEGO1/modeldb/modeldb.h | 10 +++++-- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/LEGO1/modeldb/modeldb.cpp b/LEGO1/modeldb/modeldb.cpp index e472e7e7..57980ec8 100644 --- a/LEGO1/modeldb/modeldb.cpp +++ b/LEGO1/modeldb/modeldb.cpp @@ -6,16 +6,70 @@ DECOMP_SIZE_ASSERT(ModelDbModel, 0x38) DECOMP_SIZE_ASSERT(ModelDbPartList, 0x1c) DECOMP_SIZE_ASSERT(ModelDbPartListCursor, 0x10) -// STUB: LEGO1 0x100276b0 +// FUNCTION: LEGO1 0x100276b0 MxResult ModelDbModel::Read(FILE* p_file) { - return SUCCESS; + MxU32 len; + + if (fread(&len, sizeof(len), 1, p_file) != 1) { + return FAILURE; + } + + m_modelName = new char[len]; + if (fread(m_modelName, len, 1, p_file) != 1) { + return FAILURE; + } + + if (fread(&m_unk0x04, sizeof(m_unk0x04), 1, p_file) != 1) { + return FAILURE; + } + if (fread(&m_unk0x08, sizeof(m_unk0x08), 1, p_file) != 1) { + return FAILURE; + } + if (fread(&len, sizeof(len), 1, p_file) != 1) { + return FAILURE; + } + + m_presenterName = new char[len]; + if (fread(m_presenterName, len, 1, p_file) != 1) { + return FAILURE; + } + + if (fread(&m_unk0x10, sizeof(*m_unk0x10), 3, p_file) != 3) { + return FAILURE; + } + if (fread(&m_unk0x1c, sizeof(*m_unk0x1c), 3, p_file) != 3) { + return FAILURE; + } + if (fread(&m_unk0x28, sizeof(*m_unk0x28), 3, p_file) != 3) { + return FAILURE; + } + + return fread(&m_unk0x34, sizeof(m_unk0x34), 1, p_file) == 1 ? SUCCESS : FAILURE; } -// STUB: LEGO1 0x10027850 +// FUNCTION: LEGO1 0x10027850 MxResult ModelDbPart::Read(FILE* p_file) { - return SUCCESS; + MxU32 len; + char buff[128]; + + if (fread(&len, sizeof(len), 1, p_file) != 1) { + return FAILURE; + } + + // Critical bug: buffer overrun + if (fread(buff, len, 1, p_file) != 1) { + return FAILURE; + } + + m_roiName = buff; + + if (fread(&m_unk0x10, sizeof(m_unk0x10), 1, p_file) != 1) { + return FAILURE; + } + + return fread(&m_unk0x14, sizeof(m_unk0x14), 1, p_file) == 1 ? SUCCESS : FAILURE; } // FUNCTION: LEGO1 0x10027910 diff --git a/LEGO1/modeldb/modeldb.h b/LEGO1/modeldb/modeldb.h index ad60e677..ebebae17 100644 --- a/LEGO1/modeldb/modeldb.h +++ b/LEGO1/modeldb/modeldb.h @@ -93,8 +93,14 @@ class ModelDbPartListCursor : public MxListCursor { struct ModelDbModel { MxResult Read(FILE* p_file); - char* m_modelName; // 0x00 - undefined m_unk0x04[0x34]; // 0x04 + char* m_modelName; // 0x00 + undefined4 m_unk0x04; // 0x04 + undefined4 m_unk0x08; // 0x08 + char* m_presenterName; // 0x0c + undefined4 m_unk0x10[3]; // 0x10 + undefined4 m_unk0x1c[3]; // 0x1c + undefined4 m_unk0x28[3]; // 0x28 + undefined m_unk0x34; // 0x34 }; // SIZE 0x18