From d0990e3271f038a7f09913eb56434590e1eb674f Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Thu, 10 Oct 2024 16:10:16 -0400 Subject: [PATCH] d_a_bk work, FILI inline cleanup --- include/d/actor/d_a_bk.h | 65 +++++------- include/d/d_stage.h | 59 +++++------ src/d/actor/d_a_bk.cpp | 210 +++++++++++++++++++++++++++++++++++++-- src/d/d_com_inf_game.cpp | 14 +-- src/d/d_kankyo.cpp | 8 +- src/d/d_stage.cpp | 4 +- 6 files changed, 275 insertions(+), 85 deletions(-) diff --git a/include/d/actor/d_a_bk.h b/include/d/actor/d_a_bk.h index e54363360..378f556b1 100644 --- a/include/d/actor/d_a_bk.h +++ b/include/d/actor/d_a_bk.h @@ -99,7 +99,8 @@ public: /* 0x11B4 */ u8 m11B4[0x11C0 - 0x11B4]; /* 0x11C0 */ cXyz m11C0; /* 0x11CC */ cXyz m11CC; - /* 0x11D8 */ u8 m11D8[0x11F0 - 0x11D8]; + /* 0x11D8 */ u8 m11D8[0x11E4 - 0x11D8]; + /* 0x11E4 */ cXyz m11E4; /* 0x11F0 */ u8 m11F0; /* 0x11F1 */ u8 m11F1; /* 0x11F2 */ u8 m11F2; @@ -189,30 +190,30 @@ public: m0A2 = 0x1; m0A4 = 0x1; m0A6 = 0x0; - m0A8 = 1.0f; - m0AC = 1.0f; - m0B0 = 0.5f; - m0B4 = 1.0f; - m0B8 = 1.0f; - m0BC = 1.0f; - m0C0 = 1.0f; - m0C4 = 1.0f; - m0C8 = 1.0f; - m0CC = 1.0f; + m0A8[0] = 1.0f; + m0A8[1] = 1.0f; + m0A8[2] = 1.0f; + m0A8[3] = 1.0f; + m0A8[4] = 1.0f; + m0A8[5] = 1.0f; + m0A8[6] = 1.0f; + m0A8[7] = 1.0f; + m0A8[8] = 1.0f; + m0A8[9] = 1.0f; m0D0 = 0x5; m0D2 = 0x1; m0D4 = 0x1; m0D6 = 0x1; - m0D8 = 1.0f; - m0DC = 1.0f; - m0E0 = 1.0f; - m0E4 = 0.8f; - m0E8 = 0.5f; - m0EC = 1.0f; - m0F0 = 1.0f; - m0F4 = 1.0f; - m0F8 = 1.0f; - m0FC = 1.0f; + m0D8[0] = 1.0f; + m0D8[1] = 1.0f; + m0D8[2] = 1.0f; + m0D8[3] = 0.8f; + m0D8[4] = 0.5f; + m0D8[5] = 1.0f; + m0D8[6] = 1.0f; + m0D8[7] = 1.0f; + m0D8[8] = 1.0f; + m0D8[9] = 1.0f; m100 = -60.0f; m018 = 0.7f; m104 = 0xc8; @@ -278,30 +279,12 @@ public: /* 0x0A2 */ s16 m0A2; /* 0x0A4 */ s16 m0A4; /* 0x0A6 */ s16 m0A6; - /* 0x0A8 */ f32 m0A8; - /* 0x0AC */ f32 m0AC; - /* 0x0B0 */ f32 m0B0; - /* 0x0B4 */ f32 m0B4; - /* 0x0B8 */ f32 m0B8; - /* 0x0BC */ f32 m0BC; - /* 0x0C0 */ f32 m0C0; - /* 0x0C4 */ f32 m0C4; - /* 0x0C8 */ f32 m0C8; - /* 0x0CC */ f32 m0CC; + /* 0x0A8 */ f32 m0A8[10]; /* 0x0D0 */ s16 m0D0; /* 0x0D2 */ s16 m0D2; /* 0x0D4 */ s16 m0D4; /* 0x0D6 */ s16 m0D6; - /* 0x0D8 */ f32 m0D8; - /* 0x0DC */ f32 m0DC; - /* 0x0E0 */ f32 m0E0; - /* 0x0E4 */ f32 m0E4; - /* 0x0E8 */ f32 m0E8; - /* 0x0EC */ f32 m0EC; - /* 0x0F0 */ f32 m0F0; - /* 0x0F4 */ f32 m0F4; - /* 0x0F8 */ f32 m0F8; - /* 0x0FC */ f32 m0FC; + /* 0x0D8 */ f32 m0D8[10]; /* 0x100 */ f32 m100; /* 0x104 */ s16 m104; /* 0x106 */ s16 m106; diff --git a/include/d/d_stage.h b/include/d/d_stage.h index 887a77b15..9f4588138 100644 --- a/include/d/d_stage.h +++ b/include/d/d_stage.h @@ -1071,48 +1071,51 @@ inline s32 dStage_sclsInfo_getWipe(stage_scls_info_class* p_info) { return p_info->mWipe & 0xF; } -inline int dStage_FileList_dt_ChkPathWindEffect(dStage_FileList_dt_c* i_fili) { - return i_fili->mParam & 0x100000; -} - -inline int dStage_FileList_dt_GlobalWindLevel(dStage_FileList_dt_c* i_fili) { - return (i_fili->mParam >> 18) & 3; -} - -inline f32 dStage_FileList_dt_SeaLevel(dStage_FileList_dt_c* i_fili) { - return i_fili->mSeaLevel; -} - -inline u8 dStage_FileList_dt_PhotoDepth(dStage_FileList_dt_c* i_fili) { - return (i_fili->mParam >> 7) & 0xFF; -} - inline s32 dStage_FileList_dt_CheckDarkOn(dStage_FileList_dt_c* i_fili) { - return i_fili->mParam & 1; -} - -inline u8 dStage_FileList_dt_DarkNo(dStage_FileList_dt_c* i_fili) { - return (i_fili->mParam & 0x78) >> 3; + return i_fili->mParam & 0x00000001; } inline u8 dStage_FileList_dt_CheckAgbCom(dStage_FileList_dt_c* i_fili) { - return i_fili->mParam & 2; + return i_fili->mParam & 0x00000002; } inline u8 dStage_FileList_dt_CheckAgbHover(dStage_FileList_dt_c* i_fili) { - return i_fili->mParam & 4; + return i_fili->mParam & 0x00000004; +} + +inline u8 dStage_FileList_dt_DarkNo(dStage_FileList_dt_c* i_fili) { + return (i_fili->mParam & 0x00000078) >> 3; +} + +inline u8 dStage_FileList_dt_PhotoDepth(dStage_FileList_dt_c* i_fili) { + return (i_fili->mParam & 0x00007F80) >> 7; +} + +inline int dStage_FileList_dt_GlobalWindLevel(dStage_FileList_dt_c* i_fili) { + return (i_fili->mParam & 0x000C0000) >> 18; +} + +inline int dStage_FileList_dt_ChkPathWindEffect(dStage_FileList_dt_c* i_fili) { + return i_fili->mParam & 0x00100000; +} + +inline u32 dStage_FileList_dt_GetParticleNo(dStage_FileList_dt_c* i_fili) { + return (i_fili->mParam & 0x1FE00000) >> 21; } inline u32 dStage_FileList_dt_GetSongOk(dStage_FileList_dt_c* i_fili) { return i_fili->mParam & 0x40000000; } -// inline u8 dStage_FileList_dt_GetToonsw(dStage_FileList_dt_c* i_fili) { - -// } +inline u8 dStage_FileList_dt_GetToonsw(dStage_FileList_dt_c* i_fili) { + return i_fili->mParam & 0; // TODO. + // Seems unused in the final game. + // It could be one of the following bits which have no known inline: 0xA0038000 + // Of those, these three are the most likely, as there are rooms with these set: 0x20028000 +} -inline u32 dStage_FileList_dt_GetParticleNo(dStage_FileList_dt_c* i_fili) { - return (i_fili->mParam >> 21) & 0xFF; +inline f32 dStage_FileList_dt_SeaLevel(dStage_FileList_dt_c* i_fili) { + return i_fili->mSeaLevel; } bool dStage_chkPlayerId(int playerId, int room_no); diff --git a/src/d/actor/d_a_bk.cpp b/src/d/actor/d_a_bk.cpp index 439df602f..3b9899539 100644 --- a/src/d/actor/d_a_bk.cpp +++ b/src/d/actor/d_a_bk.cpp @@ -1702,7 +1702,7 @@ static void path_run(bk_class* i_this) { static void attack_set(bk_class* i_this, u8 r28) { i_this->m0B5C = 0; i_this->m11F1 = 0; - i_this->m11FC = -1; + i_this->m11FC = fpcM_ERROR_PROCESS_ID_e; i_this->m11F2 = 0; i_this->m0B64 = 0.0f; i_this->m0300[4] = 0; @@ -2139,7 +2139,205 @@ static fopAc_ac_c* yari_hit_check(bk_class* i_this) { /* 000075E8-00007EF4 .text fight__FP8bk_class */ static void fight(bk_class* i_this) { - /* Nonmatching */ + daPy_py_c* player = (daPy_py_c*)dComIfGp_getPlayer(0); + switch (i_this->dr.m004) { + case -0x0A: + if (i_this->dr.mAcch.ChkGroundHit()) { + anm_init(i_this, BK_BCK_BK_JUMP2, 0.0f, J3DFrameCtrl::LOOP_ONCE_e, 1.0f, BK_BAS_BK_JUMP2); + i_this->dr.m004 = -0x09; + i_this->speedF = 0.0f; + } + break; + case -0x09: + if (i_this->mpMorf->isStop()) { + i_this->dr.m004 = 1; + i_this->m0300[2] = 8; + anm_init(i_this, BK_BCK_BK_JATTACK1, 2.0f, J3DFrameCtrl::LOOP_ONCE_e, 1.0f, -1); + i_this->speedF = 80.0f + REG0_F(5); + i_this->speed.y = 115.0f + REG0_F(6); + goto temp_1B8; + } + break; + case 0x00: + if (i_this->m0B30 != 0) { + attack_set(i_this, 0); + } else { + attack_set(i_this, 2); + i_this->speedF = 70.0f + REG0_F(7); + i_this->speed.y = 105.0f + REG0_F(8); + fopAcM_monsSeStart(i_this, JA_SE_CV_BK_ATTACK_L, 0); + } + i_this->dr.m004 = 1; + i_this->m0300[2] = 8; + // Fall-through +temp_1B8: + case 0x01: + i_this->m1040.SetAtAtp(bk_attack_AP[i_this->m0B5C]); + f32 f1 = attack_info[i_this->m0B5C][i_this->m0B60].speed; + if (i_this->dr.mAcch.ChkGroundHit() || (i_this->m0B5C != 1 && i_this->m0B5C != 2)) { + i_this->m0B64 += f1; + cLib_addCalc2(&i_this->speedF, 0.0f, 1.0f, 20.0f); + } + if ( + i_this->m0B64 > i_this->m0B70 && + daBk_player_view_check(i_this, &i_this->dr.m714->current.pos, i_this->m0332, l_bkHIO.m034) + ) { + i_this->dr.m710 = 1; + } + + if (i_this->m0B7A > 0) { + if (i_this->m0B5C == 0) { + int r3 = l_bkHIO.m0A0 + l_bkHIO.m0A2 + l_bkHIO.m0A4 + l_bkHIO.m0A6; + if ((int)i_this->m0B64 >= l_bkHIO.m0A0 && (int)i_this->m0B64 <= r3) { + i_this->m02F0 = 1; + if ((int)i_this->m0B64 >= (l_bkHIO.m0A0 + l_bkHIO.m0A2) && (int)i_this->m0B64 < (l_bkHIO.m0A0 + l_bkHIO.m0A2 + l_bkHIO.m0A4)) { + i_this->m02F4 = 1; + } + int r0 = (int)i_this->m0B64 - l_bkHIO.m0A0; + if (r0 < (int)ARRAY_SIZE(l_bkHIO.m0A8)) { + i_this->m02EC = l_bkHIO.m0A8[r0]; + } + } + } else if (i_this->m0B5C == 1) { + int r3 = l_bkHIO.m0D0 + l_bkHIO.m0D2 + l_bkHIO.m0D4 + l_bkHIO.m0D6; + if ((int)i_this->m0B64 >= l_bkHIO.m0D0 && (int)i_this->m0B64 <= r3) { + i_this->m02F0 = 1; + if ((int)i_this->m0B64 >= (l_bkHIO.m0D0 + l_bkHIO.m0D2) && (int)i_this->m0B64 < (l_bkHIO.m0D0 + l_bkHIO.m0D2 + l_bkHIO.m0D4)) { + i_this->m02F4 = 1; + } + int r0 = (int)i_this->m0B64 - l_bkHIO.m0D0; + if (r0 < (int)ARRAY_SIZE(l_bkHIO.m0D8)) { + i_this->m02EC = l_bkHIO.m0D8[r0]; + } + } + } + } + + if ((i_this->m0B64 < i_this->m0B74) || i_this->m11F2 != 0) { + i_this->dr.m4D0 = i_this->m0332; + } + + cLib_addCalcAngleS2(&i_this->current.angle.y, i_this->dr.m4D0, 4, 0x800); + + u8 attackType = 0; + f32 startFrame = 1000.0f; + f32 endFrame = 1000.0f; + f32 maxDist = 10000.0f; + if (i_this->m0B5C == 0) { + startFrame = 12.0f + REG0_F(8); + endFrame = 25.0f + REG0_F(9); + attackType = 2; + } else if (i_this->m0B5C == 1) { + startFrame = REG0_F(10); + endFrame = 10.0f + REG0_F(11); + attackType = 2; + } + i_this->setBtAttackData(startFrame, endFrame, maxDist, attackType); + i_this->setBtMaxDis(l_bkHIO.m014); + i_this->setBtNowFrame(i_this->m0B64); + + fopAc_ac_c* hitActor = yari_hit_check(i_this); + if (hitActor != NULL) { + if (fopAcM_GetName(hitActor) == PROC_PLAYER) { + // Note: The code seems to assume that the hit actor and the controlled player are the same actor. + // This isn't necessarily correct, but likely doesn't cause any bugs in practice as checkPlayerGuard always + // returns false for non-Link player actors. + if (player->checkPlayerGuard() && (i_this->m0B5C == 0 || i_this->m0B5C == 1)) { + i_this->mpMorf->setPlaySpeed(-1.0f); + if (i_this->m034C != 0) { + i_this->m034C = l_bkHIO.m00C + 6; + } + + i_this->m0B7A = -1; + i_this->mpMorf->play(&i_this->eyePos, 0, 0); + if (i_this->m0B30 != 0 && i_this->m02D5 == 0 && cM_rndF(1.0f) < 0.5f) { + i_this->m0B34 = 1; + i_this->dr.mState = 8; + i_this->dr.m004 = -10; + i_this->m0300[0] = 10; + i_this->m0300[1] = 100; + } + } + } else if (fopAcM_GetName(hitActor) == PROC_BK) { + i_this->m11FC = fopAcM_GetID(hitActor); + } + } else { + i_this->m1040.ClrAtHit(); + if (i_this->m11F0 != 0) { + if (i_this->m11F0 == 2) { + i_this->mpMorf->setPlaySpeed(-1.0f); + i_this->m02F0 = 0; + if (i_this->m034C != 0) { + i_this->m034C = l_bkHIO.m00C + 6; + } + i_this->m0B7A = -1; + i_this->mpMorf->play(&i_this->eyePos, 0, 0); + } else { + i_this->dr.mState = 0; + path_check(i_this, 0); + wait_set(i_this); + i_this->dr.m004 = 2; + } + i_this->m0318 = 1; + i_this->m0314 = 0x10; + cXyz sp18; + sp18.x = sp18.y = sp18.z = 1.0f; + dComIfGp_particle_set(dPa_name::ID_COMMON_PURPLE_HIT, &i_this->m11E4, NULL, &sp18); + } + } + + if (!i_this->mpMorf->isStop()) { + break; + } + + if ( + (i_this->m0B60 == 2 && i_this->m0B7A > 0) || + (i_this->m0B7A < 0 && i_this->m0B60 == 0) || + (i_this->m0B5C == 2 && i_this->m0B60 == 1) + ) { + if (i_this->m11FC != fpcM_ERROR_PROCESS_ID_e) { + i_this->dr.mState = 0xE; + i_this->dr.m004 = 0; + } else if (i_this->mPlayerDistance < l_bkHIO.m02C) { + if (daBk_player_view_check(i_this, &i_this->dr.m714->current.pos, i_this->m0332, l_bkHIO.m034)) { + if (cM_rndF(1.0f) < 0.8f || i_this->m0B7A < 0) { + i_this->dr.mState = 4; + i_this->dr.m004 = 2; + i_this->m0300[1] = 0; + } else { + i_this->dr.m004 = 0; + } + } else { + if (i_this->m0B30 != 0 || i_this->m11F3 != 0) { + i_this->dr.mState = 8; + i_this->dr.m004 = 0; + } else { + i_this->dr.mState = 0; + wait_set(i_this); + i_this->dr.m004 = 2; + } + } + } else { + i_this->dr.mState = 0; + path_check(i_this, 0); + wait_set(i_this); + i_this->dr.m004 = 2; + } + } else if (i_this->dr.mAcch.ChkGroundHit()) { + attack_info_s* r6 = attack_info[i_this->m0B5C]; + f32 speed; + if (i_this->m0B7A > 0) { + i_this->m0B60++; + speed = r6[i_this->m0B60].speed; + } else { + i_this->m0B60--; + speed = -r6[i_this->m0B60].speed; + } + anm_init(i_this, r6[i_this->m0B60].bckFileIdx, 0.0f, J3DFrameCtrl::LOOP_ONCE_e, speed, r6[i_this->m0B60].soundFileIdx); + } + + break; + } } /* 00007EF4-00008108 .text p_lost__FP8bk_class */ @@ -2191,7 +2389,7 @@ static void aite_miru(bk_class* i_this) { } } if (i_this->m0300[1] == 0) { - i_this->m11FC = -1; + i_this->m11FC = fpcM_ERROR_PROCESS_ID_e; i_this->dr.mState = 0; i_this->dr.m004 = 0; path_check(i_this, 0); @@ -2348,6 +2546,8 @@ static void bou_mtx_set(bk_class* i_this) { } } +static u8 temp[0x118] = {}; + /* 0000CE18-0000DD1C .text daBk_Execute__FP8bk_class */ static BOOL daBk_Execute(bk_class* i_this) { another_hit = 0; @@ -2517,7 +2717,7 @@ static BOOL daBk_Execute(bk_class* i_this) { int r3 = damage_reaction(&i_this->dr); if (r3 != 0) { i_this->m034C = 1; - i_this->m11FC = -1; + i_this->m11FC = fpcM_ERROR_PROCESS_ID_e; switch (r3) { case 1: anm_init(i_this, BK_BCK_BK_AOMUKE, 2.0f, J3DFrameCtrl::LOOP_ONCE_e, 1.0f, BK_BAS_BK_AOMUKE); @@ -2733,8 +2933,6 @@ static BOOL daBk_Delete(bk_class* i_this) { return TRUE; } -static u8 temp[0x118] = {}; - /* 0000DDD8-0000E2C8 .text useHeapInit__FP10fopAc_ac_c */ static BOOL useHeapInit(fopAc_ac_c* i_actor) { bk_class* i_this = (bk_class*)i_actor; diff --git a/src/d/d_com_inf_game.cpp b/src/d/d_com_inf_game.cpp index 935a4e039..ad34c0f65 100644 --- a/src/d/d_com_inf_game.cpp +++ b/src/d/d_com_inf_game.cpp @@ -58,12 +58,12 @@ void dComIfG_play_c::ct() /* 800521A4-800521D4 .text init__14dComIfG_play_cFv */ void dComIfG_play_c::init() { - for (int i = 0; i < 1; i++) { + for (int i = 0; i < ARRAY_SIZE(mpPlayer); i++) { mpPlayer[i] = NULL; mCurCamera[i] = -1; } - for (int i = 0; i < 3; i++) { + for (int i = 0; i < ARRAY_SIZE(mpPlayerPtr); i++) { mpPlayerPtr[i] = NULL; } } @@ -111,7 +111,7 @@ void dComIfG_play_c::itemInit() { field_0x4931 = 0; field_0x4932 = 0; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < ARRAY_SIZE(mSelectItem); i++) { mSelectItem[i] = 0; mSelectEquip[i] = 0; } @@ -138,7 +138,7 @@ void dComIfG_play_c::itemInit() { mMesgSendButton = 0; mMesgCancelButton = 0; - for (int i = 0; i < 6; i++) { + for (int i = 0; i < ARRAY_SIZE(field_0x494a); i++) { field_0x494a[i] = 0; } @@ -174,7 +174,7 @@ void dComIfG_play_c::itemInit() { mMesgCameraTagInfo = 0; field_0x4984 = 0; - for (int i = 0; i < 10; i++) { + for (int i = 0; i < ARRAY_SIZE(field_0x4988); i++) { field_0x4988[i] = 0; } @@ -1105,7 +1105,7 @@ BOOL dComIfGs_checkSeaLandingEvent(s8 i_roomNo) { landing_event* event_check = l_landingEvent; - for (u32 i = 0; i < 6; i++) { + for (u32 i = 0; i < ARRAY_SIZE(l_landingEvent); i++) { if (i_roomNo == event_check->roomNo && !dComIfGs_isEventBit(event_check->event)) { return FALSE; } @@ -1136,7 +1136,7 @@ void dComIfGs_setGameStartStage() { }; check_data* data_p = l_checkData; - for (u32 i = 0; i < 5; i++) { + for (u32 i = 0; i < ARRAY_SIZE(l_checkData)-1; i++) { if (data_p->mbHasEvent == true && dComIfGs_isEventBit(data_p->mEvent)) { break; } diff --git a/src/d/d_kankyo.cpp b/src/d/d_kankyo.cpp index d951414cc..fdc12a760 100644 --- a/src/d/d_kankyo.cpp +++ b/src/d/d_kankyo.cpp @@ -90,11 +90,17 @@ u16 lightMaskData[] = { GX_LIGHT0, GX_LIGHT1, GX_LIGHT2, GX_LIGHT3, GX_LIGHT4, GX_LIGHT5, GX_LIGHT6, GX_LIGHT7, }; +/** + * Returns true if toon lighting and shadow should be reversed. + */ /* 8018F7FC-8018F848 .text toon_proc_check__Fv */ BOOL toon_proc_check() { s32 roomNo = dComIfGp_roomControl_getStayNo(); if (roomNo >= 0) { - dComIfGp_roomControl_getStatusRoomDt(roomNo)->getFileListInfo(); + dStage_FileList_dt_c* fili_p = dComIfGp_roomControl_getStatusRoomDt(roomNo)->getFileListInfo(); + if (dStage_FileList_dt_GetToonsw(fili_p)) { + // Something was probably commented out here. + } } return false; diff --git a/src/d/d_stage.cpp b/src/d/d_stage.cpp index ff9746be0..e93a44945 100644 --- a/src/d/d_stage.cpp +++ b/src/d/d_stage.cpp @@ -338,7 +338,7 @@ dStage_darkStatus_c* dStage_roomControl_c::getDarkStatus() { if (plist_p == NULL) return NULL; - int idx = (plist_p->mParam & 0x78) >> 3; + int idx = dStage_FileList_dt_DarkNo(plist_p); return &mDarkStatus[idx]; } @@ -348,7 +348,7 @@ u32 dStage_roomControl_c::getDarkMode() { dStage_FileList_dt_c* plist_p = pRoomStatus->mRoomDt.mpFileList; u8 mode = 0; - if (plist_p != NULL && (plist_p->mParam & 1) != 0) + if (plist_p != NULL && dStage_FileList_dt_CheckDarkOn(plist_p) != 0) mode = 1; return mode; }