Skip to content

Commit

Permalink
MAR assets + CutsceneRun (#1619)
Browse files Browse the repository at this point in the history
PSX: https://decomp.me/scratch/RL97B
PSP: https://decomp.me/scratch/3WKmX

`func_us_8018B4A0` needed to be decompiled before importing all the
assets due to GCC compiling `PfnEntityUpdates[entity->entityId - 1]`
into a hardcoded offset landing to the `header.c` data as a fake symbol.

The decompiled function seem to be some kind of object spawner for the
cutscenes controller. I have yet to confirm that, so I did not rename
any symbols yet.

EDIT: `func_us_8018B4A0` turned out to be a shared function I renamed as
`CutsceneRun`. DRE and CEN use slightly different variants and they will
not use the new `cutscene.h`. I plan on putting more stuff into
`cutscene.h` in a separate PR and maybe rename all the C files that
handle cutscenes accordingly.
  • Loading branch information
Xeeynamo committed Sep 16, 2024
1 parent 7689f77 commit 2917d62
Show file tree
Hide file tree
Showing 29 changed files with 296 additions and 336 deletions.
13 changes: 10 additions & 3 deletions config/splat.us.bomar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ segments:
align: 4
subalign: 4
subsegments:
- [0x0, data]
- [0x0, .data, header]
- [0xCC, .data, header] # layers
- [0xF4, .data, header]
- [0x168, .data, e_laydef] # layout entries header
- [0x310, .data, e_init]
- [0x4E8, .data, st_debug]
- [0x568, .data, e_breakable]
Expand All @@ -51,10 +54,14 @@ segments:
- [0x1174, .data, e_particles]
- [0x11F4, .data, e_room_fg]
- [0x1280, data] # 17FEC
- [0x12EC, data] # rooms
- [0x12EC, .data, rooms]
- [0x1308, .data, e_life_up]
- [0x135C, data] # e_layout
- [0x135C, .data, e_layout] # layout entries data
- [0x1424, data]
- [0x5300, .data, tile_data] # tile data
- [0x5700, .data, tile_data] # tile definitions
- [0x9710, .data, sprites]
- [0xA9D4, data]
- [0xA9EC, .rodata, AFC4]
- [0xAAB0, .rodata, e_red_door]
- [0xAAC8, .rodata, e_collect]
Expand Down
10 changes: 3 additions & 7 deletions config/symbols.us.bomar.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
g_pStObjLayoutHorizontal = 0x80180168;
g_pStObjLayoutVertical = 0x8018023C;
D_80180A60 = 0x801803B4;
D_80180608 = 0x80180744;
g_StoneDoorTiles = 0x801812DC;
CutsceneRun = 0x8018B4A0;
EntityMariaCutscene = 0x8018B850;
Update = 0x8018CFA0;
UpdateStageEntities = 0x8018D29C;
HitDetection = 0x8018D3A4;
InitRoomEntities = 0x8018F3BC;
UpdateRoomPosition = 0x8018F534;
DestroyEntity = 0x80190388;
AnimateEntity = 0x801904B8;
MoveEntity = 0x8019073C;
Expand All @@ -18,4 +12,6 @@ g_LayoutObjHorizontal = 0x8019A260;
g_LayoutObjVertical = 0x8019A264;
g_LayoutObjPosHorizontal = 0x8019A268;
g_LayoutObjPosVertical = 0x8019A26C;
g_Dialogue = 0x8019AE74;
g_CutsceneFlags = 0x8019AF20;
g_Statues = 0x8019AF28;
2 changes: 1 addition & 1 deletion src/boss/mar/AFC4.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ INCLUDE_ASM("boss/mar/nonmatchings/AFC4", func_us_8018B2F0);

INCLUDE_ASM("boss/mar/nonmatchings/AFC4", func_us_8018B474);

INCLUDE_ASM("boss/mar/nonmatchings/AFC4", func_us_8018B4A0);
#include "../../st/cutscene.h"

INCLUDE_ASM("boss/mar/nonmatchings/AFC4", func_us_8018B74C);

Expand Down
59 changes: 59 additions & 0 deletions src/boss/mar/header.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include "mar.h"

extern RoomHeader OVL_EXPORT(rooms)[];
extern signed short* spriteBanks[];
extern void* Cluts[];
extern MyRoomDef rooms_layers[];
static GfxBank* gfxBanks[];
void UpdateStageEntities();

AbbreviatedOverlay OVL_EXPORT(Overlay) = {
.Update = Update,
.HitDetection = HitDetection,
.UpdateRoomPosition = UpdateRoomPosition,
.InitRoomEntities = InitRoomEntities,
.rooms = OVL_EXPORT(rooms),
.spriteBanks = spriteBanks,
.cluts = Cluts,
.objLayoutHorizontal = g_pStObjLayoutHorizontal,
.tileLayers = rooms_layers,
.gfxBanks = gfxBanks,
.UpdateStageEntities = UpdateStageEntities,
};

#include "sprite_banks.h"

extern u16* D_us_80184EE0[];
extern u16* D_us_801850E0[];
extern u16* D_us_801852E0[];
static u16** D_us_8018008C[] = {
0x00000005, 0x00002000, 0x00000080, D_us_80184EE0,
0x00002080, 0x00000080, D_us_801850E0, 0x00002100,
0x00000010, D_us_801852E0, PAL_TERMINATE(),
};

static void* Cluts[] = {
D_us_8018008C,
};

#include "layers.h"

static u_long* D_us_801800F4_TERM = GFX_TERMINATE();

extern u_long* D_us_801830F0;
extern u_long* D_us_80184220;
static u_long* D_us_801800F8[] = {
// TODO GfxBank
0x00000004, 0x00800100, 0x00800080, &D_us_801830F0,
0x00A00100, 0x00800080, &D_us_80184220, 0xFFFFFFFF,
};

static GfxBank* gfxBanks[] = {
&D_us_801800F4_TERM, &D_us_801800F8, &D_us_801800F4_TERM,
&D_us_801800F4_TERM, &D_us_801800F4_TERM, &D_us_801800F4_TERM,
&D_us_801800F4_TERM, &D_us_801800F4_TERM, &D_us_801800F4_TERM,
&D_us_801800F4_TERM, &D_us_801800F4_TERM, &D_us_801800F4_TERM,
&D_us_801800F4_TERM, &D_us_801800F4_TERM, &D_us_801800F4_TERM,
&D_us_801800F4_TERM, &D_us_801800F4_TERM, &D_us_801800F4_TERM,
&D_us_801800F4_TERM, &D_us_801800F4_TERM};
2 changes: 2 additions & 0 deletions src/boss/mar/mar.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <stage.h>

#define OVL_EXPORT(x) MAR_##x

typedef enum {
/* 0x00 */ E_NONE,
/* 0x01 */ E_BREAKABLE,
Expand Down
6 changes: 6 additions & 0 deletions src/boss/mar/tile_data.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include <stage.h>

#include "tilemap_05300.h"
#include "tilemap_05500.h"
#include "tiledef_09700.h"
12 changes: 6 additions & 6 deletions src/st/cen/F890.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "game.h"
#include "sfx.h"

extern u32 D_8019D424;
extern u32 g_CutsceneFlags;
extern s32 D_8019D428;

// tile layout
Expand Down Expand Up @@ -172,7 +172,7 @@ void EntityPlatform(Entity* self) {
player->posX.i.hi = 384 - tilemap->scrollX.i.hi;
self->step++;
g_api.PlaySfx(SFX_METAL_CLANG_A);
D_8019D424 |= 1;
g_CutsceneFlags |= 1;
tilemap->height = ((s16)tilemap->scrollY.i.hi + 0x100);
func_8018F8EC(0);
}
Expand All @@ -192,7 +192,7 @@ void EntityPlatform(Entity* self) {
if (player->facingLeft == 0) {
g_Player.padSim = PAD_LEFT;
}
D_8019D424 |= 4;
g_CutsceneFlags |= 4;
self->step++;
}
func_8018F890(0x200);
Expand All @@ -203,7 +203,7 @@ void EntityPlatform(Entity* self) {
g_Player.padSim = 0;
g_Player.D_80072EFC = 1;

if (D_8019D424 & 8) {
if (g_CutsceneFlags & 8) {
CreateEntityFromCurrentEntity(E_EQUIP_ITEM_DROP, &g_Entities[204]);
g_Entities[204].params = NUM_HAND_ITEMS + ITEM_HOLY_GLASSES;
g_Entities[204].step = 5;
Expand All @@ -213,7 +213,7 @@ void EntityPlatform(Entity* self) {
break;

case 6:
if (D_8019D424 & 2) {
if (g_CutsceneFlags & 2) {
self->step++;
g_api.PlaySfx(SFX_METAL_CLANG_A);
}
Expand Down Expand Up @@ -321,7 +321,7 @@ void EntityRoomDarkness(Entity* self) {
break;

case 1:
if (D_8019D424 & 4) {
if (g_CutsceneFlags & 4) {
prim = &g_PrimBuf[self->primIndex];
prim->r0 = prim->r1 = prim->r2 = prim->r3 = prim->g0 = prim->g1 =
prim->g2 = prim->g3 = prim->b0 = prim->b1 = prim->b2 =
Expand Down
50 changes: 22 additions & 28 deletions src/st/cen/holyglassescutscene.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ static u8 __unused[0xC00];
static s32 D_8019D374;
static Dialogue g_Dialogue;
static u32 __unused0[26];
u32 D_8019D424;
u32 g_CutsceneFlags;
u32 D_8019D428;

// Bizarre variable - u8 here, but u16 in EntityHeartDrop
Expand Down Expand Up @@ -210,59 +210,53 @@ void func_8018E3BC(s32 arg0) {
g_Dialogue.unk3C = 1;
}

void func_8018E3E8(void) {
void CutsceneRun(void) {
Entity* entity;
u16 startTimer;
u8 entityIndex;

g_Dialogue.timer++;
// protect from overflows
if (g_Dialogue.timer > 0xFFFE) {
if (g_Dialogue.timer >= 0xFFFF) {
g_Dialogue.unk3C = 0;
return;
}

while (true) {
// Start the dialogue script only if the start timer has passed
startTimer = (*g_Dialogue.unk40++ << 8) | *g_Dialogue.unk40++;
startTimer = *g_Dialogue.unk40++ << 8;
startTimer |= *g_Dialogue.unk40++;
if (g_Dialogue.timer < startTimer) {
// Re-evaluate the condition at the next frame
g_Dialogue.unk40 -= 2;
return;
}

switch (*g_Dialogue.unk40++) {
case 0:
entityIndex = *g_Dialogue.unk40++;
entity = &g_Entities[STAGE_ENTITY_START + entityIndex];
entity =
&g_Entities[*g_Dialogue.unk40++ & 0xFF] + STAGE_ENTITY_START;
DestroyEntity(entity);

entity->entityId = *g_Dialogue.unk40++;
entity->pfnUpdate = PfnEntityUpdates[entity->entityId - 1];
entity->posX.i.hi = *g_Dialogue.unk40++ * 0x10;
entity->posX.i.hi = *g_Dialogue.unk40++ | entity->posX.i.hi;
entity->posX.i.hi |= *g_Dialogue.unk40++;
entity->posY.i.hi = *g_Dialogue.unk40++ * 0x10;
entity->posY.i.hi = *g_Dialogue.unk40++ | entity->posY.i.hi;
entity->posY.i.hi |= *g_Dialogue.unk40++;
entity->posX.i.hi -= g_Tilemap.scrollX.i.hi;
entity->posY.i.hi -= g_Tilemap.scrollY.i.hi;
break;

case 1:
entityIndex = *g_Dialogue.unk40++;
entity = &g_Entities[STAGE_ENTITY_START + entityIndex];
entity =
&g_Entities[*g_Dialogue.unk40++ & 0xFF] + STAGE_ENTITY_START;
DestroyEntity(entity);
break;

case 2:
if (!((D_8019D424 >> *g_Dialogue.unk40) & 1)) {
if (!((g_CutsceneFlags >> *g_Dialogue.unk40) & 1)) {
g_Dialogue.unk40--;
return;
}
D_8019D424 &= ~(1 << *g_Dialogue.unk40++);
g_CutsceneFlags &= ~(1 << *g_Dialogue.unk40++);
break;

case 3:
D_8019D424 |= 1 << *g_Dialogue.unk40++;
g_CutsceneFlags |= 1 << *g_Dialogue.unk40++;
break;
}
}
Expand Down Expand Up @@ -328,7 +322,7 @@ void EntityHolyGlassesCutscene(Entity* self) {
self->step_s = 0;
}
if ((self->step) && (g_Dialogue.unk3C != 0)) {
func_8018E3E8();
CutsceneRun();
}
}
switch (self->step) {
Expand All @@ -340,7 +334,7 @@ void EntityHolyGlassesCutscene(Entity* self) {
if (func_8018DF60(D_801813F0) & 0xFF) {
self->flags |= FLAG_HAS_PRIMS | FLAG_UNK_2000;
D_8003C704 = 1;
D_8019D424 = 0;
g_CutsceneFlags = 0;
D_8019D428 = 0;
D_8019D374 = 0;
self->primIndex = g_Dialogue.primIndex[2];
Expand Down Expand Up @@ -554,15 +548,15 @@ void EntityHolyGlassesCutscene(Entity* self) {
continue;

case 16:
if (!((D_8019D424 >> *g_Dialogue.nextCharDialogue) & 1)) {
if (!((g_CutsceneFlags >> *g_Dialogue.nextCharDialogue) & 1)) {
g_Dialogue.nextCharDialogue--;
return;
}
D_8019D424 &= ~(1 << *g_Dialogue.nextCharDialogue);
g_CutsceneFlags &= ~(1 << *g_Dialogue.nextCharDialogue);
*g_Dialogue.nextCharDialogue++;
continue;
case 17:
D_8019D424 |= 1 << *g_Dialogue.nextCharDialogue++;
g_CutsceneFlags |= 1 << *g_Dialogue.nextCharDialogue++;
continue;
case 18:
g_Dialogue.unk3C = 0;
Expand Down Expand Up @@ -591,17 +585,17 @@ void EntityHolyGlassesCutscene(Entity* self) {
g_api.PlaySfx(nextChar);
continue;
case 21:
D_8019D424 = 0;
g_CutsceneFlags = 0;
D_8019D374 = 0;
D_8019D428 = 0;
continue;
case 22:
D_8019D424 &= ~(1 << *g_Dialogue.nextCharDialogue++);
g_CutsceneFlags &= ~(1 << *g_Dialogue.nextCharDialogue++);
continue;
case 23:
return;
case 24:
if (!((D_8019D424 >> *g_Dialogue.nextCharDialogue) & 1)) {
if (!((g_CutsceneFlags >> *g_Dialogue.nextCharDialogue) & 1)) {
*g_Dialogue.nextCharDialogue--;
return;
}
Expand Down
55 changes: 55 additions & 0 deletions src/st/cutscene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include <stage.h>

extern Dialogue g_Dialogue;
extern u32 g_CutsceneFlags;
extern PfnEntityUpdate PfnEntityUpdates[];
void CutsceneRun(void) {
Entity* entity;
u16 startTimer;

g_Dialogue.timer++;
// protect from overflows
if (g_Dialogue.timer >= 0xFFFF) {
g_Dialogue.unk3C = 0;
return;
}
while (true) {
// Start the dialogue script only if the start timer has passed
startTimer = *g_Dialogue.unk40++ << 8;
startTimer |= *g_Dialogue.unk40++;
if (g_Dialogue.timer < startTimer) {
// Re-evaluate the condition at the next frame
g_Dialogue.unk40 -= 2;
return;
}
switch (*g_Dialogue.unk40++) {
case 0:
entity =
&g_Entities[*g_Dialogue.unk40++ & 0xFF] + STAGE_ENTITY_START;
DestroyEntity(entity);
entity->entityId = *g_Dialogue.unk40++;
entity->pfnUpdate = PfnEntityUpdates[entity->entityId - 1];
entity->posX.i.hi = *g_Dialogue.unk40++ * 0x10;
entity->posX.i.hi |= *g_Dialogue.unk40++;
entity->posY.i.hi = *g_Dialogue.unk40++ * 0x10;
entity->posY.i.hi |= *g_Dialogue.unk40++;
break;
case 1:
entity =
&g_Entities[*g_Dialogue.unk40++ & 0xFF] + STAGE_ENTITY_START;
DestroyEntity(entity);
break;
case 2:
if (!((g_CutsceneFlags >> *g_Dialogue.unk40) & 1)) {
g_Dialogue.unk40--;
return;
}
g_CutsceneFlags &= ~(1 << *g_Dialogue.unk40++);
break;
case 3:
g_CutsceneFlags |= 1 << *g_Dialogue.unk40++;
break;
}
}
}
Loading

0 comments on commit 2917d62

Please sign in to comment.