From 780d148f4410dc7229470b6ae32feb9ffa8cb38c Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 29 Sep 2026 22:01:56 +0000 Subject: [PATCH] Decompile iplSDChannelTitle to 63/69 functions (gpt-6.1-sol low) (worker b1c15e3d) --- include/scene/sdButton/iplSDButton.h | 4 + include/scene/sdChannelMemory/iplSDMemory.h | 6 + .../sdChannelSelect/iplSDChannelSelect.h | 8 + .../scene/sdChannelTitle/iplSDChannelTitle.h | 89 + include/system/iplSaveDataManager.h | 3 + .../sdChannelTitle/iplSDChannelTitle.cpp | 1563 +++++++++++++++++ .../iplSDChannelTitle.attempts.md | 57 + 7 files changed, 1730 insertions(+) create mode 100644 src/scene/sdChannelTitle/iplSDChannelTitle.cpp create mode 100644 tools/decomp-assist/iplSDChannelTitle.attempts.md diff --git a/include/scene/sdButton/iplSDButton.h b/include/scene/sdButton/iplSDButton.h index a3de1f2b..38e1c743 100644 --- a/include/scene/sdButton/iplSDButton.h +++ b/include/scene/sdButton/iplSDButton.h @@ -97,6 +97,10 @@ namespace ipl { void startLeftEvent(const char* paneName); bool isActive() const; +#ifdef IPL_SD_CHANNEL_TITLE_CPP + bool isLeftArrowVisible() const { return mbArrowVisible[ARROW_BTN_LEFT]; } + static const char* getButtonName(int button) { return smButtonName[button]; } +#endif #ifdef IPL_SD_CHANNEL_SELECT_CPP void setEventHandler(::gui::EventHandler * event, diff --git a/include/scene/sdChannelMemory/iplSDMemory.h b/include/scene/sdChannelMemory/iplSDMemory.h index f74b691b..2ad39f8e 100644 --- a/include/scene/sdChannelMemory/iplSDMemory.h +++ b/include/scene/sdChannelMemory/iplSDMemory.h @@ -39,7 +39,11 @@ namespace ipl { void hideLeftArrow(); void hideRightArrow(); +#ifdef IPL_SD_CHANNEL_TITLE_CPP + public: +#else private: +#endif s32 updateState(); void drawTransferTitles(); void onDialogState0(); @@ -149,8 +153,10 @@ namespace ipl { scroller mScroller; s32 mButtonState; u8 mControllerFlags[4]; +#ifndef IPL_SD_CHANNEL_TITLE_CPP u32 mFinalState[3]; u8 mFinalFlags[4]; +#endif }; } // namespace scene } // namespace ipl diff --git a/include/scene/sdChannelSelect/iplSDChannelSelect.h b/include/scene/sdChannelSelect/iplSDChannelSelect.h index de47f1fb..8257a4f1 100644 --- a/include/scene/sdChannelSelect/iplSDChannelSelect.h +++ b/include/scene/sdChannelSelect/iplSDChannelSelect.h @@ -28,7 +28,11 @@ namespace ipl { int getIndex() const { return mIndex; } nw4r::math::VEC3& getTranslate() const; +#ifdef IPL_SD_CHANNEL_TITLE_CPP + public: +#else private: +#endif friend class SDChannelSelect; nw4r::ut::Link mListLink; @@ -172,7 +176,11 @@ namespace ipl { static const char* mscClockPaneNames[3]; static const char* mscMaskPaneName; +#ifdef IPL_SD_CHANNEL_TITLE_CPP + public: +#else private: +#endif #ifdef IPL_SD_CHANNEL_SELECT_CPP friend class SDChannelSelectEventHandler; friend class SDChannelSelectButtonEventHandler; diff --git a/include/scene/sdChannelTitle/iplSDChannelTitle.h b/include/scene/sdChannelTitle/iplSDChannelTitle.h index efeb7fce..11211494 100644 --- a/include/scene/sdChannelTitle/iplSDChannelTitle.h +++ b/include/scene/sdChannelTitle/iplSDChannelTitle.h @@ -3,15 +3,104 @@ #include "iplSceneHeader.h" +#ifdef IPL_SD_CHANNEL_TITLE_CPP +#include "math/iplInterporation.h" +#include "scene/sdChannelMemory/iplSDMemory.h" +#include "system/iplChannelRsoThread.h" +#include "utility/iplCapture.h" +#include +#include +#endif + namespace ipl { namespace scene { class SDChannelSelect; + class SDButtonEventHandlerBase; FADER_SCENE_CLASS(SDChannelTitle) { public: SDChannelTitle(EGG::Heap * heap, SDChannelSelect * chanSel); +#ifdef IPL_SD_CHANNEL_TITLE_CPP + virtual ~SDChannelTitle(); + virtual void prepare(); + virtual void create(); + virtual void calcCommon(); + virtual FaderSceneCommand calcFadein(); + virtual FaderSceneCommand calcNormal(); + virtual void initCalcFadeout(); + virtual FaderSceneCommand calcFadeout(); + virtual void draw(); + virtual void destroy(); + BOOL isResetAcceptable(); + virtual void startResetting(); + + using Base::reserveAllSceneDestruction; + using Base::createChildScene; + + s32 mState; + EGG::ExpHeap* mpBannerHeap; + EGG::ExpHeap* mpCaptureHeap; + s32 mPage; + s32 mIndex; + s32 mPageCount; + s32 mNextScene; + s32 mParentalResult; + math::VEC3 mPosition; + u32 mLaunchFrame; + s32 mStartButtonState; + bool mbBannerStarting; + layout::Animator* mpButtonAnimations[7][6]; + math::HermiteIntp* mpFade; + SDChannelSelect* mpChannelSelect; + nand::LayoutFile* mpLayoutFile; + layout::Object* mpLayout; + gui::PaneManager* mpPaneManager; + layout::Object* mpIconLayout; + EGG::ExpHeap* mpIconHeap; + layout::Object* mpProgressLayout; + s32 mLoadedIndex; + nand::LayoutFile* mpBannerFiles[2]; + nand::File* mpSoundFiles[2]; + layout::Object* mpBannerLayout; + layout::Animator* mpBannerAnimations[3]; + nw4r::snd::SoundHandle* mpSoundHandle; + nand::File* mpSaveFile; + u32 mWpadStopTick; + s32 mHoverCounts[2]; + SDButtonEventHandlerBase* mpButtonEventHandler; + utility::Capture* mpScreenCapture; + utility::Capture* mpBannerCapture; + ESTmdView* mpTmd; + u8 mbTmdReady; + u8 mTitleFlags; + u16 mMakerCode; + u8 mbStartAnimation; + s32 mScriptState; + s32 mScriptEnabled; + bool mbStopScript; + u32 mScriptFrame; + u32 mScriptDuration; + nand::File* mpScriptFile; + EGG::ExpHeap* mpScriptHeaps[2]; + s32 mScriptHeapIndex; + channel::RsoThread* mpRsoThread; + EGG::ExpHeap* mpRsoHeap; + layout::Animator* mpScriptAnimations[16]; + bool mbScriptFailed; + EGG::ExpHeap* mpScriptHeap; + ESTitleId mTitleId; + SDMemory::TitleRange mTitleRange; + u8 mUnknownTitleWork[0x800]; + SDMemory mMemory; + u32 mErrorMessage; + s32 mChangeFrame; + u8 mbCopiedTitle; + u8 mbResetAcceptable; + nw4r::snd::SoundHandle* mpCopySound; +#else private: u8 unk_0x58[0x3460]; +#endif }; } // namespace scene } // namespace ipl diff --git a/include/system/iplSaveDataManager.h b/include/system/iplSaveDataManager.h index 151ea485..b910175c 100644 --- a/include/system/iplSaveDataManager.h +++ b/include/system/iplSaveDataManager.h @@ -34,6 +34,9 @@ namespace ipl { void initManager(); void setPrevPage(int prevPage); +#ifdef IPL_SD_CHANNEL_TITLE_CPP + int& getSDPrevPage() { return mData.prevSDPage; } +#endif void setChanInfo(int page, int index, const channel::SInfo& chanInfo); void setMemoSetting(const textinput::extend::savedata::MemoSetting& memoSetting); diff --git a/src/scene/sdChannelTitle/iplSDChannelTitle.cpp b/src/scene/sdChannelTitle/iplSDChannelTitle.cpp new file mode 100644 index 00000000..34be7c1e --- /dev/null +++ b/src/scene/sdChannelTitle/iplSDChannelTitle.cpp @@ -0,0 +1,1563 @@ +#define IPL_SD_CHANNEL_TITLE_CPP +#define IPL_SD_CHANNEL_SELECT_ACCESS +#define IPL_SDMEMORY_DIALOG_STATE_ACCESSOR +#define IPL_SDMEMORY_COMPLETION_PCT_ACCESSOR + +#include "scene/sdChannelTitle/iplSDChannelTitle.h" +#include "scene/sdChannelSelect/iplSDChannelSelect.h" +#include "system/iplSystem.h" +#include "sound/iplSound.h" +#include "scene/setting/iplNCDSetting.h" +#include "utility/iplESMisc.h" +#include +#include +#include "scene/parentalDialog/iplParentalDialog.h" +#include "system/iplNandWall.h" +#include +#include +#include + +namespace ipl { +namespace scene { + +class SDTitlePaneEventHandler; +class SDTitleButtonEventHandler; + +extern "C" void iplSDChannelTitle_813E8AB4(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E8C08(SDChannelTitle* scene, const nw4r::ut::Rect& bounds, GXColor color); +extern "C" void iplSDChannelTitle_813E81FC(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E6348(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E6424(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E8034(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E8160(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E8360(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E8258(SDChannelTitle* scene, layout::Object* layout, + layout::Animator** animations, const char* prefix); +extern "C" void iplSDChannelTitle_813E7C0C(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E7D14(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E7DD0(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E7FB0(SDChannelTitle* scene); + +extern "C" void iplSDChannelTitle_813E630C(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E696C(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E6FB4(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E71A4(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E724C(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E7418(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E7498(SDChannelTitle* scene); +extern "C" bool iplSDChannelTitle_813E79B0(SDChannelTitle* scene); +extern "C" BOOL iplSDChannelTitle_813E847C(SDChannelTitle*, ESTmdView*, ESTitleId titleId); +extern "C" BOOL iplSDChannelTitle_813E84C8(); +extern "C" void iplSDChannelTitle_813E86A0(SDChannelTitle* scene, SDChannelObj* channel); +extern "C" void iplSDChannelTitle_813E899C(SDChannelTitle* scene, int nextScene); +extern "C" void iplSDChannelTitle_813E8AB4(SDChannelTitle*); +extern "C" bool iplSDChannelTitle_813E8B1C(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E8B70(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E8C08(SDChannelTitle*, const nw4r::ut::Rect& bounds, GXColor color); +extern "C" void iplSDChannelTitle_813E8D14(SDChannelTitle*, nw4r::lyt::Pane* pane, u32 message, bool allocate); +extern "C" nand::LayoutFile* iplSDChannelTitle_813E8DCC(SDChannelTitle*, ESTitleId title, nand::File** sound); +extern "C" void iplSDChannelTitle_813E8E70(void* argument); +extern "C" BOOL iplSDChannelTitle_813E8F04(SDChannelTitle* scene, ESTmdView* tmd); +extern "C" void iplSDChannelTitle_813E65D4(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E6760(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E69B4(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E6B88(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E6CCC(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E6E24(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E7074(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E72B8(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E74EC(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E7618(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E76C8(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E7780(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E7800(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E787C(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E7A18(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E7B30(SDChannelTitle* scene, ESTitleId title); +extern "C" void iplSDChannelTitle_813E850C(SDChannelTitle* scene, void* arguments); +extern "C" void iplSDChannelTitle_813E85C0(SDChannelTitle* scene, int page, int index); +extern "C" void iplSDChannelTitle_813E86D8(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E88CC(SDChannelTitle* scene, bool settings); +extern "C" void iplSDChannelTitle_813E8A20(SDChannelTitle* scene, int nextScene); +extern "C" SDMemory::TitleRange* iplSDChannelTitle_813E6FA0(SDMemory::TitleRange*, const SDMemory::TitleRange*); + +static const int sCaptureSizes[2][2] = {{128, 96}, {176, 96}}; + +static const char* sButtonGroups[7] = { + "G_FocusBtnA", "G_FocusBtnB", "G_SelectBtnA", "G_SelectBtnB", + "G_OnOffBtnA", "G_OnOffBtnB", "G_OutBtn" +}; +static const char* sButtonAnimationNames[6] = { + "mn_SdcardMenuBanner_bc_FocusBtnA_off.brlan", + "mn_SdcardMenuBanner_bc_FocusBtn_on.brlan", + "mn_SdcardMenuBanner_bc_SelectBtn_Ac.brlan", + "mn_SdcardMenuBanner_bc_OffBtn.brlan", + "mn_SdcardMenuBanner_bc_OnBtn.brlan", + "mn_SdcardMenuBanner_bc_OutBtn.brlan" +}; +static const char* sBannerAnimationNames[3] = { + "banner.brlan", "banner_Start.brlan", "banner_Loop.brlan" +}; +static const char* sTextNames[2] = {"T_BtnA", "T_BtnB"}; +static const char* sButtonNames[2] = {"B_BtnA", "B_BtnB"}; +static const char* sTexturePaneNames[3][4] = { + {"Fre_a", "Fre_d", "Fre_i", "Fre_l"}, + {"Fre_e", "Fre_f", "Fre_g", "Fre_h"}, + {"Fre_b", "Fre_c", "Fre_j", "Fre_k"} +}; + +class SDTitleButtonEventHandler : public SDButtonEventHandlerBase { +public: + SDTitleButtonEventHandler(SDChannelTitle* scene) : mpScene(scene) {} + virtual void onEventDerived(u32 component, u32 event, const controller::Interface* controller); + nw4r::lyt::Pane* getPane(u32 component) { + return static_cast< ::gui::PaneComponent*>(mpManager->getComponent(component))->getPane(); + } + SDChannelTitle* mpScene; +}; + +class SDTitlePaneEventHandler : public ::gui::EventHandler { +public: + SDTitlePaneEventHandler(SDChannelTitle* scene) : mpScene(scene) {} + virtual void onEvent(u32 component, u32 event, void* data); + nw4r::lyt::Pane* getPane(u32 component) { + return static_cast< ::gui::PaneComponent*>(mpManager->getComponent(component))->getPane(); + } + SDChannelTitle* mpScene; +}; + +extern "C" void iplSDChannelObj_813E3580(layout::Object* layout); +extern "C" const wchar_t* iplSDChannelObj_813E4060(SDChannelObj* channel, int nameIndex); +extern "C" bool iplSDChannelTitle_813E79B0(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E630C(SDChannelTitle* scene); +extern "C" void iplSDChannelTitle_813E8D14(SDChannelTitle* scene, nw4r::lyt::Pane* pane, u32 message, bool allocate); + +SDChannelTitle::SDChannelTitle(EGG::Heap* heap, SDChannelSelect* channelSelect) + : FaderSceneBase(heap), mState(0), mNextScene(0), mParentalResult(0), + mLaunchFrame(0), mStartButtonState(0), mbBannerStarting(false), + mpChannelSelect(channelSelect), mpIconLayout(NULL), mpIconHeap(NULL), + mLoadedIndex(0), mpBannerLayout(NULL), mpSoundHandle(NULL), mpSaveFile(NULL), + mWpadStopTick(0), mpButtonEventHandler(new SDTitleButtonEventHandler(this)), + mpTmd(NULL), mbTmdReady(false), mbStartAnimation(false), mScriptState(0), + mScriptEnabled(0), mbStopScript(false), mScriptFrame(0), mpScriptFile(NULL), + mScriptHeapIndex(0), mbScriptFailed(false), mpScriptHeap(NULL), + mbResetAcceptable(true), mpCopySound(NULL) { + mPage = channelSelect->mCurrentPage; + mIndex = channelSelect->mCurrentChannelIndex; + SDChannelObj* channel = channelSelect->findChannelObject(mPage, mIndex); + if (channel) { + mTitleId = channel->mAppMeta.titleId; + } + mPageCount = mpChannelSelect->mPageCount; + mPosition.x = SDChannelSelect::getChannelPanePosition(mpChannelSelect, mIndex).x; + mPosition.y = SDChannelSelect::getChannelPanePosition(mpChannelSelect, mIndex).y; + mPosition.z = 0.0f; + mpBannerFiles[0] = NULL; + mpBannerFiles[1] = NULL; + mpSoundFiles[0] = NULL; + mpSoundFiles[1] = NULL; + for (int button = 0; button < 2; ++button) { + mHoverCounts[button] = 0; + } + setSceneParentFlags(3); + mpRsoHeap = mpChannelSelect->mpRsoHeap; + mpRsoThread = mpChannelSelect->mpRsoThread; + memset(mpScriptAnimations, 0, sizeof(mpScriptAnimations)); + mpBannerHeap = EGG::ExpHeap::create(0x48000, getSceneHeap(), 6); + mpIconHeap = EGG::ExpHeap::create(0x8100, getSceneHeap(), 6); +} + +SDChannelTitle::~SDChannelTitle() {} + +void SDChannelTitle::prepare() { + mpLayoutFile = System::getNandManager()->readLayoutAsync(getSceneHeap(), "sdChanTtl.ash", false); +} + +void SDChannelTitle::create() { + mpLayout = new layout::Object(getSceneHeap(), mpLayoutFile, "arc", "mn_SdcardMenuBanner_bc.brlyt"); + if (SCGetAspectRatio() == SC_ASPECT_RATIO_16x9) { + GXTexObj textures[3]; + mpLayout->FindPaneByName("Picture_04")->GetMaterial()->GetTexture(&textures[0], 0); + mpLayout->FindPaneByName("Picture_05")->GetMaterial()->GetTexture(&textures[1], 0); + mpLayout->FindPaneByName("Picture_06")->GetMaterial()->GetTexture(&textures[2], 0); + for (int row = 0; row < 3; ++row) { + for (int column = 0; column < 4; ++column) { + mpLayout->FindPaneByName(sTexturePaneNames[row][column])->GetMaterial()->SetTexture(0, textures[row]); + } + } + } + iplSDChannelTitle_813E8D14(this, mpLayout->FindPaneByName(sTextNames[0]), 0xa2, true); + iplSDChannelTitle_813E8D14(this, mpLayout->FindPaneByName(sTextNames[1]), 2, true); + mStartButtonState = 1; + mpButtonAnimations[0][0] = mpLayout->bindToGroup(sButtonAnimationNames[0], sButtonGroups[0], false, false); + mpButtonAnimations[0][1] = mpLayout->bindToGroup(sButtonAnimationNames[1], sButtonGroups[0], false, true); + mpButtonAnimations[1][0] = mpLayout->bindToGroup(sButtonAnimationNames[0], sButtonGroups[1], false, false); + mpButtonAnimations[1][1] = mpLayout->bindToGroup(sButtonAnimationNames[1], sButtonGroups[1], false, true); + mpButtonAnimations[2][2] = mpLayout->bindToGroup(sButtonAnimationNames[2], sButtonGroups[2], false, false); + mpButtonAnimations[3][2] = mpLayout->bindToGroup(sButtonAnimationNames[2], sButtonGroups[3], false, false); + mpButtonAnimations[4][3] = mpLayout->bindToGroup(sButtonAnimationNames[3], sButtonGroups[4], false, false); + mpButtonAnimations[5][3] = mpLayout->bindToGroup(sButtonAnimationNames[3], sButtonGroups[5], false, false); + mpButtonAnimations[4][4] = mpLayout->bindToGroup(sButtonAnimationNames[4], sButtonGroups[4], false, false); + mpButtonAnimations[5][4] = mpLayout->bindToGroup(sButtonAnimationNames[4], sButtonGroups[5], false, false); + mpButtonAnimations[6][5] = mpLayout->bindToGroup(sButtonAnimationNames[5], sButtonGroups[6], false, false); + mpLayout->finishBinding(); + SDTitlePaneEventHandler* paneHandler = new SDTitlePaneEventHandler(this); + mpPaneManager = new gui::PaneManager(paneHandler, mpLayout->getDrawInfo(), NULL, NULL); + mpPaneManager->setupScene(mpLayout); + mpPaneManager->setAllComponentTriggerTarget(false); + mpPaneManager->getPaneComponentByPane(mpLayout->FindPaneByName(sButtonNames[0]))->setTriggerTarget(true); + mpPaneManager->getPaneComponentByPane(mpLayout->FindPaneByName(sButtonNames[1]))->setTriggerTarget(true); + mpProgressLayout = new layout::Object(getSceneHeap(), mpLayoutFile, "arc", "mn_SdcardMenuBanner_a.brlyt"); + mpProgressLayout->bind("mn_SdcardMenuBanner_a_Ch_Fin.brlan"); + mpProgressLayout->bindToGroup("mn_SdcardMenuBanner_a_T_Change.brlan", "G_T_Change", false, true); + mpProgressLayout->bindToGroup("mn_SdcardMenuBanner_a_Bar.brlan", "G_Prog", false, true); + mpProgressLayout->bindToGroup("mn_SdcardMenuBanner_a_Wait.brlan", "G_Wait", false, true); + mpProgressLayout->finishBinding(); + nw4r::lyt::TextBox* comment = nw4r::ut::DynamicCast(mpProgressLayout->FindPaneByName("T_Comment_02")); + comment->SetString(System::getMessage(0xad)); + iplSDChannelTitle_813E630C(this); + mpFade = new math::HermiteIntp(); + const f32 fadeStart = 0.0f; + const f32 fadeEnd = 255.0f; + mpFade->init(fadeStart, fadeEnd, 10.0f, 0.0f, 0.0f); + mpFade->setAnmType(ANIM_TYPE_FORWARD); + mpScreenCapture = new (System::getTreasureHeap(), 32) utility::Capture(System::getTreasureHeap(), 0, 0, + System::getRenderModeObj()->fbWidth, System::getRenderModeObj()->efbHeight, GX_TF_RGB565); + mpCaptureHeap = EGG::ExpHeap::create(0x20000, System::getMem2App(), 6); + mpBannerCapture = new (mpCaptureHeap, 32) utility::Capture(mpCaptureHeap, + (System::getRenderModeObj()->fbWidth - sCaptureSizes[SCGetAspectRatio()][0]) / 2, + (System::getRenderModeObj()->efbHeight - sCaptureSizes[SCGetAspectRatio()][1]) / 2, + sCaptureSizes[SCGetAspectRatio()][0], sCaptureSizes[SCGetAspectRatio()][1], GX_TF_RGB565); + mpProgressLayout->FindPaneByName("Ch_Picture")->GetMaterial()->SetTexture(1, mpBannerCapture->getGXTex()); + mpProgressLayout->FindPaneByName("Chm_Picture")->GetMaterial()->SetTexture(1, mpBannerCapture->getGXTex()); + u32 duration = 36000; + mScriptDuration = duration; + mState = 2; + mScriptFrame = duration; + iplSDChannelTitle_813E79B0(this); + mpScriptHeaps[0] = EGG::ExpHeap::create(0x80000, System::getMem2App(), 6); + mpScriptHeaps[1] = EGG::ExpHeap::create(0x80000, System::getMem2App(), 6); + mMemory.create(getSceneHeap(), mpLayoutFile, mpChannelSelect); +} + +void SDChannelTitle::calcCommon() { + mpPaneManager->calc(); + mpLayout->calc(); + if (mScriptEnabled == 1) { + iplSDChannelTitle_813E7C0C(this); + } + if ((mState == 1 || mState == 13 || static_cast(mState - 4) <= 1) && + !mbBannerStarting && mpBannerAnimations[1] && !mpBannerAnimations[1]->isPlaying()) { + if (mpBannerAnimations[2]) { + mpBannerAnimations[2]->play(); + } else if (mpBannerAnimations[0]) { + mpBannerAnimations[0]->play(); + } + mpBannerAnimations[1] = NULL; + } + if (mState == 5 && !mbStartAnimation && !mpButtonAnimations[3][2]->isPlaying()) { + mpButtonAnimations[1][0]->play(); + mbStartAnimation = true; + } + if (mpBannerLayout) { + mpBannerLayout->calc(); + } + if (mpIconLayout) { + mpIconLayout->calc(); + } + mpProgressLayout->calc(); +} + +FaderSceneCommand SDChannelTitle::calcFadein() { + if (mState == 2) { + iplSDChannelTitle_813E79B0(this); + return FADER_SCN_CONTINUE; + } + if (!mpFade->isPlaying()) { + iplSDChannelTitle_813E8034(this); + SDButton* button = static_cast(System::getScene(0x24)); + button->setEventHandler(mpButtonEventHandler, NULL); + button->animation(13); + button->animation(14); + mState = 1; + return FADER_SCN_NEXT; + } else { + mpFade->calc(); + return FADER_SCN_CONTINUE; + } +} + +FaderSceneCommand SDChannelTitle::calcNormal() { + switch (mState) { + case 1: iplSDChannelTitle_813E65D4(this); break; + case 4: iplSDChannelTitle_813E8A20(this, mNextScene); mState = 5; break; + case 8: iplSDChannelTitle_813E6760(this); break; + case 9: iplSDChannelTitle_813E696C(this); break; + case 10: iplSDChannelTitle_813E7A18(this); break; + case 11: iplSDChannelTitle_813E69B4(this); break; + case 12: iplSDChannelTitle_813E6B88(this); break; + case 13: iplSDChannelTitle_813E787C(this); break; + case 14: return FADER_SCN_CONTINUE; + case 15: iplSDChannelTitle_813E7074(this); break; + case 16: iplSDChannelTitle_813E71A4(this); break; + case 17: SCSetTmpTitleID(mTitleId); SCFlushAsync(NULL); mState = 18; break; + case 18: if (SCCheckStatus() != 1) { mState = 21; } break; + case 19: iplSDChannelTitle_813E6CCC(this); break; + case 20: iplSDChannelTitle_813E6E24(this); break; + case 21: iplSDChannelTitle_813E724C(this); break; + case 22: iplSDChannelTitle_813E72B8(this); break; + case 23: iplSDChannelTitle_813E6FB4(this); break; + case 24: iplSDChannelTitle_813E76C8(this); break; + case 25: iplSDChannelTitle_813E7780(this); break; + case 26: iplSDChannelTitle_813E7418(this); break; + case 27: iplSDChannelTitle_813E7498(this); break; + case 28: iplSDChannelTitle_813E7800(this); break; + case 29: iplSDChannelTitle_813E74EC(this); break; + case 30: iplSDChannelTitle_813E7618(this); break; + } + if (mState == 5) { + mbStopScript = true; + ++mLaunchFrame; + System::getPointer()->setVisible(false); + return static_cast(iplSDChannelTitle_813E8B1C(this)); + } + if (mState == 6 || mState == 7 || mState == 31) { + mbStopScript = true; + return FADER_SCN_NEXT; + } + return FADER_SCN_CONTINUE; +} + +void SDChannelTitle::initCalcFadeout() { + SDButton* button = static_cast(System::getScene(0x24)); + if (mState == 5 || mState == 7 || mState == 31) { + System::getFader()->fadeOut(); + snd::getSystem()->stopAllSound(20); + OSReport("sound stopped\n"); + } else if (mState == 6) { + button->animation(15); + button->animation(16); + } + button->setEventHandler(NULL, NULL); +} + +FaderSceneCommand SDChannelTitle::calcFadeout() { + if (mState == 5) { + if (!mWpadStopTick && WPADGetStatus() == 0) { + mWpadStopTick = OSGetTick(); + } + if (System::getFader()->getStatus() == EGG::Fader::PREPARE_IN && System::isReceiveScheduleStopped() && + (!System::getNwc24Manager() || System::getNwc24Manager()->isUnk0xA31())) { + OSReport("NWC24 Scheduler stopped.\n"); + NandSDWorker* worker = mpChannelSelect->getWorker(); + if (mNextScene == 17) { + if (!nandwall::checkNandCapacityAppBootable()) { + OSReport("Nand full! OSRebootSystem.\n"); + iplSDChannelTitle_813E8AB4(this); + } + while (WPADGetStatus() != 0 || System::getBS2Manager()->getIPLState() != bs2::IPL_STATE_8 || + !System::getSaveData()->isFinished(mpSaveFile) || + (mScriptEnabled && mScriptState != 4) || (worker && worker->is_working())) { + snd::getSystem()->calc(); + System::getBS2Manager()->update(); + VIWaitForRetrace(); + if (mScriptEnabled == 1) { + iplSDChannelTitle_813E7C0C(this); + } + if (WPADGetStatus() != 0) { + OSReport("wait for WPAD\n"); + } + if (System::getBS2Manager()->getIPLState() != bs2::IPL_STATE_8) { + OSReport("wait for BS2\n"); + } + } + if (worker) { + worker->terminate_async(); + while (!worker->is_terminated()) { + snd::getSystem()->calc(); + VIWaitForRetrace(); + } + OSReport("NandSDWorker teminated.\n"); + } + delete mpSaveFile; + VISetBlack(TRUE); + VIFlush(); + VIWaitForRetrace(); + OSReport("VI Black\n"); + while (!__OSSyncSram()) { + OSReport("sync sram\n"); + } + SDChannelObj* channel = mpChannelSelect->findChannelObject(mPage, mIndex); + union TitleCode { + ESTitleId id; + struct { u32 type; char code[4]; } parts; + } title; + title.id = channel->mAppMeta.titleId; + wchar_t names[2][21]; + memcpy(names[0], iplSDChannelObj_813E4060(channel, 0), sizeof(names[0])); + memcpy(names[1], iplSDChannelObj_813E4060(channel, 1), sizeof(names[1])); + union MakerCode { + u16 code; + char bytes[2]; + } maker; + const u8* makerBytes = reinterpret_cast(&mMakerCode); + maker.bytes[0] = makerBytes[0]; + maker.bytes[1] = makerBytes[1]; + __OSCreatePlayRecord(names[0], title.parts.code, maker.bytes); + OSReport("Create play recode\n"); + BS2SetStateFlags(); + OSReport("Launch\n"); + __OSLaunchTitlevForSystem(title.id, FALSE, NULL); + } else { + math::VEC3 position(0.0f, 0.0f, 0.0f); + math::VEC2 scale(1.0f, 1.0f); + utility::Graphics::setOrthoTrans(position); + utility::Graphics::setOrthoScale(scale); + } + return FADER_SCN_NEXT; + } + } else if (mState == 6) { + if (!mpFade->isPlaying()) { + return FADER_SCN_NEXT; + } + mpFade->calc(); + } else if ((mState == 7 || mState == 31) && System::getFader()->getStatus() == EGG::Fader::PREPARE_IN) { + math::VEC3 position(0.0f, 0.0f, 0.0f); + utility::Graphics::setOrthoTrans(position); + math::VEC2 scale(1.0f, 1.0f); + utility::Graphics::setOrthoScale(scale); + snd::getSystem()->initFx(); + snd::getSystem()->startBGM("WIPL_BGM_MENU"); + return FADER_SCN_NEXT; + } + return FADER_SCN_CONTINUE; +} + +void SDChannelTitle::draw() { + if (mState == 2) { + return; + } + if (System::onDrawLayer(1)) { + if (mState == 3 || mState == 6) { + utility::Graphics::setOrtho(0); + nw4r::ut::Rect bounds(mPosition.x - mpChannelSelect->mThumbOffsetX, + mPosition.y + mpChannelSelect->mThumbOffsetY, + mPosition.x + mpChannelSelect->mThumbOffsetX, + mPosition.y - mpChannelSelect->mThumbOffsetY); + GXColor color = {255, 255, 255, static_cast(mpFade->get())}; + utility::Graphics::drawTexture(bounds, mpScreenCapture->getGXTex(), color, 1); + GXColor mask = {0, 0, 0, static_cast(mpFade->get())}; + iplSDChannelTitle_813E8C08(this, bounds, mask); + } else { + if (mpIconLayout) { + utility::Graphics::setOrthoProjection(0); + mpIconLayout->draw(); + mpBannerCapture->capture(FALSE); + } + utility::Graphics::setDefaultOrtho(0); + if (mpBannerLayout) { + mpBannerLayout->draw(); + } else { + mpProgressLayout->draw(); + } + mpLayout->draw(); + if (mState == 23) { + mMemory.draw(); + } + } + } else if (System::onDrawLayer(0) && (mState == 3 || mState == 6)) { + utility::Graphics::setDefaultOrtho(0); + if (mpBannerLayout) { + mpBannerLayout->draw(); + } else { + mpProgressLayout->draw(); + } + mpLayout->draw(); + mpScreenCapture->capture(TRUE); + } +} + +void SDChannelTitle::destroy() { + if (mpBannerFiles[0]) { + delete mpBannerFiles[0]; + } + if (mpBannerFiles[1]) { + delete mpBannerFiles[1]; + } + if (mpBannerLayout) { + mpBannerLayout->destroyHeap(); + } + if (mpSoundFiles[0]) { + delete mpSoundFiles[0]; + } + if (mpSoundFiles[1]) { + delete mpSoundFiles[1]; + } + delete mpScreenCapture; + if (mpScriptFile) { + delete mpScriptFile; + } + mpScriptHeaps[0]->destroy(); + mpScriptHeaps[1]->destroy(); + mpBannerHeap->destroy(); + if (mpIconLayout) { + mpIconLayout->destroyHeap(); + } + mpIconHeap->destroy(); + delete mpBannerCapture; + mpCaptureHeap->destroy(); +} + +BOOL SDChannelTitle::isResetAcceptable() { + if (mMemory.mTransferFlags[0]) { + return mbResetAcceptable; + } + return FALSE; +} + +extern "C" void iplSDChannelTitle_813E630C(SDChannelTitle* scene) { + iplSDChannelTitle_813E6348(scene); + if (scene->mpBannerLayout) { + scene->mpBannerLayout->finishBinding(); + } +} + +extern "C" void iplSDChannelTitle_813E6348(SDChannelTitle* scene) { + if (scene->mpIconLayout) { + scene->mpIconLayout->destroyHeap(); + scene->mpIconLayout = NULL; + } + if (scene->mpBannerFiles[scene->mLoadedIndex] && scene->mpBannerFiles[scene->mLoadedIndex]->checkData() == 1) { + scene->mpBannerLayout = layout::Object::create(scene->mpBannerHeap, 0x40000, + scene->mpBannerFiles[scene->mLoadedIndex], "arc", "banner.brlyt"); + iplSDChannelObj_813E3580(scene->mpBannerLayout); + iplSDChannelTitle_813E81FC(scene); + } else { + scene->mpBannerLayout = NULL; + for (int index = 0; index < 3; ++index) { + scene->mpBannerAnimations[index] = NULL; + } + iplSDChannelTitle_813E6424(scene); + } +} + +extern "C" void iplSDChannelTitle_813E6424(SDChannelTitle* scene) { + SDChannelObj* channel = scene->mpChannelSelect->findChannelObject(scene->mPage, scene->mIndex); + if (channel) { + scene->mpIconLayout = layout::Object::create(scene->mpIconHeap, 0x8000, + iplSDChannelObj_813E3128(channel), "arc", "icon.brlyt"); + iplSDChannelObj_813E3580(scene->mpIconLayout); + if (scene->mpIconLayout->searchFile("icon.brlan")) { + scene->mpIconLayout->bind("icon.brlan")->play(); + } else if (scene->mpIconLayout->searchFile("icon_Whole.brlan")) { + scene->mpIconLayout->bind("icon_Whole.brlan")->play(); + } + if (channel->mStateFlags == 0) { + static_cast(scene->mpProgressLayout->FindPaneByName("T_title"))->SetString(iplSDChannelObj_813E4060(channel, 0)); + } else { + static_cast(scene->mpProgressLayout->FindPaneByName("T_title"))->SetString(L""); + } + scene->mpProgressLayout->getAnim(0)->stop(); + scene->mpProgressLayout->getAnim(0)->initAnmFrame(); + scene->mpProgressLayout->calc(); + } +} + +extern "C" void iplSDChannelTitle_813E65D4(SDChannelTitle* scene) { + SDButton* button = static_cast(System::getScene(0x24)); + if (button && button->isActive()) { + button->update(); + } + if (scene->mState == 1) { + if (static_cast(scene->mpChannelSelect->mCurrentSDState - 1) <= 1) { + scene->mState = 10; + iplSDChannelTitle_813E7A18(scene); + } else { + controller::Interface* controller = System::getMasterController(); + int page; + int index; + if (controller->down(0x30001000)) { + scene->mpChannelSelect->findAdjacentChannel(1, &page, &index); + iplSDChannelTitle_813E85C0(scene, page, index); + snd::getSystem()->startSE("WSD_SELECT"); + } else if (controller->down(0x6000010)) { + scene->mpChannelSelect->findAdjacentChannel(0, &page, &index); + iplSDChannelTitle_813E85C0(scene, page, index); + snd::getSystem()->startSE("WSD_SELECT"); + } else { + scene->mpPaneManager->update(); + if (scene->mStartButtonState == 0) { + scene->mStartButtonState = 1; + } else if (scene->mStartButtonState == 1) { + scene->mStartButtonState = 2; + } + } + } + } +} + +extern "C" void iplSDChannelTitle_813E6760(SDChannelTitle* scene) { + if (static_cast(scene->mpChannelSelect->mCurrentSDState - 1) <= 1) { + scene->mState = 1; + } else { + SDChannelObj* channel = scene->mpChannelSelect->findChannelObject(scene->mPage, scene->mIndex); + ++scene->mChangeFrame; + if ((!scene->mpBannerFiles[1 - scene->mLoadedIndex] || scene->mpBannerFiles[1 - scene->mLoadedIndex]->isFinished()) && + (!scene->mpSoundFiles[1 - scene->mLoadedIndex] || scene->mpSoundFiles[1 - scene->mLoadedIndex]->isFinished()) && + iplSDChannelObj_813E3330(channel) && scene->mChangeFrame > 10 && + (!scene->mScriptEnabled || scene->mScriptState == 4)) { + if (scene->mpBannerFiles[scene->mLoadedIndex]) { + delete scene->mpBannerFiles[scene->mLoadedIndex]; + if (scene->mpBannerLayout) { + scene->mpBannerLayout->destroyHeap(); + } + } + scene->mpBannerFiles[scene->mLoadedIndex] = NULL; + scene->mpBannerLayout = NULL; + scene->mpScriptHeaps[scene->mScriptHeapIndex]->freeAll(); + scene->mScriptHeapIndex ^= 1; + snd::getSystem()->stopBannerSound(0); + snd::getSystem()->stopSE(scene->mpSoundHandle, 0); + if (scene->mpSoundFiles[scene->mLoadedIndex]) { + delete scene->mpSoundFiles[scene->mLoadedIndex]; + } + scene->mpSoundFiles[scene->mLoadedIndex] = NULL; + scene->mLoadedIndex = 1 - scene->mLoadedIndex; + iplSDChannelTitle_813E630C(scene); + iplSDChannelTitle_813E8B70(scene); + scene->mState = 9; + } + } +} + +extern "C" void iplSDChannelTitle_813E696C(SDChannelTitle* scene) { + if (++scene->mChangeFrame > 20) { + iplSDChannelTitle_813E8034(scene); + scene->mState = 1; + } +} + +extern "C" void iplSDChannelTitle_813E69B4(SDChannelTitle* scene) { + ParentalDialog* parental = static_cast(System::getScene(0x1b)); + if (!parental && !System::getReservedScene()) { + if (scene->mParentalResult == 1) { + if (scene->mNextScene == 0x12) { + scene->reserveAllSceneDestruction(0x12, reinterpret_cast(1)); + scene->mState = 7; + } else if (scene->mbCopiedTitle) { + scene->mState = 25; + } else { + scene->mState = 15; + } + } else if (scene->mbCopiedTitle) { + scene->mState = 29; + } else { + scene->mpButtonAnimations[1][0]->play(); + static_cast(System::getScene(0x24))->animation(13); + static_cast(System::getScene(0x24))->animation(14); + for (int button = 0; button < 2; ++button) { + scene->mHoverCounts[button] = 0; + scene->mpPaneManager->initPane(scene->mpLayout->FindPaneByName(sButtonNames[button])); + } + System::startReceiveSchedule(); + scene->mState = 1; + } + } else if (parental) { + int result = parental->getResult(); + switch (result) { + case 1: + if (!scene->mParentalResult) { + iplSDChannelTitle_813E899C(scene, scene->mNextScene); + scene->mParentalResult = 1; + } + break; + case 2: + scene->mParentalResult = 2; + break; + case 3: + scene->mParentalResult = 2; + break; + } + } +} + +extern "C" void iplSDChannelTitle_813E6B88(SDChannelTitle* scene) { + int result = System::getDialog()->getLastResult(); + switch (result) { + case 2: { + if (scene->mbCopiedTitle) { + scene->mState = 29; + } else { + static_cast(System::getScene(0x24))->animation(13); + static_cast(System::getScene(0x24))->animation(14); + scene->mpButtonAnimations[1][0]->play(); + for (int button = 0; button < 2; ++button) { + scene->mHoverCounts[button] = 0; + scene->mpPaneManager->initPane(scene->mpLayout->FindPaneByName(sButtonNames[button])); + } + System::startReceiveSchedule(); + scene->mState = 1; + } + break; + } + case 1: { + if (iplSDChannelTitle_813E84C8()) { + iplSDChannelTitle_813E850C(scene, reinterpret_cast(1)); + } else { + scene->reserveAllSceneDestruction(0x12, reinterpret_cast(1)); + scene->mState = 7; + } + break; + } + } +} + +extern "C" void iplSDChannelTitle_813E6CCC(SDChannelTitle* scene) { + if (scene->mpChannelSelect->getWorker()->is_working() || scene->mpProgressLayout->isPlaying(0) || + scene->mpButtonAnimations[3][2]->isPlaying()) { + return; + } + { + scene->mpProgressLayout->getAnim(1)->setAnmType(ANIM_TYPE_FORWARD); + scene->mpProgressLayout->getAnim(1)->initAnmFrame(); + scene->mpProgressLayout->getAnim(1)->play(); + scene->mpButtonAnimations[1][0]->initAnmFrame(); + scene->mpButtonAnimations[1][0]->play(); + scene->mpButtonAnimations[6][5]->setAnmType(ANIM_TYPE_FORWARD); + scene->mpButtonAnimations[6][5]->initAnmFrame(); + scene->mpButtonAnimations[6][5]->play(); + SDChannelObj* channel = scene->mpChannelSelect->findChannelObject(scene->mPage, scene->mIndex); + if (channel->mStateFlags == 3) { + scene->mState = 26; + scene->mErrorMessage = 0xaf; + } else if (scene->mpChannelSelect->enqueueChannelNotice(0, static_cast(scene->mTitleId >> 32), + static_cast(scene->mTitleId), reinterpret_cast(&scene->mTitleRange))) { + scene->mState = 20; + } else { + scene->mState = 26; + scene->mErrorMessage = 0xae; + } + } +} + +extern "C" void iplSDChannelTitle_813E6E24(SDChannelTitle* scene) { + if (scene->mpChannelSelect->getWorker()->is_working() || scene->mpProgressLayout->isPlaying(1)) { + return; + } + { + int result = scene->mpChannelSelect->getWorker()->get_async_result(); + if (result == 0 || result == -6) { + if (scene->mpChannelSelect->isCurrentTitleUsageEnough(reinterpret_cast(&scene->mTitleRange))) { + scene->mState = 15; + } else { + SDMemory::TitleRange sdRange; + SDMemory::TitleRange nandRange; + if (static_cast(scene->mTitleRange.mByteSize) < 0x3800000) { + nandRange.mByteSize = 0x3800000; + nandRange.mCount = scene->mTitleRange.mCount; + iplSDChannelTitle_813E6FA0(&sdRange, &scene->mTitleRange); + } else { + iplSDChannelTitle_813E6FA0(&nandRange, iplSDChannelTitle_813E6FA0(&sdRange, &scene->mTitleRange)); + } + SDMemory* memory = &scene->mMemory; + memory->setTitleLists(SDMemory::TitleRange(sdRange), SDMemory::TitleRange(nandRange)); + scene->mMemory.calc(); + scene->mbResetAcceptable = true; + System::getHomeButtonMenu()->enable(); + scene->mState = 23; + } + } else if (static_cast(result + 15) <= 1) { + scene->mState = 26; + scene->mErrorMessage = 0xaf; + } else if (result == -16) { + scene->mState = 26; + scene->mErrorMessage = 199; + } else { + scene->mState = 26; + scene->mErrorMessage = 0xae; + } + } +} + +extern "C" SDMemory::TitleRange* iplSDChannelTitle_813E6FA0( + SDMemory::TitleRange* target, const SDMemory::TitleRange* source) { + s32 bytes = source->mByteSize; + target->mCount = source->mCount; + target->mByteSize = bytes; + return target; +} + +extern "C" void iplSDChannelTitle_813E6FB4(SDChannelTitle* scene) { + if (!scene->mMemory.calc()) { + return; + } + switch (static_cast(scene->mMemory.mErrorCode)) { + case 4: + scene->reserveAllSceneDestruction(0x15, reinterpret_cast(2)); + scene->mState = 31; + return; + case 1: + case 2: + case 3: + case 5: + case 6: + scene->mbResetAcceptable = false; + System::getHomeButtonMenu()->disable(); + scene->mState = 29; + return; + } + scene->mbResetAcceptable = false; + System::getHomeButtonMenu()->disable(); + scene->mState = 15; +} + +extern "C" void iplSDChannelTitle_813E7074(SDChannelTitle* scene) { + if (!scene->mpChannelSelect->getWorker()->is_working()) { + if (scene->mbCopiedTitle && !scene->mpProgressLayout->isPlaying(3)) { + scene->mpProgressLayout->getAnim(3)->play(); + scene->mpCopySound = snd::getSystem()->startSE("WIPL_SE_COPYING"); + } + ESTitleId temporaryTitle = SCGetTmpTitleID(); + if (temporaryTitle && scene->mTitleId != temporaryTitle) { + if (System::isReceiveScheduleStopped()) { + if (scene->mpChannelSelect->enqueueStateNotice(0, static_cast(temporaryTitle >> 32), + static_cast(temporaryTitle), 1)) { + scene->mState = 16; + } else { + scene->mState = 26; + scene->mErrorMessage = 0xae; + } + } + } else if (scene->mbCopiedTitle) { + scene->mState = 17; + } else { + scene->mState = 24; + } + } +} + +extern "C" void iplSDChannelTitle_813E71A4(SDChannelTitle* scene) { + if (!scene->mpChannelSelect->getWorker()->is_working()) { + SCSetTmpTitleID(0); + System::getChannelManager()->fn_8133A9F0(); + int result = scene->mpChannelSelect->getWorker()->get_async_result(); + if (!result) { + if (scene->mbCopiedTitle) { + scene->mState = 17; + } else { + scene->mState = 24; + } + } else { + SCFlushAsync(NULL); + scene->mState = 26; + scene->mErrorMessage = 0xae; + } + } +} + +extern "C" void iplSDChannelTitle_813E724C(SDChannelTitle* scene) { + if (!scene->mpChannelSelect->getWorker()->is_working()) { + if (scene->mpChannelSelect->enqueueResultNotice(static_cast(scene->mTitleId))) { + scene->mState = 22; + } else { + scene->mState = 26; + scene->mErrorMessage = 0xae; + } + } +} + +extern "C" void iplSDChannelTitle_813E72B8(SDChannelTitle* scene) { + scene->mpProgressLayout->getAnim(2)->initAnmFrame(NandSDWorker::getCompletionPct()); + if (!scene->mpChannelSelect->getWorker()->is_working()) { + int result = scene->mpChannelSelect->getWorker()->get_async_result(); + if (result == 0 || result == -6) { + System::getChannelManager()->loadTmpMetaHeader(scene->mTitleId); + scene->mpProgressLayout->getAnim(3)->stop(); + snd::getSystem()->stopSE(scene->mpCopySound, 0); + scene->mpCopySound = NULL; + snd::getSystem()->startSE("WIPL_SE_COPY_FINISH"); + System::getTask1()->request(iplSDChannelTitle_813E8E70, scene, NULL); + scene->mState = 24; + } else { + SCSetTmpTitleID(0); + SCFlushAsync(NULL); + scene->mState = 26; + if (result == -15) { + scene->mErrorMessage = 0xaf; + } else if (result == -16) { + scene->mErrorMessage = 199; + } else { + scene->mErrorMessage = 0xae; + } + } + } +} + +extern "C" void iplSDChannelTitle_813E7418(SDChannelTitle* scene) { + scene->mpProgressLayout->getAnim(3)->stop(); + snd::getSystem()->stopSE(scene->mpCopySound, 0); + scene->mpCopySound = NULL; + System::getDialog()->callBtn1(scene->mErrorMessage, 0x2e); + scene->mState = 27; +} + +extern "C" void iplSDChannelTitle_813E7498(SDChannelTitle* scene) { + if (SCCheckStatus() != 1 && System::getDialog()->getLastResult() != -1) { + scene->mState = 29; + } +} + +extern "C" void iplSDChannelTitle_813E74EC(SDChannelTitle* scene) { + if (!scene->mpProgressLayout->isPlaying(1) && !scene->mpButtonAnimations[1][0]->isPlaying() && + !scene->mpButtonAnimations[6][5]->isPlaying()) { + scene->mbResetAcceptable = true; + System::getHomeButtonMenu()->enable(); + scene->mpProgressLayout->getAnim(1)->setAnmType(ANIM_TYPE_BACKWARD); + scene->mpProgressLayout->getAnim(1)->initAnmFrame(); + scene->mpProgressLayout->getAnim(1)->play(); + scene->mpButtonAnimations[6][5]->setAnmType(ANIM_TYPE_BACKWARD); + scene->mpButtonAnimations[6][5]->initAnmFrame(); + scene->mpButtonAnimations[6][5]->play(); + scene->mpButtonAnimations[1][0]->initAnmFrame(); + scene->mpButtonAnimations[1][0]->play(); + static_cast(System::getScene(0x24))->animation(13); + static_cast(System::getScene(0x24))->animation(14); + System::startReceiveSchedule(); + scene->mState = 30; + } +} + +extern "C" void iplSDChannelTitle_813E7618(SDChannelTitle* scene) { + if (!scene->mpProgressLayout->isPlaying(1) && !scene->mpButtonAnimations[6][5]->isPlaying()) { + for (int button = 0; button < 2; ++button) { + scene->mHoverCounts[button] = 0; + scene->mpPaneManager->initPane(scene->mpLayout->FindPaneByName(sButtonNames[button])); + } + scene->mState = 1; + } +} + +extern "C" void iplSDChannelTitle_813E76C8(SDChannelTitle* scene) { + int page; + int index; + if (System::getChannelManager()->isLoadedTmp() || System::getChannelManager()->hasChannel(scene->mTitleId, &page, &index)) { + scene->mpBannerFiles[scene->mLoadedIndex] = iplSDChannelTitle_813E8DCC(scene, scene->mTitleId, + &scene->mpSoundFiles[scene->mLoadedIndex]); + if (scene->mbCopiedTitle) { + scene->mState = 13; + } else { + scene->mState = 25; + } + } +} + +extern "C" void iplSDChannelTitle_813E7780(SDChannelTitle* scene) { + if (!scene->mpBannerFiles[scene->mLoadedIndex] || scene->mpBannerFiles[scene->mLoadedIndex]->isFinished()) { + iplSDChannelTitle_813E7B30(scene, scene->mTitleId); + iplSDChannelTitle_813E630C(scene); + scene->mState = 4; + iplSDChannelTitle_813E8034(scene); + } +} + +extern "C" void iplSDChannelTitle_813E7800(SDChannelTitle* scene) { + if (static_cast(scene->mpChannelSelect->mCurrentSDState - 1) <= 1) { + scene->mState = 1; + } else { + SDChannelObj* channel = scene->mpChannelSelect->findChannelObject(scene->mPage, scene->mIndex); + if (iplSDChannelObj_813E3330(channel)) { + iplSDChannelTitle_813E86A0(scene, channel); + } + } +} + +extern "C" void iplSDChannelTitle_813E787C(SDChannelTitle* scene) { + if (scene->mbTmdReady) { + if (!System::getChannelManager()->fn_8133A678(scene->mTitleId) && !utility::ESMisc::CheckTmdCountryCode(scene->mpTmd)) { + System::getErrorHandler()->set(ErrorHandler::DEFAULT, 3, NULL, 0, -1); + } + scene->mMakerCode = scene->mpTmd->head.groupId; + if (!iplSDChannelTitle_813E847C(scene, scene->mpTmd, scene->mTitleId)) { + iplSDChannelTitle_813E88CC(scene, false); + scene->mNextScene = 18; + } else if (iplSDChannelTitle_813E8F04(scene, scene->mpTmd)) { + iplSDChannelTitle_813E899C(scene, scene->mNextScene); + if (scene->mbCopiedTitle) { + scene->mState = 25; + } else { + scene->mState = 15; + } + } else { + iplSDChannelTitle_813E850C(scene, NULL); + } + if (scene->mpTmd) { + scene->mpBannerHeap->free(scene->mpTmd); + } + } +} + +extern "C" bool iplSDChannelTitle_813E79B0(SDChannelTitle* scene) { + if (!scene->mpChannelSelect->tellStartingZoomAnm()) { + return false; + } + scene->mpFade->play(); + scene->mState = 3; + return true; +} + +extern "C" void iplSDChannelTitle_813E7A18(SDChannelTitle* scene) { + if (!scene->mScriptEnabled || scene->mScriptState == 4) { + if (scene->mpChannelSelect->prepareRestarting(scene->mPage)) { + scene->mpChannelSelect->startPageTransition(scene->mPage, scene->mIndex); + const f32 fadeStart = 255.0f; + const f32 fadeEnd = 0.0f; + scene->mpFade->init(fadeStart, fadeEnd, 10.0f, 0.0f, 0.0f); + scene->mpFade->setAnmType(ANIM_TYPE_BACKWARD); + scene->mpFade->play(); + scene->mState = 6; + snd::getSystem()->startSE("WIPL_SE_CH_UNSELECT"); + if (snd::getBannerPlayer()->isStarted()) { + snd::getSystem()->stopBannerSound(28); + } + if (scene->mpSoundHandle && scene->mpSoundHandle->IsAttachedSound()) { + snd::getSystem()->stopSE(scene->mpSoundHandle, 28); + } + } + } else { + scene->mbStopScript = true; + } +} + +extern "C" void iplSDChannelTitle_813E7B30(SDChannelTitle* scene, ESTitleId title) { + if (!System::isSafeMode()) { + if (scene->mScriptEnabled) { + delete scene->mpScriptFile; + scene->mpScriptFile = NULL; + } + if (System::getChannelManager()->fn_8133A57C(title)) { + scene->mpScriptFile = System::getChannelManager()->fn_8133A924(scene->mpRsoHeap, title); + scene->mbScriptFailed = false; + scene->mScriptEnabled = 1; + scene->mScriptState = 1; + } else { + scene->mScriptEnabled = 0; + scene->mScriptState = 0; + } + } +} + +extern "C" void iplSDChannelTitle_813E7C0C(SDChannelTitle* scene) { + if (scene->mScriptEnabled != 1) { + return; + } + if (scene->mState == 2 || scene->mState == 3 || scene->mState == 9) { + return; + } + switch (scene->mScriptState) { + case 0: + iplSDChannelTitle_813E7D14(scene); + break; + case 1: + iplSDChannelTitle_813E7DD0(scene); + break; + case 2: + System::getCSManager()->calc(); + if (scene->mpRsoThread->IsThreadTerminated()) { + if (System::getCSManager()->getAltSoundState() == 1) { + iplSDChannelTitle_813E8160(scene); + System::getCSManager()->setAltSoundState(0); + } + System::getCSManager()->finish(); + scene->mScriptState = 3; + } + break; + case 3: + iplSDChannelTitle_813E7FB0(scene); + break; + } +} + +extern "C" void iplSDChannelTitle_813E7D14(SDChannelTitle* scene) { + if (scene->mbStopScript) { + scene->mbStopScript = false; + scene->mScriptFrame = 0; + scene->mScriptState = 4; + } else { + if (++scene->mScriptFrame > scene->mScriptDuration) { + int nextHeap = scene->mScriptHeapIndex ^ 1; + scene->mScriptState = 1; + scene->mScriptHeapIndex = nextHeap; + } + if (System::getChannelManager()->fn_8133A634(scene->mTitleId) && + scene->mScriptFrame == scene->mScriptDuration - 240) { + snd::getSystem()->stopBannerSound(180); + } + } +} + +extern "C" void iplSDChannelTitle_813E7DD0(SDChannelTitle* scene) { + if (!scene->mpScriptFile->isFinished()) { + return; + } + if (scene->mpScriptFile->checkData() != 1 && scene->mpScriptFile->checkData() != 0) { + scene->mScriptFrame = 0; + scene->mbScriptFailed = true; + scene->mScriptState = 0; + return; + } + if (!scene->mpScriptHeap) { + scene->mpScriptHeap = EGG::ExpHeap::create(-1, scene->mpRsoHeap, 0); + } + System::getCSManager()->create(scene->mpScriptHeap); + channel::ChannelScriptManager::CSData data = {NULL, NULL, NULL, 0, false, false, true}; + data.heap = scene->mpScriptHeaps[scene->mScriptHeapIndex]; + data.layout = scene->mpBannerLayout; + data.anims = scene->mpScriptAnimations; + data.titleId = scene->mTitleId; + data.threadTerminated = scene->mbScriptFailed; + if (!System::getNwc24Manager() || !System::getNwc24Manager()->isNewMessageThere(static_cast(data.titleId & 0xffffffffULL))) { + data.unk_0x1A = false; + } + System::getCSManager()->setData(data); + if (!System::getCSManager()->init(scene->mpScriptFile, scene->mpRsoThread)) { + scene->mScriptState = 3; + } else { + scene->mScriptState = 2; + } +} + +extern "C" void iplSDChannelTitle_813E7FB0(SDChannelTitle* scene) { + scene->mbScriptFailed = true; + System::getCSManager()->destroy(); + scene->mScriptFrame = 0; + scene->mpScriptHeaps[1 - scene->mScriptHeapIndex]->freeAll(); + scene->mpScriptHeap->destroy(); + scene->mpScriptHeap = NULL; + scene->mScriptState = 0; +} + +extern "C" void iplSDChannelTitle_813E8034(SDChannelTitle* scene) { + if (scene->mpBannerAnimations[1]) { + scene->mpBannerAnimations[1]->play(); + scene->mbBannerStarting = false; + } else if (scene->mpBannerAnimations[2]) { + scene->mpBannerAnimations[2]->play(); + } else if (scene->mpBannerAnimations[0]) { + scene->mpBannerAnimations[0]->play(); + } + if (scene->mState != 6) { + if (!System::getChannelManager()->fn_8133A634(scene->mTitleId) || !scene->mScriptEnabled) { + iplSDChannelTitle_813E8160(scene); + } + if (!scene->mpBannerLayout) { + scene->mpProgressLayout->getAnim(0)->initAnmFrame(); + scene->mpProgressLayout->getAnim(0)->play(); + scene->mpSoundHandle = snd::getSystem()->startSE("WIPL_ME_SD_BANNER"); + } + } +} + +extern "C" void iplSDChannelTitle_813E8160(SDChannelTitle* scene) { + if (scene->mpSoundFiles[scene->mLoadedIndex] && scene->mpSoundFiles[scene->mLoadedIndex]->checkData() == 1) { + void* sound = scene->mpSoundFiles[scene->mLoadedIndex]->getBuffer(); + u32 size = System::getChannelManager()->fn_8133A5B8(scene->mTitleId); + snd::getSystem()->startBannerSound(sound, size, false); + } +} + +extern "C" void iplSDChannelTitle_813E81FC(SDChannelTitle* scene) { + iplSDChannelTitle_813E8360(scene); + if (scene->mScriptEnabled) { + memset(scene->mpScriptAnimations, 0, sizeof(scene->mpScriptAnimations)); + iplSDChannelTitle_813E8258(scene, scene->mpBannerLayout, scene->mpScriptAnimations, "banner"); + } +} + +extern "C" void iplSDChannelTitle_813E8258(SDChannelTitle*, layout::Object* layout, + layout::Animator** animations, const char* prefix) { + char groupName[8]; + char animationName[20]; + for (int index = 0; index < 16; ++index) { + sprintf(animationName, "%s_Rso%d.brlan", prefix, index); + if (layout->searchFile(animationName)) { + sprintf(groupName, "Rso%d", index); + bool bound = false; + nw4r::lyt::GroupList& groups = layout->GetGroupList(); + for (nw4r::lyt::GroupList::Iterator group = groups.GetBeginIter(); group != groups.GetEndIter(); ++group) { + if (strcmp(group->GetName(), groupName) == 0) { + animations[index] = layout->bindToGroup(animationName, groupName, false, false); + bound = true; + break; + } + } + if (!bound) { + animations[index] = layout->bind(animationName, false); + } + } + } +} + +extern "C" void iplSDChannelTitle_813E8360(SDChannelTitle* scene) { + for (int index = 0; index < 3; ++index) { + if (scene->mpBannerLayout->searchFile(sBannerAnimationNames[index])) { + if (index == 0) { + scene->mpBannerAnimations[index] = scene->mpBannerLayout->bind(sBannerAnimationNames[index]); + scene->mpBannerAnimations[index]->setAnmType(ANIM_TYPE_LOOP); + } else if (index == 1) { + scene->mpBannerAnimations[index] = scene->mpBannerLayout->bind(sBannerAnimationNames[index]); + scene->mpBannerAnimations[index]->setAnmType(ANIM_TYPE_FORWARD); + } else { + if (!scene->mpBannerAnimations[1]) { + scene->mpBannerAnimations[index] = scene->mpBannerLayout->bind(sBannerAnimationNames[index], true); + } else { + scene->mpBannerAnimations[index] = scene->mpBannerLayout->bind(sBannerAnimationNames[index], false); + } + scene->mpBannerAnimations[index]->setAnmType(ANIM_TYPE_LOOP); + } + } else { + scene->mpBannerAnimations[index] = NULL; + } + } +} + +extern "C" BOOL iplSDChannelTitle_813E847C(SDChannelTitle*, ESTmdView*, ESTitleId titleId) { + if (!System::getChannelManager()->fn_8133A5F0(titleId) || ncd::NCDSetting::getConnectEnableFlag()) { + return TRUE; + } + return FALSE; +} + +extern "C" BOOL iplSDChannelTitle_813E84C8() { + SCParentalControlsInfo parental; + if (SCGetParentalControl(&parental) && (parental.enable & SC_PARENTAL_FLAG_ENABLED)) { + return TRUE; + } + return FALSE; +} + +extern "C" void iplSDChannelTitle_813E850C(SDChannelTitle* scene, void* arguments) { + System::getHomeButtonMenu()->enable(); + scene->mbResetAcceptable = true; + if (static_cast(System::getScene(0x24))->isLeftArrowVisible()) { + static_cast(System::getScene(0x24))->animation(15); + static_cast(System::getScene(0x24))->animation(16); + } + scene->createChildScene(0x1b, scene, NULL, arguments); + scene->mParentalResult = 0; + scene->mState = 11; +} + +extern "C" void iplSDChannelTitle_813E85C0(SDChannelTitle* scene, int page, int index) { + SDChannelObj* keep = NULL; + if (scene->mpIconLayout) { + keep = scene->mpChannelSelect->findChannelObject(scene->mPage, scene->mIndex); + } + scene->mPage = page; + scene->mIndex = index; + scene->mpChannelSelect->setCurrentPageAndRefresh(page, index, keep); + SDChannelObj* channel = scene->mpChannelSelect->findChannelObject(scene->mPage, scene->mIndex); + scene->mPosition.x = SDChannelSelect::getChannelPanePosition(scene->mpChannelSelect, scene->mIndex).x; + scene->mPosition.y = SDChannelSelect::getChannelPanePosition(scene->mpChannelSelect, scene->mIndex).y; + if (iplSDChannelObj_813E3330(channel)) { + iplSDChannelTitle_813E86A0(scene, channel); + } else { + scene->mState = 28; + } +} + +extern "C" void iplSDChannelTitle_813E86A0(SDChannelTitle* scene, SDChannelObj* channel) { + scene->mTitleId = channel->mAppMeta.titleId; + if (scene->mScriptEnabled) { + scene->mbStopScript = true; + } + scene->mChangeFrame = 0; + scene->mState = 8; +} + +extern "C" void iplSDChannelTitle_813E86D8(SDChannelTitle* scene) { + scene->mParentalResult = 0; + scene->mbStartAnimation = false; + static_cast(System::getScene(0x24))->animation(15); + static_cast(System::getScene(0x24))->animation(16); + if (scene->mpBannerFiles[scene->mLoadedIndex]) { + delete scene->mpBannerFiles[scene->mLoadedIndex]; + } + if (scene->mpSoundFiles[scene->mLoadedIndex]) { + delete scene->mpSoundFiles[scene->mLoadedIndex]; + } + if (scene->mpBannerLayout) { + scene->mpBannerLayout->destroyHeap(); + } + scene->mpBannerFiles[scene->mLoadedIndex] = NULL; + scene->mpBannerLayout = NULL; + scene->mpSoundFiles[scene->mLoadedIndex] = NULL; + int page; + int index; + bool hasTitle = System::getChannelManager()->hasChannel(scene->mTitleId, &page, &index) != 0; + bool hasTemporaryTitle = false; + if (scene->mTitleId == SCGetTmpTitleID() && System::getChannelManager()->isLoadedTmp()) { + hasTemporaryTitle = true; + } + scene->mNextScene = 17; + scene->mbTmdReady = false; + scene->mMakerCode = 0; + scene->mbResetAcceptable = false; + System::getHomeButtonMenu()->disable(); + System::stopReceiveSchedule(); + if (hasTitle || hasTemporaryTitle) { + System::getTask1()->request(iplSDChannelTitle_813E8E70, scene, NULL); + scene->mbCopiedTitle = false; + scene->mState = 13; + } else { + scene->mpChannelSelect->clearCommandQueue(); + scene->mpChannelSelect->clearNoticeQueue(); + scene->mbCopiedTitle = true; + scene->mState = 19; + } +} + +extern "C" void iplSDChannelTitle_813E88CC(SDChannelTitle* scene, bool settings) { + if (settings) { + scene->reserveAllSceneDestruction(0x12, reinterpret_cast(1)); + scene->mState = 7; + } else { + if (static_cast(System::getScene(0x24))->isLeftArrowVisible()) { + static_cast(System::getScene(0x24))->animation(15); + static_cast(System::getScene(0x24))->animation(16); + } + System::getDialog()->callBtn2(0x143, 0x146, 0x25, false); + scene->mState = 12; + System::getHomeButtonMenu()->enable(); + scene->mbResetAcceptable = true; + } +} + +extern "C" void iplSDChannelTitle_813E899C(SDChannelTitle* scene, int nextScene) { + for (int index = 0; index < 4; ++index) { + controller::Interface* controller = System::getController(index); + if (controller) { + controller->cancelRumbling(); + } + } + if (nextScene == 17) { + System::getHomeButtonMenu()->disable(); + scene->mbResetAcceptable = false; + } +} + +extern "C" void iplSDChannelTitle_813E8A20(SDChannelTitle* scene, int nextScene) { + int page; + int index; + if (System::getChannelManager()->hasChannel(scene->mTitleId, &page, &index)) { + System::getSaveData()->iplSavedata_813596B8(scene->mTitleId); + } + System::getSaveData()->getSDPrevPage() = scene->mPage; + EGG::Heap* saveHeap = System::getMem2App(); + scene->mpSaveFile = System::getSaveData()->flushAsync(saveHeap); + __WPADReconnect(TRUE); +} + +extern "C" void iplSDChannelTitle_813E8AB4(SDChannelTitle*) { + snd::getSystem()->stopAllSound(0); + snd::getSystem()->calc(); + VISetBlack(TRUE); + VIFlush(); + VIWaitForRetrace(); + while (!__OSSyncSram()) { + } + OSRebootSystem(); +} + +extern "C" bool iplSDChannelTitle_813E8B1C(SDChannelTitle* scene) { + return static_cast(120.0f / System::getAnimDelta()) < scene->mLaunchFrame; +} + +extern "C" void iplSDChannelTitle_813E8B70(SDChannelTitle* scene) { + if (!scene->mStartButtonState) { + scene->mpButtonAnimations[5][3]->stop(); + scene->mpButtonAnimations[5][4]->play(); + scene->mpPaneManager->initPane(scene->mpLayout->FindPaneByName(sButtonNames[1])); + scene->mHoverCounts[1] = 0; + } + scene->mStartButtonState = 1; +} + +extern "C" void iplSDChannelTitle_813E8C08(SDChannelTitle*, const nw4r::ut::Rect& bounds, GXColor color) { + nw4r::ut::Rect screen; + System::getProjectionRect(&screen); + nw4r::ut::Rect rectangles[4]; + rectangles[0].left = screen.left; + rectangles[0].top = screen.bottom; + rectangles[0].right = screen.right; + rectangles[0].bottom = bounds.top; + rectangles[1].left = bounds.right; + rectangles[1].top = bounds.top; + rectangles[1].right = screen.right; + rectangles[1].bottom = screen.top; + rectangles[2].left = screen.left; + rectangles[2].top = bounds.bottom; + rectangles[2].right = bounds.right; + rectangles[2].bottom = screen.top; + rectangles[3].left = screen.left; + rectangles[3].top = bounds.top; + rectangles[3].right = bounds.left; + rectangles[3].bottom = bounds.bottom; + for (int index = 0; index < 4; ++index) { + utility::Graphics::drawPolygon(rectangles[index], color); + } +} + +extern "C" void iplSDChannelTitle_813E8D14(SDChannelTitle*, nw4r::lyt::Pane* pane, u32 message, bool allocate) { + wchar_t text[256]; + wcsncpy(text, System::getMessage(message), 256); + text[255] = 0; + nw4r::lyt::TextBox* textBox = nw4r::ut::DynamicCast(pane); + if (allocate) { + size_t length = wcslen(text); + textBox->AllocStringBuffer(static_cast(length)); + } + textBox->SetString(text); +} + +extern "C" nand::LayoutFile* iplSDChannelTitle_813E8DCC(SDChannelTitle*, ESTitleId title, nand::File** sound) { + *sound = System::getChannelManager()->fn_8133A85C(System::getMem2App(), title); + nand::MetaFile* banner = System::getChannelManager()->fn_8133A7A4(System::getMem2App(), title); + return new (System::getMem2App(), 4) nand::LayoutFile(banner, NULL); +} + +extern "C" void iplSDChannelTitle_813E8E70(void* argument) { + SDChannelTitle* scene = static_cast(argument); + ESError result = utility::ESMisc::GetTmdView(scene->mpBannerHeap, scene->mTitleId, &scene->mpTmd); + if (result) { + System::getErrorHandler()->log("ES", result, "iplSDChannelTitle.cpp", 0xc6d); + System::getErrorHandler()->set(ErrorHandler::DEFAULT, 2, NULL, 0, -1); + } + scene->mbTmdReady = true; +} + +extern "C" BOOL iplSDChannelTitle_813E8F04(SDChannelTitle* scene, ESTmdView* tmd) { + if (!utility::ESMisc::__IsPCEnable()) { + return TRUE; + } + SCParentalControlsInfo parental; + if (!SCGetParentalControl(&parental)) { + return TRUE; + } + if (parental.enable & SC_PARENTAL_FLAG_ENABLED) { + u32 restrictions = System::getChannelManager()->fn_8133A6B8(scene->mTitleId); + u32 networkRestrictions = SCGetNetContentRestrictions(); + if (networkRestrictions & restrictions) { + return FALSE; + } + if (SCGetWwwRestriction() && System::getChannelManager()->fn_8133A73C(scene->mTitleId)) { + return FALSE; + } + if (System::getChannelManager()->fn_8133A73C(scene->mTitleId)) { + return TRUE; + } else { + return utility::ESMisc::CheckTmdParentalControl(tmd); + } + } + return TRUE; +} + +extern "C" void iplSDChannelTitle_813E9004(SDTitlePaneEventHandler* handler, u32 component, + u32 event, const controller::Interface* controller) { + const char* paneName = handler->getPane(component)->GetName(); + switch (event) { + case ::gui::EventHandler::ON_TRIG: { + if (handler->mpScene->mState == 1 && controller->downTrg(0x100800)) { + if (strcmp(paneName, sButtonNames[0]) == 0) { + handler->mpScene->mpButtonAnimations[2][2]->play(); + snd::getSystem()->startSE("WIPL_SE_BT_PUSH"); + handler->mpScene->mState = 10; + iplSDChannelTitle_813E7A18(handler->mpScene); + } else if (strcmp(paneName, sButtonNames[1]) == 0) { + if (handler->mpScene->mStartButtonState != 2) { + snd::getSystem()->startSE("WIPL_SE_GRAY_BUTTON"); + } else { + iplSDChannelTitle_813E86D8(handler->mpScene); + handler->mpScene->mpButtonAnimations[3][2]->play(); + snd::getSystem()->stopSE(handler->mpScene->mpSoundHandle, 30); + snd::getSystem()->startSE("WIPL_SE_DECIDE"); + } + } + } + break; + } + case ::gui::EventHandler::ON_POINT: { + for (int button = 0; button < 2; ++button) { + if (strcmp(paneName, sButtonNames[button]) == 0 && + (button == 0 || handler->mpScene->mStartButtonState > 0)) { + ++handler->mpScene->mHoverCounts[button]; + if (handler->mpScene->mHoverCounts[button] <= 1) { + handler->mpScene->mpButtonAnimations[button][1]->play(); + snd::getSystem()->startSE("WIPL_SE_BT_TARGETTING"); + const_cast(controller)->rumble(0); + break; + } + } + } + break; + } + case ::gui::EventHandler::ON_LEFT: { + for (int button = 0; button < 2; ++button) { + if (strcmp(paneName, sButtonNames[button]) == 0 && + (button == 0 || handler->mpScene->mStartButtonState > 0)) { + s32& count = handler->mpScene->mHoverCounts[button]; + if (count <= 0) { + break; + } + --count; + if (handler->mpScene->mHoverCounts[button] <= 0) { + handler->mpScene->mpButtonAnimations[button][0]->play(); + break; + } + } + } + break; + } + } +} + +extern "C" void iplSDChannelTitle_813E92EC(SDTitleButtonEventHandler* handler, u32 component, + u32 event, const controller::Interface* controller) { + const char* name = handler->getPane(component)->GetName(); + switch (event) { + case 0: + if (handler->mpScene->mState == 1 && controller->downTrg(0x100800)) { + SDButton* button = static_cast(System::getScene(0x24)); + if (strcmp(name, SDButton::getButtonName(SDButton::BTN_ARROW_LEFT)) == 0) { + int page; + int index; + handler->mpScene->mpChannelSelect->findAdjacentChannel(1, &page, &index); + button->animation(7); + iplSDChannelTitle_813E85C0(handler->mpScene, page, index); + snd::getSystem()->startSE("WSD_SELECT"); + } else if (strcmp(name, SDButton::getButtonName(SDButton::BTN_ARROW_RIGHT)) == 0) { + int page; + int index; + handler->mpScene->mpChannelSelect->findAdjacentChannel(0, &page, &index); + button->animation(8); + iplSDChannelTitle_813E85C0(handler->mpScene, page, index); + snd::getSystem()->startSE("WSD_SELECT"); + } + } + break; + } +} + +void SDChannelTitle::startResetting() { + snd::getSystem()->resetAllSound(); +} + +void SDTitlePaneEventHandler::onEvent(u32 component, u32 event, void* data) { + iplSDChannelTitle_813E9004(this, component, event, static_cast(data)); +} + +void SDTitleButtonEventHandler::onEventDerived(u32 component, u32 event, const controller::Interface* controller) { + iplSDChannelTitle_813E92EC(this, component, event, controller); +} + +} +} diff --git a/tools/decomp-assist/iplSDChannelTitle.attempts.md b/tools/decomp-assist/iplSDChannelTitle.attempts.md new file mode 100644 index 00000000..c7db695e --- /dev/null +++ b/tools/decomp-assist/iplSDChannelTitle.attempts.md @@ -0,0 +1,57 @@ +# SDChannelTitle attempts + +Unit: `src/scene/sdChannelTitle/iplSDChannelTitle`, Wii Menu 4.3U. +All 69 original functions have C++ definitions. The source follows original object order; +the 55-string pool is identical. The unit remains NonMatching. + +The default gate baseline `70970038` is absent from this checkout. Checks use the +available ancestor `e265d9664e73912f2dbf8dd02425f9dc64eac55b` through the gate's +supported `--base` option. Its unit baseline is zero instruction-exact functions. + +## Remaining functions + +| Function | Distinct source attempts | Final instruction evidence | +| --- | --- | --- | +| `calcFadein` | Reversed fade-playing branch; cached event-handler pointer; explicitly typed null callback; named fade-playing condition. The latter three all kept 48/47 instructions. | One extra `li r5,0` for the declared unused second `SDButton::setEventHandler` argument. | +| `initCalcFadeout` | Cached empty handler (50/49); explicitly typed null arguments (50/49); reloaded SDButton directly at cleanup (54/49, reverted). | One extra `li r5,0` for the same unused argument. | +| `813E6CCC` | Combined positive early-return guards corrected the final animation branch; passed the actual title-range output pointer; cached title halves (89/86); cached selector (88/86); named enqueue result (87/86). Reverted the latter three. | 87/86; explicit ignored controller argument adds `li r4,0`; call setup also schedules differently. | +| `813E6E24` | Explicit range copies replaced reference-only arguments; reversed usage-enough branch; combined positive early-return guards; named copied ranges and cached memory receiver; reversed copy declaration order and original range declaration order. Named copies produced 6, 8, or 9 differing instructions; restored temporary copies. | 95/95; five differences in copy-load register selection and receiver/argument setup order. | +| `813E7074` | Reversed title comparison operands and copied-title branch; cached title halves (77/76); cached selector (77/76); named enqueue result (77/76). Reverted the latter three. | 77/76; explicit ignored controller argument adds `li r4,0`, with argument-move ordering differing. | +| `813E8A20` | Supplied page/index output locals to `hasChannel`; stored the SD previous page through a scoped inline setter; evaluated save heap separately; used a scoped reference accessor instead of the setter. | 37/37; six register/load-order differences around save-manager and heap access. | + +## Resolved iterations + +Constructor, destructor/thunk, layout creation, common calculation, normal calculation, +fadeout calculation, drawing, destruction, reset checks and most state handlers now +match instruction-exactly. Notable successful source changes were: + +- Original function order and event-case order restored all pooled strings. +- Explicit nullable-file checks reproduced virtual-destructor branches. +- Dialog last-result access corrected offset 0x24. +- Arrow visibility access used the real byte at offset 0x81. +- Text-pane names used a normal pointer table instead of direct literals. +- Named pane-handler and text-box temporaries restored allocation/call order. +- Script-data aggregate initialization and a real low-title-ID mask restored 120/120 instructions. +- Script-state heap-index temporary restored register selection. +- Separate result switch cases preserved the original dispatch tree. +- Event switches and a hover-count reference restored both event handlers. +- Combined positive early-return scene-state checks restored script calculation (66/66). +- Named capture-dimension table restored the full .rodata section. +- Fadeout used two-byte maker-code access and separately timed vector construction. + +## Layout and interface uncertainties + +The 0x800 bytes following the title-range output are preserved as opaque scene work +storage; their internal type is not recovered. This is instance layout, not linker padding. +The embedded SDMemory's original following-member offset requires size 0x2a78; its +existing header's unused 16-byte tail is excluded only for this translation unit. + +The original nonconst `isResetAcceptable` symbol differs from Base's existing const +virtual declaration. This needs review before linking. The event handler classes use +ordinary forwarding virtual methods, whose weak metadata may differ from the original. +The original extracted object's weak data can be zero-filled after linker deduplication; +no artificial data or force-active workaround was added. + +The two notice APIs declare an ignored controller argument that the target callers do +not initialize. The source supplies zero rather than depending on an uninitialized value. +The title-range output pointer is passed as the fourth channel-notice argument. -- 2.49.1