diff --git a/config/43U/symbols.txt b/config/43U/symbols.txt index 1aa0bdf3..2679503c 100644 --- a/config/43U/symbols.txt +++ b/config/43U/symbols.txt @@ -4580,9 +4580,9 @@ handleNandTitleUsage__Q33ipl5scene15SDChannelSelectFv = .text:0x813DBD94; // typ compareTitleUsage__Q33ipl5scene15SDChannelSelectFPCvPCv = .text:0x813DBE6C; // type:function size:0x28 handleSDTitleList__Q33ipl5scene15SDChannelSelectFv = .text:0x813DBE94; // type:function size:0x124 compareTitleInfo__Q33ipl5scene15SDChannelSelectFPCvPCv = .text:0x813DBFB8; // type:function size:0x28 -iplSDChannelSelect_813DBFE0 = .text:0x813DBFE0; // type:function size:0x2AC +handleSDTitleListResult__Q33ipl5scene15SDChannelSelectFv = .text:0x813DBFE0; // type:function size:0x2AC handleSDMountComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC28C; // type:function size:0x64 -iplSDChannelSelect_813DC2F0 = .text:0x813DC2F0; // type:function size:0x1B0 +handleSDChannelUpdateComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC2F0; // type:function size:0x1B0 handleSDCardReady__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC4A0; // type:function size:0x5C handleCardCommand__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC4FC; // type:function size:0x78 handleCopyComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC574; // type:function size:0x80 @@ -4592,7 +4592,7 @@ handleMoveComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC684; // type: handleBackupFitComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC714; // type:function size:0x48 handleNandSDCleanupComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC75C; // type:function size:0x48 handleSDDeleteComplete__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC7A4; // type:function size:0x48 -iplSDChannelSelect_813DC7EC = .text:0x813DC7EC; // type:function size:0x14C +updateChannelNotices__Q33ipl5scene15SDChannelSelectFii = .text:0x813DC7EC; // type:function size:0x14C processWorkerState__Q33ipl5scene15SDChannelSelectFv = .text:0x813DC938; // type:function size:0x18C updateDialogAnimation__Q33ipl5scene15SDChannelSelectFv = .text:0x813DCAC4; // type:function size:0x42C setDialogMessage__Q33ipl5scene15SDChannelSelectFUlUl = .text:0x813DCEF0; // type:function size:0x24 @@ -4632,15 +4632,15 @@ iplSDChannelSelect_813DF3FC = .text:0x813DF3FC; // type:function size:0x110 iplSDChannelSelect_813DF50C = .text:0x813DF50C; // type:function size:0x4C iplSDChannelSelect_813DF558 = .text:0x813DF558; // type:function size:0x178 iplSDChannelSelect_813DF6D0 = .text:0x813DF6D0; // type:function size:0x164 -iplSDChannelSelect_813DF834 = .text:0x813DF834; // type:function size:0x110 -iplSDChannelSelect_813DF944 = .text:0x813DF944; // type:function size:0x84 -iplSDChannelSelect_813DF9C8 = .text:0x813DF9C8; // type:function size:0xF8 -iplSDChannelSelect_813DFAC0 = .text:0x813DFAC0; // type:function size:0xFC -iplSDChannelSelect_813DFBBC = .text:0x813DFBBC; // type:function size:0xE4 +createChannelList__Q33ipl5scene15SDChannelSelectFib = .text:0x813DF834; // type:function size:0x110 +createChannelObject__Q33ipl5scene15SDChannelSelectFii = .text:0x813DF944; // type:function size:0x84 +destroyUnusedChannelObjects__Q33ipl5scene15SDChannelSelectFiPQ33ipl5scene12SDChannelObj = .text:0x813DF9C8; // type:function size:0xF8 +refreshChannelList__Q33ipl5scene15SDChannelSelectFv = .text:0x813DFAC0; // type:function size:0xFC +refreshAfterSDTitleList__Q33ipl5scene15SDChannelSelectFv = .text:0x813DFBBC; // type:function size:0xE4 destroyChannelObject__Q33ipl5scene15SDChannelSelectFPQ33ipl5scene12SDChannelObj = .text:0x813DFCA0; // type:function size:0x50 iplSDChannelSelect_813DFCF0 = .text:0x813DFCF0; // type:function size:0x74 iplSDChannelSelect_813DFD64 = .text:0x813DFD64; // type:function size:0x154 -iplSDChannelSelect_813DFEB8 = .text:0x813DFEB8; // type:function size:0x74 +findChannelObject__Q33ipl5scene15SDChannelSelectCFii = .text:0x813DFEB8; // type:function size:0x74 iplSDChannelSelect_813DFF2C = .text:0x813DFF2C; // type:function size:0x1C0 hasChannelObject__Q33ipl5scene15SDChannelSelectCFii = .text:0x813E00EC; // type:function size:0x140 isChannelInCalc__Q33ipl5scene15SDChannelSelectCFiii = .text:0x813E022C; // type:function size:0x68 diff --git a/include/scene/sdChannelSelect/iplSDChannelSelect.h b/include/scene/sdChannelSelect/iplSDChannelSelect.h index d650b64d..ea16e604 100644 --- a/include/scene/sdChannelSelect/iplSDChannelSelect.h +++ b/include/scene/sdChannelSelect/iplSDChannelSelect.h @@ -12,6 +12,7 @@ namespace ipl { namespace scene { class SDChannelObj { public: + SDChannelObj(EGG::Heap* heap, int page, int index); ~SDChannelObj(); EGG::Heap* getHeap() const { return mpHeap; } @@ -19,13 +20,41 @@ namespace ipl { int getIndex() const { return mIndex; } private: + friend class SDChannelSelect; + nw4r::ut::Link mListLink; - f32 mOffsetX; - f32 mOffsetY; + EGG::ExpHeap* mpDialogHeap; + EGG::ExpHeap* mpChannelHeap; EGG::Heap* mpHeap; u32 mState; int mPage; int mIndex; + nand::LayoutFile* mpLayoutFile; + nw4r::lyt::Pane* mpPane; + layout::Animator* mpPaneAnimator; + layout::Object* mpBaseLayout; + layout::Animator* mpBaseAnimator; + layout::Object* mpPageLayout; + layout::Animator* mpPageAnimators[3]; + int mPageAnimation; + int mPageAnimationFrame; + layout::Object* mpDialogLayout; + layout::Animator* mpDialogAnimator; + int mDialogState; + int mDialogFrame; + int mDialogTimer; + int mAnimationState; + nw4r::lyt::Group* mpNewMessageGroup; + int mNewMessageCount; + u8 mbNewMessageGroupActive; + int mNewMessageState; + int mNewMessageFrame; + f32 mOffsetX; + f32 mOffsetY; + f32 mAspectRatioScale; + int mStateFlags; + void* mpThumbnailData; + NandSDWorker::SDAppMetaEntry mAppMeta; }; extern "C" void iplSDChannelObj_813E3104(SDChannelObj* channel); extern "C" void iplSDChannelObj_813E311C(SDChannelObj* channel, EGG::ExpHeap* firstHeap, @@ -35,6 +64,8 @@ namespace ipl { extern "C" void iplSDChannelObj_813E3180(SDChannelObj* channel, nand::LayoutFile* layoutFile); extern "C" void iplSDChannelObj_813E3304(SDChannelObj* channel); extern "C" void iplSDChannelObj_813E330C(SDChannelObj* channel); + extern "C" void* iplSDChannelObj_813E3128(SDChannelObj* channel); + extern "C" bool iplSDChannelObj_813E3330(SDChannelObj* channel); union SDChannelSelectCommandArguments { u32 values[3]; @@ -68,7 +99,7 @@ namespace ipl { struct SDChannelSelectTitleInfo { ESTitleId32 titleId; - u32 state; + bool used; }; struct SDChannelSelectNoticeQueue { @@ -147,6 +178,10 @@ namespace ipl { void handleNandTitleUsage(); void handleNandTitleUsageComplete(); void handleSDTitleList(); + void handleSDTitleListResult(); + void refreshAfterSDTitleList(); + void handleSDChannelUpdateComplete(); + void updateChannelNotices(int pageOffset, int index); void handleSDMountComplete(); void handleCopyComplete(); void handleDeleteComplete(); @@ -164,7 +199,10 @@ namespace ipl { static int compareTitleInfo(const void* lhs, const void* rhs); void createChannelList(int page, bool force); void destroyChannelObject(SDChannelObj* channel); + void destroyUnusedChannelObjects(int currentPage, SDChannelObj* keepChannel); + void refreshChannelList(); bool hasChannelObject(int page, int index) const; + SDChannelObj* findChannelObject(int page, int index) const; void createChannelObject(int page, int index); void createBaseLayout(); void updateNoCardLayouts(); diff --git a/src/scene/sdChannelSelect/iplSDChannelSelect.cpp b/src/scene/sdChannelSelect/iplSDChannelSelect.cpp index 793ccfb9..678f43af 100644 --- a/src/scene/sdChannelSelect/iplSDChannelSelect.cpp +++ b/src/scene/sdChannelSelect/iplSDChannelSelect.cpp @@ -433,7 +433,7 @@ namespace ipl { mpSDWorker->startup_async(); mWorkerState = 2; } else if (mPreviousSDState != mCurrentSDState && mCurrentSDState == 7) { - System::getErrorHandler()->set(ErrorHandler::DEFAULT, 1); + setDialogMessage(8, 0xaa); } } @@ -544,6 +544,91 @@ namespace ipl { return left->titleId != right->titleId; } + void SDChannelSelect::handleSDTitleListResult() { + if (mpSDWorker->is_working()) { + return; + } + + mLastOperation = 14; + if (mDialogState != 0) { + return; + } + + if (OSGetTime() - mOperationStartTime >= OS_TIMER_CLOCK) { + setDialogMessage(1, 0); + int result = mpSDWorker->get_async_result(); + if (result == NandSDWorker::RESULT_OK || + result == NandSDWorker::RESULT_SD_APP_LOC_NOT_FOUND) { + for (int channelIndex = 0; channelIndex < mPageCount * 12; + ++channelIndex) { + if (mpChannelTitleIds[channelIndex] != 0) { + SDChannelSelectTitleInfo* info = + static_cast( + bsearch(mpChannelTitleIds + channelIndex, mpSDTitleInfo, + mSDTitleCount, sizeof(SDChannelSelectTitleInfo), + compareTitleInfo)); + if (info != NULL) { + info->used = true; + } else { + mpChannelTitleIds[channelIndex] = 0; + } + } + } + + int channelIndex = 0; + u32 titleIndex = 0; + bool addedTitle = false; + for (; channelIndex < mPageCount * 12; ++channelIndex) { + if (mpChannelTitleIds[channelIndex] == 0) { + if (titleIndex == mSDTitleCount) { + break; + } + + for (; titleIndex < mSDTitleCount; ++titleIndex) { + SDChannelSelectTitleInfo* info = &mpSDTitleInfo[titleIndex]; + if (!info->used && info->titleId != 0x48415A41) { + mpChannelTitleIds[channelIndex] = info->titleId; + addedTitle = true; + ++titleIndex; + break; + } + } + } + } + + if (addedTitle || result == NandSDWorker::RESULT_SD_APP_LOC_NOT_FOUND) { + enqueueLoadNotice(); + } + } else { + int channelCount = 0; + int channelIndex = 0; + u32 titleIndex = 0; + for (; titleIndex < mSDTitleCount; ++titleIndex) { + u32 titleId = mpSDTitleInfo[titleIndex].titleId; + if (titleId != 0x48415A41) { + ++channelCount; + mpChannelTitleIds[channelIndex++] = titleId; + if (channelCount == mPageCount * 12) { + break; + } + } + } + enqueueLoadNotice(); + } + + mWorkerCommand = 1; + mbNeedsRefresh = true; + u32 titleCount = mbHazardTitleFound ? mSDTitleCount - 1 : mSDTitleCount; + if (titleCount > static_cast(mPageCount * 12)) { + mbOperationActive = true; + } + if (titleCount >= static_cast(mPageCount * 12)) { + mbSDCardBroken = true; + } + refreshAfterSDTitleList(); + } + } + void SDChannelSelect::processWorkerCommands() { if (mpSDWorker->is_working() || mWorkerState != 4) { return; @@ -643,6 +728,53 @@ namespace ipl { } } + void SDChannelSelect::handleSDChannelUpdateComplete() { + if (mpSDWorker->is_working()) { + return; + } + + mLastOperation = 14; + SDChannelObj* channel = mpCurrentLoadedChannel; + int page = channel->mPage; + int index = channel->mIndex; + if (!isChannelInCalc(page, index, mCurrentPage) || + static_cast(mCurrentSDState) - 1 <= 1) { + destroyChannelObject(channel); + mWorkerCommand = 1; + mpCurrentLoadedChannel = NULL; + return; + } + + if (mpSDWorker->get_async_result() >= 0) { + channel->mStateFlags = 0; + channel->mState = 2; + DCFlushRange(iplSDChannelObj_813E3128(channel), 0x19000); + } else { + memcpy(iplSDChannelObj_813E3128(channel), + mpCorruptIconFile->getBuffer(), mpCorruptIconFile->getLength()); + memset(&channel->mAppMeta, 0, sizeof(channel->mAppMeta)); + channel->mStateFlags = 3; + channel->mState = 2; + } + + SDChannelObj* previous = findChannelObject(page, index); + if (previous != NULL) { + nw4r::ut::List_Insert(&mChannelObjects, previous, channel); + nw4r::ut::List_Remove(&mChannelObjects, previous); + destroyChannelObject(previous); + } else { + nw4r::ut::List_Append(&mChannelObjects, channel); + } + + updateChannelObject(channel); + if (mCurrentPage == page) { + mpPaneManager->initPane(getChannelPane(index)); + } + + mWorkerCommand = 1; + mpCurrentLoadedChannel = NULL; + } + void SDChannelSelect::handleCopyComplete() { if (!mpSDWorker->is_working()) { mLastOperation = 14; @@ -736,6 +868,50 @@ namespace ipl { } } + void SDChannelSelect::updateChannelNotices(int pageOffset, int index) { + int page = mCurrentPage + pageOffset; + if (page < 0 || mpChannelTitleIds == NULL) { + return; + } + + int firstIndex; + int indexStep; + if (pageOffset == 2) { + firstIndex = 0; + indexStep = 4; + } else if (pageOffset < 2) { + if (pageOffset == -2) { + firstIndex = 3; + indexStep = 4; + } else { + firstIndex = 0; + indexStep = 1; + } + } else { + firstIndex = 0; + indexStep = 1; + } + + int pageTitleIndex = page * 12; + SDChannelObj* channel; + if (index >= 0 && index < 12 && + (channel = findChannelObject(page, index)) != NULL && channel->mState == 2 && + mpChannelTitleIds[pageTitleIndex + index] != 0) { + enqueueNotice(mpChannelTitleIds[pageTitleIndex + index], page, index); + } + + for (int channelIndex = firstIndex; channelIndex < 12; + channelIndex += indexStep) { + if (channelIndex != index && + (channel = findChannelObject(page, channelIndex)) != NULL && + channel->mState == 2 && + mpChannelTitleIds[pageTitleIndex + channelIndex] != 0) { + enqueueNotice(mpChannelTitleIds[pageTitleIndex + channelIndex], page, + channelIndex); + } + } + } + void SDChannelSelect::processWorkerState() { mPreviousSDState = mCurrentSDState; mCurrentSDState = mpSDWorker->get_sd_state(); @@ -761,7 +937,7 @@ namespace ipl { handleSDTitleList(); break; case 3: - handleCopyComplete(); + handleSDChannelUpdateComplete(); break; case 4: handleSDMountComplete(); @@ -1337,6 +1513,129 @@ namespace ipl { return mpLayout->FindPaneByName(mscChannelPaneNames[2][index]); } + void SDChannelSelect::createChannelList(int page, bool force) { + for (int index = 0; index < MAX_CHANNEL_INDEX; ++index) { + if (force || findChannelObject(page, index) == NULL) { + createChannelObject(page, index); + } + } + + if (page < mPageCount - 1) { + for (int index = 0; index < MAX_CHANNEL_INDEX; index += 4) { + if (force || findChannelObject(page + 1, index) == NULL) { + createChannelObject(page + 1, index); + } + } + } + + if (page > 0) { + for (int index = 3; index < MAX_CHANNEL_INDEX; index += 4) { + if (force || findChannelObject(page - 1, index) == NULL) { + createChannelObject(page - 1, index); + } + } + } + } + + void SDChannelSelect::destroyUnusedChannelObjects(int currentPage, + SDChannelObj* keepChannel) { + int keepPage; + int keepIndex; + if (keepChannel != NULL) { + keepPage = keepChannel->getPage(); + keepIndex = keepChannel->getIndex(); + } + + SDChannelObj* channel = NULL; + while (channel = static_cast( + nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + int page = channel->getPage(); + int index = channel->getIndex(); + if (keepChannel != NULL && page == keepPage && index == keepIndex) { + continue; + } + if (mState < 0x18) { + if (mState >= 0xF && page == mSourcePage && index == mSourceIndex) { + continue; + } + } + if (!isChannelInCalc(page, index, currentPage)) { + SDChannelObj* previous = static_cast( + nw4r::ut::List_GetPrev(&mChannelObjects, channel)); + nw4r::ut::List_Remove(&mChannelObjects, channel); + destroyChannelObject(channel); + channel = previous; + } + } + } + + void SDChannelSelect::createChannelObject(int page, int index) { + EGG::FrmHeap* objectHeap = EGG::FrmHeap::create(0x212B8, mpLayoutHeap, 2); + SDChannelObj* channel = new (mpThumbnailHeap, 4) SDChannelObj(objectHeap, page, index); + nw4r::ut::List_Append(&mChannelObjects, channel); + } + + void SDChannelSelect::refreshChannelList() { + SDChannelObj* channel = NULL; + while (channel = static_cast( + nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + if (iplSDChannelObj_813E3330(channel)) { + SDChannelObj* previous = static_cast( + nw4r::ut::List_GetPrev(&mChannelObjects, channel)); + nw4r::ut::List_Remove(&mChannelObjects, channel); + destroyChannelObject(channel); + channel = previous; + } else if (channel->mStateFlags == 2) { + channel->mStateFlags = 1; + } + } + + createChannelList(mCurrentPage, false); + if (mCurrentPage < mPageCount - 1) { + createChannelList(mCurrentPage + 1, false); + } + if (mCurrentPage > 0) { + createChannelList(mCurrentPage - 1, false); + } + updateChannelObjects(); + } + + void SDChannelSelect::refreshAfterSDTitleList() { + SDChannelObj* channel = NULL; + while (channel = static_cast( + nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + int channelIndex = channel->mPage * 12 + channel->mIndex; + if (!iplSDChannelObj_813E3330(channel) && + mpChannelTitleIds[channelIndex] != 0) { + channel->mStateFlags = 2; + } + } + + clearNoticeQueue(); + updateChannelNotices(0, -1); + updateChannelNotices(-1, -1); + updateChannelNotices(1, -1); + updateChannelNotices(-2, -1); + updateChannelNotices(2, -1); + } + + SDChannelObj* SDChannelSelect::findChannelObject(int page, int index) const { + SDChannelObj* channel = NULL; + while (channel = static_cast( + nw4r::ut::List_GetNext(&mChannelObjects, channel)), + channel != NULL) { + if (page == channel->getPage()) { + if (index == channel->getIndex()) { + return channel; + } + } + } + return NULL; + } + math::VEC3 SDChannelSelect::getChannelPanePosition(SDChannelSelect* scene, int index) { math::VEC3 position(0.0f, 0.0f, 0.0f); MTXMultVec(scene->getCenterChannelPane(index)->GetGlobalMtx(), position, position);