From 9d7afdbffb222409c3cac1a2654ff0c76fdd5238 Mon Sep 17 00:00:00 2001 From: bismurphy Date: Sun, 12 May 2024 06:12:19 -0400 Subject: [PATCH] Decompile weapon 15 func_ptr_80170014 (#1121) There are only a few weapons that make use of the func_ptr_80170014 function, and this is the first of them. I don't really know how to pull in data for functions, so keeping these as externs for now. Particularly, I can't find where in the assembly the bytes of D_6D000_8017A2B0 exist. They don't appear to be in asm/us/weapon/data. We identify a couple members of the `ET_Weapon` struct, and since they're a change to velocity, I named them acceleration. This breaks weapon 29's code (it uses different datatypes at offset 0x9C), but since there's already an ET_Weapon29 dedicated alternative entity, we can continue to use that instead. Been a while since I've done a PR, nice to pick it back up, hope this is good :) Co-authored-by: sozud <122322823+sozud@users.noreply.github.com> --- include/entity.h | 16 +++++++++++++--- src/weapon/w_015.c | 48 +++++++++++++++++++++++++++++++++++++++++++++- src/weapon/w_029.c | 10 +++++----- 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/include/entity.h b/include/entity.h index 57744f0d0..1c9efe948 100644 --- a/include/entity.h +++ b/include/entity.h @@ -164,9 +164,8 @@ typedef struct { /* 0x90 */ s32 unk90; /* 0x94 */ s32 unk94; /* 0x98 */ s32 unk98; - /* 0x9C */ s16 unk9C; - /* 0x9E */ s16 unk9E; - /* 0xA0 */ s32 unkA0; + /* 0x9C */ s32 accelerationX; + /* 0xA0 */ s32 accelerationY; /* 0xA4 */ s32 unkA4; /* 0xA8 */ s32 unkA8; /* 0xAC */ u8 unkAC; @@ -177,6 +176,17 @@ typedef struct { typedef struct { /* 0x7C */ u8 unk7C; /* 0x7D */ u8 unk7D; + /* 0x7E */ s16 unk7E; + /* 0x80 */ s16 unk80; + /* 0x82 */ s16 unk82; + /* 0x84 */ s32 unk84; + /* 0x88 */ s16 childPalette; + /* 0x8A */ s16 unk8A; + /* 0x8C */ struct Entity* parent; + /* 0x90 */ s32 unk90; + /* 0x94 */ s32 unk94; + /* 0x98 */ s32 unk98; + /* 0x9C */ s16 unk9C; } ET_Weapon29; typedef struct { diff --git a/src/weapon/w_015.c b/src/weapon/w_015.c index 036e7f604..1e17a701e 100644 --- a/src/weapon/w_015.c +++ b/src/weapon/w_015.c @@ -35,7 +35,53 @@ INCLUDE_ASM("weapon/nonmatchings/w_015", func_ptr_8017000C); INCLUDE_ASM("weapon/nonmatchings/w_015", func_ptr_80170010); -INCLUDE_ASM("weapon/nonmatchings/w_015", func_ptr_80170014); +extern SpriteParts D_6D000_8017A2B0[]; +extern AnimationFrame D_6D000_8017A770[]; + +void func_ptr_80170014(Entity* self) { + s16 angle; + + if (self->step == 0) { + if (self->ext.weapon.parent->entityId == 0) { + DestroyEntity(self); + return; + } + SetSpriteBank2(D_6D000_8017A2B0); + self->animSet = ANIMSET_OVL(17); + self->palette = 0x111; + self->unk5A = 101; + if (g_HandId != 0) { + self->animSet += 2; + self->palette += 24; + self->unk5A = 103; + } + self->unk4C = D_6D000_8017A770; + self->flags = FLAG_UNK_08000000 | FLAG_UNK_100000; + self->zPriority = PLAYER.zPriority - 2; + self->drawMode = DRAW_TPAGE | 0x20; + angle = ratan2(-self->ext.weapon.parent->velocityY, + self->ext.weapon.parent->velocityX); + angle += (0x500 + (rand() % 0x600)); + self->velocityX = rcos(angle) * 64; + self->velocityY = rsin(angle) * -64; + self->ext.weapon.accelerationX = -self->velocityX / 13; + self->ext.weapon.accelerationY = -self->velocityY / 13; + self->ext.weapon.equipId = self->ext.weapon.parent->ext.weapon.equipId; + SetWeaponProperties(self, 0); + self->enemyId = self->ext.weapon.parent->enemyId; + self->hitboxHeight = self->hitboxWidth = 12; + self->step++; + return; + } + if (self->animFrameDuration < 0) { + DestroyEntity(self); + return; + } + self->posY.val += self->velocityY; + self->posX.val += self->velocityX; + self->velocityX += self->ext.weapon.accelerationX; + self->velocityY += self->ext.weapon.accelerationY; +} int GetWeaponId(void) { return 15; } diff --git a/src/weapon/w_029.c b/src/weapon/w_029.c index 6296282e5..22fe3ac3a 100644 --- a/src/weapon/w_029.c +++ b/src/weapon/w_029.c @@ -391,7 +391,7 @@ void func_ptr_80170024(Entity* self) { self->ext.weapon29.unk7D = 0; } self->flags |= 0x04800000; - self->ext.weapon.unk9C = 0x40; + self->ext.weapon29.unk9C = 0x40; for (i = 0, prim = &g_PrimBuf[self->primIndex]; prim != NULL; i++, prim = prim->next) { @@ -504,9 +504,9 @@ void func_ptr_80170024(Entity* self) { break; } } - self->ext.weapon.unk9C += 2; - if (self->ext.weapon.unk9C > 0x100) { - self->ext.weapon.unk9C = 0x100; + self->ext.weapon29.unk9C += 2; + if (self->ext.weapon29.unk9C > 0x100) { + self->ext.weapon29.unk9C = 0x100; } } firstPrim = prim = &g_PrimBuf[self->primIndex]; @@ -532,7 +532,7 @@ void func_ptr_80170024(Entity* self) { } var_s7 = &D_CF000_8017C9A0[dragonNumber][0]; - size = ((self->ext.weapon.unk9C * 54 / 256) * + size = ((self->ext.weapon29.unk9C * 54 / 256) * (rsin(var_s7->unkE) * var_s7->unk14 / 256 + 4096)) / 4096; nextX = (var_s7 + 1)->posX.i.hi;