Skip to content

Commit

Permalink
tt_003 func_us_801771B0 decompile (#1972)
Browse files Browse the repository at this point in the history
Big shout to @Onenutmcgee for figuring out that hitboxOffX seems to be
s16 for Servants overlays.
  • Loading branch information
mrmidi authored Dec 5, 2024
1 parent 5b36d72 commit a2c4012
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/servant.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef SERVANT_H
#define SERVANT_H
#define SERVANT
#include <common.h>
#include <game.h>

Expand Down
127 changes: 126 additions & 1 deletion src/servant/tt_003/demon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a2c4012

Please sign in to comment.