Save first progress on BETA10 match of WriteScoreHistory

This commit is contained in:
jonschz 2025-06-20 12:44:03 +02:00
parent f64af166c8
commit eab95758dc
2 changed files with 124 additions and 60 deletions

View File

@ -168,6 +168,11 @@ class LegoGameState {
ScoreItem* GetScore(MxS32 p_index) { return p_index >= m_count ? NULL : &m_scores[p_index]; } ScoreItem* GetScore(MxS32 p_index) { return p_index >= m_count ? NULL : &m_scores[p_index]; }
MxS16 m_count; // 0x00 MxS16 m_count; // 0x00
// TODO: Enable ifdefs when done
// #ifdef BETA10
MxS16 m_indices[20];
// #endif
ScoreItem m_scores[20]; // 0x02 ScoreItem m_scores[20]; // 0x02
MxS16 m_unk0x372; // 0x372 MxS16 m_unk0x372; // 0x372
}; };

View File

@ -1441,11 +1441,12 @@ void LegoGameState::History::WriteScoreHistory()
MxU8 scores[5][5]; MxU8 scores[5][5];
InfocenterState* state = (InfocenterState*) GameState()->GetState("InfocenterState"); InfocenterState* state = (InfocenterState*) GameState()->GetState("InfocenterState");
if (state->m_letters[0]) { if (!state->m_letters[0]) {
return;
}
JetskiRaceState* jetskiRaceState = (JetskiRaceState*) GameState()->GetState("JetskiRaceState"); JetskiRaceState* jetskiRaceState = (JetskiRaceState*) GameState()->GetState("JetskiRaceState");
CarRaceState* carRaceState = (CarRaceState*) GameState()->GetState("CarRaceState"); CarRaceState* carRaceState = (CarRaceState*) GameState()->GetState("CarRaceState");
TowTrackMissionState* towTrackMissionState = TowTrackMissionState* towTrackMissionState = (TowTrackMissionState*) GameState()->GetState("TowTrackMissionState");
(TowTrackMissionState*) GameState()->GetState("TowTrackMissionState");
PizzaMissionState* pizzaMissionState = (PizzaMissionState*) GameState()->GetState("PizzaMissionState"); PizzaMissionState* pizzaMissionState = (PizzaMissionState*) GameState()->GetState("PizzaMissionState");
AmbulanceMissionState* ambulanceMissionState = AmbulanceMissionState* ambulanceMissionState =
(AmbulanceMissionState*) GameState()->GetState("AmbulanceMissionState"); (AmbulanceMissionState*) GameState()->GetState("AmbulanceMissionState");
@ -1470,49 +1471,107 @@ void LegoGameState::History::WriteScoreHistory()
MxS32 unk0x2c; MxS32 unk0x2c;
ScoreItem* p_scorehist = FUN_1003cc90(&GameState()->m_players[0], GameState()->m_unk0x24, unk0x2c); ScoreItem* p_scorehist = FUN_1003cc90(&GameState()->m_players[0], GameState()->m_unk0x24, unk0x2c);
if (p_scorehist != NULL) { if (!p_scorehist) {
p_scorehist->m_totalScore = totalScore; MxS32 i;
memcpy(p_scorehist->m_scores, scores, sizeof(p_scorehist->m_scores)); // LINE: BETA10 0x100870ee
for (i = 0; i < m_count; i++) {
if (totalScore > m_scores[m_indices[i]].m_totalScore) {
break;
}
}
// LINE: BETA10 0x1008713f
if (i < m_count) {
// short sVar2 = m_count >= 20 ? m_indices[19] : m_count++;
MxS32 sVar2;
if (m_count < 20) {
sVar2 = m_count++;
} }
else { else {
if (m_count < (MxS16) sizeOfArray(m_scores)) { // LINE: BETA10 0x10087171
m_scores[m_count].m_totalScore = totalScore; sVar2 = m_indices[19];
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) { unk0x2c = sVar2;
m_scores[19].m_totalScore = totalScore; // MxS32 count = m_count;
memcpy(m_scores[19].m_scores, scores, sizeof(m_scores[19].m_scores)); for (MxS32 j = m_count - 1; i < j; j--) {
m_scores[19].m_name = GameState()->m_players[0]; m_indices[j - 1] = m_indices[j - 2];
m_scores[19].m_unk0x2a = GameState()->m_unk0x24;
} }
m_indices[i] = sVar2;
p_scorehist = (LegoGameState::ScoreItem*) m_scores[unk0x2c].m_scores;
}
else if (i < 20) {
m_indices[m_count] = m_count;
p_scorehist = &m_scores[m_count++];
}
}
else if (p_scorehist->m_totalScore != totalScore) {
assert(totalScore > p_scorehist->m_totalScore);
// TODO: This decomp is likely still very wrong, first draft only.
// In particular, something is very confusing with a potential char->short typecast?
// But the types in Serialize do make sense.
//
// Potential explanation: There is another short[5][5] array in the parent type
for (MxS32 i = unk0x2c; (0 < i && (m_indices[i + -1] < m_indices[i])); i = i + -1) {
MxU8 tmp = m_indices[i - 1];
m_indices[i - 1] = m_indices[i];
m_indices[i] = tmp;
}
}
if (p_scorehist) {
p_scorehist->m_totalScore = totalScore;
memcpy(p_scorehist->m_scores[0], scores[0], 0x19);
// TODO: or the other way around
p_scorehist->m_name = GameState()->m_players[0];
p_scorehist->m_unk0x2a = GameState()->m_unk0x24;
} }
MxU8 tmpScores[5][5]; // if (p_scorehist != NULL) {
Username tmpPlayer; // p_scorehist->m_totalScore = totalScore;
MxS16 tmpUnk0x2a; // 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);
// TODO: Match bubble sort loops // m_scores[m_count].m_totalScore = totalScore;
for (MxS32 i = m_count - 1; i > 0; i--) { // memcpy(m_scores[m_count].m_scores, scores, sizeof(m_scores[m_count].m_scores));
for (MxS32 j = 1; j <= i; j++) { // m_scores[m_count].m_name = GameState()->m_players[0];
if (m_scores[j - 1].m_totalScore < m_scores[j].m_totalScore) { // m_scores[m_count].m_unk0x2a = GameState()->m_unk0x24;
memcpy(tmpScores, m_scores[j - 1].m_scores, sizeof(tmpScores)); // m_count++;
tmpPlayer = m_scores[j - 1].m_name; // }
tmpUnk0x2a = m_scores[j - 1].m_unk0x2a; // 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;
// }
// }
memcpy(m_scores[j - 1].m_scores, m_scores[j].m_scores, sizeof(m_scores[j - 1].m_scores)); // MxU8 tmpScores[5][5];
m_scores[j - 1].m_name = m_scores[j].m_name; // Username tmpPlayer;
m_scores[j - 1].m_unk0x2a = m_scores[j].m_unk0x2a; // MxS16 tmpUnk0x2a;
memcpy(m_scores[j].m_scores, tmpScores, sizeof(m_scores[j].m_scores)); // // TODO: Match bubble sort loops
m_scores[j].m_name = tmpPlayer; // for (MxS32 i = m_count - 1; i > 0; i--) {
m_scores[j].m_unk0x2a = tmpUnk0x2a; // 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 - 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;
// }
// }
// }
// }
} }
// FUNCTION: LEGO1 0x1003cc90 // FUNCTION: LEGO1 0x1003cc90