From a2c40122fe148812850428526721cefd0542bec6 Mon Sep 17 00:00:00 2001 From: Aleksandr Shabelnikov Date: Thu, 5 Dec 2024 12:01:51 +0100 Subject: [PATCH] `tt_003` func_us_801771B0 decompile (#1972) Big shout to @Onenutmcgee for figuring out that hitboxOffX seems to be s16 for Servants overlays. --- include/game.h | 2 +- include/servant.h | 1 + src/servant/tt_003/demon.c | 127 ++++++++++++++++++++++++++++++++++++- 3 files changed, 128 insertions(+), 2 deletions(-) diff --git a/include/game.h b/include/game.h index 7ee9d0b8af..a0298b88df 100644 --- a/include/game.h +++ b/include/game.h @@ -798,7 +798,7 @@ typedef struct Entity { /* 0x04 */ f32 posY; /* 0x08 */ s32 velocityX; /* 0x0C */ s32 velocityY; -#if defined(STAGE) || defined(WEAPON) +#if defined(STAGE) || defined(WEAPON) || defined(SERVANT) /* 0x10 */ s16 hitboxOffX; #else // hack to match in DRA and RIC /* 0x10 */ u16 hitboxOffX; diff --git a/include/servant.h b/include/servant.h index 8c8d936d10..5bd546c677 100644 --- a/include/servant.h +++ b/include/servant.h @@ -1,5 +1,6 @@ #ifndef SERVANT_H #define SERVANT_H +#define SERVANT #include #include diff --git a/src/servant/tt_003/demon.c b/src/servant/tt_003/demon.c index fc9eca162e..57c08dc681 100644 --- a/src/servant/tt_003/demon.c +++ b/src/servant/tt_003/demon.c @@ -1826,7 +1826,132 @@ void func_us_80176C1C(Entity* self) { } } -INCLUDE_ASM("servant/tt_003/nonmatchings/demon", func_us_801771B0); +// PSX: https://decomp.me/scratch/qDGTj +// PSP: https://decomp.me/scratch/D67x7 + +extern s32 D_us_80178688; +extern s32 D_us_8017868C; +extern s16 D_us_80171B44[3][8]; + +void func_us_801771B0(Entity* self) { + Primitive* prim; + s16 colorValue; + s32 i; + // s32 i; + s32 posX_hi; + s32 posY_hi; + s16* uvCoords; + + switch (self->step) { + case 0: + if (self->params == 0) { + D_us_80178688 = self->posX.val; + D_us_8017868C = self->posY.val; + } else { + self->posX.val = D_us_80178688; + self->posY.val = D_us_8017868C; + } + + self->primIndex = g_api.AllocPrimitives(PRIM_GT4, 3); + if (self->primIndex == -1) { + DestroyEntity(self); + return; + } + + self->flags = + FLAG_POS_CAMERA_LOCKED | FLAG_KEEP_ALIVE_OFFCAMERA | FLAG_HAS_PRIMS; + HIH(self->velocityX) = (self->facingLeft != 0) ? -0x10 : 0x10; + + switch (self->params) { + case 2: + self->posY.i.hi += 8; + case 1: + self->posY.i.hi += 8; + case 0: + self->posX.i.hi += (self->facingLeft != 0) ? -0x20 : 0x20; + } + + prim = &g_PrimBuf[self->primIndex]; + for (i = 0; i < 3; i++) { + prim->tpage = 0x1A; + prim->clut = 0x147; + prim->priority = self->zPriority + 1; + prim->drawMode = + DRAW_TPAGE2 | DRAW_TPAGE | DRAW_COLORS | DRAW_TRANSP; + prim->u0 = prim->u2 = 0xB; + prim->u1 = prim->u3 = 0x35; + prim->v0 = prim->v1 = 0xCB; + prim->v2 = prim->v3 = 0xF5; + PCOL(prim) = 0x80; + + prim = prim->next; + } + + g_api.GetServantStats(self, 0x1B, 1, &s_DemonStats); + + self->hitboxOffX = -4; + self->hitboxOffY = 0; + self->hitboxWidth = 0x1C; + self->hitboxHeight = 4; + + self->step++; + if (self->params >= 2) { + self->step++; + } + break; + + case 1: + self->ext.et_801737F0.animationTriggerCount += 1; + self->posX.val += self->velocityX; + + if (self->ext.et_801737F0.animationTriggerCount >= 3) { + CreateEventEntity(self, 0xDE, self->params + 1); + self->step += 1; + } + break; + + case 2: + self->posX.val += self->velocityX; + self->ext.et_801737F0.animationTriggerCount += 1; + + if ((u16)(self->posX.i.hi + 0x20) > 0x140) { + DestroyEntity(self); + return; + } + break; + } + + posX_hi = self->posX.i.hi; + posY_hi = self->posY.i.hi; + + prim = &g_PrimBuf[self->primIndex]; + for (i = 0; i < 3; i++) { + + if (self->facingLeft) { + prim->x0 = posX_hi - D_us_80171B44[i][0]; + prim->y0 = posY_hi - D_us_80171B44[i][1]; + prim->x1 = posX_hi - D_us_80171B44[i][2]; + prim->y1 = posY_hi - D_us_80171B44[i][3]; + prim->x2 = posX_hi - D_us_80171B44[i][4]; + prim->y2 = posY_hi - D_us_80171B44[i][5]; + prim->x3 = posX_hi - D_us_80171B44[i][6]; + prim->y3 = posY_hi - D_us_80171B44[i][7]; + } else { + prim->x0 = posX_hi + D_us_80171B44[i][0]; + prim->y0 = posY_hi + D_us_80171B44[i][1]; + prim->x1 = posX_hi + D_us_80171B44[i][2]; + prim->y1 = posY_hi + D_us_80171B44[i][3]; + prim->x2 = posX_hi + D_us_80171B44[i][4]; + prim->y2 = posY_hi + D_us_80171B44[i][5]; + prim->x3 = posX_hi + D_us_80171B44[i][6]; + prim->y3 = posY_hi + D_us_80171B44[i][7]; + } + + PCOL(prim) = + ((self->ext.et_801737F0.animationTriggerCount & 1) * 64) + 0x40; + prim = prim->next; + } +} extern s32 D_us_801786D0; extern s32 D_us_801786D4;