Less usage of sizeof(variableName) while (de)serializing

This commit is contained in:
Anonymous Maarten 2025-05-18 22:14:32 +02:00
parent 358a680aa4
commit 4deb27d47d
7 changed files with 58 additions and 58 deletions

View File

@ -48,7 +48,7 @@ LegoResult LegoUnknownKey::Write(LegoStorage* p_storage)
return result; return result;
} }
if ((result = p_storage->Write(&m_z, sizeof(m_z))) != SUCCESS) { if ((result = p_storage->Write(&m_z, sizeof(LegoFloat))) != SUCCESS) {
return result; return result;
} }
@ -95,7 +95,7 @@ LegoResult LegoAnimScene::Write(LegoStorage* p_storage)
LegoResult result; LegoResult result;
LegoS32 i; LegoS32 i;
if ((result = p_storage->Write(&m_unk0x00, sizeof(m_unk0x00))) != SUCCESS) { if ((result = p_storage->Write(&m_unk0x00, sizeof(LegoU16))) != SUCCESS) {
return result; return result;
} }
if (m_unk0x00 != 0) { if (m_unk0x00 != 0) {
@ -106,7 +106,7 @@ LegoResult LegoAnimScene::Write(LegoStorage* p_storage)
} }
} }
if ((result = p_storage->Write(&m_unk0x08, sizeof(m_unk0x08))) != SUCCESS) { if ((result = p_storage->Write(&m_unk0x08, sizeof(LegoU16))) != SUCCESS) {
return result; return result;
} }
if (m_unk0x08 != 0) { if (m_unk0x08 != 0) {
@ -117,7 +117,7 @@ LegoResult LegoAnimScene::Write(LegoStorage* p_storage)
} }
} }
if ((result = p_storage->Write(&m_unk0x10, sizeof(m_unk0x10))) != SUCCESS) { if ((result = p_storage->Write(&m_unk0x10, sizeof(LegoU16))) != SUCCESS) {
return result; return result;
} }
if (m_unk0x10 != 0) { if (m_unk0x10 != 0) {
@ -311,7 +311,7 @@ LegoResult LegoAnimKey::Write(LegoStorage* p_storage)
LegoResult result; LegoResult result;
LegoS32 timeAndFlags = (LegoS32) m_time | (m_flags << 24); LegoS32 timeAndFlags = (LegoS32) m_time | (m_flags << 24);
if ((result = p_storage->Write(&timeAndFlags, sizeof(timeAndFlags))) != SUCCESS) { if ((result = p_storage->Write(&timeAndFlags, sizeof(LegoS32))) != SUCCESS) {
return result; return result;
} }
@ -364,15 +364,15 @@ LegoResult LegoTranslationKey::Write(LegoStorage* p_storage)
return result; return result;
} }
if ((result = p_storage->Write(&m_x, sizeof(m_x))) != SUCCESS) { if ((result = p_storage->Write(&m_x, sizeof(LegoFloat))) != SUCCESS) {
return result; return result;
} }
if ((result = p_storage->Write(&m_y, sizeof(m_y))) != SUCCESS) { if ((result = p_storage->Write(&m_y, sizeof(LegoFloat))) != SUCCESS) {
return result; return result;
} }
if ((result = p_storage->Write(&m_z, sizeof(m_z))) != SUCCESS) { if ((result = p_storage->Write(&m_z, sizeof(LegoFloat))) != SUCCESS) {
return result; return result;
} }
@ -435,15 +435,15 @@ LegoResult LegoRotationKey::Write(LegoStorage* p_storage)
return result; return result;
} }
if ((result = p_storage->Write(&m_x, sizeof(m_x))) != SUCCESS) { if ((result = p_storage->Write(&m_x, sizeof(LegoFloat))) != SUCCESS) {
return result; return result;
} }
if ((result = p_storage->Write(&m_y, sizeof(m_y))) != SUCCESS) { if ((result = p_storage->Write(&m_y, sizeof(LegoFloat))) != SUCCESS) {
return result; return result;
} }
if ((result = p_storage->Write(&m_z, sizeof(m_z))) != SUCCESS) { if ((result = p_storage->Write(&m_z, sizeof(LegoFloat))) != SUCCESS) {
return result; return result;
} }
@ -496,15 +496,15 @@ LegoResult LegoScaleKey::Write(LegoStorage* p_storage)
return result; return result;
} }
if ((result = p_storage->Write(&m_x, sizeof(m_x))) != SUCCESS) { if ((result = p_storage->Write(&m_x, sizeof(LegoFloat))) != SUCCESS) {
return result; return result;
} }
if ((result = p_storage->Write(&m_y, sizeof(m_y))) != SUCCESS) { if ((result = p_storage->Write(&m_y, sizeof(LegoFloat))) != SUCCESS) {
return result; return result;
} }
if ((result = p_storage->Write(&m_z, sizeof(m_z))) != SUCCESS) { if ((result = p_storage->Write(&m_z, sizeof(LegoFloat))) != SUCCESS) {
return result; return result;
} }
@ -665,7 +665,7 @@ LegoResult LegoAnimNodeData::Write(LegoStorage* p_storage)
return result; return result;
} }
if ((result = p_storage->Write(&m_numTranslationKeys, sizeof(m_numTranslationKeys))) != SUCCESS) { if ((result = p_storage->Write(&m_numTranslationKeys, sizeof(LegoU16))) != SUCCESS) {
return result; return result;
} }
if (m_numTranslationKeys != 0) { if (m_numTranslationKeys != 0) {
@ -676,7 +676,7 @@ LegoResult LegoAnimNodeData::Write(LegoStorage* p_storage)
} }
} }
if ((result = p_storage->Write(&m_numRotationKeys, sizeof(m_numRotationKeys))) != SUCCESS) { if ((result = p_storage->Write(&m_numRotationKeys, sizeof(LegoU16))) != SUCCESS) {
return result; return result;
} }
if (m_numRotationKeys != 0) { if (m_numRotationKeys != 0) {
@ -687,7 +687,7 @@ LegoResult LegoAnimNodeData::Write(LegoStorage* p_storage)
} }
} }
if ((result = p_storage->Write(&m_numScaleKeys, sizeof(m_numScaleKeys))) != SUCCESS) { if ((result = p_storage->Write(&m_numScaleKeys, sizeof(LegoU16))) != SUCCESS) {
return result; return result;
} }
if (m_numScaleKeys != 0) { if (m_numScaleKeys != 0) {
@ -698,7 +698,7 @@ LegoResult LegoAnimNodeData::Write(LegoStorage* p_storage)
} }
} }
if ((result = p_storage->Write(&m_numMorphKeys, sizeof(m_numMorphKeys))) != SUCCESS) { if ((result = p_storage->Write(&m_numMorphKeys, sizeof(LegoU16))) != SUCCESS) {
return result; return result;
} }
if (m_numMorphKeys != 0) { if (m_numMorphKeys != 0) {
@ -1070,7 +1070,7 @@ LegoResult LegoAnim::Read(LegoStorage* p_storage, LegoS32 p_parseScene)
m_numActors++; m_numActors++;
} }
if ((result = p_storage->Read(&m_duration, sizeof(LegoTime))) != SUCCESS) { if ((result = p_storage->Read(&m_duration, sizeof(LegoS32))) != SUCCESS) {
goto done; goto done;
} }
@ -1200,7 +1200,7 @@ LegoResult LegoMorphKey::Write(LegoStorage* p_storage)
return result; return result;
} }
if ((result = p_storage->Write(&m_unk0x08, sizeof(m_unk0x08))) != SUCCESS) { if ((result = p_storage->Write(&m_unk0x08, sizeof(LegoU8))) != SUCCESS) {
return result; return result;
} }

