Skip to content

Commit

Permalink
Match Serialize functions to BETA10 (#1334)
Browse files Browse the repository at this point in the history
* Begin refactor Serialize functions

* Match more Serialize functions

* Match `LegoVehicleBuildState::Serialize`

* Match `LegoGameState::Username::Serialize`

* Match `LegoGameState::ScoreItem::Serialize`

* Match `LegoGameState::History::Serialize`

* Var name

* Var name

* Revert "Var name"

This reverts commit 1c0cccfba799450cfe4f75566dc1f32db1c76a6b.

* Add other Serialize implementations

* Add remaining Serialize implementations

* Add Read for char*

* Improvements
  • Loading branch information
foxtacles authored Jan 15, 2025
1 parent f95eedd commit 77a3dc0
Show file tree
Hide file tree
Showing 20 changed files with 399 additions and 317 deletions.
7 changes: 4 additions & 3 deletions LEGO1/lego/legoomni/include/legocarbuild.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MxSoundPresenter;
class MxActionNotificationParam;

// VTABLE: LEGO1 0x100d66e0
// VTABLE: BETA10 0x101bb910
// SIZE 0x50
class LegoVehicleBuildState : public LegoState {
public:
Expand All @@ -32,13 +33,13 @@ class LegoVehicleBuildState : public LegoState {
// FUNCTION: LEGO1 0x10025ff0
const char* ClassName() const override // vtable+0x0c
{
return this->m_className.GetData();
return m_className.GetData();
}

// FUNCTION: LEGO1 0x10026000
MxBool IsA(const char* p_name) const override // vtable+0x10
{
return !strcmp(p_name, this->m_className.GetData()) || LegoState::IsA(p_name);
return !strcmp(p_name, m_className.GetData()) || LegoState::IsA(p_name);
}

MxResult Serialize(LegoFile* p_file) override; // vtable+0x1c
Expand All @@ -56,7 +57,7 @@ class LegoVehicleBuildState : public LegoState {
MxString m_className; // 0x38

AnimationState m_animationState; // 0x48
undefined m_unk0x4c; // 0x4c
MxU8 m_unk0x4c; // 0x4c
MxBool m_unk0x4d; // 0x4d
MxBool m_unk0x4e; // 0x4e
MxU8 m_placedPartCount; // 0x4f
Expand Down
14 changes: 7 additions & 7 deletions LEGO1/lego/legoomni/include/legogamestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class LegoGameState {
Username(Username& p_other) { Set(p_other); }
void Set(Username& p_other) { memcpy(m_letters, p_other.m_letters, sizeof(m_letters)); }

MxResult Serialize(LegoStorage* p_storage);
MxResult Serialize(LegoFile* p_file);
Username& operator=(const Username& p_other);

MxS16 m_letters[7]; // 0x00
Expand All @@ -121,10 +121,10 @@ class LegoGameState {
struct ScoreItem {
MxResult Serialize(LegoFile* p_file);

MxS16 m_totalScore; // 0x00
MxU8 m_scores[5][5]; // 0x02
Username m_name; // 0x1c
undefined2 m_unk0x2a; // 0x2a
MxS16 m_totalScore; // 0x00
MxU8 m_scores[5][5]; // 0x02
Username m_name; // 0x1c
MxS16 m_unk0x2a; // 0x2a
};

// SIZE 0x372
Expand All @@ -141,7 +141,7 @@ class LegoGameState {

MxS16 m_count; // 0x00
ScoreItem m_scores[20]; // 0x02
undefined2 m_unk0x372; // 0x372
MxS16 m_unk0x372; // 0x372
};

LegoGameState();
Expand Down Expand Up @@ -214,7 +214,7 @@ class LegoGameState {
// TODO: Most likely getters/setters are not used according to BETA for the following members:

public:
MxU16 m_unk0x24; // 0x24
MxS16 m_unk0x24; // 0x24
MxS16 m_playerCount; // 0x26
Username m_players[9]; // 0x28
History m_history; // 0xa6
Expand Down
19 changes: 10 additions & 9 deletions LEGO1/lego/legoomni/include/legonamedplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,30 @@ class LegoNamedPlane {
void SetDirection(const Mx3DPointFloat& p_direction) { m_direction = p_direction; }
void SetUp(const Mx3DPointFloat& p_up) { m_up = p_up; }

// TODO: Unclear whether this was defined
MxBool IsPresent() { return strcmp(m_name.GetData(), "") != 0; }
void Reset() { m_name = ""; }

// FUNCTION: LEGO1 0x100344d0
MxResult Serialize(LegoFile* p_file)
{
if (p_file->IsWriteMode()) {
p_file->WriteString(m_name);
p_file->WriteVector3(m_position);
p_file->WriteVector3(m_direction);
p_file->WriteVector3(m_up);
p_file->Write(MxString(m_name));
p_file->Write(m_position);
p_file->Write(m_direction);
p_file->Write(m_up);
}
else if (p_file->IsReadMode()) {
p_file->ReadString(m_name);
p_file->ReadVector3(m_position);
p_file->ReadVector3(m_direction);
p_file->ReadVector3(m_up);
p_file->Read(m_name);
p_file->Read(m_position);
p_file->Read(m_direction);
p_file->Read(m_up);
}

return SUCCESS;
}

private:
// private:
MxString m_name; // 0x00
Mx3DPointFloat m_position; // 0x10
Mx3DPointFloat m_direction; // 0x24
Expand Down
15 changes: 9 additions & 6 deletions LEGO1/lego/legoomni/include/legorace.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ class RaceState : public LegoState {
MxResult Serialize(LegoFile* p_file)
{
if (p_file->IsReadMode()) {
Read(p_file, &m_id);
Read(p_file, &m_unk0x02);
Read(p_file, &m_score);
p_file->Read(m_id);
p_file->Read(m_unk0x02);
p_file->Read(m_score);
}
else if (p_file->IsWriteMode()) {
Write(p_file, m_id);
Write(p_file, m_unk0x02);
Write(p_file, m_score);
p_file->Write(m_id);
p_file->Write(m_unk0x02);
p_file->Write(m_score);
}
else {
return FAILURE;
}

return SUCCESS;
Expand Down
20 changes: 2 additions & 18 deletions LEGO1/lego/legoomni/include/legostate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class LegoState : public MxCore {
};

// SIZE 0x0c
class Playlist {
public:
struct Playlist {
enum Mode {
e_loop,
e_once,
Expand Down Expand Up @@ -60,21 +59,6 @@ class LegoState : public MxCore {
MxU32 Next();
MxBool Contains(MxU32 p_objectId);

void SetNextIndex(MxS16 p_nextIndex) { m_nextIndex = p_nextIndex; }

MxResult ReadFromFile(LegoFile* p_file)
{
Read(p_file, &m_nextIndex);
return SUCCESS;
}

MxResult WriteToFile(LegoFile* p_file)
{
Write(p_file, m_nextIndex);
return SUCCESS;
}

private:
MxU32* m_objectIds; // 0x00
MxS16 m_length; // 0x04
MxS16 m_mode; // 0x06
Expand All @@ -95,7 +79,7 @@ class LegoState : public MxCore {
virtual MxResult Serialize(LegoFile* p_file)
{
if (p_file->IsWriteMode()) {
p_file->WriteString(ClassName());
p_file->Write(MxString(ClassName()));
}
return SUCCESS;
} // vtable+0x1c
Expand Down
18 changes: 0 additions & 18 deletions LEGO1/lego/legoomni/include/pizza.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,6 @@ class PizzaMissionState : public LegoState {
// FUNCTION: BETA10 0x100ef7e0
MxLong GetTimeoutTime() { return m_finishTimes[3]; }

MxResult WriteToFile(LegoFile* p_file)
{
Write(p_file, m_unk0x06);
Write(p_file, m_unk0x14);
Write(p_file, m_score);
Write(p_file, m_hiScore);
return SUCCESS;
}

MxResult ReadFromFile(LegoFile* p_file)
{
Read(p_file, &m_unk0x06);
Read(p_file, &m_unk0x14);
Read(p_file, &m_score);
Read(p_file, &m_hiScore);
return SUCCESS;
}

MxS16 m_numActions; // 0x00
MxU8 m_actorId; // 0x02
undefined2 m_unk0x04; // 0x04
Expand Down
41 changes: 21 additions & 20 deletions LEGO1/lego/legoomni/src/actors/ambulance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,33 +646,34 @@ AmbulanceMissionState::AmbulanceMissionState()
}

// FUNCTION: LEGO1 0x10037440
// FUNCTION: BETA10 0x10024480
MxResult AmbulanceMissionState::Serialize(LegoFile* p_file)
{
LegoState::Serialize(p_file);

if (p_file->IsReadMode()) {
Read(p_file, &m_peScore);
Read(p_file, &m_maScore);
Read(p_file, &m_paScore);
Read(p_file, &m_niScore);
Read(p_file, &m_laScore);
Read(p_file, &m_peHighScore);
Read(p_file, &m_maHighScore);
Read(p_file, &m_paHighScore);
Read(p_file, &m_niHighScore);
Read(p_file, &m_laHighScore);
p_file->Read(m_peScore);
p_file->Read(m_maScore);
p_file->Read(m_paScore);
p_file->Read(m_niScore);
p_file->Read(m_laScore);
p_file->Read(m_peHighScore);
p_file->Read(m_maHighScore);
p_file->Read(m_paHighScore);
p_file->Read(m_niHighScore);
p_file->Read(m_laHighScore);
}
else if (p_file->IsWriteMode()) {
Write(p_file, m_peScore);
Write(p_file, m_maScore);
Write(p_file, m_paScore);
Write(p_file, m_niScore);
Write(p_file, m_laScore);
Write(p_file, m_peHighScore);
Write(p_file, m_maHighScore);
Write(p_file, m_paHighScore);
Write(p_file, m_niHighScore);
Write(p_file, m_laHighScore);
p_file->Write(m_peScore);
p_file->Write(m_maScore);
p_file->Write(m_paScore);
p_file->Write(m_niScore);
p_file->Write(m_laScore);
p_file->Write(m_peHighScore);
p_file->Write(m_maHighScore);
p_file->Write(m_paHighScore);
p_file->Write(m_niHighScore);
p_file->Write(m_laHighScore);
}

return SUCCESS;
Expand Down
12 changes: 10 additions & 2 deletions LEGO1/lego/legoomni/src/actors/pizza.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,18 +605,25 @@ PizzaMissionState::PizzaMissionState()
}

// FUNCTION: LEGO1 0x100393c0
// FUNCTION: BETA10 0x100eebf2
MxResult PizzaMissionState::Serialize(LegoFile* p_file)
{
LegoState::Serialize(p_file);

if (p_file->IsReadMode()) {
for (MxS16 i = 0; i < 5; i++) {
m_missions[i].ReadFromFile(p_file);
p_file->Read(m_missions[i].m_unk0x06);
p_file->Read(m_missions[i].m_unk0x14);
p_file->Read(m_missions[i].m_score);
p_file->Read(m_missions[i].m_hiScore);
}
}
else if (p_file->IsWriteMode()) {
for (MxS16 i = 0; i < 5; i++) {
m_missions[i].WriteToFile(p_file);
p_file->Write(m_missions[i].m_unk0x06);
p_file->Write(m_missions[i].m_unk0x14);
p_file->Write(m_missions[i].m_score);
p_file->Write(m_missions[i].m_hiScore);
}
}

Expand All @@ -633,6 +640,7 @@ PizzaMissionState::Mission* PizzaMissionState::GetMission(MxU8 p_actorId)
}
}

assert("No pizza mission for this character!" == NULL);
return NULL;
}

Expand Down
4 changes: 2 additions & 2 deletions LEGO1/lego/legoomni/src/actors/pizzeria.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
7 changes: 4 additions & 3 deletions LEGO1/lego/legoomni/src/actors/radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ void Radio::CreateState()
}

// FUNCTION: LEGO1 0x1002ce10
// FUNCTION: BETA10 0x100f20f6
RadioState::RadioState()
{
srand(Timer()->GetTime());
Expand All @@ -217,13 +218,13 @@ RadioState::RadioState()
m_unk0x2c = random % 3;

m_unk0x08[0] = Playlist((MxU32*) g_unk0x100f3218, sizeOfArray(g_unk0x100f3218), Playlist::e_loop);
m_unk0x08[0].SetNextIndex(rand() % sizeOfArray(g_unk0x100f3218));
m_unk0x08[0].m_nextIndex = (rand() % sizeOfArray(g_unk0x100f3218));

m_unk0x08[1] = Playlist((MxU32*) g_unk0x100f3230, sizeOfArray(g_unk0x100f3230), Playlist::e_loop);
m_unk0x08[1].SetNextIndex(rand() % sizeOfArray(g_unk0x100f3230));
m_unk0x08[1].m_nextIndex = (rand() % sizeOfArray(g_unk0x100f3230));

m_unk0x08[2] = Playlist((MxU32*) g_unk0x100f3268, sizeOfArray(g_unk0x100f3268), Playlist::e_loop);
m_unk0x08[2].SetNextIndex(rand() % sizeOfArray(g_unk0x100f3268));
m_unk0x08[2].m_nextIndex = (rand() % sizeOfArray(g_unk0x100f3268));

m_active = FALSE;
}
Expand Down
41 changes: 21 additions & 20 deletions LEGO1/lego/legoomni/src/actors/towtrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,33 +609,34 @@ TowTrackMissionState::TowTrackMissionState()
}

// FUNCTION: LEGO1 0x1004dde0
// FUNCTION: BETA10 0x100f8720
MxResult TowTrackMissionState::Serialize(LegoFile* p_file)
{
LegoState::Serialize(p_file);

if (p_file->IsReadMode()) {
Read(p_file, &m_peScore);
Read(p_file, &m_maScore);
Read(p_file, &m_paScore);
Read(p_file, &m_niScore);
Read(p_file, &m_laScore);
Read(p_file, &m_peHighScore);
Read(p_file, &m_maHighScore);
Read(p_file, &m_paHighScore);
Read(p_file, &m_niHighScore);
Read(p_file, &m_laHighScore);
p_file->Read(m_peScore);
p_file->Read(m_maScore);
p_file->Read(m_paScore);
p_file->Read(m_niScore);
p_file->Read(m_laScore);
p_file->Read(m_peHighScore);
p_file->Read(m_maHighScore);
p_file->Read(m_paHighScore);
p_file->Read(m_niHighScore);
p_file->Read(m_laHighScore);
}
else if (p_file->IsWriteMode()) {
Write(p_file, m_peScore);
Write(p_file, m_maScore);
Write(p_file, m_paScore);
Write(p_file, m_niScore);
Write(p_file, m_laScore);
Write(p_file, m_peHighScore);
Write(p_file, m_maHighScore);
Write(p_file, m_paHighScore);
Write(p_file, m_niHighScore);
Write(p_file, m_laHighScore);
p_file->Write(m_peScore);
p_file->Write(m_maScore);
p_file->Write(m_paScore);
p_file->Write(m_niScore);
p_file->Write(m_laScore);
p_file->Write(m_peHighScore);
p_file->Write(m_maHighScore);
p_file->Write(m_paHighScore);
p_file->Write(m_niHighScore);
p_file->Write(m_laHighScore);
}

return SUCCESS;
Expand Down
Loading

0 comments on commit 77a3dc0

Please sign in to comment.