From e02fbe2fdee5587f05aaba21a34f26eb32f39ae3 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Sun, 12 Jan 2025 11:37:25 -0700 Subject: [PATCH] Begin refactor Serialize functions --- LEGO1/lego/legoomni/include/legonamedplane.h | 2 +- LEGO1/lego/legoomni/include/legostate.h | 4 +-- LEGO1/lego/legoomni/src/actors/pizzeria.cpp | 4 +-- .../src/common/legoanimationmanager.cpp | 2 +- LEGO1/lego/legoomni/src/common/legoutils.cpp | 4 +-- LEGO1/lego/sources/misc/legostorage.h | 32 +++++++++++++++---- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/LEGO1/lego/legoomni/include/legonamedplane.h b/LEGO1/lego/legoomni/include/legonamedplane.h index 43f97506..9b7ef69c 100644 --- a/LEGO1/lego/legoomni/include/legonamedplane.h +++ b/LEGO1/lego/legoomni/include/legonamedplane.h @@ -31,7 +31,7 @@ public: MxResult Serialize(LegoFile* p_file) { if (p_file->IsWriteMode()) { - p_file->WriteString(m_name); + p_file->Write(MxString(m_name)); p_file->WriteVector3(m_position); p_file->WriteVector3(m_direction); p_file->WriteVector3(m_up); diff --git a/LEGO1/lego/legoomni/include/legostate.h b/LEGO1/lego/legoomni/include/legostate.h index 09dc1fcf..10f761e0 100644 --- a/LEGO1/lego/legoomni/include/legostate.h +++ b/LEGO1/lego/legoomni/include/legostate.h @@ -74,7 +74,7 @@ public: return SUCCESS; } - private: + // private: MxU32* m_objectIds; // 0x00 MxS16 m_length; // 0x04 MxS16 m_mode; // 0x06 @@ -95,7 +95,7 @@ public: virtual MxResult Serialize(LegoFile* p_file) { if (p_file->IsWriteMode()) { - p_file->WriteString(ClassName()); + p_file->Write(MxString(ClassName())); } return SUCCESS; } // vtable+0x1c diff --git a/LEGO1/lego/legoomni/src/actors/pizzeria.cpp b/LEGO1/lego/legoomni/src/actors/pizzeria.cpp index a7681f87..54bf583b 100644 --- a/LEGO1/lego/legoomni/src/actors/pizzeria.cpp +++ b/LEGO1/lego/legoomni/src/actors/pizzeria.cpp @@ -124,12 +124,12 @@ MxResult PizzeriaState::Serialize(LegoFile* p_file) if (p_file->IsReadMode()) { for (MxS16 i = 0; i < 5; i++) { - m_unk0x08[i].ReadFromFile(p_file); + p_file->Read(m_unk0x08[i].m_nextIndex); } } else { for (MxS16 i = 0; i < 5; i++) { - m_unk0x08[i].WriteToFile(p_file); + p_file->Write(m_unk0x08[i].m_nextIndex); } } diff --git a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp index aa1a6b40..a5f69123 100644 --- a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp @@ -2943,7 +2943,7 @@ MxResult AnimState::Serialize(LegoFile* p_file) // LegoState::Serialize(p_file); // Option 2: if (p_file->IsWriteMode()) { - p_file->WriteString(ClassName()); + p_file->Write(MxString(ClassName())); } if (p_file->IsReadMode()) { diff --git a/LEGO1/lego/legoomni/src/common/legoutils.cpp b/LEGO1/lego/legoomni/src/common/legoutils.cpp index e1a61a38..07a43002 100644 --- a/LEGO1/lego/legoomni/src/common/legoutils.cpp +++ b/LEGO1/lego/legoomni/src/common/legoutils.cpp @@ -743,7 +743,7 @@ void WriteDefaultTexture(LegoFile* p_file, const char* p_name) LegoTexture texture; texture.SetImage(image); - p_file->WriteString(name); + p_file->Write(MxString(name)); texture.Write(p_file); } else { @@ -760,7 +760,7 @@ void WriteDefaultTexture(LegoFile* p_file, const char* p_name) // FUNCTION: LEGO1 0x1003f8a0 void WriteNamedTexture(LegoFile* p_file, LegoNamedTexture* p_namedTexture) { - p_file->WriteString(*p_namedTexture->GetName()); + p_file->Write(MxString(*p_namedTexture->GetName())); p_namedTexture->GetTexture()->Write(p_file); } diff --git a/LEGO1/lego/sources/misc/legostorage.h b/LEGO1/lego/sources/misc/legostorage.h index 553983fd..bb02cce1 100644 --- a/LEGO1/lego/sources/misc/legostorage.h +++ b/LEGO1/lego/sources/misc/legostorage.h @@ -132,16 +132,34 @@ public: return this; } - // FUNCTION: LEGO1 0x10006030 - LegoStorage* WriteString(MxString p_str) + // FUNCTION: BETA10 0x10024680 + LegoStorage* Read(LegoS16& p_data) { - const char* data = p_str.GetData(); - LegoU32 fullLength = strlen(data); + Read(&p_data, sizeof(p_data)); + return this; + } - LegoU16 limitedLength = (LegoU16) fullLength; - Write(&limitedLength, sizeof(limitedLength)); - Write((char*) data, (LegoS16) fullLength); + // FUNCTION: LEGO1 0x10006030 + // FUNCTION: BETA10 0x10017bb0 + LegoStorage* Write(MxString p_data) + { + Write(p_data.GetData()); + return this; + } + // FUNCTION: BETA10 0x10017c80 + LegoStorage* Write(const char* p_data) + { + LegoS16 length = strlen(p_data); + Write(length); + Write(p_data, length); + return this; + } + + // FUNCTION: BETA10 0x10017ce0 + LegoStorage* Write(LegoS16 p_data) + { + Write(&p_data, sizeof(p_data)); return this; }