Skip to content

Commit

Permalink
Decompile Library Background Parallax Entities (#2177)
Browse files Browse the repository at this point in the history
Decompiles background bookcase, chairs & desk, & shadows behind the
ectoplasms.

Split library background into a separate segment.
  • Loading branch information
hohle authored Feb 11, 2025
1 parent ab6e04b commit dcca39a
Show file tree
Hide file tree
Showing 6 changed files with 1,408 additions and 1,121 deletions.
5 changes: 5 additions & 0 deletions config/splat.us.stlib.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ segments:
subalign: 4
subsegments:
- [0x0, data]
- [0xDC0, .data, e_library_bg]
- [0xDF0, data, unk_2FA80]
- [0x134C, .data, e_shop]
- [0x1528, data]
- [0x1C7C, .data, st_update]
Expand All @@ -55,6 +57,7 @@ segments:
- [0x2C48, .data, e_skeleton]
- [0x2D38, data]
- [0x2B938, .rodata, first_c_file]
- [0x2B960, .rodata, unk_2FA80]
- [0x2CE78, .rodata, e_shop]
- [0x2CF14, .rodata, unk_33EC8]
- [0x2CF48, .rodata, unk_3420C]
Expand All @@ -79,6 +82,8 @@ segments:
- [0x2DDAC, .rodata, e_spellbook_magic_tome]
- [0x2DEB4, .rodata, e_life_up]
- [0x2DED0, c, first_c_file]
- [0x2F280, c, e_library_bg]
- [0x2FA80, c, unk_2FA80]
- [0x3245C, c, e_shop]
- [0x33EC8, c, unk_33EC8]
- [0x3420C, c, unk_3420C]
Expand Down
5 changes: 4 additions & 1 deletion config/symbols.us.stlib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ bone_projectile_velocity_x = 0x80182CF4;
sensors_special = 0x80182D24;
sensors_move = 0x80182D2C;
g_UnkPrimHelperRot = 0x801ADDA4;
ST0_EntityBackgroundBlock = 0x801ADED0;
LIB_EntityBackgroundBlock = 0x801ADED0;
PlayerIsWithinHitbox = 0x801ADF98;
func_801B0AA4 = 0x801AE01C;
EntityBackgroundBookcase = 0x801AF280;
EntityBackgroundFurniture = 0x801AF538;
EntityBackgroundShadow = 0x801AF7B8;
EntityLibrarianChair = 0x801B037C;
CutsceneUnk1 = 0x801B95EC;
SetCutsceneScript = 0x801B9640;
Expand Down
6 changes: 6 additions & 0 deletions include/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -2798,6 +2798,11 @@ typedef struct {
/* 0xA8 */ s16 unkA8;
} ET_801D2274;

typedef struct {
/* 0x7C */ Primitive* prim;
/* 0x80 */ Primitive* lastPrim;
} ET_LibraryShadow;

typedef union { // offset=0x7C
struct Primitive* prim;
ET_Placeholder ILLEGAL;
Expand Down Expand Up @@ -3041,6 +3046,7 @@ typedef union { // offset=0x7C
ET_801D064C et_801D064C;
ET_801D2274 et_801D2274;
ET_LibrarianChair libraryChair;
ET_LibraryShadow libraryShadow;
} Ext;

#define SYNC_FIELD(struct1, struct2, field) \
Expand Down
277 changes: 277 additions & 0 deletions src/st/lib/e_library_bg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include "lib.h"

static SVECTOR D_us_80180DC0 = {0, 0, 512};
static SVECTOR D_us_80180DC8 = {0, 0, 0};

// parallax book cases
void EntityBackgroundBookcase(Entity* self) {
Primitive* prim;
s32 primIndex;
long p, flag;
s16 x;
long sxy;
SVECTOR svector;
VECTOR vector;
MATRIX matrix;

switch (self->step) {
case 0:
InitializeEntity(g_EInitInteractable);
primIndex = g_api.AllocPrimitives(PRIM_GT4, 4);
if (primIndex != -1) {
self->flags |= FLAG_HAS_PRIMS;
self->primIndex = primIndex;
prim = &g_PrimBuf[primIndex];
self->ext.prim = prim;
while (prim != NULL) {
prim->tpage = 0xF;
prim->clut = 0x35;
prim->u0 = prim->u2 = 130;
prim->u1 = prim->u3 = 253;
prim->v0 = prim->v1 = 50;
prim->v2 = prim->v3 = 125;
prim->priority = 0x40;
prim->drawMode = DRAW_UNK02;
prim = prim->next;
}
} else {
DestroyEntity(self);
return;
}
g_GpuBuffers[0].draw.r0 = 16;
g_GpuBuffers[0].draw.g0 = 16;
g_GpuBuffers[0].draw.b0 = 16;
g_GpuBuffers[1].draw.r0 = 16;
g_GpuBuffers[1].draw.g0 = 16;
g_GpuBuffers[1].draw.b0 = 16;
// fallthrough
case 1:
SetGeomScreen(1024);
SetGeomOffset(128, self->posY.i.hi);
RotMatrix(&D_us_80180DC8, &matrix);
vector.vx = self->posX.i.hi - 128;
vector.vy = 0;
vector.vz = 1024;
TransMatrix(&matrix, &vector);
SetRotMatrix(&matrix);
SetTransMatrix(&matrix);
RotTransPers(&D_us_80180DC0, &sxy, &p, &flag);

x = sxy & 0xFFFF;
if (x > 0) {
while (x > -64) {
x -= 124;
}
} else {
while (x < -128) {
x += 124;
}
}

prim = self->ext.prim;
while (prim != NULL) {
prim->x0 = prim->x2 = x;
x += 124;
prim->x1 = prim->x3 = x;
prim->y0 = prim->y1 = self->posY.i.hi - 76;
prim->y2 = prim->y3 = self->posY.i.hi;
prim->drawMode = DRAW_UNK02;

prim = prim->next;
if (x > 256) {
break;
}
}

while (prim != NULL) {
prim->drawMode = DRAW_HIDE;
prim = prim->next;
}
break;
}
}

static SVECTOR D_us_80180DD0 = {0, 0, 256};
static SVECTOR D_us_80180DD8 = {0, 0, 0};

// parallax desk & chairs
void EntityBackgroundFurniture(Entity* self) {
Primitive* prim;
s32 primIndex;
long p, flag;
s16 x;
long sxy;
SVECTOR svector;
VECTOR vector;
MATRIX matrix;

switch (self->step) {
case 0:
InitializeEntity(g_EInitInteractable);
primIndex = g_api.AllocPrimitives(PRIM_GT4, 4);
if (primIndex != -1) {
self->flags |= FLAG_HAS_PRIMS;
self->primIndex = primIndex;
prim = &g_PrimBuf[primIndex];
self->ext.prim = prim;
while (prim != NULL) {
prim->tpage = 0xF;
prim->clut = 0x34;
prim->u0 = prim->u2 = 128;
prim->u1 = prim->u3 = 248;
prim->v0 = prim->v1 = 0;
prim->v2 = prim->v3 = 28;
prim->priority = 0x50;
prim->drawMode = DRAW_UNK02;
prim = prim->next;
}
} else {
DestroyEntity(self);
return;
}
// fallthrough
case 1:
SetGeomScreen(1024);
SetGeomOffset(128, self->posY.i.hi);
RotMatrix(&D_us_80180DD8, &matrix);
vector.vx = self->posX.i.hi - 128;
vector.vy = 0;
vector.vz = 1024;
TransMatrix(&matrix, &vector);
SetRotMatrix(&matrix);
SetTransMatrix(&matrix);
RotTransPers(&D_us_80180DD0, &sxy, &p, &flag);

x = sxy & 0xFFFF;
if (x > 0) {
while (x > -64) {
x -= 120;
}
} else {
while (x < -128) {
x += 120;
}
}

prim = self->ext.prim;
while (prim != NULL) {
prim->x0 = prim->x2 = x;
x += 120;
prim->x1 = prim->x3 = x;
prim->y0 = prim->y1 = self->posY.i.hi - 28;
prim->y2 = prim->y3 = self->posY.i.hi;
prim->drawMode = DRAW_UNK02;

prim = prim->next;
if (x > 256) {
break;
}
}

while (prim != NULL) {
prim->drawMode = DRAW_HIDE;
prim = prim->next;
}
break;
}
}

static SVECTOR D_us_80180DE0 = {0, 0, 448};
static SVECTOR D_us_80180DE8 = {0, 0, 0};

// parallax column shadow
void EntityBackgroundShadow(Entity* self) {
Primitive *prim, *last;
s32 primIndex;
long p, flag;
s16 x;
long sxy;
SVECTOR svector;
VECTOR vector;
MATRIX matrix;

switch (self->step) {
case 0:
InitializeEntity(g_EInitInteractable);
primIndex = g_api.func_800EDB58(PRIM_TILE_ALT, 10);
if (primIndex != -1) {
self->flags |= FLAG_HAS_PRIMS;
self->primIndex = primIndex;
prim = &g_PrimBuf[primIndex];
self->ext.libraryShadow.prim = prim;
while (prim != NULL) {
last = prim;
prim->u0 = 24;
prim->v0 = 64;
prim->r0 = prim->g0 = prim->b0 = 0;
prim->priority = 0x60;
prim->drawMode = DRAW_TPAGE | DRAW_UNK02 | DRAW_TRANSP;
prim = prim->next;
}
prim = last;
self->ext.libraryShadow.lastPrim = prim;
prim->u0 = 255;
prim->v0 = 48;
prim->x0 = 0;
prim->y0 = self->posY.i.hi - 112;
prim->r0 = prim->g0 = prim->b0 = 0;
prim->priority = 0x60;
prim->drawMode = DRAW_TPAGE | DRAW_UNK02 | DRAW_TRANSP;
} else {
DestroyEntity(self);
return;
}
// fallthrough
case 1:
SetGeomScreen(1024);
SetGeomOffset(128, self->posY.i.hi);
RotMatrix(&D_us_80180DE8, &matrix);
vector.vx = self->posX.i.hi - 128;
vector.vy = 0;
vector.vz = 1024;
TransMatrix(&matrix, &vector);
SetRotMatrix(&matrix);
SetTransMatrix(&matrix);
RotTransPers(&D_us_80180DE0, &sxy, &p, &flag);

x = sxy & 0xFFFF;
if (x > 0) {
while (x > -64) {
x -= 56;
}
} else {
while (x < -128) {
x += 56;
}
}

prim = self->ext.libraryShadow.prim;
while (prim != NULL) {
prim->x0 = x;
x += 56;
prim->y0 = self->posY.i.hi - 64;
prim->drawMode = DRAW_TPAGE | DRAW_UNK02 | DRAW_TRANSP;

prim = prim->next;
if (x > 256) {
break;
}
}

while (prim != NULL) {
prim->drawMode = DRAW_HIDE;
prim = prim->next;
}

prim = self->ext.libraryShadow.lastPrim;
prim->u0 = 255;
prim->v0 = 48;
prim->x0 = 0;
prim->y0 = self->posY.i.hi - 112;
prim->r0 = prim->g0 = prim->b0 = 0;
prim->priority = 0x60;
prim->drawMode = DRAW_TPAGE | DRAW_UNK02 | DRAW_TRANSP;
break;
}
}
Loading

0 comments on commit dcca39a

Please sign in to comment.