From 6988f938c3f44274c361859c69834ba2d3406b88 Mon Sep 17 00:00:00 2001 From: jonschz Date: Fri, 20 Jun 2025 14:33:37 +0200 Subject: [PATCH] re-enable LEGO1 impl --- LEGO1/lego/legoomni/include/legogamestate.h | 12 ++- .../legoomni/src/common/legogamestate.cpp | 85 ++++++++++--------- 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/LEGO1/lego/legoomni/include/legogamestate.h b/LEGO1/lego/legoomni/include/legogamestate.h index 847cef33..23bfb00e 100644 --- a/LEGO1/lego/legoomni/include/legogamestate.h +++ b/LEGO1/lego/legoomni/include/legogamestate.h @@ -168,13 +168,11 @@ class LegoGameState { ScoreItem* GetScore(MxS32 p_index) { return p_index >= m_count ? NULL : &m_scores[p_index]; } MxS16 m_count; // 0x00 -// TODO: Enable ifdefs when done -// #ifdef BETA10 - MxS16 m_indices[20]; -// #endif - - ScoreItem m_scores[20]; // 0x02 - MxS16 m_unk0x372; // 0x372 +#ifdef BETA10 + MxS16 m_indices[20]; // 0x02 +#endif + ScoreItem m_scores[20]; // 0x02 (0x22 for BETA10) + MxS16 m_unk0x372; // 0x372 (0x392 for BETA10) }; LegoGameState(); diff --git a/LEGO1/lego/legoomni/src/common/legogamestate.cpp b/LEGO1/lego/legoomni/src/common/legogamestate.cpp index c42206ee..e9ed7a89 100644 --- a/LEGO1/lego/legoomni/src/common/legogamestate.cpp +++ b/LEGO1/lego/legoomni/src/common/legogamestate.cpp @@ -1473,6 +1473,8 @@ void LegoGameState::History::WriteScoreHistory() MxS32 unk0x2c; ScoreItem* p_scorehist = FUN_1003cc90(&GameState()->m_players[0], GameState()->m_unk0x24, unk0x2c); +#ifdef BETA10 + if (!p_scorehist) { MxS32 i; // LINE: BETA10 0x100870ee @@ -1520,51 +1522,54 @@ void LegoGameState::History::WriteScoreHistory() p_scorehist->m_unk0x2a = GameState()->m_unk0x24; } - // if (p_scorehist != NULL) { - // p_scorehist->m_totalScore = totalScore; - // memcpy(p_scorehist->m_scores, scores, sizeof(p_scorehist->m_scores)); - // } - // else { - // if (m_count < (MxS16) sizeOfArray(m_scores)) { - // assert(totalScore > p_scorehist->m_totalScore); +#else + // TODO: Improve based on BETA10 if possible - // m_scores[m_count].m_totalScore = totalScore; - // memcpy(m_scores[m_count].m_scores, scores, sizeof(m_scores[m_count].m_scores)); - // m_scores[m_count].m_name = GameState()->m_players[0]; - // m_scores[m_count].m_unk0x2a = GameState()->m_unk0x24; - // m_count++; - // } - // else if (m_scores[19].m_totalScore <= totalScore) { - // m_scores[19].m_totalScore = totalScore; - // memcpy(m_scores[19].m_scores, scores, sizeof(m_scores[19].m_scores)); - // m_scores[19].m_name = GameState()->m_players[0]; - // m_scores[19].m_unk0x2a = GameState()->m_unk0x24; - // } - // } + if (p_scorehist != NULL) { + p_scorehist->m_totalScore = totalScore; + memcpy(p_scorehist->m_scores, scores, sizeof(p_scorehist->m_scores)); + } + else { + if (m_count < (MxS16) sizeOfArray(m_scores)) { + assert(totalScore > p_scorehist->m_totalScore); - // MxU8 tmpScores[5][5]; - // Username tmpPlayer; - // MxS16 tmpUnk0x2a; + m_scores[m_count].m_totalScore = totalScore; + memcpy(m_scores[m_count].m_scores, scores, sizeof(m_scores[m_count].m_scores)); + m_scores[m_count].m_name = GameState()->m_players[0]; + m_scores[m_count].m_unk0x2a = GameState()->m_unk0x24; + m_count++; + } + else if (m_scores[19].m_totalScore <= totalScore) { + m_scores[19].m_totalScore = totalScore; + memcpy(m_scores[19].m_scores, scores, sizeof(m_scores[19].m_scores)); + m_scores[19].m_name = GameState()->m_players[0]; + m_scores[19].m_unk0x2a = GameState()->m_unk0x24; + } + } - // // TODO: Match bubble sort loops - // for (MxS32 i = m_count - 1; i > 0; i--) { - // for (MxS32 j = 1; j <= i; j++) { - // if (m_scores[j - 1].m_totalScore < m_scores[j].m_totalScore) { - // memcpy(tmpScores, m_scores[j - 1].m_scores, sizeof(tmpScores)); - // tmpPlayer = m_scores[j - 1].m_name; - // tmpUnk0x2a = m_scores[j - 1].m_unk0x2a; + MxU8 tmpScores[5][5]; + Username tmpPlayer; + MxS16 tmpUnk0x2a; - // memcpy(m_scores[j - 1].m_scores, m_scores[j].m_scores, sizeof(m_scores[j - 1].m_scores)); - // m_scores[j - 1].m_name = m_scores[j].m_name; - // m_scores[j - 1].m_unk0x2a = m_scores[j].m_unk0x2a; + // TODO: Match bubble sort loops + for (MxS32 i = m_count - 1; i > 0; i--) { + for (MxS32 j = 1; j <= i; j++) { + if (m_scores[j - 1].m_totalScore < m_scores[j].m_totalScore) { + memcpy(tmpScores, m_scores[j - 1].m_scores, sizeof(tmpScores)); + tmpPlayer = m_scores[j - 1].m_name; + tmpUnk0x2a = m_scores[j - 1].m_unk0x2a; - // memcpy(m_scores[j].m_scores, tmpScores, sizeof(m_scores[j].m_scores)); - // m_scores[j].m_name = tmpPlayer; - // m_scores[j].m_unk0x2a = tmpUnk0x2a; - // } - // } - // } - // } + memcpy(m_scores[j - 1].m_scores, m_scores[j].m_scores, sizeof(m_scores[j - 1].m_scores)); + m_scores[j - 1].m_name = m_scores[j].m_name; + m_scores[j - 1].m_unk0x2a = m_scores[j].m_unk0x2a; + + memcpy(m_scores[j].m_scores, tmpScores, sizeof(m_scores[j].m_scores)); + m_scores[j].m_name = tmpPlayer; + m_scores[j].m_unk0x2a = tmpUnk0x2a; + } + } + } +#endif } // FUNCTION: LEGO1 0x1003cc90