From cc278d8d560e8338d97f60ab651461c05197296c Mon Sep 17 00:00:00 2001 From: Jonathan Hohle Date: Mon, 12 Aug 2024 11:02:36 -0700 Subject: [PATCH] Decompile `w_005` `EntityWeaponAttack` (#1501) Decompiles `EntityWeaponAttack` of `w_005`. Fixes `g_Entities` use in `w_033` to properly use the `PLAYER` macro. --- src/weapon/w_005.c | 56 +++++++++++++++++++++++++++++++++++++++++++++- src/weapon/w_033.c | 2 +- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/weapon/w_005.c b/src/weapon/w_005.c index 5198ec9ac0..a4fdfb40e7 100644 --- a/src/weapon/w_005.c +++ b/src/weapon/w_005.c @@ -9,7 +9,61 @@ extern s32 g_HandId; #define g_Animset w_005_1 #define g_Animset2 w_005_2 -INCLUDE_ASM("weapon/nonmatchings/w_005", EntityWeaponAttack); +extern WeaponAnimation D_27000_8017B2F4[]; + +void EntityWeaponAttack(Entity* self) { + WeaponAnimation* anim; + s8 animIndex; + + self->posX.val = PLAYER.posX.val; + self->posY.val = PLAYER.posY.val; + self->facingLeft = PLAYER.facingLeft; + animIndex = (self->params & 0x7fff) >> 8; + anim = &D_27000_8017B2F4[animIndex]; + + if (PLAYER.ext.player.anim >= anim->frameStart && + PLAYER.ext.player.anim < (anim->frameStart + 7) && + g_Player.unk46 != 0) { + if (self->step == 0) { + SetSpriteBank1(g_Animset); + self->animSet = ANIMSET_OVL(0x10); + self->palette = PAL_DRA(0x110); + self->unk5A = 0x64; + if (g_HandId != 0) { + self->animSet += 2; + self->palette += 0x18; + self->unk5A += 2; + } + self->palette += anim->palette; + self->flags = FLAG_UNK_20000 | FLAG_UNK_40000; + self->zPriority = PLAYER.zPriority - 2; + self->drawMode = DRAW_TPAGE2 | DRAW_TPAGE; + SetWeaponProperties(self, 0); + self->step++; + } + self->ext.weapon.anim = PLAYER.ext.player.anim - anim->frameStart; + if ((PLAYER.animFrameDuration == 1) && + (PLAYER.animFrameIdx == anim->soundFrame)) { + g_api.PlaySfx(anim->soundId); + g_api.PlaySfx(SFX_ANIME_SWORD_B); + } + if (g_api.UpdateUnarmedAnim(anim->frameProps, anim->frames) < 0) { + DestroyEntity(self); + return; + } + } else { + DestroyEntity(self); + return; + } + + if (PLAYER.animFrameIdx >= 6 && PLAYER.animFrameIdx < 8) { + self->hitboxOffX = self->hitboxOffX + 7; + self->hitboxWidth += 7; + } + self->drawFlags = PLAYER.drawFlags; + self->rotY = PLAYER.rotY; + self->rotPivotY = PLAYER.rotPivotY; +} s32 func_ptr_80170004(Entity* self) {} diff --git a/src/weapon/w_033.c b/src/weapon/w_033.c index 6a2e17bb4b..4de6dc23d4 100644 --- a/src/weapon/w_033.c +++ b/src/weapon/w_033.c @@ -15,7 +15,7 @@ void EntityWeaponAttack(Entity* self) { WeaponAnimation* anim; s8 animIndex; - self->posX.val = g_Entities->posX.val; + self->posX.val = PLAYER.posX.val; self->posY.val = PLAYER.posY.val; self->facingLeft = PLAYER.facingLeft; animIndex = (self->params & 0x7fff) >> 8;