From 5e501a6c07380233c5971b86bc7f37955b6c40e5 Mon Sep 17 00:00:00 2001 From: PikHacker Date: Tue, 19 Sep 2023 19:27:10 -0400 Subject: [PATCH] singleGS dayend and mainresult progress --- docs/recommended_todo.md | 18 +- include/Game/Result.h | 2 +- include/Game/ResultTexMgr.h | 4 +- include/Game/SingleGame.h | 57 +- include/Game/gamePlayData.h | 17 +- include/kh/khDayEndResult.h | 17 +- src/plugProjectKandoU/singleGS_DayEnd.cpp | 564 ++++-------- src/plugProjectKandoU/singleGS_Ending.cpp | 6 +- src/plugProjectKandoU/singleGS_MainResult.cpp | 825 +++++------------- 9 files changed, 466 insertions(+), 1044 deletions(-) diff --git a/docs/recommended_todo.md b/docs/recommended_todo.md index c97f37692..99c511e5a 100644 --- a/docs/recommended_todo.md +++ b/docs/recommended_todo.md @@ -26,9 +26,9 @@ | TRK_MINNOW_DOLPHIN/mpc_7xx_603e.c | 5554 | mtx/mtx44.c | 5987 | | os/OSReboot.c | 6397 | gx/GXGeometry.c | 6983 | | TRK_MINNOW_DOLPHIN/dolphin_trk_glue.c | 10320 | exi/EXIUart.c | 10329 | -| ai/ai.c | 11124 | TRK_MINNOW_DOLPHIN/dolphin_trk.c | 11230 | -| TRK_MINNOW_DOLPHIN/support.c | 12046 | gx/GXTransform.c | 12379 | -| gx/GXLight.c | 14151 | gx/GXTev.c | 14624 | +| TRK_MINNOW_DOLPHIN/dolphin_trk.c | 11230 | TRK_MINNOW_DOLPHIN/support.c | 12046 | +| gx/GXTransform.c | 12379 | gx/GXLight.c | 14151 | +| gx/GXTev.c | 14624 | gx/GXPixel.c | 15806 | ###
JSystem
| File | Size (bytes) | File | Size (bytes) | @@ -98,13 +98,13 @@ | naviWhistle.cpp | 16714 | aiBattle.cpp | 17401 | | creatureLOD.cpp | 18468 | texCaster.cpp | 20776 | | aiRescue.cpp | 21024 | gameResultTexMgr.cpp | 21221 | -| singleGS_CaveResult.cpp | 22845 | aiCrop.cpp | 26982 | -| aiTransport.cpp | 27275 | gameSystem.cpp | 27890 | -| pathfinder.cpp | 28318 | aiAttack.cpp | 28457 | -| singleGS_MainResult.cpp | 29713 | creatureStick.cpp | 29831 | +| singleGS_MainResult.cpp | 21236 | singleGS_CaveResult.cpp | 22845 | +| aiCrop.cpp | 26982 | aiTransport.cpp | 27275 | +| gameSystem.cpp | 27890 | pathfinder.cpp | 28318 | +| aiAttack.cpp | 28457 | creatureStick.cpp | 29831 | | vsCardMgr.cpp | 31129 | aiEnter.cpp | 31721 | -| gameDynamics.cpp | 34058 | aiBore.cpp | 34883 | -| singleGS_DayEnd.cpp | 35056 | baseGameSectionKantei.cpp | 35202 | +| singleGS_DayEnd.cpp | 31850 | gameDynamics.cpp | 34058 | +| aiBore.cpp | 34883 | baseGameSectionKantei.cpp | 35202 | | gamePlayDataMemCard.cpp | 36035 | piki.cpp | 36397 | | gameGeneratorCache.cpp | 37575 | aiWeed.cpp | 38056 | | collinfo.cpp | 42246 | aiFormation.cpp | 43348 | diff --git a/include/Game/Result.h b/include/Game/Result.h index bbbaec16e..49ed43809 100644 --- a/include/Game/Result.h +++ b/include/Game/Result.h @@ -16,7 +16,7 @@ namespace Result { struct TNode : public DNode { TNode(); - virtual ~TNode(); // _08 (weak) + virtual ~TNode() { } // _08 (weak) void setTNode(u64 mesgTag, JUTTexture* texture, int quantity, int totalPokos, int pokoValue); void setTNode(u64 mesgTag, JUTTexture* texture, int quantity, int totalPokos, int pokoValue, int lostNum); diff --git a/include/Game/ResultTexMgr.h b/include/Game/ResultTexMgr.h index cc97483c1..bd3e4764d 100644 --- a/include/Game/ResultTexMgr.h +++ b/include/Game/ResultTexMgr.h @@ -14,13 +14,13 @@ struct Arg { mHeap = nullptr; mItemConfigList = nullptr; mOtakaraConfigList = nullptr; - _0C = -1; + mRegionMode = -1; } PelletConfigList* mOtakaraConfigList; // _00 PelletConfigList* mItemConfigList; // _04 JKRHeap* mHeap; // _08 - s8 _0C; // _0C + s8 mRegionMode; // _0C }; struct Mgr : public JKRDisposer { diff --git a/include/Game/SingleGame.h b/include/Game/SingleGame.h index 502b10610..eb88a7d23 100644 --- a/include/Game/SingleGame.h +++ b/include/Game/SingleGame.h @@ -181,11 +181,11 @@ struct CaveState : public State { struct DayEndArg : public StateArg { DayEndArg(u16 p1) - : _00(p1) + : mEndType(p1) { } - u16 _00; + u16 mEndType; }; /** @@ -207,10 +207,10 @@ struct DayEndState : public State { // _00 = VTBL // _00-_10 = State - u16 _10; // _10 - s16 _12; // _12 - f32 _14; // _14 - PikiContainer _18; // _18 + u16 mDayEndType; // _10 + u16 mStatus; // _12 + f32 mTimer; // _14 + PikiContainer mLeftBehindPikis; // _18 }; struct EndingArg : public StateArg { @@ -411,38 +411,37 @@ struct LoadState : public State { struct MainResultState : public State { MainResultState(); - virtual void init(SingleGameSection*, StateArg*); // _08 - virtual void exec(SingleGameSection*); // _0C - virtual void cleanup(SingleGameSection*); // _10 - virtual void draw(SingleGameSection*, Graphics&); // _20 - virtual void onMovieDone(SingleGameSection*, MovieConfig*, u32, u32); // _2C + virtual void init(SingleGameSection* game, StateArg* arg); // _08 + virtual void exec(SingleGameSection* game); // _0C + virtual void cleanup(SingleGameSection* game); // _10 + virtual void draw(SingleGameSection* game, Graphics& gfx); // _20 + virtual void onMovieDone(SingleGameSection* game, MovieConfig* config, u32, u32); // _2C void beforeSave(); void createResultNodes(); void loadResource(); // Unused/inlined: - unknown open2D(SingleGameSection*); + unknown open2D(SingleGameSection* game); // _00 = VTBL // _00-_10 = State - s16 _10; // _10 - f32 _14; // _14 - Controller* _18; // _18 - u8 _1C; // _1C - u8 _1D[0x3]; // _1D, unknown/probably padding - u8 _20[4]; // _20 - ResultTexMgr::Mgr _24; // _24 - u8 _64[4]; // _64 - Result::TNode _68; // _68 - kh::Screen::IncP* _B8; // _B8 - u8 _BC[4]; // _BC - JKRHeap* _C0; // _C0 - TObjectNode* _C4; // _C4 - Delegate* _C8; // _C8 - DvdThreadCommand _CC; // _CC - SingleGameSection* _138; // _138 - Delegate* _13C; // _13C + u16 mStatus; // _10 + f32 mStartTimer; // _14 + Controller* mControl; // _18 + u8 _1C; // _1C + int mCounter; // _20 + ResultTexMgr::Mgr mResultTex; // _24 + u8 _64[4]; // _64 + Result::TNode mResultNode; // _68 + kh::Screen::IncP* mIncP; // _B8 + u8 _BC[4]; // _BC + JKRHeap* mMainHeap; // _C0 + TObjectNode* mPelletMgr; // _C4 + Delegate* mLoadDelegate; // _C8 + DvdThreadCommand mDvdThread; // _CC + SingleGameSection* mGameSect; // _138 + Delegate* mBeforeSaveDelegate; // _13C }; struct MovieArg : public StateArg { diff --git a/include/Game/gamePlayData.h b/include/Game/gamePlayData.h index 34f21959e..c560232ce 100644 --- a/include/Game/gamePlayData.h +++ b/include/Game/gamePlayData.h @@ -131,6 +131,15 @@ struct KindCounter { void copyFrom(KindCounter&); inline void addTo(KindCounter&); + inline int calcCollectedNum() + { + int ret = 0; + for (int i = 0; i < mNumKinds; i++) { + ret += *operator()(i); + } + return ret; + } + u16 mNumKinds; // _00 u8* mKinds; // _04 }; @@ -410,15 +419,15 @@ struct PlayData : public CNode { return stream.getStreamDistance(streamStartPos) + generatorCache->getHeapUsedSize(); } - inline void setSaveFlag(int a) + inline void setSaveFlag(int a, void* delegate) { - mLoadType = a; - _1C = 0; + mLoadType = a; + mBeforeSaveDelegate = delegate; } bool _18; // _18 u8 mLoadType; // _19, see SaveFlags enum - u32 _1C; // _1C + void* mBeforeSaveDelegate; // _1C u8 mDeadNaviID; // _20 f32 mNaviLifeMax[2]; // _24 u8 mHasContainerFlags; // _2C diff --git a/include/kh/khDayEndResult.h b/include/kh/khDayEndResult.h index 7e7f01429..f6e8bd040 100644 --- a/include/kh/khDayEndResult.h +++ b/include/kh/khDayEndResult.h @@ -21,8 +21,16 @@ namespace Screen { //////////////////////////////////////////// // DATA STRUCTS -enum MailCategory { +enum MailCategory { + // Acutal checking for these conditions are done in singlleGS_MainResult + PokoUnder3000 = 0x31, + PokoUnder5000 = 0x32, + PokoUnder8000 = 0x33, + PokoUnder10000 = 0x34, + PayDebt = 0x35, + SavedLouie = 0x36, + AllTreasures = 0x37, }; struct MailSaveData { @@ -121,6 +129,13 @@ struct DispDayEndResultTitl : public og::Screen::DispMemberBase { }; struct DispDayEndResult : public og::Screen::DispMemberBase { + DispDayEndResult(Game::Result::TNode* node, int treasures, int pokos, bool paydebt, IncP* incp, JKRHeap* mailheap, + MailCategory mailtype) + : mItem(node, treasures, pokos, paydebt) + , mIncP(incp) + , mMail(mailheap, mailtype) + { + } virtual u32 getSize() { return sizeof(DispDayEndResult); } // _08 (weak) virtual u32 getOwnerID() { return OWNER_KH; } // _0C (weak) diff --git a/src/plugProjectKandoU/singleGS_DayEnd.cpp b/src/plugProjectKandoU/singleGS_DayEnd.cpp index 6bb052d7a..abd25264b 100644 --- a/src/plugProjectKandoU/singleGS_DayEnd.cpp +++ b/src/plugProjectKandoU/singleGS_DayEnd.cpp @@ -3,20 +3,27 @@ #include "Game/MoviePlayer.h" #include "Game/NaviState.h" #include "Game/PikiMgr.h" +#include "Game/PikiState.h" #include "Game/cellPyramid.h" -#include "Iterator.h" -#include "JSystem/JUtility/JUTException.h" -#include "efx/TNaviEffect.h" -#include "types.h" -#include "nans.h" #include "Game/SingleGame.h" #include "Game/gameStat.h" -#include "utilityU.h" +#include "Game/generalEnemyMgr.h" #include "Game/Entities/PelletCarcass.h" #include "Game/Entities/PelletFruit.h" #include "Game/Entities/PelletItem.h" #include "Game/Entities/PelletOtakara.h" #include "Game/Navi.h" +#include "Game/MapMgr.h" +#include "efx/TNaviEffect.h" +#include "Screen/Game2DMgr.h" +#include "Dolphin/rand.h" +#include "PikiAI.h" +#include "Iterator.h" +#include "utilityU.h" +#include "nans.h" + +static const u32 padding[] = { 0, 0, 0 }; +static const char className[] = "singleGS_DayEnd"; namespace Game { namespace SingleGame { @@ -26,7 +33,7 @@ namespace SingleGame { * Address: 8023A250 * Size: 0004A0 */ -void DayEndState::init(SingleGameSection* section, StateArg* arg) +void DayEndState::init(SingleGameSection* game, StateArg* arg) { gameSystem->mFlags &= ~GAMESYS_IsGameWorldActive; gameSystem->mFlags |= GAMESYS_Unk5; @@ -34,12 +41,12 @@ void DayEndState::init(SingleGameSection* section, StateArg* arg) moviePlayer->clearSuspendedDemo(); DayEndArg* castedArg = static_cast(arg); P2ASSERTLINE(67, castedArg != nullptr); - _10 = castedArg->_00; - _14 = 0.0f; + mDayEndType = castedArg->mEndType; + mTimer = 0.0f; gameSystem->setPause(true, "dayend", 3); - _12 = 0; - _18.clear(); - if (section->mTheExpHeap != nullptr) { + mStatus = 0; + mLeftBehindPikis.clear(); + if (game->mTheExpHeap != nullptr) { PSMCancelToPauseOffMainBgm(); } Iterator iOnyon(ItemOnyon::mgr); @@ -49,7 +56,7 @@ void DayEndState::init(SingleGameSection* section, StateArg* arg) (*iOnyon)->mSuckTimer = 4.0f; (*iOnyon)->forceClose(); } - section->saveToGeneratorCache(section->mCurrentCourseInfo); + game->saveToGeneratorCache(game->mCurrentCourseInfo); PelletIterator iPellet; CI_LOOP(iPellet) { @@ -78,338 +85,6 @@ void DayEndState::init(SingleGameSection* section, StateArg* arg) effectsObj->killHamonA_(); effectsObj->killHamonB_(); } - /* - stwu r1, -0x50(r1) - mflr r0 - stw r0, 0x54(r1) - stfd f31, 0x40(r1) - psq_st f31, 72(r1), 0, qr0 - stw r31, 0x3c(r1) - stw r30, 0x38(r1) - stw r29, 0x34(r1) - lwz r6, gameSystem__4Game@sda21(r13) - mr r29, r3 - mr r31, r4 - mr r30, r5 - lbz r0, 0x3c(r6) - rlwinm r0, r0, 0, 0x1b, 0x19 - stb r0, 0x3c(r6) - lwz r3, gameSystem__4Game@sda21(r13) - lbz r0, 0x3c(r3) - ori r0, r0, 0x10 - stb r0, 0x3c(r3) - lwz r3, moviePlayer__4Game@sda21(r13) - bl reset__Q24Game11MoviePlayerFv - lwz r3, moviePlayer__4Game@sda21(r13) - bl clearSuspendedDemo__Q24Game11MoviePlayerFv - cmplwi r30, 0 - bne lbl_8023A2D0 - lis r3, lbl_80483D8C@ha - lis r5, lbl_80483DA0@ha - addi r3, r3, lbl_80483D8C@l - li r4, 0x43 - addi r5, r5, lbl_80483DA0@l - crclr 6 - bl panic_f__12JUTExceptionFPCciPCce - -lbl_8023A2D0: - lhz r0, 0(r30) - li r4, 1 - lfs f0, lbl_8051A538@sda21(r2) - addi r5, r2, lbl_8051A53C@sda21 - sth r0, 0x10(r29) - li r6, 3 - stfs f0, 0x14(r29) - lwz r3, gameSystem__4Game@sda21(r13) - bl setPause__Q24Game10GameSystemFbPci - li r0, 0 - addi r3, r29, 0x18 - sth r0, 0x12(r29) - bl clear__Q24Game13PikiContainerFv - lwz r0, 0xfc(r31) - cmplwi r0, 0 - beq lbl_8023A314 - bl PSMCancelToPauseOffMainBgm__Fv - -lbl_8023A314: - lwz r3, mgr__Q24Game9ItemOnyon@sda21(r13) - cmplwi r3, 0 - beq lbl_8023A324 - addi r3, r3, 0x30 - -lbl_8023A324: - li r0, 0 - lis r4, "__vt__23Iterator"@ha - addi r4, r4, "__vt__23Iterator"@l - stw r0, 0x24(r1) - cmplwi r0, 0 - stw r4, 0x18(r1) - stw r0, 0x1c(r1) - stw r3, 0x20(r1) - bne lbl_8023A360 - lwz r12, 0(r3) - lwz r12, 0x18(r12) - mtctr r12 - bctrl - stw r3, 0x1c(r1) - b lbl_8023A3E8 - -lbl_8023A360: - lwz r12, 0(r3) - lwz r12, 0x18(r12) - mtctr r12 - bctrl - stw r3, 0x1c(r1) - b lbl_8023A3CC - -lbl_8023A378: - lwz r3, 0x20(r1) - lwz r4, 0x1c(r1) - lwz r12, 0(r3) - lwz r12, 0x20(r12) - mtctr r12 - bctrl - mr r4, r3 - lwz r3, 0x24(r1) - lwz r12, 0(r3) - lwz r12, 8(r12) - mtctr r12 - bctrl - clrlwi. r0, r3, 0x18 - bne lbl_8023A3E8 - lwz r3, 0x20(r1) - lwz r4, 0x1c(r1) - lwz r12, 0(r3) - lwz r12, 0x14(r12) - mtctr r12 - bctrl - stw r3, 0x1c(r1) - -lbl_8023A3CC: - lwz r12, 0x18(r1) - addi r3, r1, 0x18 - lwz r12, 0x10(r12) - mtctr r12 - bctrl - clrlwi. r0, r3, 0x18 - beq lbl_8023A378 - -lbl_8023A3E8: - lfs f31, lbl_8051A544@sda21(r2) - b lbl_8023A500 - -lbl_8023A3F0: - lwz r3, 0x20(r1) - lwz r12, 0(r3) - lwz r12, 0x20(r12) - mtctr r12 - bctrl - li r4, 0 - bl setSpotEffectActive__Q24Game5OnyonFb - lwz r3, 0x20(r1) - lwz r4, 0x1c(r1) - lwz r12, 0(r3) - lwz r12, 0x20(r12) - mtctr r12 - bctrl - stfs f31, 0x244(r3) - lwz r3, 0x20(r1) - lwz r4, 0x1c(r1) - lwz r12, 0(r3) - lwz r12, 0x20(r12) - mtctr r12 - bctrl - bl forceClose__Q24Game5OnyonFv - lwz r0, 0x24(r1) - cmplwi r0, 0 - bne lbl_8023A470 - lwz r3, 0x20(r1) - lwz r4, 0x1c(r1) - lwz r12, 0(r3) - lwz r12, 0x14(r12) - mtctr r12 - bctrl - stw r3, 0x1c(r1) - b lbl_8023A500 - -lbl_8023A470: - lwz r3, 0x20(r1) - lwz r4, 0x1c(r1) - lwz r12, 0(r3) - lwz r12, 0x14(r12) - mtctr r12 - bctrl - stw r3, 0x1c(r1) - b lbl_8023A4E4 - -lbl_8023A490: - lwz r3, 0x20(r1) - lwz r4, 0x1c(r1) - lwz r12, 0(r3) - lwz r12, 0x20(r12) - mtctr r12 - bctrl - mr r4, r3 - lwz r3, 0x24(r1) - lwz r12, 0(r3) - lwz r12, 8(r12) - mtctr r12 - bctrl - clrlwi. r0, r3, 0x18 - bne lbl_8023A500 - lwz r3, 0x20(r1) - lwz r4, 0x1c(r1) - lwz r12, 0(r3) - lwz r12, 0x14(r12) - mtctr r12 - bctrl - stw r3, 0x1c(r1) - -lbl_8023A4E4: - lwz r12, 0x18(r1) - addi r3, r1, 0x18 - lwz r12, 0x10(r12) - mtctr r12 - bctrl - clrlwi. r0, r3, 0x18 - beq lbl_8023A490 - -lbl_8023A500: - lwz r3, 0x20(r1) - lwz r12, 0(r3) - lwz r12, 0x1c(r12) - mtctr r12 - bctrl - lwz r4, 0x1c(r1) - cmplw r4, r3 - bne lbl_8023A3F0 - lwz r4, 0x22c(r31) - mr r3, r31 - bl saveToGeneratorCache__Q24Game15BaseGameSectionFPQ24Game10CourseInfo - addi r3, r1, 8 - bl __ct__Q24Game14PelletIteratorFv - addi r3, r1, 8 - bl first__Q24Game14PelletIteratorFv - b lbl_8023A584 - -lbl_8023A540: - addi r3, r1, 8 - bl __ml__Q24Game14PelletIteratorFv - lwz r12, 0(r3) - mr r31, r3 - lwz r12, 0xa8(r12) - mtctr r12 - bctrl - clrlwi. r0, r3, 0x18 - beq lbl_8023A57C - lwz r0, 0xb8(r31) - cmplwi r0, 0 - bne lbl_8023A57C - mr r3, r31 - li r4, 0 - bl kill__Q24Game8CreatureFPQ24Game15CreatureKillArg - -lbl_8023A57C: - addi r3, r1, 8 - bl next__Q24Game14PelletIteratorFv - -lbl_8023A584: - addi r3, r1, 8 - bl isDone__Q24Game14PelletIteratorFv - clrlwi. r0, r3, 0x18 - beq lbl_8023A540 - lwz r3, mgr__Q24Game13PelletCarcass@sda21(r13) - lwz r12, 0(r3) - lwz r12, 0x28(r12) - mtctr r12 - bctrl - lwz r3, mgr__Q24Game11PelletFruit@sda21(r13) - lwz r12, 0(r3) - lwz r12, 0x28(r12) - mtctr r12 - bctrl - lwz r3, mgr__Q24Game10PelletItem@sda21(r13) - lwz r12, 0(r3) - lwz r12, 0x38(r12) - mtctr r12 - bctrl - lwz r3, mgr__Q24Game13PelletOtakara@sda21(r13) - lwz r12, 0(r3) - lwz r12, 0x38(r12) - mtctr r12 - bctrl - lwz r3, naviMgr__4Game@sda21(r13) - li r4, 0 - lwz r12, 0(r3) - lwz r12, 0x24(r12) - mtctr r12 - bctrl - lwz r12, 0(r3) - mr r31, r3 - lwz r12, 0xa8(r12) - mtctr r12 - bctrl - clrlwi. r0, r3, 0x18 - beq lbl_8023A658 - lwz r3, 0x270(r31) - mr r4, r31 - li r5, 0 - li r6, 0 - lwz r12, 0(r3) - lwz r12, 0x14(r12) - mtctr r12 - bctrl - lwz r31, 0x2d0(r31) - lwz r0, 0(r31) - mr r3, r31 - rlwinm r0, r0, 0, 0, 0x1e - stw r0, 0(r31) - bl killHamonA___Q23efx11TNaviEffectFv - mr r3, r31 - bl killHamonB___Q23efx11TNaviEffectFv - -lbl_8023A658: - lwz r3, naviMgr__4Game@sda21(r13) - li r4, 1 - lwz r12, 0(r3) - lwz r12, 0x24(r12) - mtctr r12 - bctrl - lwz r12, 0(r3) - mr r31, r3 - lwz r12, 0xa8(r12) - mtctr r12 - bctrl - clrlwi. r0, r3, 0x18 - beq lbl_8023A6CC - lwz r3, 0x270(r31) - mr r4, r31 - li r5, 0 - li r6, 0 - lwz r12, 0(r3) - lwz r12, 0x14(r12) - mtctr r12 - bctrl - lwz r31, 0x2d0(r31) - lwz r0, 0(r31) - mr r3, r31 - rlwinm r0, r0, 0, 0, 0x1e - stw r0, 0(r31) - bl killHamonA___Q23efx11TNaviEffectFv - mr r3, r31 - bl killHamonB___Q23efx11TNaviEffectFv - -lbl_8023A6CC: - psq_l f31, 72(r1), 0, qr0 - lwz r0, 0x54(r1) - lfd f31, 0x40(r1) - lwz r31, 0x3c(r1) - lwz r30, 0x38(r1) - lwz r29, 0x34(r1) - mtlr r0 - addi r1, r1, 0x50 - blr - */ } /* @@ -417,8 +92,80 @@ void DayEndState::init(SingleGameSection* section, StateArg* arg) * Address: 8023A6F0 * Size: 00040C */ -void DayEndState::exec(SingleGameSection* gs) +void DayEndState::exec(SingleGameSection* game) { + switch (mStatus) { + case 0: + mTimer -= sys->mDeltaTime; + if (mTimer <= 0.0f) { + mLeftBehindPikis.clear(); + // dont leave behind pikis on day 1 + if (gameSystem->mTimeMgr->mDayCount != 0) { + pikiMgr->killDayEndPikmins(mLeftBehindPikis); + } + switch (mDayEndType) { + case 0: + MoviePlayArg arg("s01_dayend", const_cast(game->mCurrentCourseInfo->mName), game->mMovieFinishCallback, 0); + int treasures = 0; + // treasures += playData->mMainCropMemory->mItem.calcCollectedNum(); + // treasures += playData->mMainCropMemory->mOtakara.calcCollectedNum(); + if (treasures == 0) { + arg.mStreamID = 0xc0011004; + } else if (treasures <= 14) { + arg.mStreamID = 0xc0011002; + } else { + arg.mStreamID = 0xc0011003; + } + JUT_ASSERTLINE(222, naviMgr->getAliveOrima(0), "no alive:s01_dayend"); + Navi* navi = naviMgr->getActiveNavi(); + arg.mPelletName = nullptr; + if (navi) { + arg.mPelletName = (char*)navi->mNaviIndex; + if ((int)arg.mPelletName == 1 && playData->mStoryFlags & STORY_DebtPaid) { + arg.mPelletName = (char*)2; + } + } + arg.mDelegateStart = game->mMovieStartCallback; + moviePlayer->play(arg); + gameSystem->setPause(true, "s01_dayend", 3); + mStatus = 1; + break; + case 1: { + MoviePlayArg arg("s06_dayend_pikminzero", const_cast(game->mCurrentCourseInfo->mName), game->mMovieFinishCallback, + 0); + arg.mDelegateStart = game->mMovieStartCallback; + moviePlayer->play(arg); + gameSystem->setPause(1, "s06_dayend", 3); + mStatus = 1; + break; + } + case 2: { + MoviePlayArg arg("s04_dayend_orimadown", const_cast(game->mCurrentCourseInfo->mName), game->mMovieFinishCallback, 0); + arg.mDelegateStart = game->mMovieStartCallback; + moviePlayer->play(arg); + gameSystem->setPause(0, "s04_dayend", 3); + mStatus = 1; + break; + } + } + } + break; + case 1: + if (moviePlayer && !moviePlayer->isFlag(MVP_IsActive)) { + pikiMgr->forceEnterPikmins(false); + gameSystem->setPause(true, "dayend-cache", 3); + game->advanceDayCount(); + gameSystem->mTimeMgr->setStartTime(); + gameSystem->detachObjectMgr(generalEnemyMgr); + gameSystem->detachObjectMgr(mapMgr); + gameSystem->mFlags |= 4; + transit(game, SGS_MainResult, nullptr); + return; + } + break; + } + game->BaseGameSection::doUpdate(); + game->updateMainMapScreen(); /* stwu r1, -0xc0(r1) mflr r0 @@ -725,8 +472,58 @@ void DayEndState::exec(SingleGameSection* gs) * Address: 8023AAFC * Size: 0005B8 */ -void DayEndState::onMovieStart(SingleGameSection* gs, MovieConfig* cfg, u32, u32) +void DayEndState::onMovieStart(SingleGameSection* game, MovieConfig* config, u32, u32) { + Screen::gGame2DMgr->startFadeBG_CourseName(); + Screen::gGame2DMgr->startCount_CourseName(); + gameSystem->mTimeMgr->setEndTime(); + if (config->is("s01_dayend")) { + P2ASSERTLINE(335, Screen::gGame2DMgr->mScreenMgr->reset() == true); + Vec origin; + origin.x = 156.0f; + origin.y = 0.0f; + origin.z = 166.0f; + if (mapMgr->getDemoMatrix()) { + Matrixf* mtx = mapMgr->getDemoMatrix(); + Vec out; + PSMTXMultVec(mtx->mMatrix.mtxView, &origin, &out); + origin = out; + + Piki* pikiBuffer[103]; + int i = 0; + Iterator iterator(pikiMgr); + CI_LOOP(iterator) + { + Piki* piki = *iterator; + if (piki->isZikatu()) { + pikiBuffer[i++] = piki; + } + } + for (int j = 0; j < i; j++) { + PikiKillArg arg(1); + pikiBuffer[j]->kill(&arg); + } + pikiMgr->moveAllPikmins(*(Vector3f*)&origin, 50.0f, nullptr); + + Iterator iterator2(pikiMgr); + CI_LOOP(iterator2) + { + Piki* piki = *iterator2; + Navi* navi = naviMgr->getAliveOrima(0); + JUT_ASSERTLINE(376, navi, "no alive navi"); + PikiAI::ActFormationInitArg arg(navi); + piki->mNavi = navi; + piki->mBrain->start(PikiAI::ACT_Formation, &arg); + piki->movie_begin(false); + } + } + } else { + if (config->is("s21_dayend_takeoff")) { + cellMgr->clear(); + generalEnemyMgr->prepareDayendEnemies(); + } + } + /* .loc_0x0: stwu r1, -0x210(r1) @@ -1242,8 +1039,42 @@ void DayEndState::onMovieDone(SingleGameSection* section, MovieConfig* cfg, u32 * Address: 8023B1A8 * Size: 0002C0 */ -void DayEndState::onMovieCommand(SingleGameSection* gs, int) +void DayEndState::onMovieCommand(SingleGameSection* game, int id) { + switch (id) { + case 1: + Vector3f origin(0.0f); + if (mapMgr->getDemoMatrix()) { + Matrixf* mtx = mapMgr->getDemoMatrix(); + Vector3f out; + PSMTXMultVec(mtx->mMatrix.mtxView, (Vec*)&origin, (Vec*)&out); + origin = out; + origin.y = mapMgr->getMinY(origin); + } + Sys::Sphere bounds(origin, 180.0f); + generalEnemyMgr->createDayendEnemies(bounds); + for (int i = 0; i <= 4; i++) { + for (int j = 0; j <= 2; j++) { + for (int k = 0; k < mLeftBehindPikis.getCount(i, j); k++) { + Piki* piki = pikiMgr->birth(); + if (piki) { + PikiInitArg arg(PIKISTATE_Escape); + piki->init(&arg); + f32 angle = randFloat() * TAU; + f32 zero = 0.0f; + Vector3f pos(pikmin2_cosf(angle) * 30.0f, origin.y + zero, pikmin2_sinf(angle) * 30.0f); + if (mapMgr) { + pos.y = mapMgr->getMinY(pos); + } + piki->setPosition(pos, false); + piki->changeShape(i); + piki->changeHappa(j); + piki->movie_begin(false); + } + } + } + } + } /* stwu r1, -0x80(r1) mflr r0 @@ -1453,14 +1284,14 @@ void DayEndState::onMovieCommand(SingleGameSection* gs, int) * Address: 8023B468 * Size: 000028 */ -void DayEndState::draw(SingleGameSection* gs, Graphics& gfx) { static_cast(gs)->doDraw(gfx); } +void DayEndState::draw(SingleGameSection* game, Graphics& gfx) { game->BaseGameSection::doDraw(gfx); } /* * --INFO-- * Address: 8023B490 * Size: 00007C */ -void DayEndState::cleanup(SingleGameSection* gs) +void DayEndState::cleanup(SingleGameSection* game) { playData->setPikminCounts_Today(); GameStat::getMapPikmins(-1); @@ -1468,39 +1299,6 @@ void DayEndState::cleanup(SingleGameSection* gs) int mePikis = GameStat::mePikis; gameSystem->setPause(false, "dayend;cln", 3); gameSystem->mFlags &= ~GAMESYS_Unk5; - /* - stwu r1, -0x10(r1) - mflr r0 - stw r0, 0x14(r1) - lwz r3, playData__4Game@sda21(r13) - bl setPikminCounts_Today__Q24Game8PlayDataFv - li r3, -1 - bl getMapPikmins__Q24Game8GameStatFi - lis r3, alivePikis__Q24Game8GameStat@ha - lwzu r12, alivePikis__Q24Game8GameStat@l(r3) - lwz r12, 8(r12) - mtctr r12 - bctrl - lis r3, mePikis__Q24Game8GameStat@ha - lwzu r12, mePikis__Q24Game8GameStat@l(r3) - lwz r12, 8(r12) - mtctr r12 - bctrl - lis r4, lbl_80483E48@ha - lwz r3, gameSystem__4Game@sda21(r13) - addi r5, r4, lbl_80483E48@l - li r6, 3 - li r4, 0 - bl setPause__Q24Game10GameSystemFbPci - lwz r3, gameSystem__4Game@sda21(r13) - lbz r0, 0x3c(r3) - rlwinm r0, r0, 0, 0x1c, 0x1a - stb r0, 0x3c(r3) - lwz r0, 0x14(r1) - mtlr r0 - addi r1, r1, 0x10 - blr - */ } } // namespace SingleGame diff --git a/src/plugProjectKandoU/singleGS_Ending.cpp b/src/plugProjectKandoU/singleGS_Ending.cpp index 600f87316..045f425b2 100644 --- a/src/plugProjectKandoU/singleGS_Ending.cpp +++ b/src/plugProjectKandoU/singleGS_Ending.cpp @@ -208,7 +208,7 @@ void EndingState::exec(SingleGameSection* game) playData->openCourse(3); } playData->mStoryFlags |= STORY_DebtPaid; - playData->setSaveFlag(4); + playData->setSaveFlag(4, nullptr); } } break; @@ -274,7 +274,7 @@ void EndingState::exec(SingleGameSection* game) sys->getPlayCommonData()->_00 |= 2; playData->mStoryFlags |= STORY_AllTreasuresCollected; mStatus = EndingStatus_ShowFinalResultsComplete; - playData->setSaveFlag(1); + playData->setSaveFlag(1, nullptr); } } break; @@ -301,7 +301,7 @@ void EndingState::exec(SingleGameSection* game) sys->getPlayCommonData()->_00 |= 2; playData->mStoryFlags |= STORY_AllTreasuresCollected; mStatus = EndingStatus_ShowFinalResultsComplete; - playData->setSaveFlag(1); + playData->setSaveFlag(1, nullptr); } } break; diff --git a/src/plugProjectKandoU/singleGS_MainResult.cpp b/src/plugProjectKandoU/singleGS_MainResult.cpp index f6182cc52..353ba8c2a 100644 --- a/src/plugProjectKandoU/singleGS_MainResult.cpp +++ b/src/plugProjectKandoU/singleGS_MainResult.cpp @@ -1,260 +1,35 @@ -#include "types.h" -#include "nans.h" #include "Game/SingleGame.h" +#include "Game/Navi.h" +#include "Game/generalEnemyMgr.h" +#include "Game/itemMgr.h" +#include "Game/Farm.h" +#include "Game/Entities/PelletItem.h" +#include "Game/Entities/PelletOtakara.h" +#include "Game/MoviePlayer.h" +#include "Game/Entities/ItemOnyon.h" +#include "Game/GameLight.h" +#include "Game/CameraMgr.h" +#include "Screen/Game2DMgr.h" +#include "TParticle2dMgr.h" +#include "utilityU.h" +#include "nans.h" -/* - Generated from dpostproc - - .section .ctors, "wa" # 0x80472F00 - 0x804732C0 - .4byte __sinit_singleGS_MainResult_cpp - - .section .rodata # 0x804732E0 - 0x8049E220 - .global lbl_80482598 - lbl_80482598: - .4byte 0x7330325F - .4byte 0x64617965 - .4byte 0x6E645F72 - .4byte 0x6573756C - .4byte 0x74000000 - .4byte 0x00000000 - - .section .data, "wa" # 0x8049E220 - 0x804EFC20 - .global lbl_804C0648 - lbl_804C0648: - .4byte 0x00000000 - .4byte 0x00000000 - .4byte 0x00000000 - .global lbl_804C0654 - lbl_804C0654: - .4byte 0x00000000 - .4byte 0xFFFFFFFF - .4byte loadResource__Q34Game10SingleGame15MainResultStateFv - .global lbl_804C0660 - lbl_804C0660: - .4byte 0x00000000 - .4byte 0xFFFFFFFF - .4byte beforeSave__Q34Game10SingleGame15MainResultStateFv - .global __vt__Q32kh6Screen20DispDayEndResultTitl - __vt__Q32kh6Screen20DispDayEndResultTitl: - .4byte 0 - .4byte 0 - .4byte getSize__Q32kh6Screen20DispDayEndResultTitlFv - .4byte getOwnerID__Q32kh6Screen20DispDayEndResultTitlFv - .4byte getMemberID__Q32kh6Screen20DispDayEndResultTitlFv - .4byte doSetSubMemberAll__Q32og6Screen14DispMemberBaseFv - .global __vt__Q32kh6Screen16DispDayEndResult - __vt__Q32kh6Screen16DispDayEndResult: - .4byte 0 - .4byte 0 - .4byte getSize__Q32kh6Screen16DispDayEndResultFv - .4byte getOwnerID__Q32kh6Screen16DispDayEndResultFv - .4byte getMemberID__Q32kh6Screen16DispDayEndResultFv - .4byte doSetSubMemberAll__Q32kh6Screen16DispDayEndResultFv - .global __vt__Q34Game10SingleGame15MainResultState - __vt__Q34Game10SingleGame15MainResultState: - .4byte 0 - .4byte 0 - .4byte - init__Q34Game10SingleGame15MainResultStateFPQ24Game17SingleGameSectionPQ24Game8StateArg - .4byte - exec__Q34Game10SingleGame15MainResultStateFPQ24Game17SingleGameSection .4byte - cleanup__Q34Game10SingleGame15MainResultStateFPQ24Game17SingleGameSection - .4byte - "resume__Q24Game36FSMStateFPQ24Game17SingleGameSection" - .4byte - "restart__Q24Game36FSMStateFPQ24Game17SingleGameSection" - .4byte - "transit__Q24Game36FSMStateFPQ24Game17SingleGameSectioniPQ24Game8StateArg" - .4byte - draw__Q34Game10SingleGame15MainResultStateFPQ24Game17SingleGameSectionR8Graphics - .4byte - onOrimaDown__Q34Game10SingleGame5StateFPQ24Game17SingleGameSectioni .4byte - onMovieStart__Q34Game10SingleGame5StateFPQ24Game17SingleGameSectionPQ24Game11MovieConfigUlUl - .4byte - onMovieDone__Q34Game10SingleGame15MainResultStateFPQ24Game17SingleGameSectionPQ24Game11MovieConfigUlUl - .4byte - onMovieCommand__Q34Game10SingleGame5StateFPQ24Game17SingleGameSectioni .4byte - onHoleIn__Q34Game10SingleGame5StateFPQ24Game17SingleGameSectionPQ34Game8ItemCave4Item - .4byte - onNextFloor__Q34Game10SingleGame5StateFPQ24Game17SingleGameSectionPQ34Game8ItemHole4Item - .4byte - onFountainReturn__Q34Game10SingleGame5StateFPQ24Game17SingleGameSectionPQ34Game15ItemBigFountain4Item - .4byte - on_section_fadeout__Q34Game10SingleGame5StateFPQ24Game17SingleGameSection - .4byte - on_demo_timer__Q34Game10SingleGame5StateFPQ24Game17SingleGameSectionUl - .global __vt__Q34Game6Result5TNode - __vt__Q34Game6Result5TNode: - .4byte 0 - .4byte 0 - .4byte __dt__Q34Game6Result5TNodeFv - .4byte getChildCount__Q24Game5DNodeFv - .global "__vt__46Delegate" - "__vt__46Delegate": - .4byte 0 - .4byte 0 - .4byte "invoke__46DelegateFv" - - .section .sbss # 0x80514D80 - 0x80516360 - .global lbl_80515BF8 - lbl_80515BF8: - .skip 0x4 - .global lbl_80515BFC - lbl_80515BFC: - .skip 0x4 - .global theTekiHeap - theTekiHeap: - .skip 0x8 - - .section .sdata2, "a" # 0x80516360 - 0x80520E40 - .global lbl_8051A038 - lbl_8051A038: - .4byte 0x00000000 - .global lbl_8051A03C - lbl_8051A03C: - .4byte 0x6D725F6C - .4byte 0x6F616400 - .4byte 0x00000000 -*/ +static JKRHeap* theTekiHeap; namespace Game { +namespace SingleGame { /* * --INFO-- * Address: 80219F48 * Size: 000150 */ -SingleGame::MainResultState::MainResultState() -{ - /* - stwu r1, -0x30(r1) - mflr r0 - lis r4, "__vt__Q24Game36FSMState"@ha - li r5, 0 - stw r0, 0x34(r1) - addi r0, r4, "__vt__Q24Game36FSMState"@l - lis r4, __vt__Q34Game10SingleGame5State@ha - stw r31, 0x2c(r1) - mr r31, r3 - addi r4, r4, __vt__Q34Game10SingleGame5State@l - stw r0, 0(r3) - li r0, 7 - lis r3, __vt__Q34Game10SingleGame15MainResultState@ha - stw r0, 4(r31) - addi r0, r3, __vt__Q34Game10SingleGame15MainResultState@l - addi r3, r31, 0x24 - stw r5, 8(r31) - stw r4, 0(r31) - stw r0, 0(r31) - bl __ct__Q34Game12ResultTexMgr3MgrFv - addi r3, r31, 0x68 - bl __ct__Q34Game6Result5TNodeFv - addi r3, r31, 0xcc - bl __ct__16DvdThreadCommandFv - li r3, 0xb0 - bl __nw__FUl - or. r0, r3, r3 - beq lbl_80219FC4 - li r4, 0 - bl __ct__10ControllerFQ210JUTGamePad8EPadPort - mr r0, r3 - -lbl_80219FC4: - stw r0, 0x18(r31) - li r3, 0x14 - bl __nw__FUl - cmplwi r3, 0 - beq lbl_8021A020 - lis r4, lbl_804C0654@ha - lis r5, __vt__9IDelegate@ha - addi r8, r4, lbl_804C0654@l - lis r4, "__vt__46Delegate"@ha - lwz r7, 0(r8) - addi r5, r5, __vt__9IDelegate@l - lwz r6, 4(r8) - addi r0, r4, "__vt__46Delegate"@l - lwz r4, 8(r8) - stw r7, 0x14(r1) - stw r5, 0(r3) - stw r0, 0(r3) - stw r31, 4(r3) - stw r7, 8(r3) - stw r6, 0xc(r3) - stw r6, 0x18(r1) - stw r4, 0x1c(r1) - stw r4, 0x10(r3) - -lbl_8021A020: - stw r3, 0xc8(r31) - li r3, 0x14 - bl __nw__FUl - cmplwi r3, 0 - beq lbl_8021A07C - lis r4, lbl_804C0660@ha - lis r5, __vt__9IDelegate@ha - addi r8, r4, lbl_804C0660@l - lis r4, "__vt__46Delegate"@ha - lwz r7, 0(r8) - addi r5, r5, __vt__9IDelegate@l - lwz r6, 4(r8) - addi r0, r4, "__vt__46Delegate"@l - lwz r4, 8(r8) - stw r7, 8(r1) - stw r5, 0(r3) - stw r0, 0(r3) - stw r31, 4(r3) - stw r7, 8(r3) - stw r6, 0xc(r3) - stw r6, 0xc(r1) - stw r4, 0x10(r1) - stw r4, 0x10(r3) - -lbl_8021A07C: - stw r3, 0x13c(r31) - mr r3, r31 - lwz r0, 0x34(r1) - lwz r31, 0x2c(r1) - mtlr r0 - addi r1, r1, 0x30 - blr - */ -} - -/* - * --INFO-- - * Address: 8021A098 - * Size: 000060 - */ -Result::TNode::~TNode() +MainResultState::MainResultState() + : State(SGS_MainResult) { - /* - stwu r1, -0x10(r1) - mflr r0 - stw r0, 0x14(r1) - stw r31, 0xc(r1) - mr r31, r4 - stw r30, 8(r1) - or. r30, r3, r3 - beq lbl_8021A0DC - lis r5, __vt__Q34Game6Result5TNode@ha - li r4, 0 - addi r0, r5, __vt__Q34Game6Result5TNode@l - stw r0, 0(r30) - bl __dt__Q24Game5DNodeFv - extsh. r0, r31 - ble lbl_8021A0DC - mr r3, r30 - bl __dl__FPv - -lbl_8021A0DC: - lwz r0, 0x14(r1) - mr r3, r30 - lwz r31, 0xc(r1) - lwz r30, 8(r1) - mtlr r0 - addi r1, r1, 0x10 - blr - */ + mControl = new Controller(Controller::PORT_0); + mLoadDelegate = new Delegate(this, loadResource); + mBeforeSaveDelegate = new Delegate(this, beforeSave); } /* @@ -262,80 +37,27 @@ Result::TNode::~TNode() * Address: 8021A0F8 * Size: 000104 */ -void SingleGame::MainResultState::init(Game::SingleGameSection*, Game::StateArg*) +void MainResultState::init(SingleGameSection* game, StateArg* arg) { - /* - .loc_0x0: - stwu r1, -0x10(r1) - mflr r0 - stw r0, 0x14(r1) - stw r31, 0xC(r1) - mr r31, r4 - stw r30, 0x8(r1) - mr r30, r3 - mr r3, r31 - lwz r5, -0x6C18(r13) - lbz r0, 0x3C(r5) - ori r0, r0, 0x4 - stb r0, 0x3C(r5) - stw r31, 0x138(r30) - lwz r12, 0x0(r31) - lwz r12, 0xC8(r12) - mtctr r12 - bctrl - lwz r5, -0x6B70(r13) - mr r3, r30 - mr r4, r31 - li r6, 0 - lwz r31, 0xE8(r5) - lwz r5, 0xB4(r5) - bl -0xC7BCC - lwz r3, -0x6B70(r13) - addi r4, r30, 0xCC - stw r31, 0xE8(r3) - lwz r3, -0x6514(r13) - lwz r5, 0xC8(r30) - bl 0x208DCC - li r0, 0 - sth r0, 0x10(r30) - stw r0, 0xC0(r30) - lwz r3, -0x6B70(r13) - stb r0, 0x20(r3) - lwz r3, -0x6D20(r13) - bl -0xBEF98 - lwz r3, -0x6E20(r13) - bl -0x10C5A0 - lwz r0, -0x6E28(r13) - stw r3, -0x6A80(r13) - cmplwi r0, 0 - beq- .loc_0xB4 - mr r3, r0 - bl -0xF5B24 - - .loc_0xB4: - lwz r3, -0x6D20(r13) - lwz r12, 0x0(r3) - lwz r12, 0x98(r12) - mtctr r12 - bctrl - lwz r3, -0x6BC8(r13) - bl -0x34F80 - lwz r4, -0x6CE0(r13) - cmplwi r4, 0 - beq- .loc_0xE0 - addi r4, r4, 0x1C - - .loc_0xE0: - lwz r3, -0x6C18(r13) - bl -0x641E4 - stw r3, 0xC4(r30) - lwz r0, 0x14(r1) - lwz r31, 0xC(r1) - lwz r30, 0x8(r1) - mtlr r0 - addi r1, r1, 0x10 - blr - */ + gameSystem->mFlags |= GAMESYS_Unk3; + mGameSect = game; + game->startFadeblack(); + + int money = playData->mPokoCount; + accountEarnings(game, playData->mMainCropMemory, false); + playData->mPokoCount = money; + sys->dvdLoadUseCallBack(&mDvdThread, mLoadDelegate); + mStatus = 0; + mMainHeap = nullptr; + playData->mDeadNaviID = 0; + naviMgr->clearDeadCount(); + theTekiHeap = generalEnemyMgr->useHeap(); + if (Farm::farmMgr) { + Farm::farmMgr->initAllFarmObjectNodes(); + } + naviMgr->killAll(); + itemMgr->killAllExceptOnyonMgr(); + mPelletMgr = gameSystem->detachObjectMgr_reuse(pelletMgr); } /* @@ -343,64 +65,25 @@ void SingleGame::MainResultState::init(Game::SingleGameSection*, Game::StateArg* * Address: 8021A1FC * Size: 000024 */ -void SingleGame::MainResultState::beforeSave() -{ - /* - stwu r1, -0x10(r1) - mflr r0 - stw r0, 0x14(r1) - lwz r3, playData__4Game@sda21(r13) - bl setPikminCounts_Yesterday__Q24Game8PlayDataFv - lwz r0, 0x14(r1) - mtlr r0 - addi r1, r1, 0x10 - blr - */ -} +void MainResultState::beforeSave() { playData->setPikminCounts_Yesterday(); } /* * --INFO-- * Address: 8021A220 * Size: 000088 */ -void SingleGame::MainResultState::loadResource() +void MainResultState::loadResource() { - /* - stwu r1, -0x20(r1) - mflr r0 - li r5, 0 - stw r0, 0x24(r1) - li r0, -1 - addi r4, r1, 8 - stw r31, 0x1c(r1) - mr r31, r3 - addi r3, r31, 0x24 - stw r5, 0x10(r1) - lwz r7, theTekiHeap@sda21(r13) - stw r5, 0xc(r1) - lwz r6, mgr__Q24Game13PelletOtakara@sda21(r13) - stw r5, 8(r1) - lwz r5, mgr__Q24Game10PelletItem@sda21(r13) - stb r0, 0x14(r1) - stw r7, 0x10(r1) - lwz r0, 8(r6) - stw r0, 8(r1) - lwz r0, 8(r5) - stw r0, 0xc(r1) - stw r7, 0xc0(r31) - bl create__Q34Game12ResultTexMgr3MgrFRQ34Game12ResultTexMgr3Arg - mr r3, r31 - bl createResultNodes__Q34Game10SingleGame15MainResultStateFv - lwz r3, particleMgr@sda21(r13) - bl killAll__11ParticleMgrFv - lwz r3, shadowMgr__4Game@sda21(r13) - bl killAll__Q24Game9ShadowMgrFv - lwz r0, 0x24(r1) - lwz r31, 0x1c(r1) - mtlr r0 - addi r1, r1, 0x20 - blr - */ + ResultTexMgr::Arg arg; + arg.mHeap = theTekiHeap; + arg.mOtakaraConfigList = PelletOtakara::mgr->mConfigList; + arg.mItemConfigList = PelletItem::mgr->mConfigList; + + mMainHeap = theTekiHeap; + mResultTex.create(arg); + createResultNodes(); + particleMgr->killAll(); + shadowMgr->killAll(); } /* @@ -408,7 +91,7 @@ void SingleGame::MainResultState::loadResource() * Address: ........ * Size: 000148 */ -unknown SingleGame::MainResultState::open2D(Game::SingleGameSection*) +unknown MainResultState::open2D(SingleGameSection* game) { // UNUSED FUNCTION } @@ -418,8 +101,93 @@ unknown SingleGame::MainResultState::open2D(Game::SingleGameSection*) * Address: 8021A2A8 * Size: 0003E8 */ -void SingleGame::MainResultState::exec(Game::SingleGameSection*) +void MainResultState::exec(SingleGameSection* game) { + switch (mStatus) { + case 0: + if (mDvdThread.mMode == 2) { + mStatus = 2; + MoviePlayArg arg("s02_dayend_result", nullptr, game->mMovieFinishCallback, 0); + moviePlayer->play(arg); + gameSystem->setPause(false, "mr_load", 3); + mCounter = 0; + } + game->BaseHIOSection::doUpdate(); + break; + case 1: + mStartTimer -= sys->mDeltaTime; + if (mStartTimer < 0.0f) + mStatus = 3; + break; + case 2: + if (mCounter++ >= 199 || mControl->getButtonDown() & Controller::PRESS_A) { + mStatus = 3; + playData->clearCurrentCave(); + playData->setSaveFlag(1, mBeforeSaveDelegate); + int pokos = playData->mPokoCount; + kh::Screen::MailCategory mailtype; + if (pokos < 3000) { + mailtype = kh::Screen::PokoUnder3000; + } else if (pokos < 5000) { + mailtype = kh::Screen::PokoUnder5000; + } else if (pokos < 8000) { + mailtype = kh::Screen::PokoUnder8000; + } else if (pokos < 10000) { + mailtype = kh::Screen::PokoUnder10000; + } else if (playData->mStoryFlags & STORY_AllTreasuresCollected) { + mailtype = kh::Screen::AllTreasures; + } else if (playData->mStoryFlags & STORY_LouieRescued) { + mailtype = kh::Screen::SavedLouie; + } else { + mailtype = kh::Screen::PayDebt; + } + + kh::Screen::DispDayEndResult disp(&mResultNode, playData->mTreasureCount, pokos, playData->mStoryFlags & STORY_DebtPaid, mIncP, + theTekiHeap, mailtype); + Screen::gGame2DMgr->open_DayEndResult(disp); + } + break; + case 3: + switch (Screen::gGame2DMgr->check_DayEndResult()) { + case 1: + moviePlayer->unsuspend(1, false); + break; + case 2: + moviePlayer->stop(); + game->clearHeap(); + transit(game, SGS_File, nullptr); + return; + break; + } + break; + case 4: + mStartTimer -= sys->mDeltaTime; + if (mStartTimer < 0.0f) { + game->clearHeap(); + FOREACH_NODE(Result::TNode, mResultNode.mChild, node) { } + transit(game, SGS_Select, nullptr); + return; + } + return; + } + ItemOnyon::mgr->doAnimation(); + ItemOnyon::mgr->doEntry(); + ItemOnyon::mgr->doSimulation(sys->mDeltaTime); + + Viewport* vp = sys->mGfx->mCurrentViewport; + SysShape::Model::setViewCalcModeInd(); + game->j3dSetView(vp, false); + moviePlayer->update(game->mControllerP1, nullptr); + if (particle2dMgr) { + particle2dMgr->update(); + } + if (particleMgr) { + particleMgr->update(); + } + Screen::gGame2DMgr->update(); + game->mLightMgr->update(); + game->BaseHIOSection::doUpdate(); + /* stwu r1, -0xc0(r1) mflr r0 @@ -725,23 +493,11 @@ lbl_8021A5B8 * Address: 8021A690 * Size: 000030 */ -void SingleGame::MainResultState::onMovieDone(Game::SingleGameSection*, Game::MovieConfig*, unsigned long, unsigned long) +void MainResultState::onMovieDone(SingleGameSection*, MovieConfig*, u32, u32) { - /* - .loc_0x0: - stwu r1, -0x10(r1) - mflr r0 - lfs f0, -0x4328(r2) - stw r0, 0x14(r1) - li r0, 0x4 - sth r0, 0x10(r3) - stfs f0, 0x14(r3) - bl 0x24CD8C - lwz r0, 0x14(r1) - mtlr r0 - addi r1, r1, 0x10 - blr - */ + mStatus = 4; + mStartTimer = 0.0f; + PSMCancelToPauseOffMainBgm(); } /* @@ -749,8 +505,60 @@ void SingleGame::MainResultState::onMovieDone(Game::SingleGameSection*, Game::Mo * Address: 8021A6C0 * Size: 00035C */ -void SingleGame::MainResultState::createResultNodes() +void MainResultState::createResultNodes() { + JKRHeap* backup = JKRGetCurrentHeap(); + mMainHeap->becomeCurrentHeap(); + + KindCounter* counter = &playData->mMainCropMemory->mItem; + for (int i = 0; i < counter->mNumKinds; i++) { + if (*counter->operator()(i)) { + PelletConfig* config = PelletItem::mgr->getPelletConfig(i); + int id = PelletList::Mgr::getOffsetFromDictionaryNo(config->mParams.mDictionary.mData - 1); + u64 tag = Result::TNode::convertByMorimun(id); + Result::TNode* node = new Result::TNode; + node->setTNode(tag, mResultTex.getItemTexture(i), *counter->operator()(i), + config->mParams.mMoney.mData * *counter->operator()(i), config->mParams.mMoney.mData); + mResultNode.add(node); + playData->mTreasureCount += *counter->operator()(i); + } + } + + counter = &playData->mMainCropMemory->mOtakara; + for (int i = 0; i < counter->mNumKinds; i++) { + if (*counter->operator()(i)) { + PelletConfig* config = PelletOtakara::mgr->getPelletConfig(i); + int id = PelletList::Mgr::getOffsetFromDictionaryNo(config->mParams.mDictionary.mData - 1); + u64 tag = Result::TNode::convertByMorimun(id); + Result::TNode* node = new Result::TNode; + node->setTNode(tag, mResultTex.getItemTexture(i), *counter->operator()(i), + config->mParams.mMoney.mData * *counter->operator()(i), config->mParams.mMoney.mData); + mResultNode.add(node); + playData->mTreasureCount += *counter->operator()(i); + } + } + + int num = 0; + int money = 0; + counter = &playData->mMainCropMemory->mCarcass; + for (int i = 0; i < counter->mNumKinds; i++) { + if (*counter->operator()(i)) { + PelletConfig* config = PelletOtakara::mgr->getPelletConfig(i); + num += *counter->operator()(i); + money += *counter->operator()(i) * config->mParams.mMoney.mData; + } + } + if (num > 0) { + playData->mTreasureCount += num; + Result::TNode* node = new Result::TNode; + node->setTNode(0, mResultTex.getCarcassTexture(), num, money, -1); + mResultNode.add(node); + } + playData->mMainCropMemory->clear(); + mIncP = new kh::Screen::IncP; + _1C = 0; + Screen::gGame2DMgr->setGamePad(mControl); + backup->becomeCurrentHeap(); /* stwu r1, -0x40(r1) mflr r0 @@ -1003,51 +811,14 @@ void SingleGame::MainResultState::createResultNodes() * Address: 8021AA1C * Size: 000094 */ -void SingleGame::MainResultState::draw(Game::SingleGameSection*, Graphics&) +void MainResultState::draw(SingleGameSection* game, Graphics& gfx) { - /* - stwu r1, -0x10(r1) - mflr r0 - stw r0, 0x14(r1) - stw r31, 0xc(r1) - mr r31, r5 - stw r30, 8(r1) - mr r30, r4 - lhz r0, 0x10(r3) - cmplwi r0, 2 - beq lbl_8021AA54 - cmplwi r0, 3 - beq lbl_8021AA54 - cmplwi r0, 4 - bne lbl_8021AA98 - -lbl_8021AA54: - lwz r3, cameraMgr__4Game@sda21(r13) - bl update__Q24Game9CameraMgrFv - mr r3, r30 - mr r4, r31 - lwz r12, 0(r30) - lwz r12, 0x10c(r12) - mtctr r12 - bctrl - lwz r3, moviePlayer__4Game@sda21(r13) - mr r4, r31 - bl drawLoading__Q24Game11MoviePlayerFR8Graphics - mr r3, r30 - mr r4, r31 - lwz r12, 0(r30) - lwz r12, 0x110(r12) - mtctr r12 - bctrl - -lbl_8021AA98: - lwz r0, 0x14(r1) - lwz r31, 0xc(r1) - lwz r30, 8(r1) - mtlr r0 - addi r1, r1, 0x10 - blr - */ + if (mStatus == 2 || mStatus == 3 || mStatus == 4) { + cameraMgr->update(); + game->draw3D(gfx); + moviePlayer->drawLoading(gfx); + game->draw2D(gfx); + } } /* @@ -1055,186 +826,16 @@ void SingleGame::MainResultState::draw(Game::SingleGameSection*, Graphics&) * Address: 8021AAB0 * Size: 00007C */ -void SingleGame::MainResultState::cleanup(Game::SingleGameSection*) +void MainResultState::cleanup(SingleGameSection* game) { - /* - stwu r1, -0x10(r1) - mflr r0 - stw r0, 0x14(r1) - stw r31, 0xc(r1) - mr r31, r3 - lwz r4, gGame2DMgr__6Screen@sda21(r13) - lwz r3, 0x18(r4) - lwz r12, 0(r3) - lwz r12, 0x18(r12) - mtctr r12 - bctrl - lwz r3, playData__4Game@sda21(r13) - lwz r3, 0xb4(r3) - bl clear__Q24Game16PelletCropMemoryFv - lwz r4, 0xc4(r31) - cmplwi r4, 0 - beq lbl_8021AAFC - lwz r3, gameSystem__4Game@sda21(r13) - bl -"addObjectMgr_reuse__Q24Game10GameSystemFP31TObjectNode<16GenericObjectMgr>" - -lbl_8021AAFC: - lwz r3, 0x138(r31) - li r0, 0 - stw r0, 0x168(r3) - lwz r3, gameSystem__4Game@sda21(r13) - lbz r0, 0x3c(r3) - rlwinm r0, r0, 0, 0x1e, 0x1c - stb r0, 0x3c(r3) - lwz r0, 0x14(r1) - lwz r31, 0xc(r1) - mtlr r0 - addi r1, r1, 0x10 - blr - */ + Screen::gGame2DMgr->mScreenMgr->reset(); + playData->mMainCropMemory->clear(); + if (mPelletMgr) { + gameSystem->addObjectMgr_reuse(mPelletMgr); + } + mGameSect->_168 = nullptr; + gameSystem->resetFlag(GAMESYS_Unk3); } +} // namespace SingleGame } // namespace Game - -namespace kh { -namespace Screen { - -/* - * --INFO-- - * Address: 8021AB2C - * Size: 000008 - */ -u32 DispDayEndResultTitl::getSize() { return 0x8; } - -/* - * --INFO-- - * Address: 8021AB34 - * Size: 000008 - */ -u32 DispDayEndResultTitl::getOwnerID() { return 0x4B48; } - -/* - * --INFO-- - * Address: 8021AB3C - * Size: 000014 - */ -void DispDayEndResultTitl::getMemberID() -{ - /* -lis r4, 0x5449544C@ha -lis r3, 0x4445525F@ha -addi r4, r4, 0x5449544C@l -addi r3, r3, 0x4445525F@l -blr - */ -} - -/* - * --INFO-- - * Address: 8021AB50 - * Size: 000008 - */ -u32 DispDayEndResult::getSize() { return 0x68; } - -/* - * --INFO-- - * Address: 8021AB58 - * Size: 000008 - */ -u32 DispDayEndResult::getOwnerID() { return 0x4B48; } - -/* - * --INFO-- - * Address: 8021AB60 - * Size: 000014 - */ -void DispDayEndResult::getMemberID() -{ - /* -lis r4, 0x52534C54@ha -lis r3, 0x0044455F@ha -addi r4, r4, 0x52534C54@l -addi r3, r3, 0x0044455F@l -blr - */ -} - -/* - * --INFO-- - * Address: 8021AB74 - * Size: 000054 - */ -void DispDayEndResult::doSetSubMemberAll() -{ - /* -stwu r1, -0x10(r1) -mflr r0 -stw r0, 0x14(r1) -stw r31, 0xc(r1) -mr r31, r3 -addi r4, r31, 8 -bl setSubMember__Q32og6Screen14DispMemberBaseFPQ32og6Screen14DispMemberBase -mr r3, r31 -addi r4, r31, 0x10 -bl setSubMember__Q32og6Screen14DispMemberBaseFPQ32og6Screen14DispMemberBase -mr r3, r31 -addi r4, r31, 0x34 -bl setSubMember__Q32og6Screen14DispMemberBaseFPQ32og6Screen14DispMemberBase -mr r3, r31 -addi r4, r31, 0x44 -bl setSubMember__Q32og6Screen14DispMemberBaseFPQ32og6Screen14DispMemberBase -lwz r0, 0x14(r1) -lwz r31, 0xc(r1) -mtlr r0 -addi r1, r1, 0x10 -blr - */ -} - -} // namespace Screen -} // namespace kh - -/* - * --INFO-- - * Address: 8021ABC8 - * Size: 000030 - */ -void Delegate::invoke() -{ - /* - stwu r1, -0x10(r1) - mflr r0 - mr r4, r3 - stw r0, 0x14(r1) - addi r12, r4, 8 - lwz r3, 4(r3) - bl __ptmf_scall - nop - lwz r0, 0x14(r1) - mtlr r0 - addi r1, r1, 0x10 - blr - */ -} - -/* - * --INFO-- - * Address: 8021ABF8 - * Size: 000028 - */ -void __sinit_singleGS_MainResult_cpp() -{ - /* - lis r4, __float_nan@ha - li r0, -1 - lfs f0, __float_nan@l(r4) - lis r3, lbl_804C0648@ha - stw r0, lbl_80515BF8@sda21(r13) - stfsu f0, lbl_804C0648@l(r3) - stfs f0, lbl_80515BFC@sda21(r13) - stfs f0, 4(r3) - stfs f0, 8(r3) - blr - */ -}