Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dedupe lib e_lock_camera + st_debug #2233

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.psp.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ $(BUILD_DIR)/dra.elf: $(BUILD_DIR)/dra.ld $(addprefix $(BUILD_DIR)/src/dra/,$(ad
$(BUILD_DIR)/tt_%.elf: $(BUILD_DIR)/tt_%.ld $$(call list_o_files_psp,servant/tt_$$*) $(BUILD_DIR)/assets/servant/tt_%/mwo_header.bin.o
$(call link_with_deadstrip,tt_$*,$@)

ST_LIB_MERGE = collision e_chair st_update create_entity e_red_door e_room_fg st_common prim_helpers e_bloody_zombie e_misc en_thornweed_corpseweed e_skeleton e_life_up e_flea_man e_mist_door e_flea_armor e_candle_table
ST_LIB_MERGE = collision e_chair st_update create_entity e_red_door e_room_fg st_common prim_helpers e_bloody_zombie e_misc en_thornweed_corpseweed e_skeleton e_life_up e_flea_man e_mist_door e_flea_armor e_candle_table st_debug e_lock_camera
$(BUILD_DIR)/stlib.elf: $(BUILD_DIR)/stlib.ld $(addprefix $(BUILD_DIR)/src/st/lib/,$(addsuffix .c.o,$(ST_LIB_MERGE))) $$(call list_o_files_psp,st/lib_psp) $(BUILD_DIR)/assets/st/lib/mwo_header.bin.o
$(call link_with_deadstrip,stlib,$@)
ST_NO4_MERGE =
Expand Down
8 changes: 7 additions & 1 deletion config/splat.pspeu.stlib.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ segments:
- [0x1D9E8, c, lib_psp/unk_1D9E8]
- [0x231B0, c, lib_psp/lang]
- [0x23250, c, lib_psp/cutscene]
- [0x25CD0, c, lib_psp/unk_25CD0]
- [0x25CD0, c, lib/st_debug]
- [0x25DB0, c, lib_psp/unk_25CD0]
- [0x290C8, c, lib_psp/e_shop]
- [0x2BC10, c, lib_psp/2BC10]
- [0x35798, c, lib/e_lock_camera]
- [0x35F60, c, lib_psp/35F60]
- [0x36428, c, lib/e_candle_table]
- [0x367C0, data]
- [0x36800, .data, lib/e_bloody_zombie]
Expand All @@ -104,6 +107,8 @@ segments:
- [0x60E50, .data, lib_psp/cutscene]
- [0x61158, data, cutscene] # LIB_EntityCutscene data
- [0x61218, data]
- [0x6D6D0, .data, lib/e_lock_camera]
- [0x6D748, data]
- [0x6D768, .data, lib/e_candle_table]
- [0x6D800, .rodata, lib_psp/e_spellbook_magic_tome]
- [0x6D858, .rodata, lib/e_life_up]
Expand All @@ -120,6 +125,7 @@ segments:
- [0x6DAD8, .rodata, lib_psp/unk_25CD0]
- [0x6DB78, .rodata, lib_psp/e_shop]
- [0x6DBB8, .rodata, lib_psp/2BC10]
- [0x6DD20, .rodata, lib_psp/35F60]
- [0x6DD80, .bss, lib/create_entity]
- [0x6DDA0, .bss, lib/e_life_up]
- [0x6DDA8, .bss, lib_psp/e_collect]
Expand Down
6 changes: 5 additions & 1 deletion 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]
- [0xAD8, .data, e_lock_camera]
- [0xB58, data]
- [0xDC0, .data, e_library_bg]
- [0xDF0, data, unk_2FA80]
- [0x134C, .data, e_shop]
Expand Down Expand Up @@ -94,7 +96,9 @@ segments:
- [0x2DDA4, .rodata, prim_helpers]
- [0x2DDAC, .rodata, e_spellbook_magic_tome]
- [0x2DEB4, .rodata, e_life_up]
- [0x2DED0, c, first_c_file]
- [0x2DED0, c, st_debug]
- [0x2DF98, c, e_lock_camera]
- [0x2E4BC, c, first_c_file]
- [0x2F280, c, e_library_bg]
- [0x2FA80, c, unk_2FA80]
- [0x3245C, c, e_shop]
Expand Down
7 changes: 7 additions & 0 deletions config/symbols.pspeu.stlib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ SetCutsceneEnd = 0x0925AFB0;
CutsceneRun = 0x0925AFE8;
CutsceneSkip = 0x0925B380;
LIB_EntityCutscene = 0x0925B470;
LIB_EntityBackgroundBlock = 0x0925D350;
EntityLibrarianChair = 0x0925E018;
PlayerIsWithinHitbox = 0x0926CE18;
EntityLockCamera = 0x0926CF18;
EntityCandleTable = 0x0926DAA8;
explosionVariantSizes = 0x0926F738;
g_UnkRecursPrim2Inds = 0x0926F798;
Expand All @@ -137,6 +140,7 @@ g_EInitObtainable = 0x09276058;
g_EInitParticle = 0x09276068;
g_EInitInteractable = 0x09276088;
g_EInitUnkId13 = 0x09276098;
g_EInitLockCamera = 0x092760A8;
g_EInitCommon = 0x092760B8;
g_EInitDamageNum = 0x092760C8;
g_EInitThornweed = 0x09276138;
Expand All @@ -151,6 +155,7 @@ D_us_801809C8 = 0x09276268;
g_EInitFleaMan = 0x09276278;
g_Rooms = 0x092762A8;
LIB_PrizeDrops = 0x09298168;
LIB_BackgroundBlockInit = 0x092988E8;
D_us_801811FC = 0x092A4520;
D_us_80181204 = 0x092A4528;
D_us_80181210 = 0x092A4538;
Expand All @@ -174,8 +179,10 @@ D_psp_0924BC70 = 0x092A5478;
D_psp_0924BC78 = 0x092A5480;
LIB_cutscene_data = 0x092A54F8;
D_us_80181ACC = 0x092A5700;
D_us_80181AD0 = 0x092A5708;
g_IsCutsceneDone = 0x092A5728;
cutsceneUnk3Unknown = 0x092A5938;
g_Dialogue = 0x092A5CE0; // size:0x40
g_SkipCutscene = 0x092A5D20;
g_CutsceneFlags = 0x092A5D28;
entityLockCameraData = 0x092A61D0;
8 changes: 1 addition & 7 deletions config/symbols.pspeu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,7 @@ g_PrimBuf = 0x091CFAF8;
g_backbufferY = 0x091E12F8;
g_backbufferX = 0x091E1300;
D_8003C708 = 0x091e1308;
g_Tilemap = 0x091e1628;
g_Tilemap_tileDef = 0x091e162C;
g_Tilemap_scrollX = 0x091e1630;
g_Tilemap_scrollX_i_hi = 0x091e1632;
g_Tilemap_scrollY_i_hi = 0x091e1636;
g_Tilemap_left = 0x091e1654;
g_Tilemap_top = 0x091e1658;
g_Tilemap = 0x091e1628; // size:0x50
g_CurrentEntity = 0x091E1678;
g_Entities = 0x091e1680;
PLAYER_posX_i_hi = 0x91E1682;
Expand Down
4 changes: 3 additions & 1 deletion config/symbols.us.stlib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ g_EInitObtainable = 0x8018080C;
g_EInitParticle = 0x80180818;
g_EInitInteractable = 0x80180830;
g_EInitUnkId13 = 0x8018083C;
g_EInitLockCamera = 0x80180848;
g_EInitCommon = 0x80180854;
g_EInitDamageNum = 0x80180860;
g_EInitBloodyZombie = 0x8018086C;
Expand All @@ -15,6 +16,7 @@ g_EInitSkeleton = 0x80180998;
g_EInitSkeletonPieces = 0x801809A4;
g_EInitSkeletonBone = 0x801809B0;
g_EInitFleaMan = 0x801809D4;
LIB_BackgroundBlockInit = 0x80180A28;
LIB_RedDoorTiles = 0x80180AC8;
actor_names = 0x80181A60;
LIB_PrizeDrops = 0x80181A90;
Expand Down Expand Up @@ -61,7 +63,7 @@ LIB_cutscene_data = 0x80183F68;
g_UnkPrimHelperRot = 0x801ADDA4;
LIB_EntityBackgroundBlock = 0x801ADED0;
PlayerIsWithinHitbox = 0x801ADF98;
func_801B0AA4 = 0x801AE01C;
EntityLockCamera = 0x801AE01C;
EntityBackgroundBookcase = 0x801AF280;
EntityBackgroundFurniture = 0x801AF538;
EntityBackgroundShadow = 0x801AF7B8;
Expand Down
7 changes: 7 additions & 0 deletions include/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,13 @@ typedef struct {

typedef struct {
u16 unk7C;
u16 unk7E;
s16 unk80;
s16 unk82;
s16 unk84;
s16 unk86;
u16 unk88;
u16 unk8A;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of the existing unkid12 code can and should use this extension struct, and I'll update them in the next PR refactor

} ET_LockCamera;

typedef struct {
Expand Down
168 changes: 168 additions & 0 deletions src/st/lib/e_lock_camera.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include "lib.h"

#include "../player_is_within_hitbox.h"

static u8 hitboxes[] = {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x50, 0x20};
#ifdef VERSION_PSP
extern u8 entityLockCameraData[]; // bss
#else
static u8 entityLockCameraData[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#endif
extern u16 tileMapProps[] = {
0x0000, 0x0000, 0x0100, 0x0100, 0x0000, 0x0000, 0x0100, 0x0100,
0x0000, 0x00FC, 0x0600, 0x01FC, 0x0000, 0x0000, 0x0600, 0x01FC,
0x0000, 0x00FC, 0x0600, 0x0300, 0x0000, 0x00FC, 0x0600, 0x01FC,
0x0000, 0x00FC, 0x0600, 0x0300, 0x0000, 0x0200, 0x0600, 0x0300,
0x0000, 0x01FB, 0x0500, 0x02FB, 0x0000, 0x0000, 0x0500, 0x0400,
0x0000, 0x0000, 0x0500, 0x0400, 0x0000, 0x01FB, 0x0500, 0x02FB,
0x00F0, 0x01FB, 0x0310, 0x02FB, 0x00F0, 0x01FB, 0x0310, 0x02FB};

extern s32 D_us_80181AD0;

void EntityLockCamera(Entity* self) {
Tilemap* tilemap = &g_Tilemap;
u16* dataPtr;
u16 facingLeft;
u16 params;
s16 var_s4;

params = self->params;
if (!self->step) {
InitializeEntity(g_EInitLockCamera);
self->hitboxState = 1;
facingLeft = self->ext.lockCamera.unk7C = entityLockCameraData[params];
if (facingLeft) {
self->hitboxWidth = hitboxes[params];
self->hitboxHeight = 0x14;
} else {
self->hitboxWidth = 0x14;
self->hitboxHeight = hitboxes[params];
}
self->ext.lockCamera.unk88 = 2;
}

switch (params) {
case 4:
case 5:
// While this looks odd being empty, it appears there is functionality
// here in other overlays to check g_Tilemap.x. Looks like this was
// removed in LIB code.
break;
case 6:
if (D_us_80181AD0 != 0) {
g_Tilemap.x = 0;
g_Tilemap.width = 0x500;
self->step++;
return;
}
}

if (PlayerIsWithinHitbox(self)) {
facingLeft = GetSideToPlayer();
if (self->ext.lockCamera.unk7C) {
facingLeft &= 2;
facingLeft *= 2;
} else {
facingLeft &= 1;
facingLeft *= 4;
}
if (facingLeft != self->ext.lockCamera.unk88) {
self->ext.lockCamera.unk88 = facingLeft;
params = (params << 3) + facingLeft;
dataPtr = &tileMapProps[params];
self->ext.lockCamera.unk7E = 0;
self->ext.lockCamera.unk8A = 0x10;
params = tilemap->scrollX.i.hi;
if (params != *dataPtr && self->ext.lockCamera.unk7C) {
self->ext.lockCamera.unk7E = 1;
tilemap->x = params;
} else {
tilemap->x = *dataPtr;
}
self->ext.lockCamera.unk80 = *dataPtr++;
facingLeft = tilemap->scrollY.i.hi - 4;
if (facingLeft != *dataPtr && !self->ext.lockCamera.unk7C) {
self->ext.lockCamera.unk7E |= 2;
tilemap->y = facingLeft;
} else {
tilemap->y = *dataPtr;
}
self->ext.lockCamera.unk82 = *dataPtr++;
params += 0x100;
if (params != *dataPtr && self->ext.lockCamera.unk7C) {
self->ext.lockCamera.unk7E |= 4;
tilemap->width = params;
} else {
tilemap->width = *dataPtr;
}
self->ext.lockCamera.unk84 = *dataPtr++;
facingLeft += 0x100;
if (facingLeft != *dataPtr && !self->ext.lockCamera.unk7C) {
self->ext.lockCamera.unk7E |= 8;
tilemap->height = facingLeft;
} else {
tilemap->height = *dataPtr;
}
self->ext.lockCamera.unk86 = *dataPtr;
}
} else {
self->ext.lockCamera.unk88 = 2;
}

if (self->ext.lockCamera.unk7E) {
if (!(--self->ext.lockCamera.unk8A)) {
tilemap->x = self->ext.lockCamera.unk80;
tilemap->y = self->ext.lockCamera.unk82;
tilemap->width = self->ext.lockCamera.unk84;
tilemap->height = self->ext.lockCamera.unk86;
self->ext.lockCamera.unk7E = 0;
return;
}
var_s4 = (self->ext.lockCamera.unk80 - tilemap->x) / 2;
if (var_s4) {
if (var_s4 > 0) {
tilemap->x += 2;
} else {
tilemap->x -= 2;
}
} else {
tilemap->x = self->ext.lockCamera.unk80;
self->ext.lockCamera.unk7E &= ~1;
}
var_s4 = (self->ext.lockCamera.unk82 - tilemap->y) / 2;
if (var_s4) {
if (var_s4 > 0) {
tilemap->y += 2;
} else {
tilemap->y -= 2;
}
} else {
tilemap->y = self->ext.lockCamera.unk82;
self->ext.lockCamera.unk7E &= ~2;
}
var_s4 = (self->ext.lockCamera.unk84 - tilemap->width) / 2;
if (var_s4) {
if (var_s4 > 0) {
tilemap->width += 2;
} else {
tilemap->width -= 2;
}
} else {
tilemap->width = self->ext.lockCamera.unk84;
self->ext.lockCamera.unk7E &= ~4;
}
var_s4 = (self->ext.lockCamera.unk86 - tilemap->height) / 2;
if (var_s4) {
if (var_s4 > 0) {
tilemap->height += 2;
} else {
tilemap->height -= 2;
}
} else {
tilemap->height = self->ext.lockCamera.unk86;
self->ext.lockCamera.unk7E &= ~8;
}
}
}
6 changes: 0 additions & 6 deletions src/st/lib/first_c_file.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include "lib.h"

INCLUDE_ASM("st/lib/nonmatchings/first_c_file", LIB_EntityBackgroundBlock);

INCLUDE_ASM("st/lib/nonmatchings/first_c_file", PlayerIsWithinHitbox);

INCLUDE_ASM("st/lib/nonmatchings/first_c_file", func_801B0AA4);

INCLUDE_ASM("st/lib/nonmatchings/first_c_file", func_us_801AE4BC);

INCLUDE_ASM("st/lib/nonmatchings/first_c_file", func_us_801AE7AC);
Expand Down
1 change: 1 addition & 0 deletions src/st/lib/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ extern EInit g_EInitObtainable;
extern EInit g_EInitParticle;
extern EInit g_EInitCommon;
extern EInit g_EInitInteractable;
extern EInit g_EInitLockCamera;

// Skeleton
extern EInit g_EInitSkeleton;
Expand Down
20 changes: 20 additions & 0 deletions src/st/lib/st_debug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include "lib.h"

extern ObjInit OVL_EXPORT(BackgroundBlockInit)[];
void OVL_EXPORT(EntityBackgroundBlock)(Entity* self) {
ObjInit* obj = &OVL_EXPORT(BackgroundBlockInit)[self->params];
if (!self->step) {
InitializeEntity(g_EInitCommon);
self->animSet = obj->animSet;
self->zPriority = obj->zPriority;
self->unk5A = obj->unk5A;
self->palette = obj->palette;
self->drawFlags = obj->drawFlags;
self->drawMode = obj->drawMode;
if (obj->flags != 0) {
self->flags = obj->flags;
}
}
AnimateEntity(obj->animFrames, self);
}
6 changes: 0 additions & 6 deletions src/st/lib_psp/2BC10.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,3 @@ INCLUDE_ASM("st/lib_psp/psp/lib_psp/2BC10", func_psp_0926AED0);
INCLUDE_ASM("st/lib_psp/psp/lib_psp/2BC10", func_psp_0926BD98);

INCLUDE_ASM("st/lib_psp/psp/lib_psp/2BC10", func_psp_0926BE68);

INCLUDE_ASM("st/lib_psp/psp/lib_psp/2BC10", func_psp_0926CE18);

INCLUDE_ASM("st/lib_psp/psp/lib_psp/2BC10", func_psp_0926CF18);

INCLUDE_ASM("st/lib_psp/psp/lib_psp/2BC10", func_psp_0926D5E0);
4 changes: 4 additions & 0 deletions src/st/lib_psp/35F60.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include "../lib/lib.h"

INCLUDE_ASM("st/lib_psp/psp/lib_psp/35F60", func_psp_0926D5E0);
2 changes: 0 additions & 2 deletions src/st/lib_psp/unk_25CD0.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include "../../st/lib/lib.h"

INCLUDE_ASM("st/lib_psp/psp/lib_psp/unk_25CD0", func_psp_0925D350);

INCLUDE_ASM("st/lib_psp/psp/lib_psp/unk_25CD0", func_psp_0925D430);

INCLUDE_ASM("st/lib_psp/psp/lib_psp/unk_25CD0", func_psp_0925D4D0);
Expand Down
Loading