View File

@ -35,13 +35,13 @@ LegoResult LegoPaletteEntry::Read(LegoStorage* p_storage)
LegoResult LegoPaletteEntry::Write(LegoStorage* p_storage) LegoResult LegoPaletteEntry::Write(LegoStorage* p_storage)
{ {
LegoResult result; LegoResult result;
if ((result = p_storage->Write(&m_red, sizeof(m_red))) != SUCCESS) { if ((result = p_storage->Write(&m_red, sizeof(LegoU8))) != SUCCESS) {
return result; return result;
} }
if ((result = p_storage->Write(&m_green, sizeof(m_green))) != SUCCESS) { if ((result = p_storage->Write(&m_green, sizeof(LegoU8))) != SUCCESS) {
return result; return result;
} }
if ((result = p_storage->Write(&m_blue, sizeof(m_blue))) != SUCCESS) { if ((result = p_storage->Write(&m_blue, sizeof(LegoU8))) != SUCCESS) {
return result; return result;
} }
return SUCCESS; return SUCCESS;
@ -153,13 +153,13 @@ LegoResult LegoImage::Read(LegoStorage* p_storage, LegoU32 p_square)
LegoResult LegoImage::Write(LegoStorage* p_storage) LegoResult LegoImage::Write(LegoStorage* p_storage)
{ {
LegoResult result; LegoResult result;
if ((result = p_storage->Write(&m_width, sizeof(m_width))) != SUCCESS) { if ((result = p_storage->Write(&m_width, sizeof(LegoU32))) != SUCCESS) {
return result; return result;
} }
if ((result = p_storage->Write(&m_height, sizeof(m_height))) != SUCCESS) { if ((result = p_storage->Write(&m_height, sizeof(LegoU32))) != SUCCESS) {
return result; return result;
} }
if ((result = p_storage->Write(&m_count, sizeof(m_height))) != SUCCESS) { if ((result = p_storage->Write(&m_count, sizeof(LegoU32))) != SUCCESS) {
return result; return result;
} }
for (LegoU32 i = 0; i < m_count; i++) { for (LegoU32 i = 0; i < m_count; i++) {

View File

@ -45,21 +45,21 @@ class LegoStorage {
// FUNCTION: BETA10 0x1004b0d0 // FUNCTION: BETA10 0x1004b0d0
LegoStorage* WriteU8(LegoU8 p_data) LegoStorage* WriteU8(LegoU8 p_data)
{ {
Write(&p_data, sizeof(p_data)); Write(&p_data, sizeof(LegoU8));
return this; return this;
} }
// FUNCTION: BETA10 0x10017ce0 // FUNCTION: BETA10 0x10017ce0
LegoStorage* WriteS16(LegoS16 p_data) LegoStorage* WriteS16(LegoS16 p_data)
{ {
Write(&p_data, sizeof(p_data)); Write(&p_data, sizeof(LegoS16));
return this; return this;
} }
// FUNCTION: BETA10 0x1004b110 // FUNCTION: BETA10 0x1004b110
LegoStorage* WriteU16(LegoU16 p_data) LegoStorage* WriteU16(LegoU16 p_data)
{ {
Write(&p_data, sizeof(p_data)); Write(&p_data, sizeof(LegoU16));
return this; return this;
} }
@ -67,7 +67,7 @@ class LegoStorage {
// FUNCTION: BETA10 0x10088540 // FUNCTION: BETA10 0x10088540
LegoStorage* WriteS32(MxS32 p_data) LegoStorage* WriteS32(MxS32 p_data)
{ {
Write(&p_data, sizeof(p_data)); Write(&p_data, sizeof(MxS32));
return this; return this;
} }
@ -75,14 +75,14 @@ class LegoStorage {
// FUNCTION: BETA10 0x1004b150 // FUNCTION: BETA10 0x1004b150
LegoStorage* WriteU32(MxU32 p_data) LegoStorage* WriteU32(MxU32 p_data)
{ {
Write(&p_data, sizeof(p_data)); Write(&p_data, sizeof(MxU32));
return this; return this;
} }
// FUNCTION: BETA10 0x10073610 // FUNCTION: BETA10 0x10073610
LegoStorage* WriteFloat(LegoFloat p_data) LegoStorage* WriteFloat(LegoFloat p_data)
{ {
Write(&p_data, sizeof(p_data)); Write(&p_data, sizeof(LegoFloat));
return this; return this;
} }

View File

@ -91,7 +91,7 @@ LegoResult LegoTree::Write(LegoStorage* p_storage, LegoTreeNode* p_node)
} }
} }
LegoU32 numChildren = p_node->GetNumChildren(); LegoU32 numChildren = p_node->GetNumChildren();
if ((result = p_storage->Write(&numChildren, sizeof(numChildren))) != SUCCESS) { if ((result = p_storage->Write(&numChildren, sizeof(LegoU32))) != SUCCESS) {
return result; return result;
} }
for (LegoU32 i = 0; i < p_node->GetNumChildren(); i++) { for (LegoU32 i = 0; i < p_node->GetNumChildren(); i++) {

View File

@ -113,14 +113,14 @@ undefined4 MxDSAction::VTable0x14()
MxU32 MxDSAction::GetSizeOnDisk() MxU32 MxDSAction::GetSizeOnDisk()
{ {
MxU32 size = MxDSObject::GetSizeOnDisk(); MxU32 size = MxDSObject::GetSizeOnDisk();
size += sizeof(m_flags); size += sizeof(MxU32);
size += sizeof(m_startTime); size += sizeof(MxS32);
size += sizeof(m_duration); size += sizeof(MxS32);
size += sizeof(m_loopCount); size += sizeof(MxS32);
size += sizeof(double) * 3; // m_location size += sizeof(double) * 3; // m_location
size += sizeof(double) * 3; // m_direction size += sizeof(double) * 3; // m_direction
size += sizeof(double) * 3; // m_up size += sizeof(double) * 3; // m_up
size += sizeof(m_extraLength); size += sizeof(MxU16);
size += m_extraLength; size += m_extraLength;
m_sizeOnDisk = size - MxDSObject::GetSizeOnDisk(); m_sizeOnDisk = size - MxDSObject::GetSizeOnDisk();
@ -261,10 +261,10 @@ void MxDSAction::Deserialize(MxU8*& p_source, MxS16 p_flags)
MxDSObject::Deserialize(p_source, p_flags); MxDSObject::Deserialize(p_source, p_flags);
// clang-format off // clang-format off
m_flags = *( MxU32*) p_source; p_source += sizeof(m_flags); m_flags = *( MxU32*) p_source; p_source += sizeof(MxU32);
m_startTime = *(MxLong*) p_source; p_source += sizeof(m_startTime); m_startTime = *(MxLong*) p_source; p_source += sizeof(MxS32);
m_duration = *(MxLong*) p_source; p_source += sizeof(m_duration); m_duration = *(MxLong*) p_source; p_source += sizeof(MxS32);
m_loopCount = *( MxS32*) p_source; p_source += sizeof(m_loopCount); m_loopCount = *( MxS32*) p_source; p_source += sizeof(MxS32);
m_location[0] = *(double*) p_source; p_source += sizeof(double); m_location[0] = *(double*) p_source; p_source += sizeof(double);
m_location[1] = *(double*) p_source; p_source += sizeof(double); m_location[1] = *(double*) p_source; p_source += sizeof(double);
m_location[2] = *(double*) p_source; p_source += sizeof(double); m_location[2] = *(double*) p_source; p_source += sizeof(double);

View File

@ -116,12 +116,12 @@ MxU32 MxDSMediaAction::GetSizeOnDisk()
totalSizeOnDisk++; totalSizeOnDisk++;
} }
totalSizeOnDisk += sizeof(m_unk0x9c.m_unk0x00); totalSizeOnDisk += sizeof(undefined4);
totalSizeOnDisk += sizeof(m_unk0x9c.m_unk0x04); totalSizeOnDisk += sizeof(undefined4);
totalSizeOnDisk += sizeof(m_framesPerSecond); totalSizeOnDisk += sizeof(MxS32);
totalSizeOnDisk += sizeof(m_mediaFormat); totalSizeOnDisk += sizeof(MxS32);
totalSizeOnDisk += sizeof(m_paletteManagement); totalSizeOnDisk += sizeof(MxS32);
totalSizeOnDisk += sizeof(m_sustainTime); totalSizeOnDisk += sizeof(MxS32);
m_sizeOnDisk = totalSizeOnDisk - MxDSAction::GetSizeOnDisk(); m_sizeOnDisk = totalSizeOnDisk - MxDSAction::GetSizeOnDisk();
return totalSizeOnDisk; return totalSizeOnDisk;
@ -137,12 +137,12 @@ void MxDSMediaAction::Deserialize(MxU8*& p_source, MxS16 p_flags)
p_source += strlen(m_mediaSrcPath) + 1; p_source += strlen(m_mediaSrcPath) + 1;
// clang-format off // clang-format off
m_unk0x9c.SetUnk0x00(*(MxU32*) p_source); p_source += sizeof(m_unk0x9c.m_unk0x00); m_unk0x9c.SetUnk0x00(*(MxU32*) p_source); p_source += sizeof(undefined4);
m_unk0x9c.SetUnk0x04(*(MxU32*) p_source); p_source += sizeof(m_unk0x9c.m_unk0x04); m_unk0x9c.SetUnk0x04(*(MxU32*) p_source); p_source += sizeof(undefined4);
m_framesPerSecond = *(MxS32*) p_source; p_source += sizeof(m_framesPerSecond); m_framesPerSecond = *(MxS32*) p_source; p_source += sizeof(MxS32);
m_mediaFormat = *(MxS32*) p_source; p_source += sizeof(m_mediaFormat); m_mediaFormat = *(MxS32*) p_source; p_source += sizeof(MxS32);
m_paletteManagement = *(MxS32*) p_source; p_source += sizeof(m_paletteManagement); m_paletteManagement = *(MxS32*) p_source; p_source += sizeof(MxS32);
m_sustainTime = *(MxS32*) p_source; p_source += sizeof(m_sustainTime); m_sustainTime = *(MxS32*) p_source; p_source += sizeof(MxS32);
// clang-format on // clang-format on
} }

View File

@ -38,16 +38,16 @@ MxU32 MxStreamChunk::ReadChunkHeader(MxU8* p_chunkData)
MxU8* chunkData = p_chunkData; MxU8* chunkData = p_chunkData;
memcpy(&m_flags, p_chunkData, sizeof(m_flags)); memcpy(&m_flags, p_chunkData, sizeof(m_flags));
p_chunkData += sizeof(m_flags); p_chunkData += sizeof(MxU16);
memcpy(&m_objectId, p_chunkData, sizeof(m_objectId)); memcpy(&m_objectId, p_chunkData, sizeof(m_objectId));
p_chunkData += sizeof(m_objectId); p_chunkData += sizeof(MxU32);
memcpy(&m_time, p_chunkData, sizeof(m_time)); memcpy(&m_time, p_chunkData, sizeof(m_time));
p_chunkData += sizeof(m_time); p_chunkData += sizeof(MxU32);
memcpy(&m_length, p_chunkData, sizeof(m_length)); memcpy(&m_length, p_chunkData, sizeof(m_length));
p_chunkData += sizeof(m_length); p_chunkData += sizeof(MxU32);
m_data = p_chunkData; m_data = p_chunkData;
headersize = p_chunkData - chunkData; headersize = p_chunkData - chunkData;