From 1cb0f0b03c8b6b274974e7005c83ffd548cd021c Mon Sep 17 00:00:00 2001 From: idefix02 <237103031+idefix02@users.noreply.github.com> Date: Mon, 21 Sep 2026 21:39:57 +0200 Subject: [PATCH] Find a much cleaner match for sub_8020A58 --- include/game/shared/stage/player.h | 2 +- src/game/sa3/stage/player.c | 123 +++++++++++------------------ 2 files changed, 47 insertions(+), 78 deletions(-) diff --git a/include/game/shared/stage/player.h b/include/game/shared/stage/player.h index b01bb8a87..a9f604731 100644 --- a/include/game/shared/stage/player.h +++ b/include/game/shared/stage/player.h @@ -419,7 +419,7 @@ extern bool32 sub_8020700(Sprite *s, s32 worldX, s32 worldY, s16 p3, Player *p, // Collision - 'p5' might be hitbox ID? extern u32 sub_8020874(Sprite *s, s32 worldX, s32 worldY, s16 p3, Player *p, s16 p5, u8 p6); u32 sub_8020950(Sprite *s, s32 worldX, s32 worldY, Player *p, u8 param4); // collision -bool32 sub_8020A58(Sprite *s, s16 param1, s32 worldX, s32 worldY, Rect8 *param4, Player *p, u8 param6); +bool32 sub_8020A58(Sprite *s, s16 hbIndex, s32 worldX, s32 worldY, Rect8 *param4, Player *p, u8 param6); bool32 sub_8020CE0(Sprite *s, s32 worldX, s32 worldY, s16 hbIndex, Player *p); bool32 sub_8020E3C(Sprite *s, s32 param1, s32 param2, s16 param3, Player *p); diff --git a/src/game/sa3/stage/player.c b/src/game/sa3/stage/player.c index 5f9211c0b..d6c5aa953 100644 --- a/src/game/sa3/stage/player.c +++ b/src/game/sa3/stage/player.c @@ -22650,9 +22650,8 @@ u32 sub_8020950(Sprite *s, s32 worldX, s32 worldY, Player *p, u8 param4) return temp_r0; } -u32 sub_8020A58(Sprite *s, s16 param1, s32 worldX, s32 worldY, Rect8 *playerBox, Player *p, u8 param6) +u32 sub_8020A58(Sprite *s, s16 hbIndex, s32 worldX, s32 worldY, Rect8 *playerBox, Player *p, u8 param6) { - s32 var_r2; s32 var_r1; s32 var_r5; s32 midX; @@ -22661,97 +22660,67 @@ u32 sub_8020A58(Sprite *s, s16 param1, s32 worldX, s32 worldY, Rect8 *playerBox, s32 playerY = I(p->qWorldY); u32 var_r6 = 0; if ((p->charFlags.anim0 == 92) || (p->charFlags.anim0 == 93)) { - if (p->moveState & 0x10000) { + if (p->moveState & MOVESTATE_GRAVITY_SWITCHED) { playerY -= 32; } else { playerY += 32; } } -#define RETURN_ZERO goto FINAL_RETURN - if ((worldX + s->hitboxes[param1].b.left) <= (playerX + playerBox->left)) { - if (((worldX + s->hitboxes[param1].b.left) + (s->hitboxes[param1].b.right - s->hitboxes[param1].b.left)) - < (playerX + playerBox->left)) { - if ((worldX + s->hitboxes[param1].b.left) < (playerX + playerBox->left)) { - RETURN_ZERO; - } - goto ELSE1; - } - } else { - ELSE1: - if (((playerX + playerBox->left) + RECT_WIDTH(playerBox)) < (worldX + s->hitboxes[param1].b.left)) { - RETURN_ZERO; + if (HB_COLLISION(worldX, worldY, s->hitboxes[hbIndex].b, playerX, playerY, (*playerBox))) { + s32 var_r2 = ((s->hitboxes[hbIndex].b.left + s->hitboxes[hbIndex].b.right) >> 1) + worldX; + midY = worldY + ((s->hitboxes[hbIndex].b.top + s->hitboxes[hbIndex].b.bottom) >> 1); + if (var_r2 <= playerX) { + var_r5 = (worldX + s->hitboxes[hbIndex].b.right) - (playerBox->left + playerX); + var_r6 |= 0x40000; + } else { + var_r5 = (worldX + s->hitboxes[hbIndex].b.left) - (playerBox->right + playerX); + var_r6 |= 0x80000; } - } - if ((worldY + s->hitboxes[param1].b.top) <= (playerY + playerBox->top)) { - if (((worldY + s->hitboxes[param1].b.top) + (s->hitboxes[param1].b.bottom - s->hitboxes[param1].b.top)) - < (playerY + playerBox->top)) { - if ((worldY + s->hitboxes[param1].b.top) < (playerY + playerBox->top)) { - RETURN_ZERO; + if (midY > playerY) { + midY = (worldY + s->hitboxes[hbIndex].b.top) - (playerY + playerBox->bottom); + if (p->moveState & MOVESTATE_GRAVITY_SWITCHED) { + var_r1 = MIN(midY - 2, 0); + var_r6 |= 0x20000; + } else { + var_r1 = MIN(midY + 5, 0); + var_r6 |= 0x10000; } - goto ELSE2; - } - } else { - ELSE2: - if (((playerY + playerBox->top) + RECT_HEIGHT(playerBox)) < (worldY + s->hitboxes[param1].b.top)) { - RETURN_ZERO; - } - } -#undef RETURN_ZERO - - var_r2 = ((s->hitboxes[param1].b.left + s->hitboxes[param1].b.right) >> 1) + worldX; - midY = worldY + ((s->hitboxes[param1].b.top + s->hitboxes[param1].b.bottom) >> 1); - if (var_r2 <= playerX) { - var_r5 = (worldX + s->hitboxes[param1].b.right) - (playerBox->left + playerX); - var_r6 |= 0x40000; - } else { - var_r5 = (worldX + s->hitboxes[param1].b.left) - (playerBox->right + playerX); - var_r6 |= 0x80000; - } - if (midY > playerY) { - midY = (worldY + s->hitboxes[param1].b.top) - (playerY + playerBox->bottom); - if (p->moveState & 0x00010000) { - var_r1 = MIN(midY - 2, 0); - var_r6 = var_r6 | 0x20000; } else { - var_r1 = MIN(midY + 5, 0); - var_r6 = var_r6 | 0x10000; + midY = (worldY + s->hitboxes[hbIndex].b.bottom) - (playerY + playerBox->top); + if (p->moveState & MOVESTATE_GRAVITY_SWITCHED) { + var_r1 = MAX(midY - 5, 0); + var_r6 |= 0x10000; + } else { + var_r1 = MAX(midY + 2, 0); + var_r6 |= 0x20000; + } } - } else { - midY = (worldY + s->hitboxes[param1].b.bottom) - (playerY + playerBox->top); - if (p->moveState & 0x00010000) { - var_r1 = MAX(midY - 5, 0); - var_r6 = var_r6 | 0x10000; + if (ABS(var_r5) < ABS(var_r1)) { + var_r6 &= 0xC0000; } else { - var_r1 = MAX(midY + 2, 0); - var_r6 = var_r6 | 0x20000; - } - } - if (ABS(var_r5) < ABS(var_r1)) { - var_r6 &= 0xC0000; - } else { - var_r6 &= 0x30000; - if (var_r6 & 0x10000) { - if ((p->qSpeedAirY < 0) && (param6 == 0)) { - return 0; + var_r6 &= 0x30000; + if (var_r6 & 0x10000) { + if ((p->qSpeedAirY < 0) && (param6 == 0)) { + return 0; + } + if ((!(p->moveState & MOVESTATE_IN_AIR)) && ((p->unk26 + 0x20) & 0x40)) { + p->qSpeedGround = 0; + } } - if ((!(p->moveState & 4)) && ((p->unk26 + 0x20) & 0x40)) { - p->qSpeedGround = 0; + } + var_r6 |= ((var_r5 << 8) & 0xFF00) | (midY & 0xFF); + if (var_r6 & 0xC0000) { + if (!(var_r6 & 0xFF00)) { + var_r6 &= 0xFFF300FF; } + } else { + var_r6 &= 0xFFFF00FF; } - } - var_r6 |= ((var_r5 << 8) & 0xFF00) | (midY & 0xFF); - if (var_r6 & 0xC0000) { - if (!(var_r6 & 0xFF00)) { - var_r6 &= 0xFFF300FF; + if (!(var_r6 & 0x30000)) { + var_r6 &= 0xFFFFFF00; } - } else { - var_r6 &= 0xFFFF00FF; - } - if (!(var_r6 & 0x30000)) { - var_r6 &= 0xFFFFFF00; } -FINAL_RETURN: return var_r6; }