diff options
| author | Tyler McGavran <tyler.taggerung@gmail.com> | 2023-12-29 12:54:39 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-29 10:54:39 -0700 |
| commit | a38d338bf0f01774d756a8eeda3eecb5eb65535d (patch) | |
| tree | 10d2e37e5177ce283256708e2398711e21c5d560 /src/code_80005FD0.c | |
| parent | c89b4f6fe72ed46495562e03d6e52428570b31fc (diff) | |
Some matches in code_80005FD0 (#517)
Signed-off-by: Taggerung <tyler.taggerung@email.com>
Diffstat (limited to 'src/code_80005FD0.c')
| -rw-r--r-- | src/code_80005FD0.c | 1195 |
1 files changed, 480 insertions, 715 deletions
diff --git a/src/code_80005FD0.c b/src/code_80005FD0.c index 738fc62e2..66cb2b9ba 100644 --- a/src/code_80005FD0.c +++ b/src/code_80005FD0.c @@ -36,7 +36,7 @@ Collision D_80162E70; s16 D_80162EB0; // Possibly a float. s16 D_80162EB2; // possibly [3] -uintptr_t *D_80162EB8[20]; +UnkCommonTextureStruct0 *D_80162EB8[20]; // more padding? s32 D_80162F08[2]; @@ -67,7 +67,7 @@ s16 D_80163050[12]; f32 D_80163068[10]; f32 D_80163090[10]; s32 D_801630B8[10]; -s16 D_801630E0; +u16 D_801630E0; s16 D_801630E2; s16 D_801630E8[10]; s16 D_801630FC; @@ -81,21 +81,19 @@ s32 D_801631CC; TrackWaypoint *D_801631D0; TrackWaypoint *D_801631D4; s16 *D_801631D8; -u16 *D_801631DC; +s16 *D_801631DC; u16 D_801631E0[12]; -s16 D_801631F8[10]; +u16 D_801631F8[10]; f32 D_8016320C; f32 D_80163210[10]; s32 D_80163238; -s16 D_80163240[12]; +u16 D_80163240[12]; u16 D_80163258[12]; u16 D_80163270[12]; s32 D_80163288[10]; -// Exact pointer type unknown -// Maybe PathNoY or TrackWaypoint? -void *D_801632B0; -s16 D_801632B8[12]; -s16 D_801632D0[12]; +UnkCommonTextureStruct0 *D_801632B0; +u16 D_801632B8[12]; +u16 D_801632D0[12]; u16 D_801632E8[12]; s16 D_80163300[12]; u16 D_80163318[12]; @@ -103,7 +101,7 @@ u16 D_80163330[10]; u16 D_80163344[2]; u16 D_80163348[2]; u16 D_8016334C[2]; -s16 D_80163350[12]; +u16 D_80163350[12]; s32 D_80163368[4]; s32 D_80163378; s32 D_8016337C; @@ -209,7 +207,7 @@ s32 D_801646BC; // end padding s16 D_801646C0[4]; u32 D_801646C8; -s16 D_801646CC; +u16 D_801646CC; UnkStruct_46D0 D_801646D0[4]; // Strings, presented by google translate! @@ -1061,40 +1059,25 @@ void func_80007FA4(s32 arg0, Player *player, f32 arg2) { } } -#ifdef MIPS_TO_C -//generated by m2c commit beb457dabfc7a01ec6540a5404a6a05097a13602 on Nov-26-2023 -? func_80007D04(f32, s32, Player *, s32, Player *); /* extern */ -s32 func_800088D8(f32, s32, s16, s16, Player *); /* extern */ -extern ? D_80164392; -extern ? D_8016440A; - -void func_80008424(s32 arg0, f32 arg1, Player *player) { - f32 sp34; - s32 sp28; - s32 sp1C; - f32 temp_f2; +void func_80008424(s32 playerId, f32 arg1, Player *player) { + f32 var_f2; f32 var_f0; - f32 var_f12; - s32 temp_t5; - s32 temp_v0; - s32 temp_v0_2; - s32 temp_v0_4; + s32 thing; s32 var_a1; - u16 temp_v0_3; - u32 temp_v1; - - temp_v1 = player->effects; - var_f12 = arg1; - temp_f2 = player->unk_094; - if (!(temp_v1 & 0x80) && !(temp_v1 & 0x40) && !(temp_v1 & 0x20000) && (temp_v0 = player->statusEffects, !(temp_v0 & 0x400000)) && !(temp_v0 & 0x01000000) && !(temp_v0 & 2) && !(temp_v0 & 4)) { - if (gCurrentCourseId == 0x0014) { - func_80007FA4(arg0, player, temp_f2); - return; - } - temp_t5 = arg0 * 2; - if ((D_801634D8[arg0] == (s16) 1) && !(temp_v1 & 0x80000200)) { + + var_f2 = player->unk_094; + if (!(player->effects & 0x80) && + !(player->effects & 0x40) && + !(player->effects & 0x20000) && + !(player->statusEffects & 0x400000) && + !(player->statusEffects & 0x01000000) && + !(player->statusEffects & 2) && + !(player->statusEffects & 4)) { + if (gCurrentCourseId == COURSE_AWARD_CEREMONY) { + func_80007FA4(playerId, player, var_f2); + } else if ((D_801634D8[playerId] == 1) && !(player->effects & 0x80000200)) { func_80031F48(player, 10.0f); - if ((f64) player->currentSpeed == 0.0) { + if (player->currentSpeed == 0.0) { player->velocity[0] = 0.0f; player->velocity[2] = 0.0f; } @@ -1111,101 +1094,76 @@ void func_80008424(s32 arg0, f32 arg1, Player *player) { var_f0 = 3.75f; break; } - if (temp_f2 < var_f0) { - player->effects = temp_v1 & 0xFFDFFFFF; + if (var_f2 < var_f0) { + player->effects &= ~0x00200000; player_speed(player); - return; - } - if (player->type & 0x800) { - if (temp_f2 < var_f12) { - player->effects = temp_v1 & 0xFFDFFFFF; + } else if (player->type & 0x800) { + if (var_f2 < arg1) { + player->effects &= ~0x00200000; player_speed(player); - return; + } else { + player->effects &= ~0x00200000; + func_80031F48(player, 1.0f); } - player->effects = temp_v1 & 0xFFDFFFFF; - func_80031F48(player, 1.0f); - return; - } - if ((D_801631E0[arg0] == (u16) 1) && (D_80163330[arg0] != (u16) 1)) { - temp_v0_2 = arg0 * 4; - if (func_800088D8(var_f12, arg0, *(&D_80164392 + temp_v0_2), *(&D_8016440A + temp_v0_2), player) == 1) { + } else if ((D_801631E0[playerId] == 1) && (D_80163330[playerId] != 1)) { + if (func_800088D8(playerId, gLapCountByPlayerId[playerId], D_80164408[playerId]) == 1) { player->effects |= 0x200000; player_speed(player); - return; + } else { + player->effects &= ~0x00200000; + func_80031F48(player, 1.0f); } - player->effects &= 0xFFDFFFFF; - func_80031F48(player, 1.0f); - return; - } - temp_v0_3 = (u16) D_80163350[arg0]; - switch (temp_v0_3) { /* switch 1; irregular */ - case 1: /* switch 1 */ - player->effects = temp_v1 & 0xFFDFFFFF; - sp34 = temp_f2; - sp1C = temp_t5; - sp28 = 1; - player_speed(player); - var_a1 = 1; - var_f12 = arg1; - break; - case 3: /* switch 1 */ - player->effects = temp_v1 | 0x200000; - sp34 = temp_f2; - sp1C = temp_t5; - sp28 = 1; - player_speed(player); + } else { var_a1 = 1; - var_f12 = arg1; - break; - case 2: /* switch 1 */ - if (((temp_f2 / 18.0f) * 216.0f) > 20.0f) { - var_f12 = 1.6666666f; - } - /* fallthrough */ - default: /* switch 1 */ - case 0: /* switch 1 */ - var_a1 = 0; - break; - } - if (var_a1 != 1) { - if (temp_f2 < var_f12) { - if ((gDemoMode == (u16) 1) && (gCurrentCourseId != 0x0014)) { - player_speed(player); - return; - } - temp_v0_4 = arg0 * 4; - if (D_80163330[arg0] == (u16) 1) { - func_80007D04(var_f12, arg0, player, temp_t5, player); - return; - } - if (func_800088D8(var_f12, arg0, *(&D_80164392 + temp_v0_4), *(&D_8016440A + temp_v0_4), player) == 1) { - player->effects |= 0x200000; - player_speed(player); - return; + switch (D_80163350[playerId]) { /* switch 1; irregular */ + case 1: /* switch 1 */ + player->effects &= ~0x00200000; + player_speed(player); + break; + case 3: /* switch 1 */ + player->effects |= 0x200000; + player_speed(player); + break; + case 2: /* switch 1 */ + if (((var_f2 / 18.0f) * 216.0f) > 20.0f) { + arg1 = 1.6666666f; } - player->effects &= 0xFFDFFFFF; - func_80031F48(player, 1.0f); - return; + var_a1 = 0; + break; + case 0: /* switch 1 */ + default: /* switch 1 */ + var_a1 = 0; + break; } - player->effects &= 0xFFDFFFFF; - if (var_f12 > 1.0f) { - func_80031F48(player, 2.0f); - return; + if (var_a1 != 1) { + if (var_f2 < arg1) { + if ((gDemoMode == 1) && (gCurrentCourseId != 0x0014)) { + player_speed(player); + }else if (D_80163330[playerId] == 1) { + func_80007D04(playerId, player); + } else if (func_800088D8(playerId, gLapCountByPlayerId[playerId], D_80164408[playerId]) == 1) { + player->effects |= 0x200000; + player_speed(player); + } else { + player->effects &= ~0x00200000; + func_80031F48(player, 1.0f); + } + } else { + player->effects &= ~0x00200000; + if (arg1 > 1.0f) { + func_80031F48(player, 2.0f); + } else { + func_80031F48(player, 5.0f); + } + } } - func_80031F48(player, 5.0f); } } } } -#else -GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_80008424.s") -#endif #ifdef MIPS_TO_C -//generated by m2c commit beb457dabfc7a01ec6540a5404a6a05097a13602 on Nov-26-2023 -extern ? D_80164376; -extern s16 D_80164386; -extern ? D_801643BA; +//generated by m2c commit beb457dabfc7a01ec6540a5404a6a05097a13602 on Dec-26-2023 static ? D_800DCAF4; /* unable to generate initializer */ static ? D_800DCB34; /* unable to generate initializer */ static ? *D_800DCBB4[0x15] = { @@ -1288,7 +1246,7 @@ s32 func_800088D8(s32 arg0, s16 arg1, s16 arg2) { temp_a3 = D_800DCBB4[gCurrentCourseId] + (temp_t2 * 2); if (arg2 == 0) { if (gDemoMode == (u16) 1) { - temp_a2 = D_80164450[arg0].unk2 - D_80164450[D_80164386].unk2; + temp_a2 = D_80164450[arg0].unk2 - D_80164450[*(D_80164378 + 0xE)].unk2; var_a1_2 = temp_a2; if (temp_a2 < 0) { var_a1_2 = -temp_a2; @@ -1305,11 +1263,11 @@ s32 func_800088D8(s32 arg0, s16 arg1, s16 arg2) { } return 1; } - temp_v0 = D_80164450[arg0 + 1]; - var_a1_3 = temp_v0 - D_80164450[D_80163478 + 1]; - temp_t5_2 = gGPCurrentRaceRankByPlayerId[D_80163478]; + temp_v0 = D_80164450[arg0].unk2; + var_a1_3 = temp_v0 - D_80164450[D_80163478].unk2; + temp_t5_2 = *(gGPCurrentRaceRankByPlayerId + 2 + (D_80163478 * 4)); if ((((s32) (*gWaypointCountByPathIndex * 2) / 3) < var_a1_3) && (temp_t5_2 >= 6)) { - var_a1_3 = temp_v0 - D_80164450[gLapCountByPlayerId[temp_t5_2 - 6]].unk2; + var_a1_3 = temp_v0 - D_80164450[*(gLapCountByPlayerId - 0x1A + (temp_t5_2 * 2))].unk2; } if (var_a1_3 < 0) { var_a1_3 = -var_a1_3; @@ -1497,25 +1455,16 @@ f32 func_80009258(UNUSED s32 playerId, f32 arg1, f32 arg2) { } #ifdef MIPS_TO_C -//generated by m2c commit beb457dabfc7a01ec6540a5404a6a05097a13602 on Nov-27-2023 -? func_800065D0(s32, Player *, s32 *); /* extern */ -extern s16 D_801630E0; -extern s16 D_801630E2; -extern ? D_80163240; -extern ? D_801642DE; -extern ? D_801643B0; -extern s32 D_8016440C; - +//generated by m2c commit beb457dabfc7a01ec6540a5404a6a05097a13602 on Dec-28-2023 void func_8000929C(s32 playerId, Player *player) { f32 sp4C; f32 sp44; f32 sp38; s16 sp34; u16 *sp30; /* compiler-managed */ - s16 *sp2C; + u16 *sp2C; f32 temp_f0; f32 temp_f12; - s16 *temp_v1; s16 temp_a3; s16 var_t0; s32 *temp_v0; @@ -1529,13 +1478,14 @@ void func_8000929C(s32 playerId, Player *player) { s32 var_a3; s32 var_v1; u16 *temp_t0; + u16 *temp_v1; u16 temp_v0_3; u16 temp_v0_4; temp_f0 = player->pos[2]; temp_f12 = player->pos[0]; D_801630E2 = 0; - temp_v1 = (playerId * 2) + &D_80163240; + temp_v1 = &D_80163240[playerId]; *temp_v1 = 0; temp_t0 = &gNearestWaypointByPlayerId[playerId]; sp30 = temp_t0; @@ -1544,7 +1494,7 @@ void func_8000929C(s32 playerId, Player *player) { sp4C = temp_f12; D_80162FCE = func_8000CD24(temp_f12, player->pos[1], temp_f0, (s16) *temp_t0, player, playerId, D_80163448); temp_a3 = D_80162FCE; - D_801630E0 = temp_a3; + D_801630E0 = (u16) temp_a3; if (temp_a3 != *temp_t0) { *temp_t0 = (u16) temp_a3; D_801630E2 = 1; @@ -1613,7 +1563,7 @@ block_25: var_v0->unk-8 = (s32) (temp_t9 - 1); var_v0->unk-C = (s32) (temp_t7 - 1); var_v0->unk-10 = (s32) (temp_t5 - 1); - } while (var_v0 != &D_801643B0); + } while (var_v0 != (gLapCountByPlayerId + 0x20)); } } *sp2C = 1; @@ -1621,7 +1571,7 @@ block_25: sp30 = var_a3; func_80008F38(playerId); func_80011AE4(playerId); - *(&D_801642DE + (playerId * 0x10)) = 0; + *(&D_801642D8->unk_06 + (playerId * 0x10)) = 0; if ((D_8016348C == 0) && !(player->type & 0x800)) { sp30 = var_a3; sp34 = var_t0; @@ -1643,9 +1593,9 @@ block_25: } temp_v0_4 = player->type; if ((temp_v0_4 & 0x4000) && !(temp_v0_4 & 0x1000)) { - func_800065D0(playerId, player, &D_80163448); + func_800065D0(playerId, player); if ((gModeSelection == 0) && (gPlayerCount == 2) && (playerId == 0)) { - if (*D_80164408 < D_8016440C) { + if (*D_80164408 < *(D_80164408 + 4)) { D_80163478 = 0; } else { D_80163478 = 1; @@ -1738,7 +1688,7 @@ block_15: GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_800098FC.s") #endif -void func_800099EC(s32 playerId, s32 unused) { +void func_800099EC(s32 playerId, Player *unused) { s32 var_s0; if (D_801633C8[playerId] >= 0x65) { @@ -1762,189 +1712,120 @@ void func_800099EC(s32 playerId, s32 unused) { } } -#ifdef MIPS_TO_C -//generated by m2c commit beb457dabfc7a01ec6540a5404a6a05097a13602 on Nov-28-2023 -? func_80008424(s32, f32, Player *); /* extern */ -? func_8000929C(s32, Player *); /* extern */ -? func_8000D438(s32, u16); /* extern */ -extern s16 D_80162FD0; -extern u16 D_801630E0; -extern s16 D_801630E2; -extern f32 D_8016320C; -extern ? D_80163240; -extern ? D_80163300; -extern ? D_801633E0; -extern s16 D_8016344A; -extern ? D_801634FC; -extern ? D_80163504; -static s16 D_800DCA20[0]; /* unable to generate initializer */ -f32 D_800DCA4C[0x15] = { - 50.0f, - 35.0f, - 35.0f, - 40.0f, - 35.0f, - 50.0f, - 50.0f, - 50.0f, - 50.0f, - 50.0f, - 50.0f, - 50.0f, - 50.0f, - 50.0f, - 50.0f, - -1.0f, - -1.0f, - -1.0f, - 40.0f, - -1.0f, - 40.0f, -}; +#ifdef NON_MATCHING +#define FAKEMATCH1 0 +#define FAKEMATCH2 0 +// https://decomp.me/scratch/uJCh3 +// Lots of register allocation differences, but messing around seems to suggest they stem from 2 specific areas +// MISMATCH1: something about the loading of `playerId` is off +// MISMATCH2: something about the handling of the math is off. Not sure exactly what though +// MISMATCH3: there's a small instruction ordering issue concerning `D_8015F6F0`. No idea what to do about it +// FAKEMATCH1 is the best improvement I've seen yet, MISMATCH2/3 become the only issues. void func_80009B60(s32 playerId) { - s16 sp94; - Player *sp40; - f32 *sp3C; - s32 sp38; - s32 sp34; /* compiler-managed */ - s32 sp30; /* compiler-managed */ - u16 *sp2C; - f32 *sp28; - u16 *sp24; - u16 *sp20; - f32 *sp1C; - Player *temp_v1; - Test *temp_v1_2; - Test *temp_v1_3; - Test *temp_v1_6; - f32 *temp_a2_2; - f32 *temp_v0_9; - f32 *temp_v1_5; - f32 *temp_v1_7; - f32 *var_t0; - f32 *var_t0_2; - f32 *var_v0_2; - f32 *var_v1_3; - f32 temp_f0; - f32 temp_f0_2; - f32 temp_f0_3; - f32 temp_f0_4; - f32 temp_f0_5; - f32 temp_f2; - f32 temp_f2_2; - s16 *temp_v0_2; - s16 *temp_v1_4; - s16 temp_v0_10; - s16 temp_v0_12; - s16 temp_v0_13; - s16 temp_v0_14; - s16 temp_v0_3; - s16 temp_v0_5; - s16 temp_v0_6; - s16 temp_v0_7; - s16 temp_v1_8; + s32 stackPadding00; + s32 stackPadding01; + s32 stackPadding02; + s32 stackPadding03; + s32 stackPadding04; + s32 stackPadding05; + s32 stackPadding06; + s32 stackPadding07; + s32 stackPadding08; + s32 stackPadding09; + s32 stackPadding0A; + s32 stackPadding0B; + s32 stackPadding0C; + s32 stackPadding0D; s16 var_a0_2; s16 var_a1; - s16 var_a1_2; + s32 stackPadding0E; + s32 stackPadding0F; + s32 stackPadding10; + s32 stackPadding11; + s32 stackPadding12; + s32 stackPadding13; + s32 stackPadding14; + s32 stackPadding15; + s32 stackPadding16; + s32 stackPadding17; + s32 stackPadding18; + u16 stackPadding19; + u16 stackPadding1A; + f32 temp_f0; + f32 temp_f2; s16 var_a2; - s16 var_v0; s16 var_v1; - s16 var_v1_2; - s32 *temp_v0; - s32 temp_a1_2; - s32 temp_a2; - s32 temp_f10; s32 temp_f6; - s32 temp_t5; - s32 temp_t6; - u16 *temp_a1; - u16 *temp_a3; - u16 *temp_t0; - u16 *temp_t0_2; - u16 *temp_t6_2; - u16 *temp_t8; - u16 temp_a0; - u16 var_a0; - u32 temp_v0_11; - u32 temp_v0_4; - void *temp_v0_8; + Player *player; + TrackWaypoint *waypoint; + f32 athing = 1.5f; - temp_v0 = &D_80163100[playerId]; + player = &gPlayers[playerId]; if ((s32) D_800DCA4C[gCurrentCourseId] >= 0) { - *temp_v0 += 1; + D_80163100[playerId] += 1; if (playerId == 0) { - temp_t6 = D_80163378 + 1; - D_80163378 = temp_t6; - if (temp_t6 & 1) { + D_80163378++; + if (D_80163378 & 1) { D_80163488 += 1; } } - temp_v1 = &gPlayers[playerId]; - temp_a2 = playerId * 2; - if (!(temp_v1->type & 0x8000)) { + if (!(player->type & 0x8000)) { D_80164450[playerId] = -0x00000014; gCourseCompletionPercentByPlayerId[playerId] = -1000.0f; gLapCompletionPercentByPlayerId[playerId] = -1000.0f; return; } - temp_v0_2 = temp_a2 + &D_801633E0; - *temp_v0_2 = 0; - if (temp_v1->pos[0] < (f32) D_8015F6EA) { - *temp_v0_2 = 1; + D_801633E0[playerId] = 0; + if (player->pos[0] < D_8015F6EA) { + D_801633E0[playerId] = 1; } - if ((f32) D_8015F6E8 < temp_v1->pos[0]) { - *temp_v0_2 = 2; + if (D_8015F6E8 < player->pos[0]) { + D_801633E0[playerId] = 2; } - if (temp_v1->pos[2] < (f32) D_8015F6F2) { - *temp_v0_2 = 3; + if (player->pos[2] < D_8015F6F2) { + D_801633E0[playerId] = 3; } - if ((f32) D_8015F6F0 < temp_v1->pos[2]) { - *temp_v0_2 = 4; + // MISMATCH3 + if (D_8015F6F0 < player->pos[2]) { + D_801633E0[playerId] = 4; } - temp_v0_3 = temp_v1->unk_0CA; - if (!(temp_v0_3 & 2) && !(temp_v0_3 & 8)) { - temp_a0 = gPathIndexByPlayerId[playerId]; - sp40 = temp_v1; - sp34 = temp_a2; - sp38 = playerId * 4; - D_80163448 = (s32) temp_a0; - func_80008DC0((s32) temp_a0); + if (!(player->unk_0CA & 2) && !(player->unk_0CA & 8)) { + D_80163448 = gPathIndexByPlayerId[playerId]; + func_80008DC0(D_80163448); switch (gCurrentCourseId) { /* irregular */ case 11: - func_80012DC0(playerId, sp40); + func_80012DC0(playerId, player); if (playerId == 0) { func_80013054(); } break; case 18: - func_80013854(sp40); + func_80013854(player); break; case 10: - func_800148C4(playerId, sp40); - func_80014A18(playerId, sp40); - func_80014B6C(playerId, sp40); - func_80014CC0(playerId, sp40); + func_800148C4(playerId, player); + func_80014A18(playerId, player); + func_80014B6C(playerId, player); + func_80014CC0(playerId, player); break; } - if (sp40->type & 0x800) { - sp40->effects &= 0xFFBFFFFF; - sp40->unk_044 &= 0xFFFE; + if (player->type & 0x800) { + player->effects &= ~0x00400000; + player->unk_044 &= ~0x0001; } - func_8000929C(playerId, sp40); - if ((gCurrentCourseId != 0x0014) && ((*(&D_80163240 + sp34) == 1) || (playerId == 0))) { + func_8000929C(playerId, player); + if ((gCurrentCourseId != 0x0014) && ((D_80163240[playerId] == 1) || (playerId == 0))) { set_places(); } - if (sp40->type & 0x1000) { + if (player->type & 0x1000) { if ((D_801630E2 == 1) && (gCurrentCourseId != 0x0014)) { func_80011E38(playerId); } - temp_t5 = playerId & 1; - sp30 = temp_t5; - if ((D_80163378 & 1) != temp_t5) { + if ((playerId & 1) != (D_80163378 & 1)) { func_8001AC10(playerId); } - func_800099EC(playerId, (s32) sp40); + func_800099EC(playerId, player); D_80162FD0 = 0; switch (gModeSelection) { /* switch 1; irregular */ case 1: /* switch 1 */ @@ -1954,313 +1835,272 @@ void func_80009B60(s32 playerId) { case 0: /* switch 1 */ break; } - temp_a1 = sp34 + D_801631E0; - *temp_a1 = 0; - if ((sp40->effects & 0x1000) && (gCurrentCourseId != 0x0014)) { - *temp_a1 = 1; + D_801631E0[playerId] = 0; + if ((player->effects & 0x1000) && (gCurrentCourseId != 0x0014)) { + D_801631E0[playerId] = 1; } - if (((u16) D_801646CC == 1) || (sp40->type & 0x800) || (gCurrentCourseId == 0x0014)) { + if ((D_801646CC == 1) || (player->type & 0x800) || (gCurrentCourseId == 0x0014)) { if (gCurrentCourseId != 0x000A) { - *(&D_801634FC + (playerId * 0x10)) = 0.0f; + D_801634F8[playerId].unk4 = 0.0f; } - *(&D_80163504 + (playerId * 0x10)) = 0.0f; + D_801634F8[playerId].unkC = 0.0f; } if (D_80163448 > 0) { - temp_v1_2 = &D_801634F8[playerId]; - temp_v1_2->unk4 = 0.0f; - temp_v1_2->unkC = 0.0f; + D_801634F8[playerId].unk4 = 0.0f; + D_801634F8[playerId].unkC = 0.0f; } - temp_t6_2 = sp34 + gNearestWaypointByPlayerId; - sp24 = temp_t6_2; - temp_a2_2 = sp38 + D_80164510; - temp_a3 = sp34 + D_801631F8; - *temp_a2_2 = (f32) D_80164550[D_80163448][*temp_t6_2].posY + 4.3f; - if ((*temp_a3 == 1) && (*temp_a1 == 0)) { - sp2C = temp_a1; - sp28 = temp_a2_2; - sp20 = temp_a3; - func_8002E4C4(sp40); + // gNearestWaypointByPlayerId[playerId] might need to be saved to a temp + D_80164510[playerId] = D_80164550[D_80163448][gNearestWaypointByPlayerId[playerId]].posY + 4.3f; + if ((D_801631F8[playerId] == 1) && (D_801631E0[playerId] == 0)) { + func_8002E4C4(player); } - if (*temp_a1 == 1) { - sp40->pos[1] = *temp_a2_2; + if (D_801631E0[playerId] == 1) { + player->pos[1] = D_80164510[playerId]; } - *temp_a3 = *temp_a1; - if (gCurrentCourseId != 4) { - if (gCurrentCourseId != 0x000A) { - var_a0 = *temp_a1; - if (gCurrentCourseId != 0x0014) { - - } else { - goto block_63; - } - } else { - sp2C = temp_a1; - func_8001490C(playerId); - func_80014A60(playerId); - func_80014BB4(playerId); - func_80014D08(playerId); - var_a0 = *temp_a1; - } - } else { - var_a0 = *temp_a1; -block_63: - *(&D_801634FC + (playerId * 0x10)) = 0.0f; + D_801631F8[playerId] = D_801631E0[playerId]; + switch (gCurrentCourseId) { + case 4: + case 0x0014: + D_801634F8[playerId].unk4 = 0.0f; + break; + default: + break; + case 10: + func_8001490C(playerId); + func_80014A60(playerId); + func_80014BB4(playerId); + func_80014D08(playerId); + break; } - if (var_a0 == 1) { - *(D_801630E8 + sp34) = 0; - sp40->effects &= ~0x10; - if ((D_80163378 & 1) != sp30) { - func_8003680C(sp40, 0); - func_80008424(playerId, *(D_80163210 + sp38), sp40); + if (D_801631E0[playerId] == 1) { + D_801630E8[playerId] = 0; + player->effects &= ~0x10; + if ((playerId & 1) != (D_80163378 & 1)) { + func_8003680C(player, 0); + func_80008424(playerId, D_80163210[playerId], player); return; } - if ((gPlayerCount > 0) && (gPlayerCount < 3) && (*(D_80163330 + sp34) == 1) && ((s32) *(D_8016334C + sp34) < *(gGPCurrentRaceRankByPlayerId + sp38))) { - var_t0 = sp38 + D_80163210; - *var_t0 = 8.333333f; + if ((gPlayerCount > 0) && (gPlayerCount < 3) && (D_80163330[playerId] == 1) && (D_8016334C[playerId] < gGPCurrentRaceRankByPlayerId[playerId])) { + D_80163210[playerId] = 8.333333f; } else if (D_80162FD0 == (s16) 1U) { - temp_v1_3 = &D_801634F8[playerId]; - sp30 = temp_v1_3; - var_t0 = sp38 + D_80163210; - *var_t0 = *segmented_to_virtual_dupe_2((gCurrentCourseId * 0x10) + (gCCSelection * 4) + D_0D0096B8); - temp_v1_3->unk4 = -0.5f; + D_80163210[playerId] = *(f32*)segmented_to_virtual_dupe_2(&D_0D0096B8[gCurrentCourseId][gCCSelection]); + D_801634F8[playerId].unk4 = -0.5f; } else if (D_801645E0[D_80162FCE] > 0) { - var_t0 = sp38 + D_80163210; - *var_t0 = *segmented_to_virtual_dupe_2((gCurrentCourseId * 0x10) + (gCCSelection * 4) + D_0D009418); + D_80163210[playerId] = *(f32*)segmented_to_virtual_dupe_2(&D_0D009418[gCurrentCourseId][gCCSelection]); } else { - var_t0 = sp38 + D_80163210; - *var_t0 = *segmented_to_virtual_dupe_2((gCurrentCourseId * 0x10) + (gCCSelection * 4) + D_0D009568); + D_80163210[playerId] = *(f32*)segmented_to_virtual_dupe_2(&D_0D009568[gCurrentCourseId][gCCSelection]); } - sp3C = var_t0; func_800131DC(playerId); func_8000D3B8(playerId); func_8000D438(playerId, D_801630E0); - temp_v0_4 = sp40->effects; - temp_f0 = D_80162FA0->unk0 - sp40->pos[0]; - var_t0_2 = var_t0; - temp_f2 = D_80162FA0->unk8 - sp40->pos[2]; - if (!(temp_v0_4 & 0x80) && !(temp_v0_4 & 0x40) && !(temp_v0_4 & 0x800)) { + temp_f0 = D_80162FA0[0] - player->pos[0]; + temp_f2 = D_80162FA0[2] - player->pos[2]; + if (!(player->effects & 0x80) && !(player->effects & 0x40) && !(player->effects & 0x800)) { if (((temp_f0 * temp_f0) + (temp_f2 * temp_f2)) > 6400.0f) { if (D_80163448 == 0) { - sp3C = var_t0_2; func_8000B140(playerId); - if (*(D_80162FF8 + sp34) > 0) { - sp3C = var_t0_2; - func_8000BBD8(((s32) ((D_801630E0 + 5) & 0xFFFF) % (s32) D_80164430) & 0xFFFF, *(D_80163090 + sp38), D_8016344A); + if (D_80162FF8[playerId] > 0) { + stackPadding1A = D_801630E0 + 5; + stackPadding1A %= D_80164430; + func_8000BBD8(stackPadding1A, D_80163090[playerId], D_80163448); } } - sp3C = var_t0_2; - sp40->unk_02C[1] = -get_angle_between_points(sp40->pos, D_80162FA0); + player->unk_02C[1] = -get_angle_between_points(player->pos, D_80162FA0); } else { - sp40->unk_02C[1] = D_80164590[D_80163448][(s32) (D_801630E0 + 4) % (s32) D_80164430]; + player->unk_02C[1] = D_80164590[D_80163448][(D_801630E0 + 4) % D_80164430]; } } - sp3C = var_t0_2; - func_8003680C(sp40, 0); - func_80008424(playerId, *var_t0_2, sp40); + func_8003680C(player, 0); + func_80008424(playerId, D_80163210[playerId], player); return; } - temp_t8 = sp34 + D_801630E8; - sp2C = temp_t8; - var_v0 = *temp_t8; - if ((var_v0 == (s16) 1U) || (var_v0 == -1)) { - sp40->effects |= 0x10; - var_v0 = (s16) *sp2C; + if ((D_801630E8[playerId] == 1) || (D_801630E8[playerId] == -1)) { + player->effects |= 0x10; } - if (var_v0 != 0) { - temp_v1_4 = sp34 + &D_80163300; - *temp_v1_4 = -get_angle_between_points(&sp40->rotX, sp40->pos); - var_a0_2 = (s16) ((s32) ((s16) D_801631DC[(s32) (D_80162FCE + 2) % (s32) D_80164430] * 0x168) / 65535); - var_a1 = (s16) ((s32) (*temp_v1_4 * 0x168) / 65535); + if (D_801630E8[playerId] != 0) { + D_80163300[playerId] = -get_angle_between_points(&player->rotX, player->pos); + var_a0_2 = (D_801631DC[(D_80162FCE + 2) % D_80164430] * 0x168) / 65535; + var_a1 = (D_80163300[playerId] * 0x168) / 65535; if (var_a0_2 < -0xB4) { var_a0_2 += 0x168; } - if (var_a0_2 >= 0xB5) { + if (var_a0_2 > 0xB4) { var_a0_2 -= 0x168; } if (var_a1 < -0xB4) { var_a1 += 0x168; } - if (var_a1 >= 0xB5) { + if (var_a1 > 0xB4) { var_a1 -= 0x168; } - temp_v0_5 = var_a0_2 - var_a1; - var_v1 = temp_v0_5; - if (temp_v0_5 < -0xB4) { - var_v1 = temp_v0_5 + 0x168; + var_v1 = var_a0_2 - var_a1; + if (var_v1 < -0xB4) { + var_v1 += 0x168; } - if (var_v1 >= 0xB5) { + if (var_v1 > 0xB4) { var_v1 -= 0x168; } - temp_v0_6 = (s16) *sp2C; - switch (temp_v0_6) { /* switch 2; irregular */ - case -1: /* switch 2 */ - if (var_v1 >= 6) { - *sp2C = 0; - sp40->effects &= ~0x10; + switch (D_801630E8[playerId]) { + case -1: + if (var_v1 > 5) { + D_801630E8[playerId] = 0; + player->effects &= ~0x10; } break; - case 1: /* switch 2 */ + case 1: if (var_v1 < -5) { - *sp2C = 0; - sp40->effects &= ~0x10; + D_801630E8[playerId] = 0; + player->effects &= ~0x10; } break; + default: + break; } } - if ((D_80163378 & 1) != sp30) { - func_8003680C(sp40, *(D_80163050 + sp34)); - func_80008424(playerId, *(D_80163210 + sp38), sp40); + // MISMATCH1 +#if FAKEMATCH2 == 1 + stackPadding00 = (playerId & 1) != (D_80163378 & 1); + if (stackPadding00) { +#else + if ((playerId & 1) != (D_80163378 & 1)) { +#endif + func_8003680C(player, D_80163050[playerId]); + func_80008424(playerId, D_80163210[playerId], player); return; } - sp1C = sp40->pos; - temp_v1_5 = sp38 + D_801630B8; - *temp_v1_5 = func_8000B7E4(playerId, (u16) D_80162FCE); - sp28 = temp_v1_5; - func_8000D438(playerId, (u16) D_80162FCE); + D_801630B8[playerId] = func_8000B7E4(playerId, D_80162FCE); + func_8000D438(playerId, D_80162FCE); if (gCurrentCourseId != 0x0014) { - temp_a1_2 = *(D_80164450 + sp38); - if (temp_a1_2 < 0xB) { - temp_v1_6 = &D_801634F8[playerId]; - if ((temp_a1_2 > 0) && (gCurrentCourseId == 0x000A)) { - sp30 = temp_v1_6; - func_8000BBD8(((s32) ((D_801630E0 + 0x14) & 0xFFFF) % (s32) D_80164430) & 0xFFFF, 0.0f, 0); - temp_v1_6->unk4 = 0.0f; + if (D_80164450[playerId] < 0xB) { + stackPadding1A = D_801630E0; + if ((D_80164450[playerId] > 0) && (gCurrentCourseId == 0x000A)) { + stackPadding1A += 0x14; + stackPadding1A %= D_80164430; + func_8000BBD8(stackPadding1A, 0.0f, 0); + D_801634F8[playerId].unk4 = 0.0f; } else { - temp_t0 = sp38 + D_80163068; - sp20 = temp_t0; - sp30 = temp_v1_6; - func_8000BBD8(((s32) ((D_801630E0 + 8) & 0xFFFF) % (s32) D_80164430) & 0xFFFF, *temp_t0, D_8016344A); - temp_v1_6->unk0 = *temp_t0; + stackPadding1A += 8; + stackPadding1A %= D_80164430; + func_8000BBD8(stackPadding1A, D_80163068[playerId], D_80163448); + D_801634F8[playerId].unk0 = D_80163068[playerId]; } } - if ((D_80162FD0 == 1) && (*(D_80162FF8 + sp34) == 0)) { - func_8000BBD8(((s32) ((D_801630E0 + 7) & 0xFFFF) % (s32) D_80164430) & 0xFFFF, -0.7f, D_8016344A); + if ((D_80162FD0 == 1) && (D_80162FF8[playerId] == 0)) { + stackPadding1A = D_801630E0 + 7; + stackPadding1A %= D_80164430; + func_8000BBD8(stackPadding1A, -0.7f, D_80163448); } if (D_80163448 == 0) { - sp3C = sp34 + D_80162FF8; func_8000B140(playerId); - if (*sp3C > 0) { - func_8000BBD8(((s32) ((D_801630E0 + 5) & 0xFFFF) % (s32) D_80164430) & 0xFFFF, *(D_80163090 + sp38), D_8016344A); + if (D_80162FF8[playerId] > 0) { + stackPadding1A = D_801630E0 + 5; +#if FAKEMATCH1 == 1 + if (1) { } if (1) { } if (1) { } if (1) { } if (1) { } if (1) { } +#endif + stackPadding1A %= D_80164430; + func_8000BBD8(stackPadding1A, D_80163090[playerId], D_80163448); } } } - temp_t0_2 = sp38 + D_80163068; if (gCurrentCourseId == 0x0014) { - temp_v0_7 = *(D_80163410 + sp34); - switch (temp_v0_7) { /* switch 3; irregular */ + switch (D_80163410[playerId]) { /* switch 3; irregular */ case 3: /* switch 3 */ - D_80162FA0->unk0 = *(D_80163418 + sp38); - D_80162FA0->unk8 = (f32) *(D_80163438 + sp38); + D_80162FA0[0] = D_80163418[playerId]; + D_80162FA0[2] = D_80163438[playerId]; break; case 4: /* switch 3 */ - temp_v0_8 = (((s32) (*sp24 + 0xA) % (s32) *(gWaypointCountByPathIndex + sp34)) * 8) + *(D_80164550 + sp38); - D_80162FA0->unk0 = (f32) temp_v0_8->unk0; - D_80162FA0->unk8 = (f32) temp_v0_8->unk4; + waypoint = &D_80164550[playerId][(gNearestWaypointByPlayerId[playerId] + 0xA) % gWaypointCountByPathIndex[playerId]]; + D_80162FA0[0] = waypoint->posX; + D_80162FA0[2] = waypoint->posZ; break; } } - temp_v0_9 = sp38 + D_80163178; - temp_v1_7 = sp38 + D_801631A0; - D_80162FA0->unk0 = (D_80162FA0->unk0 + *temp_v0_9) * 0.5f; - D_80162FA0->unk8 = (f32) ((D_80162FA0->unk8 + *temp_v1_7) * 0.5f); - *temp_v0_9 = D_80162FA0->unk0; - sp20 = temp_t0_2; - *temp_v1_7 = D_80162FA0->unk8; - temp_f2_2 = 1.5f * 182.0f; - temp_v1_8 = -get_angle_between_points(sp1C, D_80162FA0) - sp40->unk_02C[1]; - temp_f10 = (s32) temp_f2_2; - var_a2 = temp_v1_8; - temp_f6 = (s32) (-1.5f * 182.0f); - if ((s16) temp_f10 < temp_v1_8) { - var_a2 = (s16) temp_f10; + D_80162FA0[0] = (D_80163178[playerId] + D_80162FA0[0]) * 0.5f; + D_80162FA0[2] = (D_801631A0[playerId] + D_80162FA0[2]) * 0.5f; + D_80163178[playerId] = D_80162FA0[0]; + D_801631A0[playerId] = D_80162FA0[2]; + temp_f2 = athing * 182.0f; + temp_f6 = -athing * 182.0f; + // MISMATCH2 + // This fixes part of the register allocation problems, makes fixing others + // harder though. Needs more investigation + // var_a2 = (-get_angle_between_points(player->pos, D_80162FA0)) - (var_a1 = player->unk_02C[1]); + stackPadding19 = -get_angle_between_points(player->pos, D_80162FA0) - player->unk_02C[1]; + var_a1 = stackPadding19; + var_a2 = var_a1; + if ((s16) temp_f2 < var_a1) { + var_a2 = temp_f2; } if (var_a2 < (s16) temp_f6) { - var_a2 = (s16) temp_f6; + var_a2 = temp_f6; } - temp_v0_10 = *(D_801631D8 + sp34); - var_v1_2 = D_800DCA20[gCurrentCourseId]; - switch (temp_v0_10) { /* switch 4; irregular */ + var_v1 = D_800DCA20[gCurrentCourseId]; + switch (D_801631D8[playerId]) { /* switch 4; irregular */ case 2: /* switch 4 */ - temp_f0_2 = *temp_t0_2; - if (temp_f0_2 > 0.5f) { - var_v1_2 = 0x0014; + if (D_80163068[playerId] > (0.5f * 1.0f)) { + var_v1 = 0x0014; } - if (temp_f0_2 < -0.5f) { - var_v1_2 = 0x0035; + if (D_80163068[playerId] < -0.5f) { + var_v1 = 0x0035; } break; case 3: /* switch 4 */ - temp_f0_3 = *temp_t0_2; - if (temp_f0_3 > 0.5f) { - var_v1_2 = 0x0035; + if (D_80163068[playerId] > 0.5f) { + var_v1 = 0x0035; } - if (temp_f0_3 < -0.5f) { - var_v1_2 = 0x0014; + if (D_80163068[playerId] < -0.5f) { + var_v1 = 0x0014; } break; } - if ((*(D_801632E8 + sp34) == 2) && ((temp_f0_4 = *temp_t0_2, (temp_f0_4 > 0.9f)) || (temp_f0_4 < -0.9f))) { - *sp2C = 0; - sp40->effects &= ~0x10; + if ((D_801632E8[playerId] == 2) && ((D_80163068[playerId] > 0.9f) || (D_80163068[playerId] < -0.9f))) { + D_801630E8[playerId] = 0; + player->effects &= ~0x10; } - temp_v0_11 = sp40->effects; - if (temp_v0_11 & 2) { - temp_v0_12 = (s16) *sp2C; - var_a1_2 = -0x0035; - if (temp_v0_12 != -1) { - var_a1_2 = 0x0035; - if (temp_v0_12 != 1) { - var_v0_2 = sp34 + D_80163050; - var_a1_2 = (s16) (s32) (((f32) *var_v0_2 + ((f32) (var_a2 * var_v1_2) / temp_f2_2)) / 2.0f); - } else { - var_v0_2 = sp34 + D_80163050; - } - } else { - var_v0_2 = sp34 + D_80163050; + if (player->effects & 2) { + switch (D_801630E8[playerId]) { + case 1: + var_a1 = 0x0035; + break; + case -1: + var_a1 = -0x0035; + break; + default: + var_a1 = (D_80163050[playerId] + ((var_a2 * var_v1) / temp_f2)) / 2; + break; } - } else if (temp_v0_11 & 0x1000000C) { - var_a1_2 = 0; - var_v0_2 = sp34 + D_80163050; + } else if (player->effects & 0x1000000C) { + var_a1 = 0; } else { - var_v0_2 = sp34 + D_80163050; - var_a1_2 = (s16) (s32) (((f32) *var_v0_2 + ((f32) (var_a2 * var_v1_2) / temp_f2_2)) / 2.0f); + var_a1 = (D_80163050[playerId] + ((var_a2 * var_v1) / temp_f2)) / 2; } - sp3C = var_v0_2; - sp94 = var_a1_2; - sp20 = temp_t0_2; - func_8003680C(sp40, var_a1_2); - *var_v0_2 = var_a1_2; - if (((bitwise s32) *sp28 == 1) || (temp_v0_13 = (s16) *sp2C, (temp_v0_13 == 1)) || (temp_v0_13 == -1) || (sp40->effects & 0x1000000C)) { - sp20 = temp_t0_2; - var_v1_3 = sp38 + D_80163028; - *var_v1_3 = *segmented_to_virtual_dupe_2((gCurrentCourseId * 0x10) + (gCCSelection * 4) + D_0D009418); + func_8003680C(player, var_a1); + D_80163050[playerId] = var_a1; + if ((D_801630B8[playerId] == 1) || (D_801630E8[playerId] == 1) || (D_801630E8[playerId] == -1) || (player->effects & 0x1000000C)) { + D_80163028[playerId] = *(f32*)segmented_to_virtual_dupe_2(&D_0D009418[gCurrentCourseId][gCCSelection]); } else { - sp20 = temp_t0_2; - var_v1_3 = sp38 + D_80163028; - *var_v1_3 = *segmented_to_virtual_dupe_2((gCurrentCourseId * 0x10) + (gCCSelection * 4) + D_0D009568); + D_80163028[playerId] = *(f32*)segmented_to_virtual_dupe_2(&D_0D009568[gCurrentCourseId][gCCSelection]); } - temp_f0_5 = *temp_t0_2; - if ((temp_f0_5 > 0.9f) || (temp_f0_5 < -0.9f)) { - sp34 = var_v1_3; - *var_v1_3 = *segmented_to_virtual_dupe_2((gCurrentCourseId * 0x10) + (gCCSelection * 4) + D_0D009808); + if ((D_80163068[playerId] > 0.9f) || (D_80163068[playerId] < -0.9f)) { + D_80163028[playerId] = *(f32*)segmented_to_virtual_dupe_2(&D_0D009808[gCurrentCourseId][gCCSelection]); } if (D_80162FD0 == 1) { - sp34 = var_v1_3; - *var_v1_3 = *segmented_to_virtual_dupe_2((gCurrentCourseId * 0x10) + (gCCSelection * 4) + D_0D0096B8); + D_80163028[playerId] = *(f32*)segmented_to_virtual_dupe_2(&D_0D0096B8[gCurrentCourseId][gCCSelection]); } - temp_v0_14 = (s16) *sp2C; - if ((temp_v0_14 == 2) || (temp_v0_14 == -2) || (temp_v0_14 == 3)) { - *var_v1_3 = 3.3333333f; + if ((D_801630E8[playerId] == 2) || (D_801630E8[playerId] == -2) || (D_801630E8[playerId] == 3)) { + D_80163028[playerId] = 3.3333333f; } - D_8016320C = *var_v1_3; - sp40->effects &= 0xFFDFFFFF; - *(D_80163210 + sp38) = D_8016320C; + D_8016320C = D_80163028[playerId]; + player->effects &= ~0x00200000; + D_80163210[playerId] = D_8016320C; func_800131DC(playerId); - func_80008424(playerId, D_8016320C, sp40); + func_80008424(playerId, D_8016320C, player); } } } } +#undef FAKEMATCH1 +#undef FAKEMATCH2 #else GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_80009B60.s") #endif @@ -2883,57 +2723,38 @@ block_17: GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_8000CD24.s") #endif -#ifdef MIPS_TO_C -//generated by m2c commit 08138748803d75e73e4a94bb0c619a273754ee9c on Oct-12-2023 -extern s32 D_80163598; -extern s32 D_8016359C; +s16 func_8000D100(f32 xPos, f32 yPos, f32 zPos, s16 arg3) { + f32 xdiff; + f32 zdiff; + f32 minimumDistance; + f32 considerSquaredDistance; + s16 realIndex; + s16 minimumIndex; + s16 considerIndex; + PathNoY *considerWaypoint; -s16 func_8000D100(f32 arg0, f32 arg1, f32 arg2, s16 arg3) { - f32 temp_f14; - f32 temp_f16; - f32 temp_f2; - f32 var_f0; - s16 temp_a0; - s16 temp_v0; - s16 var_a0; - s16 var_v0; - s16 var_v1; - s32 temp_a1; - s32 temp_hi; - void *temp_t0; - - temp_a0 = arg3 - 2; - var_f0 = 250000.0f; - temp_a1 = arg3 + 7; - var_v1 = -1; - var_v0 = temp_a0; - if (temp_a0 < temp_a1) { - do { - var_a0 = var_v0; - if (var_v0 < 0) { - var_a0 = var_v0 + D_8016359C; - } - temp_hi = var_a0 % (s32) D_8016359C; - temp_t0 = ((s16) temp_hi * 4) + D_80163598; - temp_v0 = var_v0 + 1; - temp_f2 = (f32) temp_t0->unk0 - arg0; - temp_f14 = (f32) temp_t0->unk2 - arg2; - temp_f16 = (temp_f2 * temp_f2) + (temp_f14 * temp_f14); - if (temp_f16 < var_f0) { - var_f0 = temp_f16; - var_v1 = (s16) temp_hi; - } - var_v0 = temp_v0; - } while (temp_v0 < temp_a1); + minimumDistance = 250000.0f; + minimumIndex = -1; + for (realIndex = arg3 - 2; realIndex < arg3 + 7; realIndex++) { + considerIndex = realIndex; + if (realIndex < 0) { + considerIndex = realIndex + D_8016359C; + } + considerIndex %= D_8016359C; + considerWaypoint = &D_80163598[considerIndex]; + xdiff = considerWaypoint->x - xPos; + zdiff = considerWaypoint->z - zPos; + considerSquaredDistance = (xdiff * xdiff) + (zdiff * zdiff); + if (considerSquaredDistance < minimumDistance) { + minimumDistance = considerSquaredDistance; + minimumIndex = considerIndex; + } } - if (var_v1 == -1) { - var_v1 = arg3; + if (minimumIndex == -1) { + minimumIndex = arg3; } - return var_v1; + return minimumIndex; } -#else -GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_8000D100.s") -#endif s16 func_8000D24C(f32 posX, f32 posY, f32 posZ, s32 *pathIndex) { UNUSED s32 pad; @@ -3052,15 +2873,17 @@ void func_8000D438(s32 arg0, u16 arg1) { D_80162FA0[2] = (sp44 + stackPadding4) * 0.5f; } -#ifdef NON_MATCHING -// Something about the handling of D_80162FA0 is really off, can't figure out what s16 func_8000D6D0(Vec3f arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathIndex, s16 arg5) { - UNUSED s32 pad[4]; - s16 waypoint2; + f32 temp1; + f32 temp2; + f32 midX; + s16 stackPadding1; s16 waypoint1; - UNUSED s32 pad2[2]; + s16 waypoint2; f32 pad3; + f32 midY; f32 pad4; + f32 midZ; f32 distance; f32 temp_f20; f32 temp_f22; @@ -3092,11 +2915,15 @@ s16 func_8000D6D0(Vec3f arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathIn pad3 = D_80162FA0[0]; pad4 = D_80162FA0[2]; func_8000BBD8(waypoint2, arg3, pathIndex); - ydiff = ((path[waypoint2].posY + path[waypoint1].posY) * 0.5f) - temp_f22; - xdiff = ((pad3 + D_80162FA0[0]) * 0.5f) - temp_f20; - zdiff = ((pad4 + D_80162FA0[2]) * 0.5f) - temp_f24; + temp1 = D_80162FA0[0]; + temp2 = D_80162FA0[2]; + midY = (path[waypoint1].posY + path[waypoint2].posY) * 0.5f; + midX = (pad3 + temp1) * 0.5f; + midZ = (pad4 + temp2) * 0.5f; + xdiff = midX - temp_f20; + ydiff = midY - temp_f22; + zdiff = midZ - temp_f24; distance = sqrtf((xdiff * xdiff) + (ydiff * ydiff) + (zdiff * zdiff)); - if (distance && distance) {} if (distance > 0.01f) { var_f2 = ((xdiff * arg2) / distance) + temp_f20; var_f12 = ((ydiff * arg2) / distance) + temp_f22; @@ -3111,20 +2938,20 @@ s16 func_8000D6D0(Vec3f arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathIn arg0[2] = var_f14; return func_80005FD0(sp50, arg0); } -#else -GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_8000D6D0.s") -#endif -#ifdef NON_MATCHING -// Something about ordering of the math regarding x/y/zdiff is off, can't figure out why s16 func_8000D940(f32 *arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathIndex) { - UNUSED s32 pad[4]; - s16 waypoint2; + f32 pad; + f32 thing1; + f32 thing2; + s16 stackPadding1; s16 waypoint1; + s16 waypoint2; + s16 stackPadding2; f32 pad2; + f32 midX; f32 pad3; - f32 pad4; - s32 pad5; + f32 midY; + f32 midZ; f32 distance; f32 temp_f20; f32 temp_f22; @@ -3133,13 +2960,11 @@ s16 func_8000D940(f32 *arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathInd f32 var_f12; f32 var_f14; s16 temp_v0; - s32 waypointCount; f32 xdiff; f32 ydiff; f32 zdiff; + s32 waypointCount; Vec3f sp54; - s32 pad6; - TrackWaypoint *path; sp54[0] = arg0[0]; sp54[1] = arg0[1]; @@ -3156,9 +2981,14 @@ s16 func_8000D940(f32 *arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathInd pad2 = D_80162FA0[0]; pad3 = D_80162FA0[2]; func_8000BBD8(waypoint2, arg3, pathIndex); - ydiff = ((D_80164550[pathIndex][waypoint2].posY + D_80164550[pathIndex][waypoint1].posY) * 0.5f) - temp_f22; - xdiff = ((pad2 + D_80162FA0[0]) * 0.5f) - temp_f20; - zdiff = ((pad3 + D_80162FA0[2]) * 0.5f) - temp_f24; + thing1 = D_80162FA0[0]; + thing2 = D_80162FA0[2]; + midY = (D_80164550[pathIndex][waypoint1].posY + D_80164550[pathIndex][waypoint2].posY) * 0.5f; + midX = (pad2 + thing1) * 0.5f; + midZ = (pad3 + thing2) * 0.5f; + xdiff = midX - temp_f20; + ydiff = midY - temp_f22; + zdiff = midZ - temp_f24; distance = sqrtf((xdiff * xdiff) + (ydiff * ydiff) + (zdiff * zdiff)); if (distance > 0.01f) { var_f2 = ((xdiff * arg2) / distance) + temp_f20; @@ -3174,80 +3004,63 @@ s16 func_8000D940(f32 *arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathInd arg0[2] = var_f14; return func_80005FD0(sp54, arg0); } -#else -GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_8000D940.s") -#endif - -#ifdef MIPS_TO_C -//generated by m2c commit 3b40ab93768f52ac241c5ae84ef58ef6bc4cb1de -s16 func_8000D100(f32, f32, f32, s16); /* extern */ -extern TrackWaypoint *D_80163598; - s16 func_8000DBAC(Vec3f pos, s16 *waypointIndex, f32 speed) { - f32 sp98; - f32 sp94; - //f32 sp40; - //f32 sp3C; - Vec3f sp38; - f32 sp34; - f32 sp30; - f32 temp_f0; - f32 temp_f12; - f32 temp_f14; - f32 temp_f16; - f32 temp_f18; - f32 temp_f2; + f32 origXPos; + f32 origYPos; + f32 origZPos; + s32 stackPadding0; + s32 stackPadding1; + s32 stackPadding2; + s32 stackPadding3; + s32 stackPadding4; + s32 stackPadding5; + s32 stackPadding6; + s32 stackPadding7; + s32 stackPadding8; + f32 midX; + f32 midZ; + f32 x_dist; + f32 y_dist; + f32 distance; f32 var_f12; f32 var_f14; s16 temp_v0; - s32 temp_a1; - s32 temp_v1; - void *temp_a0; - void *temp_a2; - - temp_f12 = pos[0]; - temp_f14 = pos[1]; - temp_f2 = pos[2]; + s16 anIndex; + s16 anIndex2; + PathNoY *temp_a0; + PathNoY *temp_a2; + Vec3f sp38; + origXPos = pos[0]; + origYPos = pos[1]; + origZPos = pos[2]; sp38[0] = pos[0]; sp38[1] = pos[1]; sp38[2] = pos[2]; - - sp98 = temp_f14; - sp94 = temp_f2; - temp_v0 = func_8000D100(temp_f12, temp_f14, temp_f2, *waypointIndex); + temp_v0 = func_8000D100(origXPos, origYPos, origZPos, *waypointIndex); *waypointIndex = temp_v0; - - temp_a0 = ((s16) ((s32) (temp_v0 + 3) % temp_v1)); - temp_a2 = ((s16) ((s32) (temp_v0 + 4) % temp_v1)); - - temp_v1 = D_8016359C[temp_a0]; - temp_a1 = D_80163598[temp_a2]; - - temp_f16 = ((f32) (temp_v1->waypointX + temp_a1->waypointX) * 0.5f) - temp_f12; - temp_f18 = ((f32) (temp_v1->waypointY + temp_a1->waypointY) * 0.5f) - temp_f2; - - sp34 = temp_f16; - sp30 = temp_f18; - - temp_f0 = sqrtf((temp_f16 * temp_f16) + (temp_f18 * temp_f18)); - - if (temp_f0 > 0.01f) { - var_f12 = ((temp_f16 * speed) / temp_f0) + temp_f12; - var_f14 = ((temp_f18 * speed) / temp_f0) + temp_f2; + anIndex = (temp_v0 + 3) % D_8016359C; + anIndex2 = (temp_v0 + 4) % D_8016359C; + temp_a0 = &D_80163598[anIndex]; + temp_a2 = &D_80163598[anIndex2]; + midX = (temp_a0->x + temp_a2->x) * 0.5f; + midZ = (temp_a0->z + temp_a2->z) * 0.5f; + x_dist = midX - origXPos; + y_dist = midZ - origZPos; + distance = sqrtf((x_dist * x_dist) + (y_dist * y_dist)); + if (distance > 0.01f) { + var_f12 = ((x_dist * speed) / distance) + origXPos; + var_f14 = ((y_dist * speed) / distance) + origZPos; } else { - var_f12 = temp_f12; - var_f14 = temp_f2; + var_f12 = origXPos; + var_f14 = origZPos; } pos[0] = var_f12; - pos[1] = sp98; + pos[1] = origYPos; pos[2] = var_f14; - return func_80005FD0(&sp38, pos); + return func_80005FD0(sp38, pos); } -#else -GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_8000DBAC.s") -#endif void set_bomb_kart_spawn_positions(void) { Collision *var_s2; @@ -4503,31 +4316,27 @@ void func_80011AE4(s32 index) { } #ifdef MIPS_TO_C -//generated by m2c commit beb457dabfc7a01ec6540a5404a6a05097a13602 on Dec-17-2023 -extern ? D_80162EB8; -extern void *D_801632B0; -extern ? D_801634FC; - +//generated by m2c commit beb457dabfc7a01ec6540a5404a6a05097a13602 on Dec-27-2023 void func_80011B14(s32 playerId, Player *player) { u16 sp2E; s32 sp1C; Player *temp_v0; + UnkCommonTextureStruct0 *temp_t0; + UnkCommonTextureStruct0 *temp_t6; s16 *temp_a3; s16 temp_t1; s32 temp_t3; u16 temp_a2; - void *temp_t0; - void *temp_t6; temp_a3 = &D_801632B8[playerId]; temp_a2 = (u16) *temp_a3; - temp_t0 = *(&D_80162EB8 + (gCurrentCourseId * 4)); - temp_t6 = (temp_a2 * 8) + temp_t0; + temp_t0 = D_80162EB8[gCurrentCourseId]; + temp_t6 = &temp_t0[temp_a2]; D_801632B0 = temp_t6; sp2E = gNearestWaypointByPlayerId[playerId]; - temp_t1 = temp_t6->unk0; + temp_t1 = temp_t6->waypointId1; temp_t3 = temp_t6->unk4; - if ((temp_t1 == -1) && (temp_t6->unk2 == -1)) { + if ((temp_t1 == -1) && (temp_t6->waypointId2 == -1)) { D_801632B0 = temp_t0; func_80011AB8(playerId); return; @@ -4547,13 +4356,13 @@ void func_80011B14(s32 playerId, Player *player) { D_801630E8[playerId] = 0; return; case 3: - *(&D_801634FC + (playerId * 0x10)) = 0.0f; + *(&D_801634F8->unk4 + (playerId * 0x10)) = 0.0f; return; case 4: - *(&D_801634FC + (playerId * 0x10)) = -0.6f; + *(&D_801634F8->unk4 + (playerId * 0x10)) = -0.6f; return; case 5: - *(&D_801634FC + (playerId * 0x10)) = 0.6f; + *(&D_801634F8->unk4 + (playerId * 0x10)) = 0.6f; return; case 6: D_80163350[playerId] = 0; @@ -4562,7 +4371,7 @@ void func_80011B14(s32 playerId, Player *player) { D_80163350[playerId] = 1; return; case 8: - D_80163350[playerId] = (s16) 2U; + D_80163350[playerId] = 2; return; case 11: D_80163350[playerId] = 3; @@ -4585,29 +4394,17 @@ void func_80011B14(s32 playerId, Player *player) { GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_80011B14.s") #endif -// Need to know more about D_801632B0 and D_80162EB8 and D_801632D0 -#ifdef NON_MATCHING -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -//extern ? D_80162EB8; -extern s16 D_801630E8[]; -extern void *D_801632B0; - void func_80011D48(s32 playerIndex, Player *player) { - //s32 temp_a2; - //s32 temp_v0; - //s32 temp_t3; - //void *temp_v1; - u16 test; - s16 temp; + u16 nearestWaypoint; + u32 thing; + s32 temp_a2; - // temp_v0 = playerIndex * 2; - // * 8) ? - //temp_t3 = D_801632D0[playerIndex] + D_80162EB8[gCurrentCourseId]; - D_801632B0 = D_801632D0[playerIndex] + D_80162EB8[gCurrentCourseId]; - test = gNearestWaypointByPlayerId[playerIndex]; - // temp_a2 = temp_t3; - if (test >= (*(u16*)D_801632B0)) { - switch (*(u16*)D_801632B0) { + D_801632B0 = &D_80162EB8[gCurrentCourseId][D_801632D0[playerIndex]]; + nearestWaypoint = gNearestWaypointByPlayerId[playerIndex]; + temp_a2 = D_801632B0->unk4; + thing = D_801632B0->waypointId2; + if (nearestWaypoint >= thing) { + switch (temp_a2) { case 1: player->effects &= ~0x10; D_801630E8[playerIndex] = 0; @@ -4616,7 +4413,6 @@ void func_80011D48(s32 playerIndex, Player *player) { case 3: case 4: case 5: - //temp_v1 = D_801634F8[playerIndex]; D_801634F8[playerIndex].unk4 = D_801634F8[playerIndex].unkC; D_801632E8[playerIndex] = 1; break; @@ -4628,14 +4424,12 @@ void func_80011D48(s32 playerIndex, Player *player) { case 10: case 11: D_801632E8[playerIndex] = 1; - /* Duplicate return node #6. Try simplifying control flow for better match */ + break; + default: break; } } } -#else -GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_80011D48.s") -#endif void func_80011E38(s32 playerIndex) { Player *player = gPlayerOne + playerIndex; @@ -5585,10 +5379,6 @@ f32 func_800145A8(s16 arg0, f32 arg1, s16 arg2) { return arg1; } -#ifdef NON_MATCHING -extern f32 D_801634FC[][4]; -// Something about the handling of `vehicle` is the source of -// mismatch. Not sure how to fix it. void func_800146B8(s32 playerId, s32 arg1, VehicleStuff *vehicle) { s32 var_v1; s32 var_v0; @@ -5599,20 +5389,17 @@ void func_800146B8(s32 playerId, s32 arg1, VehicleStuff *vehicle) { waypointCount = gWaypointCountByPathIndex[0]; if (!(gPlayers[playerId].unk_094 < 1.6666666666666667)) { - for (var_s2 = 0; var_s2 < arg1; var_s2++) { - temp_a1 = vehicle[var_s2].waypointIndex; - for (var_v0 = 0, var_v1 = D_80162FCE; var_v0 < 0x18; var_v0 += 3, var_v1 += 3) { - if ((var_v1 % waypointCount) == temp_a1) { - D_801634FC[playerId][0] = func_800145A8(vehicle[var_s2].someType, D_80163068[playerId], temp_a1); + for (var_s2 = 0; var_s2 < arg1; var_s2++, vehicle++) { + temp_a1 = vehicle->waypointIndex; + for (var_v0 = 0; var_v0 < 0x18; var_v0 += 3) { + if (((D_80162FCE + var_v0) % waypointCount) == temp_a1) { + D_801634F8[playerId].unk4 = func_800145A8(vehicle->someType, D_80163068[playerId], temp_a1); return; } } } } } -#else -GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_800146B8.s") -#endif void func_800147E0(void) { f32 a = ((gCCSelection * 90.0) / 216.0f) + 4.583333333333333; @@ -5729,21 +5516,9 @@ void func_80014D30(s32 cameraId, s32 pathIndex) { func_802ADDC8(&cameras[cameraId].unk_54, 10.0f, (f32) temp_v0->posX, (f32) temp_v0->posY + 30.0f, (f32) temp_v0->posZ); } -#ifdef NEEDS_BSS -//generated by m2c commit 08138748803d75e73e4a94bb0c619a273754ee9c on Oct-10-2023 -//extern s32 D_80163238; -//extern ? D_80164680; -//extern ? D_801646C0; -extern s32 D_801646C8; - - - -extern UnkStruct_46D0 D_801646D0[]; // size of 8 - void func_80014DE4(s32 arg0) { - UnkStruct_46D0 *temp_v1; - // s32 temp_v0; - //temp_v0 = arg0 * 2; + s32 cameraId; + D_801646CC = 0; D_80164678[arg0] = D_80164670[arg0]; if ((gModeSelection != 1) && ((gCupCourseSelection == 0) || (gDemoMode == (u16) 1))) { @@ -5755,21 +5530,17 @@ void func_80014DE4(s32 arg0) { D_80163238 = 0; D_801646C0[arg0] = 0; D_801646C8 = 0; - temp_v1 = &D_801646D0[arg0]; - temp_v1->unk0 = 0; - temp_v1->unk2 = 0; - temp_v1->unk4 = 0; + D_801646D0[arg0].unk0 = 0; + D_801646D0[arg0].unk2 = 0; + D_801646D0[arg0].unk4 = 0; if ((gModeSelection == 1) && (D_8018EDFC == 0)) { D_80164678[arg0] = 0; } - for (i = 0 ; i < i++) { - gNearestWaypointByCameraId[i] = 0; + for (cameraId = 0 ; cameraId < 4; cameraId++) { + gNearestWaypointByCameraId[cameraId] = 0; } } -#else -GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_80014DE4.s") -#endif f32 func_80014EE4(f32 arg0, s32 arg1) { f32 temp_f0; @@ -7551,21 +7322,15 @@ void func_80019DE4(void) { D_801646CC = 1; } -#ifdef NON_MATCHING -// It really seems like this should be it, -// its unclear what about that for-loop is wrong void func_80019DF4(void) { s32 i; - for (i = 0; i < 4; i++) { - D_80164670[i] = D_80164678[i]; - } - camera1->playerId = gGPCurrentRacePlayerIdByRank[0]; + s32 playerId = gGPCurrentRacePlayerIdByRank[0]; + // Has to be on a single line to match. Because IDO hates you :) + for (i = 0; i < 4; i++) { D_80164670[i] = D_80164678[i]; } + camera1->playerId = playerId; D_80164678[0] = 1; D_801646CC = 2; } -#else -GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_80019DF4.s") -#endif void func_80019E58(void) { D_80164680[0] = 1; |
