mirror of
https://github.com/Xeeynamo/sotn-decomp.git
synced 2024-11-23 13:09:44 +00:00
Refactor DRA func_800FD5BC (#980)
Came across this function today and found several improvements for it. - Unkstruct_800FD5BC is a duplicate of DamageParam. Therefore, I have changed all instances of Unkstruct_800FD5BC to DamageParam. The fields make sense in context and everything. - Because func_800FD5BC is in GameApi, which is defined in `game.h`, its argument (now a DamageParam) needs to be accessible in `game.h`. Therefore, DamageParam moves from dra.h to game.h. - We had a fake division being done with using a `temp` and checking a comparison to zero; this has been changed to be a normal division. This is a common pattern I see in initial m2c output and I'm sure it exists in other places in the repo, would be nice if we could find an automated way to search for this type of structure to simplify the code. - Changed a 0x14 to 20 since it makes way more sense that way - Changed an `if(){dostuff; return} else{morestuff}` to just `if(){dostuff; return} morestuff`, eliminating the `else` I think this function should not be in `menu.c` since it has no close connection to any kind of menu. It would also be nice if we could figure out what damageKind actually is, and maybe make an enum for it. Overall, no new decompiling here, but lots of improvement to the readability of the code. This might actually be a good PR to keep in mind as an example for people who are interested in the project but aren't comfortable with assembly, since this is a lot of improvement and change, without touching assembly at all.
This commit is contained in:
parent
2f376b66f9
commit
ef86fd2b45
@ -75,7 +75,7 @@ set(SOURCE_FILES_DRA
|
||||
src/dra/lba_stage.c
|
||||
src/dra/config_us.c
|
||||
src/dra/menu.c
|
||||
src/dra/5D6C4.c
|
||||
src/dra/5D5BC.c
|
||||
src/dra/627C4.c
|
||||
src/dra/63ED4.c
|
||||
src/dra/91EBC.c
|
||||
|
@ -15,7 +15,7 @@ C_FILES_MOCK_SDK := libapi.c libetc.c libgpu.c libgte.c libgs.c libcd.c libca
|
||||
C_FILES_3RD := cJSON/cJSON.c
|
||||
C_FILES_DRA := 42398.c play.c loading.c pads.c
|
||||
C_FILES_DRA += save_mgr_pre.c save_mgr.c 4A538.c collider.c demo.c 5087C.c
|
||||
C_FILES_DRA += lba_stage.c config_us.c menu.c 5D6C4.c 627C4.c 63ED4.c
|
||||
C_FILES_DRA += lba_stage.c config_us.c menu.c 5D5BC.c 627C4.c 63ED4.c
|
||||
C_FILES_DRA += 91EBC.c 92F60.c 93290.c 93BDC.c 94F50.c 953A0.c
|
||||
C_FILES_ST_SEL := banks.c CD54.c 2C048.c 33164.c 3410C.c 3585C.c 3642C.c
|
||||
|
||||
|
@ -78,11 +78,11 @@ segments:
|
||||
- [0x2CF4, .data, menu] # array of strings
|
||||
- [0x2D1C, .data, menu] # HD exclusive array of strings
|
||||
- [0x2D88, .data, menu]
|
||||
- [0x2ED0, .data, 5D6C4] # g_LevelHPIncrease
|
||||
- [0x2EF8, .data, 5D6C4] # hud sprites def
|
||||
- [0x2FCC, .data, 5D6C4] # g_CapePaletteDefs
|
||||
- [0x301C, .data, 5D6C4] # g_CheatCodes
|
||||
- [0x3024, .data, 5D6C4] # D_800A3014
|
||||
- [0x2ED0, .data, 5D5BC] # g_LevelHPIncrease
|
||||
- [0x2EF8, .data, 5D5BC] # hud sprites def
|
||||
- [0x2FCC, .data, 5D5BC] # g_CapePaletteDefs
|
||||
- [0x301C, .data, 5D5BC] # g_CheatCodes
|
||||
- [0x3024, .data, 5D5BC] # D_800A3014
|
||||
- [0x3144, data, 627C4]
|
||||
- [0x37E8, data]
|
||||
- [0x3C50, .data, lba_stage]
|
||||
@ -129,8 +129,8 @@ segments:
|
||||
- [0x3C788, .rodata, menu] # MenuHandleCursorInput
|
||||
- [0x3C7A0, .rodata, menu] # MenuHandle str
|
||||
- [0x3C7C8, .rodata, menu] # MenuHandle jtbl
|
||||
- [0x3CC18, .rodata, 5D6C4]
|
||||
- [0x3CC60, .rodata, 5D6C4] # g_CheatCodes
|
||||
- [0x3CC18, .rodata, 5D5BC]
|
||||
- [0x3CC60, .rodata, 5D5BC] # g_CheatCodes
|
||||
- [0x3CC78, .rodata, 627C4] # jtbl_800DCC78
|
||||
- [0x3CC98, .rodata, 627C4] # jtbl_800DCC98
|
||||
- [0x3CCC0, .rodata, 627C4]
|
||||
@ -213,7 +213,7 @@ segments:
|
||||
- [0x5027C, c, demo]
|
||||
- [0x50F00, c, 5087C]
|
||||
- [0x54E50, c, menu]
|
||||
- [0x5D678, c, 5D6C4]
|
||||
- [0x5D570, c, 5D5BC]
|
||||
- [0x62654, c, 627C4]
|
||||
- [0x63D1C, c, 63ED4]
|
||||
- [0x67200, c, cd]
|
||||
|
@ -76,11 +76,11 @@ segments:
|
||||
- [0x2BC0, .data, 5087C] # D_800A2BC0
|
||||
- [0x2C0C, .data, 5087C] # D_800A2C0C, D_800A2D44
|
||||
- [0x2D48, .data, menu]
|
||||
- [0x2EC0, .data, 5D6C4] # g_LevelHPIncrease
|
||||
- [0x2EE8, .data, 5D6C4] # hud sprites def
|
||||
- [0x2FBC, .data, 5D6C4] # g_CapePaletteDefs
|
||||
- [0x300C, .data, 5D6C4] # g_CheatCodes
|
||||
- [0x3014, .data, 5D6C4] # D_800A3014
|
||||
- [0x2EC0, .data, 5D5BC] # g_LevelHPIncrease
|
||||
- [0x2EE8, .data, 5D5BC] # hud sprites def
|
||||
- [0x2FBC, .data, 5D5BC] # g_CapePaletteDefs
|
||||
- [0x300C, .data, 5D5BC] # g_CheatCodes
|
||||
- [0x3014, .data, 5D5BC] # D_800A3014
|
||||
- [0x3134, data, 627C4]
|
||||
- [0x31B0, data, 63ED4]
|
||||
- [0x37D8, data]
|
||||
@ -143,8 +143,8 @@ segments:
|
||||
- [0x3C71C, .rodata, menu] # MenuHandleCursorInput
|
||||
- [0x3C734, .rodata, menu] # MenuHandle str
|
||||
- [0x3C75C, .rodata, menu] # MenuHandle jtbl
|
||||
- [0x3CBAC, .rodata, 5D6C4] # func_800FD6C4
|
||||
- [0x3CBF4, .rodata, 5D6C4] # g_CheatCodes
|
||||
- [0x3CBAC, .rodata, 5D5BC] # func_800FD6C4
|
||||
- [0x3CBF4, .rodata, 5D5BC] # g_CheatCodes
|
||||
- [0x3CC0C, .rodata, 627C4]
|
||||
- [0x3CC2C, .rodata, 627C4] # func_801028AC
|
||||
- [0x3CC54, .rodata, 627C4] # func_80102D70
|
||||
@ -226,7 +226,7 @@ segments:
|
||||
- [0x4FBF8, c, demo]
|
||||
- [0x5087C, c, 5087C]
|
||||
- [0x5483C, c, menu]
|
||||
- [0x5D6C4, c, 5D6C4]
|
||||
- [0x5D5BC, c, 5D5BC]
|
||||
- [0x627C4, c, 627C4]
|
||||
- [0x63ED4, c, 63ED4]
|
||||
- [0x673C0, c, cd]
|
||||
|
@ -1173,6 +1173,13 @@ typedef struct {
|
||||
/* 0x40 */ const char* unk40; // dialogue settings, maybe?
|
||||
} Dialogue; // size = 0x44
|
||||
|
||||
typedef struct {
|
||||
u32 unk0;
|
||||
u32 damageKind;
|
||||
s32 damageTaken;
|
||||
s32 unkC;
|
||||
} DamageParam;
|
||||
|
||||
typedef struct {
|
||||
/* 8003C774 */ Overlay o;
|
||||
/* 8003C7B4 */ void (*FreePrimitives)(s32);
|
||||
@ -1237,7 +1244,7 @@ typedef struct {
|
||||
/* 8003C888 */ bool (*func_800F27F4)(s32 arg0);
|
||||
/* 8003C88C */ s32 (*func_800FF110)(s32 arg0);
|
||||
/* 8003C890 */ s32 (*func_800FD664)(s32 arg0);
|
||||
/* 8003C894 */ s32 (*func_800FD5BC)(Unkstruct_800FD5BC* arg0);
|
||||
/* 8003C894 */ s32 (*func_800FD5BC)(DamageParam* arg0);
|
||||
/* 8003C898 */ void (*LearnSpell)(s32 spellId);
|
||||
/* 8003C89C */ void (*DebugInputWait)(const char* str);
|
||||
/* 8003C8A0 */ void* unused12C;
|
||||
@ -1300,7 +1307,7 @@ extern bool (*g_api_func_80133950)(void);
|
||||
extern bool (*g_api_func_800F27F4)(s32 arg0);
|
||||
extern s32 (*g_api_func_800FF110)(s32 arg0);
|
||||
extern s32 (*g_api_func_800FD664)(s32 arg0);
|
||||
extern s32 (*g_api_func_800FD5BC)(Unkstruct_800FD5BC* arg0);
|
||||
extern s32 (*g_api_func_800FD5BC)(DamageParam* arg0);
|
||||
extern void (*g_api_LearnSpell)(s32 spellId);
|
||||
extern void (*g_api_func_800E2438)(const char* str);
|
||||
/***************************/
|
||||
|
@ -85,12 +85,6 @@ typedef struct {
|
||||
/* 0x04 */ s16 unk04;
|
||||
} SfxRingBufferItem;
|
||||
|
||||
typedef struct {
|
||||
/* 0x00 */ s32 unk0;
|
||||
/* 0x04 */ s32 unk4;
|
||||
/* 0x08 */ s32 unk8;
|
||||
} Unkstruct_800FD5BC;
|
||||
|
||||
typedef struct {
|
||||
/* 0x00 */ u8 unk00[3];
|
||||
/* 0x03 */ char unk03[9];
|
||||
|
@ -53,6 +53,32 @@ s32 g_CapePaletteDefs[] = {
|
||||
ITEM_TWILIGHT_CLOAK, 0x40A, CAPE_PAL_TERMINATOR, 0x409,
|
||||
};
|
||||
|
||||
bool func_800FD5BC(DamageParam* arg0) {
|
||||
if (arg0->damageKind != 5) {
|
||||
if (arg0->damageKind >= 16) {
|
||||
arg0->damageTaken = g_Status.hpMax / 8;
|
||||
} else if (g_Status.hpMax >= (arg0->damageTaken * 20)) {
|
||||
arg0->damageKind = 3;
|
||||
} else {
|
||||
arg0->damageKind = 2;
|
||||
}
|
||||
}
|
||||
if (g_Status.hp <= arg0->damageTaken) {
|
||||
g_Status.hp = 0;
|
||||
return true;
|
||||
}
|
||||
g_Status.hp -= arg0->damageTaken;
|
||||
return false;
|
||||
}
|
||||
|
||||
s32 func_800FD664(s32 arg0) {
|
||||
return g_StageId & STAGE_INVERTEDCASTLE_FLAG ? arg0 << 1 : arg0;
|
||||
}
|
||||
|
||||
ItemCategory GetEquipItemCategory(s32 equipId) {
|
||||
return g_EquipDefs[g_Status.equipment[equipId]].itemCategory;
|
||||
}
|
||||
|
||||
s32 func_800FD6C4(s32 equipTypeFilter) {
|
||||
s32 itemCount;
|
||||
s32 equipType;
|
||||
@ -126,7 +152,7 @@ u32 CheckEquipmentItemCount(u32 itemId, u32 equipType) {
|
||||
}
|
||||
|
||||
#ifndef NON_EQUIVALENT
|
||||
INCLUDE_ASM("dra/nonmatchings/5D6C4", AddToInventory);
|
||||
INCLUDE_ASM("dra/nonmatchings/5D5BC", AddToInventory);
|
||||
#else
|
||||
void AddToInventory(u16 itemId, s32 itemCategory) {
|
||||
u8 temp_a1;
|
||||
@ -1595,7 +1621,7 @@ s32 D_800A3014[] = {
|
||||
0x018, 0x018, 0x080, 0x0D8, 0x01E, 0x17F,
|
||||
};
|
||||
|
||||
INCLUDE_ASM("dra/nonmatchings/5D6C4", DrawRichterHudSubweapon);
|
||||
INCLUDE_ASM("dra/nonmatchings/5D5BC", DrawRichterHudSubweapon);
|
||||
|
||||
extern Unkstruct_80137990 D_80137990;
|
||||
|
@ -286,13 +286,6 @@ typedef struct {
|
||||
RECT D_800ACDF0;
|
||||
} Vram;
|
||||
|
||||
typedef struct {
|
||||
u32 unk0;
|
||||
u32 damageKind;
|
||||
s32 damageTaken;
|
||||
s32 unkC;
|
||||
} DamageParam;
|
||||
|
||||
typedef struct {
|
||||
/* 8013761C */ MenuContext menus[NUM_MENU]; // 761C, 763A, 7658, 7676
|
||||
} MenuData;
|
||||
|
@ -61,7 +61,7 @@ bool func_80133950(void);
|
||||
bool func_800F27F4(s32 arg0);
|
||||
s32 func_800FF110(s32 arg0);
|
||||
s32 func_800FD664(s32 arg0);
|
||||
bool func_800FD5BC(Unkstruct_800FD5BC* arg0);
|
||||
bool func_800FD5BC(DamageParam* arg0);
|
||||
void LearnSpell(s32 spellId);
|
||||
void DebugInputWait(const char* msg);
|
||||
|
||||
|
@ -3871,36 +3871,3 @@ s32 TimeAttackController(TimeAttackEvents eventId, TimeAttackActions action) {
|
||||
g_Settings.D_8003CB00 |= 1 << eventId;
|
||||
}
|
||||
}
|
||||
|
||||
bool func_800FD5BC(Unkstruct_800FD5BC* arg0) {
|
||||
s32 temp;
|
||||
|
||||
if (arg0->unk4 != 5) {
|
||||
if (((u32)arg0->unk4) >= 0x10U) {
|
||||
temp = g_Status.hpMax;
|
||||
if (g_Status.hpMax < 0) {
|
||||
temp += 7;
|
||||
}
|
||||
arg0->unk8 = temp >> 3;
|
||||
} else if (g_Status.hpMax >= (arg0->unk8 * 0x14)) {
|
||||
arg0->unk4 = 3;
|
||||
} else {
|
||||
arg0->unk4 = 2;
|
||||
}
|
||||
}
|
||||
if (g_Status.hp <= arg0->unk8) {
|
||||
g_Status.hp = 0;
|
||||
return true;
|
||||
} else {
|
||||
g_Status.hp -= arg0->unk8;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
s32 func_800FD664(s32 arg0) {
|
||||
return g_StageId & STAGE_INVERTEDCASTLE_FLAG ? arg0 << 1 : arg0;
|
||||
}
|
||||
|
||||
ItemCategory GetEquipItemCategory(s32 equipId) {
|
||||
return g_EquipDefs[g_Status.equipment[equipId]].itemCategory;
|
||||
}
|
||||
|
@ -912,7 +912,7 @@ void func_80159C04(void) {
|
||||
}
|
||||
|
||||
void func_80159CE4(s32 arg0, u32 arg1, s16 arg2) {
|
||||
Unkstruct_800FD5BC sp10;
|
||||
DamageParam sp10;
|
||||
s32 xShift;
|
||||
s32 i;
|
||||
bool step_s_zero = false;
|
||||
@ -1104,8 +1104,8 @@ void func_80159CE4(s32 arg0, u32 arg1, s16 arg2) {
|
||||
PLAYER.velocityY = 0;
|
||||
PLAYER.step_s = 5;
|
||||
sp10.unk0 = 0;
|
||||
sp10.unk4 = 1;
|
||||
sp10.unk8 = g_Player.unk5A;
|
||||
sp10.damageKind = 1;
|
||||
sp10.damageTaken = g_Player.unk5A;
|
||||
if (g_api.func_800FD5BC(&sp10) != 0) {
|
||||
SetPlayerStep(Player_Kill);
|
||||
func_8015A9B0(0, 2, 10, 2);
|
||||
@ -1145,8 +1145,8 @@ void func_80159CE4(s32 arg0, u32 arg1, s16 arg2) {
|
||||
g_api.func_80102CD8(2);
|
||||
PLAYER.step_s = 1;
|
||||
sp10.unk0 = 0;
|
||||
sp10.unk4 = 1;
|
||||
sp10.unk8 = g_Player.unk5A;
|
||||
sp10.damageKind = 1;
|
||||
sp10.damageTaken = g_Player.unk5A;
|
||||
if (g_api.func_800FD5BC(&sp10) != 0) {
|
||||
SetPlayerStep(Player_Kill);
|
||||
func_8015A9B0(0, 2, 10, 2);
|
||||
@ -1163,8 +1163,8 @@ void func_80159CE4(s32 arg0, u32 arg1, s16 arg2) {
|
||||
CreateEntFactoryFromEntity(g_CurrentEntity, FACTORY(0x800, 75), 0);
|
||||
}
|
||||
sp10.unk0 = 0;
|
||||
sp10.unk4 = 1;
|
||||
sp10.unk8 = g_Player.unk5A;
|
||||
sp10.damageKind = 1;
|
||||
sp10.damageTaken = g_Player.unk5A;
|
||||
if (g_api.func_800FD5BC(&sp10) != 0) {
|
||||
SetPlayerStep(Player_Kill);
|
||||
func_8015A9B0(0, 2, 10, 2);
|
||||
@ -1239,7 +1239,7 @@ void func_80159CE4(s32 arg0, u32 arg1, s16 arg2) {
|
||||
const s32 rodata_padding_1A784 = 0;
|
||||
|
||||
void func_8015A7D0(void) {
|
||||
Unkstruct_800FD5BC sp10;
|
||||
DamageParam sp10;
|
||||
switch (g_CurrentEntity->step_s) {
|
||||
case 0:
|
||||
func_80159BC8();
|
||||
@ -1257,8 +1257,8 @@ void func_8015A7D0(void) {
|
||||
// Effectively a switch on g_Player.unk60
|
||||
if (g_Player.unk60 == 3) {
|
||||
sp10.unk0 = 0;
|
||||
sp10.unk4 = 1;
|
||||
sp10.unk8 = g_Player.unk5A;
|
||||
sp10.damageKind = 1;
|
||||
sp10.damageTaken = g_Player.unk5A;
|
||||
if (g_api.func_800FD5BC(&sp10)) {
|
||||
SetPlayerStep(Player_Kill);
|
||||
func_8015A9B0(0, 2, 12, 1);
|
||||
|
Loading…
Reference in New Issue
Block a user