From e4def8a88dfae9d943d5eaaf9fbca97746416e48 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Fri, 26 Aug 2022 07:00:12 +0300 Subject: [PATCH] Match sub_080A2E00 --- .../playerItemShield/sub_080A2E00.inc | 315 ------------------ src/playerItem/playerItemShield.c | 171 +++++----- 2 files changed, 88 insertions(+), 398 deletions(-) delete mode 100644 asm/non_matching/playerItemShield/sub_080A2E00.inc diff --git a/asm/non_matching/playerItemShield/sub_080A2E00.inc b/asm/non_matching/playerItemShield/sub_080A2E00.inc deleted file mode 100644 index c585fc59..00000000 --- a/asm/non_matching/playerItemShield/sub_080A2E00.inc +++ /dev/null @@ -1,315 +0,0 @@ - .syntax unified - push {r4, r5, r6, r7, lr} - adds r4, r0, #0 - ldr r0, _080A2E90 @ =gPlayerEntity - mov ip, r0 - mov r1, ip - adds r1, #0x3d - ldrb r0, [r1] - lsls r0, r0, #0x18 - cmp r0, #0 - beq _080A2E1A - lsrs r0, r0, #0x18 - cmp r0, #0x81 - bne _080A2E40 -_080A2E1A: - adds r5, r4, #0 - adds r5, #0x3d - ldrb r0, [r5] - movs r2, #0 - strb r0, [r1] - adds r0, r4, #0 - adds r0, #0x3e - ldrb r0, [r0] - mov r1, ip - adds r1, #0x3e - strb r0, [r1] - adds r3, r4, #0 - adds r3, #0x42 - ldrb r1, [r3] - mov r0, ip - adds r0, #0x42 - strb r1, [r0] - strb r2, [r3] - strb r2, [r5] -_080A2E40: - ldr r0, _080A2E94 @ =gPlayerState - ldrb r3, [r0, #3] - adds r7, r0, #0 - cmp r3, #0 - beq _080A2F20 - ldr r0, [r7, #0x2c] - cmp r4, r0 - bne _080A2F20 - movs r2, #0x80 - adds r0, r2, #0 - ands r0, r3 - cmp r0, #0 - beq _080A2E9C - ldr r1, _080A2E98 @ =gUnk_08127240 - ldrb r0, [r4, #0x14] - lsrs r0, r0, #1 - lsls r0, r0, #2 - adds r0, r0, r1 - ldr r0, [r0] - str r0, [r4, #0x48] - ldr r0, _080A2E90 @ =gPlayerEntity - adds r0, #0x3c - ldrb r0, [r0] - adds r0, #1 - movs r1, #0x20 - adds r2, r4, #0 - adds r2, #0x3c - orrs r0, r1 - strb r0, [r2] - ldrb r1, [r4, #0x10] - movs r0, #0x80 - orrs r0, r1 - strb r0, [r4, #0x10] - movs r0, #0x7f - ands r0, r3 - strb r0, [r7, #3] - adds r0, r4, #0 - bl sub_080176E4 - b _080A2F30 - .align 2, 0 -_080A2E90: .4byte gPlayerEntity -_080A2E94: .4byte gPlayerState -_080A2E98: .4byte gUnk_08127240 -_080A2E9C: - adds r0, r4, #0 - adds r0, #0x41 - ldrb r1, [r0] - adds r0, r2, #0 - ands r0, r1 - cmp r0, #0 - beq _080A2F30 - movs r0, #0x7f - ands r0, r1 - cmp r0, #0x42 - bne _080A2F06 - adds r0, r4, #0 - adds r0, #0x68 - ldrb r1, [r0] - adds r5, r0, #0 - cmp r1, #0xe - bne _080A2F06 - movs r0, #0x40 - ands r0, r3 - lsls r0, r0, #0x18 - lsrs r6, r0, #0x18 - cmp r6, #0 - bne _080A2F06 - ldrb r3, [r5] - movs r0, #0x15 - movs r1, #0 - movs r2, #0 - bl CreatePlayerItem - adds r1, r0, #0 - str r1, [r4, #0x54] - cmp r1, #0 - beq _080A2EF4 - movs r0, #1 - strb r0, [r1, #0xf] - ldr r2, [r4, #0x54] - adds r0, r4, #0 - adds r0, #0x3e - ldrb r0, [r0] - movs r1, #0x10 - eors r0, r1 - strb r0, [r2, #0x15] - ldr r0, [r4, #0x54] - str r4, [r0, #0x50] -_080A2EF4: - ldr r1, _080A2F1C @ =gUnk_08127220 - ldrb r0, [r1, #1] - str r0, [r4, #0x78] - str r6, [r4, #0x74] - str r1, [r4, #0x7c] - ldrb r0, [r7, #3] - movs r1, #0x40 - orrs r0, r1 - strb r0, [r7, #3] -_080A2F06: - ldr r0, [r4, #0x6c] - cmp r0, #0 - bne _080A2F30 - movs r0, #0x8c - lsls r0, r0, #1 - bl SoundReq - movs r0, #8 - str r0, [r4, #0x6c] - b _080A2F30 - .align 2, 0 -_080A2F1C: .4byte gUnk_08127220 -_080A2F20: - movs r1, #0 - strb r1, [r7, #3] - ldr r0, [r7, #0x2c] - cmp r0, r4 - bne _080A2F2C - str r1, [r7, #0x2c] -_080A2F2C: - bl DeleteThisEntity -_080A2F30: - ldr r6, _080A301C @ =gPlayerEntity - ldrh r0, [r6, #0x12] - cmp r0, #1 - beq _080A2F3E - cmp r0, #4 - beq _080A2F3E - b _080A3064 -_080A2F3E: - ldrb r0, [r6, #0x1e] - subs r0, #0x25 - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #0x3e - bls _080A2F4C - b _080A3064 -_080A2F4C: - ldrb r2, [r6, #0x18] - movs r1, #0x40 - ands r1, r2 - ldrb r3, [r4, #0x18] - movs r0, #0x41 - rsbs r0, r0, #0 - ands r0, r3 - orrs r0, r1 - lsrs r2, r2, #7 - lsls r2, r2, #7 - movs r3, #0x7f - ands r0, r3 - orrs r0, r2 - strb r0, [r4, #0x18] - ldrb r2, [r6, #0x1e] - ldr r1, [r4, #0x70] - adds r0, r1, #0 - subs r0, #0x25 - adds r0, r2, r0 - adds r5, r4, #0 - adds r5, #0x68 - ldrb r7, [r4, #0x1e] - cmp r0, r7 - beq _080A2FA2 - adds r0, r1, #0 - adds r0, #0xdb - adds r0, r2, r0 - strb r0, [r4, #0x1e] - ldrb r0, [r5] - cmp r0, #0xe - bne _080A2F98 - adds r0, r6, #0 - adds r0, #0x5a - ldrb r1, [r0] - adds r0, r3, #0 - ands r0, r1 - cmp r0, #0 - bne _080A2FA2 -_080A2F98: - ldrb r1, [r4, #0x1e] - ldrh r2, [r4, #0x12] - adds r0, r4, #0 - bl sub_080042D0 -_080A2FA2: - ldrb r0, [r5] - cmp r0, #0xe - bne _080A303E - ldr r0, _080A301C @ =gPlayerEntity - adds r0, #0x5a - ldrb r1, [r0] - movs r0, #0x7f - ands r0, r1 - cmp r0, #0 - beq _080A303E - ldr r0, [r4, #0x78] - subs r3, r0, #1 - str r3, [r4, #0x78] - cmp r3, #0 - bne _080A303E - ldr r0, [r4, #0x74] - adds r0, #1 - str r0, [r4, #0x74] - lsls r0, r0, #2 - ldr r1, [r4, #0x7c] - adds r2, r1, r0 - ldrb r0, [r2] - ldr r7, _080A3020 @ =gPlayerState - cmp r0, #0xff - bne _080A2FEC - ldrb r1, [r7, #3] - movs r0, #0x40 - ands r0, r1 - cmp r0, #0 - beq _080A2FE8 - ldr r0, _080A3024 @ =gUnk_081271DC - str r0, [r4, #0x7c] - movs r0, #0xbf - ands r0, r1 - strb r0, [r7, #3] -_080A2FE8: - str r3, [r4, #0x74] - ldr r1, [r4, #0x7c] -_080A2FEC: - ldr r0, [r4, #0x74] - lsls r0, r0, #2 - adds r2, r1, r0 - ldrb r0, [r2, #1] - str r0, [r4, #0x78] - ldrb r1, [r7, #3] - movs r0, #0x40 - ands r0, r1 - cmp r0, #0 - beq _080A3028 - ldr r0, _080A301C @ =gPlayerEntity - adds r0, #0x5a - ldrb r0, [r0] - movs r1, #0x7f - ands r1, r0 - adds r1, #8 - ldrb r2, [r2] - adds r1, r1, r2 - ldrh r2, [r4, #0x12] - adds r0, r4, #0 - bl sub_080042D0 - b _080A303E - .align 2, 0 -_080A301C: .4byte gPlayerEntity -_080A3020: .4byte gPlayerState -_080A3024: .4byte gUnk_081271DC -_080A3028: - ldr r0, _080A3060 @ =gPlayerEntity - adds r0, #0x5a - ldrb r0, [r0] - movs r1, #0x7f - ands r1, r0 - ldrb r2, [r2] - adds r1, r1, r2 - ldrh r2, [r4, #0x12] - adds r0, r4, #0 - bl sub_080042D0 -_080A303E: - ldr r1, _080A3060 @ =gPlayerEntity - adds r0, r1, #0 - adds r0, #0x5a - ldrb r0, [r0] - adds r2, r4, #0 - adds r2, #0x5a - strb r0, [r2] - adds r0, r1, #0 - adds r0, #0x5b - ldrb r0, [r0] - adds r2, #1 - strb r0, [r2] - adds r0, r4, #0 - bl sub_08078E84 - b _080A3068 - .align 2, 0 -_080A3060: .4byte gPlayerEntity -_080A3064: - movs r0, #0xff - strb r0, [r4, #0x1e] -_080A3068: - pop {r4, r5, r6, r7, pc} - .align 2, 0 - .syntax divided diff --git a/src/playerItem/playerItemShield.c b/src/playerItem/playerItemShield.c index 0c1a98ee..74211ade 100644 --- a/src/playerItem/playerItemShield.c +++ b/src/playerItem/playerItemShield.c @@ -1,3 +1,4 @@ +#define NENT_DEPRECATED #include "entity.h" #include "player.h" @@ -6,131 +7,135 @@ #include "collision.h" #include "playeritem.h" -extern void (*const gUnk_081271D4[])(Entity*); -extern u8 gUnk_081271DC[]; -void sub_080A2E00(Entity* this); +typedef struct { + Entity base; + u8 unk_68; + u8 unk_69[3]; + u32 bounceTimer; + u32 unk_70; + u32 unk_74; + u32 unk_78; + u8* unk_7c; +} PlayerItemShieldEntity; -void PlayerItemShield(Entity* this) { - if (*(int*)&this->field_0x6c != 0) { - *(int*)&this->field_0x6c += -1; +extern void (*const gUnk_081271D4[])(PlayerItemShieldEntity*); +extern u8 gUnk_081271DC[]; +void sub_080A2E00(PlayerItemShieldEntity* this); + +void PlayerItemShield(PlayerItemShieldEntity* this) { + if (this->bounceTimer != 0) { + this->bounceTimer--; } - gUnk_081271D4[this->action](this); + gUnk_081271D4[super->action](this); } -void sub_080A2D98(Entity* this) { - gPlayerState.item = this; - this->action = 1; - this->updatePriority = 6; - this->frameIndex = 0xff; - if (this->field_0x68.HALF.LO == 14) { - this->field_0x70.WORD = 0x27; - *(u32*)&this->field_0x78 = gUnk_081271DC[1]; - *(u32*)&this->field_0x74 = 0; - *(u8**)&this->field_0x7c = gUnk_081271DC; +void sub_080A2D98(PlayerItemShieldEntity* this) { + gPlayerState.item = super; + super->action = 1; + super->updatePriority = 6; + super->frameIndex = 0xff; + if (this->unk_68 == 14) { + this->unk_70 = 0x27; + this->unk_78 = gUnk_081271DC[1]; + this->unk_74 = 0; + this->unk_7c = gUnk_081271DC; } else { - this->field_0x70.WORD = 0; + this->unk_70 = 0; } - this->animationState = gPlayerEntity.animationState & 0xe; - sub_08079BD8(this); - LoadSwapGFX(this, 1, 3); + super->animationState = gPlayerEntity.animationState & 0xe; + sub_08079BD8(super); + LoadSwapGFX(super, 1, 3); sub_080A2E00(this); } extern Hitbox* gUnk_08127240[]; extern u8 gUnk_08127220[]; -NONMATCH("asm/non_matching/playerItemShield/sub_080A2E00.inc", void sub_080A2E00(Entity* this)) { - Entity* pEVar1; - u8* iVar2; +void sub_080A2E00(PlayerItemShieldEntity* this) { + Entity* playerItem; u8* pbVar3; - u8 uVar4; - int iVar5; - u32 tmp; + u32 tmp2; if ((gPlayerEntity.iframes == 0) || ((u8)gPlayerEntity.iframes == 0x81)) { - gPlayerEntity.iframes = this->iframes; - gPlayerEntity.knockbackDirection = this->knockbackDirection; - gPlayerEntity.knockbackDuration = this->knockbackDuration; - this->knockbackDuration = 0; - this->iframes = 0; + gPlayerEntity.iframes = super->iframes; + gPlayerEntity.knockbackDirection = super->knockbackDirection; + gPlayerEntity.knockbackDuration = super->knockbackDuration; + super->knockbackDuration = 0; + super->iframes = 0; } - uVar4 = gPlayerState.shield_status; - if ((uVar4 != 0) && (this == gPlayerState.item)) { - if ((uVar4 & 0x80) != 0) { - this->hitbox = gUnk_08127240[this->animationState >> 1]; - this->collisionFlags = (gPlayerEntity.collisionFlags + 1) | 0x20; - this->flags = this->flags | 0x80; - gPlayerState.shield_status = uVar4 & 0x7f; - sub_080176E4(this); + if ((gPlayerState.shield_status != 0) && (super == gPlayerState.item)) { + if ((gPlayerState.shield_status & 0x80) != 0) { + super->hitbox = gUnk_08127240[super->animationState >> 1]; + super->collisionFlags = (gPlayerEntity.collisionFlags + 1) | 0x20; + COLLISION_ON(super); + gPlayerState.shield_status &= ~0x80; + sub_080176E4(super); } else { - if ((this->contactFlags & 0x80) != 0) { - if ((((this->contactFlags & 0x7f) == 0x42) && (*(char*)&this->field_0x68 == 0xe)) && - ((uVar4 & 0x40) == 0)) { - pEVar1 = CreatePlayerItem(PLAYER_ITEM_FIRE_ROD_PROJECTILE, 0, 0, *(char*)&this->field_0x68); - this->child = pEVar1; - if (pEVar1 != NULL) { - pEVar1->subtimer = 1; - this->child->direction = this->knockbackDirection ^ 0x10; - this->child->parent = this; + if ((super->contactFlags & 0x80) != 0) { + if ((((super->contactFlags & 0x7f) == 0x42) && this->unk_68 == 0xe) && + ((gPlayerState.shield_status & 0x40) == 0)) { + playerItem = CreatePlayerItem(PLAYER_ITEM_FIRE_ROD_PROJECTILE, 0, 0, this->unk_68); + super->child = playerItem; + if (playerItem != NULL) { + playerItem->subtimer = 1; + super->child->direction = DirectionTurnAround(super->knockbackDirection); + super->child->parent = super; } - *(u32*)&this->field_0x78 = gUnk_08127220[1]; - *(u32*)&this->field_0x74 = uVar4 & 0x40; - *(u8**)&this->field_0x7c = gUnk_08127220; + this->unk_78 = gUnk_08127220[1]; + this->unk_74 = 0; + this->unk_7c = gUnk_08127220; gPlayerState.shield_status |= 0x40; } - if (*(int*)&this->field_0x6c == 0) { - SoundReq(0x118); - *(u32*)&this->field_0x6c = 8; + if (this->bounceTimer == 0) { + SoundReq(SFX_ITEM_SHIELD_BOUNCE); + this->bounceTimer = 8; } } } } else { gPlayerState.shield_status = 0; - if (gPlayerState.item == this) { + if (gPlayerState.item == super) { gPlayerState.item = NULL; } DeleteThisEntity(); } - if (((gPlayerEntity.spriteIndex == 1U) || (gPlayerEntity.spriteIndex == 4U)) && + if (((gPlayerEntity.spriteIndex == 1u) || (gPlayerEntity.spriteIndex == 4u)) && ((u8)(gPlayerEntity.frameIndex - 0x25) < 0x3f)) { - this->spriteSettings.flipX = gPlayerEntity.spriteSettings.flipX; - this->spriteSettings.flipY = gPlayerEntity.spriteSettings.flipY; - if ((gPlayerEntity.frameIndex - 0x25 + this->field_0x70.WORD != (u32)this->frameIndex) && - ((this->frameIndex = gPlayerEntity.frameIndex - 0x25 + this->field_0x70.WORD, - *(char*)&this->field_0x68 != 0xe || ((gPlayerEntity.frame & 0x7f) == 0)))) { - sub_080042D0(this, this->frameIndex, (u16)this->spriteIndex); + super->spriteSettings.flipX = gPlayerEntity.spriteSettings.flipX; + super->spriteSettings.flipY = gPlayerEntity.spriteSettings.flipY; + if ((gPlayerEntity.frameIndex - 0x25 + this->unk_70 != super->frameIndex) && + ((super->frameIndex = gPlayerEntity.frameIndex - 0x25 + this->unk_70, + this->unk_68 != 0xe || ((gPlayerEntity.frame & 0x7f) == 0)))) { + sub_080042D0(super, super->frameIndex, super->spriteIndex); } - if (((*(char*)&this->field_0x68 == 0xe) && ((gPlayerEntity.frame & 0x7f) != 0))) { - (*(int*)&this->field_0x78)--; - if ((*(int*)&this->field_0x78) == 0) { - (*(int*)&this->field_0x74)++; - iVar5 = (*(int*)&this->field_0x74) * 4; - iVar2 = *(u8**)&this->field_0x7c; - if (iVar2[iVar5] == 0xff) { + if (((this->unk_68 == 0xe) && ((gPlayerEntity.frame & 0x7f) != 0))) { + if (--this->unk_78 == 0) { + this->unk_74++; + tmp2 = this->unk_74 * 4; + pbVar3 = &this->unk_7c[tmp2]; + if (pbVar3[0] == 0xff) { if ((gPlayerState.shield_status & 0x40) != 0) { - *(u8**)&this->field_0x7c = gUnk_081271DC; - gPlayerState.shield_status = gPlayerState.shield_status & 0xbf; + this->unk_7c = gUnk_081271DC; + gPlayerState.shield_status &= ~0x40; } - *(u32*)&this->field_0x74 = 0; - iVar2 = *(u8**)&this->field_0x7c; + this->unk_74 = 0; } - pbVar3 = &iVar2[*(int*)&this->field_0x74 * 4]; - *(u32*)&this->field_0x78 = pbVar3[1]; + pbVar3 = &this->unk_7c[this->unk_74 * 4]; + this->unk_78 = pbVar3[1]; if ((gPlayerState.shield_status & 0x40) != 0) { u32 temp = (gPlayerEntity.frame & 0x7f) + 8; - sub_080042D0(this, temp + *pbVar3, (u16)this->spriteIndex); + sub_080042D0(super, temp + pbVar3[0], super->spriteIndex); } else { - sub_080042D0(this, (gPlayerEntity.frame & 0x7f) + *pbVar3, (u16)this->spriteIndex); + sub_080042D0(super, (gPlayerEntity.frame & 0x7f) + pbVar3[0], super->spriteIndex); } } } - this->frame = gPlayerEntity.frame; - this->frameSpriteSettings = gPlayerEntity.frameSpriteSettings; - sub_08078E84(this, &gPlayerEntity); + super->frame = gPlayerEntity.frame; + super->frameSpriteSettings = gPlayerEntity.frameSpriteSettings; + sub_08078E84(super, &gPlayerEntity); } else { - this->frameIndex = 0xff; + super->frameIndex = 0xff; } } -END_NONMATCH