|
| 1 | +#include <types.h> |
| 2 | + |
| 3 | +#include "core/ItemMgr.h" |
| 4 | +#include "hooks/trampoline.h" |
| 5 | + |
| 6 | +#include <Sports2/Sp2Cmn.h> |
| 7 | +#include <Sports2/Sp2MiiSelect.h> |
| 8 | + |
| 9 | +#include <libkiwi.h> |
| 10 | + |
| 11 | +namespace AP { |
| 12 | +namespace MiiSelect { |
| 13 | + |
| 14 | +/** |
| 15 | + * @brief Overrides a stage select button's state based on the AP item unlocks |
| 16 | + * |
| 17 | + * @param pBtnInfo Stage select save data info |
| 18 | + * @param idx Button index |
| 19 | + * @param state Pending button state |
| 20 | + */ |
| 21 | +void InterceptStageBtnState(Sp2::MiiSelect::StageSelectBtnInfo* pBtnInfo, |
| 22 | + u32 idx, |
| 23 | + Sp2::MiiSelect::StageSelectBtnInfo::EState state) { |
| 24 | + |
| 25 | + ASSERT(pBtnInfo != nullptr); |
| 26 | + |
| 27 | + // Scene group determines which sport we are dealing with |
| 28 | + switch (RP_GET_INSTANCE(Sp2::Cmn::StaticMem)->getSceneGroup()) { |
| 29 | + case Sp2::Cmn::EGroupID_Jsk: { |
| 30 | + state = ItemMgr::GetInstance().IsJskStageUnlock(idx) |
| 31 | + ? Sp2::MiiSelect::StageSelectBtnInfo::EState_Open |
| 32 | + : Sp2::MiiSelect::StageSelectBtnInfo::EState_Locked; |
| 33 | + break; |
| 34 | + } |
| 35 | + |
| 36 | + case Sp2::Cmn::EGroupID_Arc: { |
| 37 | + state = ItemMgr::GetInstance().IsArcStageUnlock(idx) |
| 38 | + ? Sp2::MiiSelect::StageSelectBtnInfo::EState_Open |
| 39 | + : Sp2::MiiSelect::StageSelectBtnInfo::EState_Locked; |
| 40 | + break; |
| 41 | + } |
| 42 | + |
| 43 | + case Sp2::Cmn::EGroupID_Can: { |
| 44 | + state = ItemMgr::GetInstance().IsCanStageUnlock(idx) |
| 45 | + ? Sp2::MiiSelect::StageSelectBtnInfo::EState_Open |
| 46 | + : Sp2::MiiSelect::StageSelectBtnInfo::EState_Locked; |
| 47 | + break; |
| 48 | + } |
| 49 | + |
| 50 | + case Sp2::Cmn::EGroupID_Wkb: { |
| 51 | + state = ItemMgr::GetInstance().IsWkbStageUnlock(idx) |
| 52 | + ? Sp2::MiiSelect::StageSelectBtnInfo::EState_Open |
| 53 | + : Sp2::MiiSelect::StageSelectBtnInfo::EState_Locked; |
| 54 | + break; |
| 55 | + } |
| 56 | + |
| 57 | + case Sp2::Cmn::EGroupID_Pln: { |
| 58 | + state = ItemMgr::GetInstance().IsPlnStageUnlock(idx) |
| 59 | + ? Sp2::MiiSelect::StageSelectBtnInfo::EState_Open |
| 60 | + : Sp2::MiiSelect::StageSelectBtnInfo::EState_Locked; |
| 61 | + break; |
| 62 | + } |
| 63 | + |
| 64 | + case Sp2::Cmn::EGroupID_Glf: { |
| 65 | + state = ItemMgr::GetInstance().IsGlfStageUnlock(idx) |
| 66 | + ? Sp2::MiiSelect::StageSelectBtnInfo::EState_Open |
| 67 | + : Sp2::MiiSelect::StageSelectBtnInfo::EState_Locked; |
| 68 | + break; |
| 69 | + } |
| 70 | + |
| 71 | + case Sp2::Cmn::EGroupID_Dgl: { |
| 72 | + state = ItemMgr::GetInstance().IsDglStageUnlock(idx) |
| 73 | + ? Sp2::MiiSelect::StageSelectBtnInfo::EState_Open |
| 74 | + : Sp2::MiiSelect::StageSelectBtnInfo::EState_Locked; |
| 75 | + break; |
| 76 | + } |
| 77 | + |
| 78 | + case Sp2::Cmn::EGroupID_Bic: { |
| 79 | + state = ItemMgr::GetInstance().IsBicStageUnlock(idx) |
| 80 | + ? Sp2::MiiSelect::StageSelectBtnInfo::EState_Open |
| 81 | + : Sp2::MiiSelect::StageSelectBtnInfo::EState_Locked; |
| 82 | + break; |
| 83 | + } |
| 84 | + |
| 85 | + default: { |
| 86 | + UNREACHABLE(); |
| 87 | + break; |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + pBtnInfo->setBtnState(idx, state); |
| 92 | +} |
| 93 | + |
| 94 | +/** |
| 95 | + * @brief InterceptStageBtnState trampoline |
| 96 | + */ |
| 97 | +TRAMPOLINE_DEF(0x8031bda0, 0x8031bdac) { |
| 98 | + // clang-format off |
| 99 | + TRAMPOLINE_BEGIN |
| 100 | + |
| 101 | + bl InterceptStageBtnState |
| 102 | + |
| 103 | + TRAMPOLINE_END |
| 104 | + blr |
| 105 | + // clang-format on |
| 106 | +} |
| 107 | + |
| 108 | +} // namespace MiiSelect |
| 109 | +} // namespace AP |
0 commit comments