diff --git a/src/code_80057C60.c b/src/code_80057C60.c index d9807e954..1618bf57f 100644 --- a/src/code_80057C60.c +++ b/src/code_80057C60.c @@ -1246,10 +1246,14 @@ void func_80059AC8(void) { if (gIsGamePaused == false) { func_8008C1D8(&D_80165678); gRaceFrameCounter++; - for (i = 0; i < NUM_PLAYERS; i++) { + for (i = 0; i < gPlayerCount; i++) { D_8018CF68[i] = func_8008A890(&camera1[i]); + } + + for (i = 0; i < NUM_PLAYERS; i++) { func_800892E0(i); } + switch (gScreenModeSelection) { case SCREEN_MODE_1P: if (gGamestate != CREDITS_SEQUENCE) { diff --git a/src/render_player.c b/src/render_player.c index 0856f184e..4aa6e01b8 100644 --- a/src/render_player.c +++ b/src/render_player.c @@ -722,7 +722,7 @@ const char** wheelPtr[] = { donkeykong_kart_wheels, wario_kart_wheels, peach_kart_wheels, bowser_kart_wheels, }; -s32 D_800DDE74[] = { 96, 128, 192, 256, 288, 384, 512, 544, 576, 0}; +s32 D_800DDE74[] = { 96, 128, 192, 256, 288, 384, 512, 544, 576, 0, 0}; void render_players_on_screen_two(void) { gPlayersToRenderCount = 0; diff --git a/src/save.c b/src/save.c index 607e4b1a3..7fc5441ed 100644 --- a/src/save.c +++ b/src/save.c @@ -754,7 +754,7 @@ u8 func_800B60E8(s32 page) { u32 checksum = 0; u8* addr; - for (i = 0, addr = (u8*) &((u8*) D_800DC714)[page * 256]; i < 256; i++) { + for (i = 0, addr = (u8*) &((u8*) gReplayGhostCompressed)[page * 256]; i < 256; i++) { checksum += (*addr++ * (page + 1) + i); } return checksum; @@ -785,7 +785,7 @@ s32 func_800B6178(s32 arg0) { } } else { var_v0 = osPfsReadWriteFile(&gControllerPak1FileHandle, gControllerPak1FileNote, 1U, (arg0 * 0x3C00) + 0x100, - 0x00003C00, (u8*) D_800DC714); + 0x00003C00, (u8*) gReplayGhostCompressed); if (var_v0 == 0) { temp_s3->ghostDataSaved = 1; if (gGamestate == 4) { @@ -874,7 +874,7 @@ s32 func_800B64EC(s32 arg0) { } temp_v0 = osPfsReadWriteFile(&gControllerPak1FileHandle, gControllerPak1FileNote, PFS_READ, (arg0 * 0x3C00) + 0x100, - 0x3C00, (u8*) D_800DC714); + 0x3C00, (u8*) gReplayGhostCompressed); if (temp_v0 == 0) { // clang-format off phi_s1 = (u8 *) &D_8018EE10[arg0]; temp_s0 = 0; while (1) { @@ -912,7 +912,7 @@ s32 func_800B65F4(s32 arg0, s32 arg1) { return -1; } writeStatus = osPfsReadWriteFile(&gControllerPak2FileHandle, gControllerPak2FileNote, 0U, (arg0 * 0x3C00) + 0x100, - 0x00003C00, (u8*) D_800DC714); + 0x00003C00, (u8*) gReplayGhostCompressed); if (writeStatus == 0) { temp_s3 = &((struct_8018EE10_entry*) gSomeDLBuffer)[arg0]; for (i = 0; i < 0x3C; i++) { diff --git a/src/save.h b/src/save.h index 8983a9677..ec3e027bb 100644 --- a/src/save.h +++ b/src/save.h @@ -87,7 +87,7 @@ s32 func_800B6A68(void); /* data */ // these might not be in this file, but for now... -extern u32* D_800DC714; +extern u32* gReplayGhostCompressed; extern struct_8018EE10_entry D_8018EE10[]; extern u16 gCompanyCode; diff --git a/src/staff_ghosts.c b/src/staff_ghosts.c index f2fca0490..2287bc54a 100644 --- a/src/staff_ghosts.c +++ b/src/staff_ghosts.c @@ -17,14 +17,14 @@ #include "port/Game.h" #include "courses/staff_ghost_data.h" -u8* D_80162D80; -s16 D_80162D84; +u8* sReplayGhostBuffer; +s16 sReplayGhostBufferSize; s16 D_80162D86; u16 D_80162D88; u32 D_80162D8C; s16 D_80162D90; -u32* D_80162D94; +u32* sReplayGhostDecompressed; u16 D_80162D98; u32 D_80162D9C; @@ -59,8 +59,8 @@ s32 D_80162DFC; s32 D_80162E00; -u32* D_800DC710 = (u32*) &D_802BFB80.arraySize8[0][2][3]; -u32* D_800DC714 = (u32*) &D_802BFB80.arraySize8[1][1][3]; +u32* sReplayGhostEncoded = (u32*) &D_802BFB80.arraySize8[0][2][3]; +u32* gReplayGhostCompressed = (u32*) &D_802BFB80.arraySize8[1][1][3]; extern s32 gLapCountByPlayerId[]; @@ -71,8 +71,17 @@ void func_80004EF0(void) { u8* ghost = (u8*) D_80162DC4; + size_t size = 0; + if (ghost == d_luigi_raceway_staff_ghost) { + size = 187 * sizeof(StaffGhost); + } else if (ghost == d_mario_raceway_staff_ghost) { + size = 208 * sizeof(StaffGhost); + } else if (ghost == d_royal_raceway_staff_ghost) { + size = 377 * sizeof(StaffGhost); + } + // Manual memcpy required for byte swap - for (int i = 0; i < 0x4000; i += 4) { + for (int i = 0; i < size; i += 4) { dest[i] = ghost[i + 3]; dest[i + 1] = ghost[i + 2]; dest[i + 2] = ghost[i + 1]; @@ -91,8 +100,8 @@ void func_80004FB0(void) { } void func_80004FF8(void) { - D_80162D94 = (u32*) &D_802BFB80.arraySize8[0][D_80162DC8][3]; - D_80162D8C = (s32) *D_80162D94 & 0xFF0000; + sReplayGhostDecompressed = (u32*) &D_802BFB80.arraySize8[0][D_80162DC8][3]; + D_80162D8C = (s32) *sReplayGhostDecompressed & 0xFF0000; D_80162D90 = 0; } /** @@ -117,18 +126,18 @@ void set_staff_ghost(void) { s32 func_800051C4(void) { s32 phi_v0; - if (D_80162D84 != 0) { + if (sReplayGhostBufferSize != 0) { // func_80040174 in mio0_decode.s - func_80040174((void*) D_80162D80, (D_80162D84 * 4) + 0x20, (s32) D_800DC710); - phi_v0 = mio0encode((s32) D_800DC710, (D_80162D84 * 4) + 0x20, (s32) D_800DC714); + func_80040174((void*) sReplayGhostBuffer, (sReplayGhostBufferSize * 4) + 0x20, (s32) sReplayGhostEncoded); + phi_v0 = mio0encode((s32) sReplayGhostEncoded, (sReplayGhostBufferSize * 4) + 0x20, (s32) gReplayGhostCompressed); return phi_v0 + 0x1e; } } void func_8000522C(void) { - D_80162D94 = (u32*) &D_802BFB80.arraySize8[0][D_80162DC8][3]; - mio0decode((u8*) D_800DC714, (u8*) D_80162D94); - D_80162D8C = (s32) (*D_80162D94 & 0xFF0000); + sReplayGhostDecompressed = (u32*) &D_802BFB80.arraySize8[0][D_80162DC8][3]; + mio0decode((u8*) gReplayGhostCompressed, (u8*) sReplayGhostDecompressed); + D_80162D8C = (s32) (*sReplayGhostDecompressed & 0xFF0000); D_80162D90 = 0; D_80162E00 = 1; } @@ -144,8 +153,8 @@ void func_800052A4(void) { D_80162DCC = 0; } temp_v0 = D_80162DB8; - D_80162D80 = (void*) &D_802BFB80.arraySize8[0][D_80162DC8][3]; - D_80162D84 = temp_v0; + sReplayGhostBuffer = (void*) &D_802BFB80.arraySize8[0][D_80162DC8][3]; + sReplayGhostBufferSize = temp_v0; D_80162D86 = temp_v0; } @@ -320,7 +329,7 @@ void func_800057DC(void) { func_80005AE8(gPlayerTwo); return; } - temp_a0 = D_80162D94[D_80162D90]; + temp_a0 = sReplayGhostDecompressed[D_80162D90]; temp_v0 = temp_a0 & 0xFF; if (temp_v0 < 0x80U) { phi_v1 = (s16) (temp_v0 & 0xFF); @@ -362,7 +371,7 @@ void func_800057DC(void) { if (D_80162D8C == 0) { D_80162D90++; - D_80162D8C = (s32) (D_80162D94[D_80162D90] & 0xFF0000); + D_80162D8C = (s32) (sReplayGhostDecompressed[D_80162D90] & 0xFF0000); } else { D_80162D8C += (s32) 0xFFFF0000; } @@ -461,8 +470,8 @@ void func_80005B18(void) { func_80005AE8(gPlayerTwo); func_80005AE8(gPlayerThree); } else { - D_80162D80 = D_802BFB80.arraySize8[0][D_80162DC8][3].pixel_index_array; - D_80162D84 = D_80162D86; + sReplayGhostBuffer = D_802BFB80.arraySize8[0][D_80162DC8][3].pixel_index_array; + sReplayGhostBufferSize = D_80162D86; D_80162DD0 = D_80162DCC; D_80162DE8 = gPlayerOne->characterId; D_80162DD8 = 0; @@ -473,8 +482,8 @@ void func_80005B18(void) { } } else { if ((gLapCountByPlayerId[0] == 3) && (D_80162DDC == 0) && (D_80162DF8 == 1)) { - D_80162D80 = D_802BFB80.arraySize8[0][D_80162DC8][3].pixel_index_array; - D_80162D84 = D_80162D86; + sReplayGhostBuffer = D_802BFB80.arraySize8[0][D_80162DC8][3].pixel_index_array; + sReplayGhostBufferSize = D_80162D86; D_80162DDC = 1; } if ((gPlayerOne->type & 0x800) == 0x800) {