From b06d60c503f3432c2291c28c6877cfb44165a71d Mon Sep 17 00:00:00 2001 From: HeartPiece Date: Sat, 18 May 2024 00:08:26 +1000 Subject: [PATCH] assorted kono progress --- docs/recommended_todo.md | 6 +- include/JSystem/JGeometry.h | 2 + include/kh/khDayEndResult.h | 35 ++++++++---- include/kh/khUtil.h | 6 ++ src/plugProjectKonoU/khDayEndResult.cpp | 30 +++++----- src/plugProjectKonoU/khWorldMap.cpp | 75 +++++++++++-------------- 6 files changed, 87 insertions(+), 67 deletions(-) diff --git a/docs/recommended_todo.md b/docs/recommended_todo.md index 0a3a8892a..2a117ac7b 100644 --- a/docs/recommended_todo.md +++ b/docs/recommended_todo.md @@ -102,7 +102,7 @@ | File | Size (bytes) | File | Size (bytes) | | ---- | ---- | ---- | ---- | | khCaveResult.cpp | 42208 | khFinalResult.cpp | 59951 | -| khDayEndResult.cpp | 81577 | khWorldMap.cpp | 157461 | +| khDayEndResult.cpp | 81617 | khWorldMap.cpp | 157286 | ###
plugProjectMorimuraU
| File | Size (bytes) | File | Size (bytes) | @@ -137,7 +137,7 @@ | SaraiState.cpp | 27370 | MarState.cpp | 28356 | | FrogState.cpp | 30811 | SnakeCrowState.cpp | 32065 | | HanachirashiState.cpp | 32837 | KabutoState.cpp | 32923 | -| TankState.cpp | 33068 | playCamera.cpp | 33631 | +| TankState.cpp | 33069 | playCamera.cpp | 33631 | | ShadowCylinder.cpp | 36098 | BombSaraiState.cpp | 36432 | | RandMapScore.cpp | 37034 | DangoMushi.cpp | 37037 | | Hanachirashi.cpp | 39557 | SnakeCrow.cpp | 39739 | @@ -161,7 +161,7 @@ | ---- | ---- | ---- | ---- | | enemyStoneDrawInfo.cpp | 19376 | singleGS_ZukanParms.cpp | 22080 | | vtxAnm.cpp | 31268 | enemyAction.cpp | 51416 | -| kochappyState.cpp | 65627 | gameLightMgr.cpp | 74592 | +| kochappyState.cpp | 65638 | gameLightMgr.cpp | 74592 | | chappyState.cpp | 76099 | | | ###
sysBootupU
diff --git a/include/JSystem/JGeometry.h b/include/JSystem/JGeometry.h index 1d3ba96c5..94fc2caa0 100644 --- a/include/JSystem/JGeometry.h +++ b/include/JSystem/JGeometry.h @@ -145,6 +145,8 @@ struct TVec2 { return dist; } + f32 dot(const TVec2& other) const { return x * other.x + y * other.y; } + bool isAbove(const TVec2& other) const { return (x >= other.x) && (y >= other.y) ? true : false; } bool isZero() const { return squared() <= 32.0f * FLT_EPSILON; } diff --git a/include/kh/khDayEndResult.h b/include/kh/khDayEndResult.h index d471abc14..c3733036c 100644 --- a/include/kh/khDayEndResult.h +++ b/include/kh/khDayEndResult.h @@ -34,6 +34,8 @@ enum MailCategory { }; union MailSaveFlags { + inline u8 getReverseByte(int i) { return byteView[15 - i]; } + u32 typeView[4]; u8 byteView[16]; }; @@ -652,29 +654,42 @@ struct SceneDayEndResultItem : public ::Screen::SceneBase { // TODO: work out if this has extra members }; +struct MailTableDataEntry { + u64 mMessageID; // _00 + u8 mFlag[4]; // _08 + const char mFileName[0]; // _0C +}; + struct MailTableData { - MailTableData(MailTableData* data, MailSaveFlags& flags, int i) + MailTableData(MailTableDataEntry* data, MailSaveFlags& flags, int i) { + u8 bit = flags.getReverseByte(i >> 3); + int shift = (i - (int(i >> 3) << 3)); mMessageID = data->mMessageID; mFlag[0] = data->mFlag[0]; mFlag[1] = data->mFlag[1]; mFlag[2] = data->mFlag[2]; - mFileName = data->mFileName; - int byte = i >> 3; - mSaveFlag = bool(flags.byteView[15 - byte] & (1 << (i - (byte << 3)))); + mFileName = (const char*)&data->mFileName; + mSaveFlag = ((1 << shift) & bit) != 0; + } + + inline u32 calcSaveFlag(MailSaveFlags& flags, int i) + { + u32 cleared = (i >> 3); + return (1 << (i - (cleared << 3))) & flags.byteView[15 - (i >> 3)]; } inline const char* getFileName() { return mFileName; } - u64 mMessageID; // _00 - u8 mFlag[3]; // _08 - char* mFileName; // _0C - u8 mSaveFlag; // _10 + u64 mMessageID; // _00 + u8 mFlag[3]; // _08 + const char* mFileName; // _0C + u8 mSaveFlag; // _10 }; struct MailTableFile { - int mEntries; // _00 - MailTableData** mData; // _04, might be double pointer + int mEntries; // _00 + MailTableDataEntry** mData; // _04 }; struct SceneDayEndResultMail : public ::Screen::SceneBase { diff --git a/include/kh/khUtil.h b/include/kh/khUtil.h index 5863a407d..8f76727ec 100644 --- a/include/kh/khUtil.h +++ b/include/kh/khUtil.h @@ -102,6 +102,12 @@ struct khUtilColorAnm : public P2DScreen::CallBackNode { inline void setColor(JUtility::TColor color, int id) { mColorList[id] = color; } inline void setDisabledColor(JUtility::TColor color) { mDisabledColor = color; } + inline void reset() + { + mColor = mColorList[0]; + mFrame = 0; + } + // _00 = VTBL // _00-_1C = P2DScreen::Node JUtility::TColor* mColorList; // _1C diff --git a/src/plugProjectKonoU/khDayEndResult.cpp b/src/plugProjectKonoU/khDayEndResult.cpp index c61d0f7e0..cc57f2e85 100644 --- a/src/plugProjectKonoU/khDayEndResult.cpp +++ b/src/plugProjectKonoU/khDayEndResult.cpp @@ -2343,30 +2343,34 @@ void SceneDayEndResultMail::doUserCallBackFunc(Resource::MgrCommand* mgr) JUT_PANICLINE(2674, "failed"); } + // problem is from here int offset = 4; MailSaveFlags saveFlags = Game::playData->mMailSaveData.mPastLogs; u32 entries = file->mEntries; mTableData = new MailTableData*[entries]; for (int i = 0; i < entries; i++) { - mTableData[i] = new MailTableData(file[offset].mData[0], saveFlags, i); + mTableData[i] + = new MailTableData(reinterpret_cast((u8*)file + offset), saveFlags, i); // this is the main issue int fileNameLen = 0; for (u8* ptr = (u8*)mTableData[i]->mFileName; *ptr; ptr++, fileNameLen++) { ; } offset += (fileNameLen + 16) & ~0x3; } + // to here if (!getDispMember()->isID(OWNER_KH, MEMBER_DAY_END_RESULT)) { JUT_PANICLINE(2690, "disp member err"); } - DispDayEndResult* dispResult = static_cast(getDispMember()); - if (dispResult->mMail.mHeap && !dispResult->mMail.mBackupHeap) { - dispResult->mMail.mBackupHeap = makeSolidHeap(-1, dispResult->mMail.mHeap, false); - int mailID = -1; + int mailID; + DispDayEndResultMail& dispResult = static_cast(getDispMember())->mMail; + if (dispResult.mHeap && !dispResult.mBackupHeap) { + dispResult.mBackupHeap = makeSolidHeap(-1, dispResult.mHeap, false); + mailID = -1; for (int i = 0; i < entries; i++) { - if (dispResult->mMail.mMailCategory != mTableData[i]->mFlag[0]) { + if (dispResult.mMailCategory != mTableData[i]->mFlag[0]) { continue; } @@ -2379,7 +2383,7 @@ void SceneDayEndResultMail::doUserCallBackFunc(Resource::MgrCommand* mgr) JUT_ASSERTLINE(2710, mailID != -1, "error"); for (int i = 0; i < entries; i++) { - if (dispResult->mMail.mMailCategory != mTableData[i]->mFlag[0]) { + if (dispResult.mMailCategory != mTableData[i]->mFlag[0]) { continue; } if (!mTableData[i]->mSaveFlag || (s8)mTableData[i]->mFlag[1] < 0) { @@ -2391,20 +2395,20 @@ void SceneDayEndResultMail::doUserCallBackFunc(Resource::MgrCommand* mgr) } } - dispResult->mMail.mTodayMailID = mailID; + dispResult.mTodayMailID = mailID; - if (dispResult->mMail.mTodayMailID < 128) { - int byte = dispResult->mMail.mTodayMailID >> 3; - saveFlags.byteView[15 - byte] |= (1 << (dispResult->mMail.mTodayMailID - (byte << 3))); + if (dispResult.mTodayMailID < 128) { + int byte = dispResult.mTodayMailID >> 3; + saveFlags.byteView[15 - byte] |= (1 << (dispResult.mTodayMailID - (byte << 3))); } Game::playData->mMailSaveData.mPastLogs = saveFlags; - Game::playData->mMailSaveData.set_history(dispResult->mMail.mTodayMailID); + Game::playData->mMailSaveData.set_history(dispResult.mTodayMailID); mMailFlags = Game::playData->mMailSaveData.mHistory; LoadResource::Arg iconArg("/user/Koono/mail_icon.szs"); - iconArg.mHeap = dispResult->mMail.mBackupHeap; + iconArg.mHeap = dispResult.mBackupHeap; LoadResource::Node* iconNode = gLoadResourceMgr->mountArchive(iconArg); if (iconNode) { mIconArchive = static_cast(iconNode->mArchive); diff --git a/src/plugProjectKonoU/khWorldMap.cpp b/src/plugProjectKonoU/khWorldMap.cpp index e59372c49..bb21c99aa 100644 --- a/src/plugProjectKonoU/khWorldMap.cpp +++ b/src/plugProjectKonoU/khWorldMap.cpp @@ -783,21 +783,18 @@ void WorldMap::update(::Game::WorldMap::UpdateArg& arg) mRocketAngle = JGeometry::TVec2f(temp.x * x - temp.y * y, temp.x * y + temp.y * x); f32 angle = mRocketAngle.squared(); mRocketAngle.normalize(); - // f32 angle = mRocketAngle.x * mRocketAngle.x + mRocketAngle.y + mRocketAngle.y; - // if (angle > FLT_EPSILON) { - // mRocketAngle = angle; - // } - Vector2f rot; + getRotDir(temp, 0.0f); mRocketPosition.x += msVal._04 * (mRocketAngle.x * msVal._00); mRocketPosition.y += msVal._04 * (mRocketAngle.y * msVal._00); + // this is the regswap JGeometry::TVec2f vec(getPaneCenterX(cPointPane) - mRocketPosition.x, getPaneCenterY(cPointPane) - mRocketPosition.y); f32 dist = vec.x * vec.x + vec.y + vec.y; // is this a typo? if (!isFlag(WMAPFLAG_Unk4)) { vec.normalize(); - if (vec.x * mRocketAngle.x + vec.y * mRocketAngle.y > 0.7f) { - // resetFlag(WMAPFLAG_Unk2); + if (vec.dot(mRocketAngle) > 0.7f) { + if (!isFlag(WMAPFLAG_Unk1)) { setFlag(WMAPFLAG_Unk1 | WMAPFLAG_Unk2); } else if (!isFlag(WMAPFLAG_Unk2)) { @@ -981,7 +978,7 @@ void WorldMap::update(::Game::WorldMap::UpdateArg& arg) break; } - case WMAP_Unk10: { // UP TO HERE + case WMAP_Unk10: { f32 angle = pikmin2_atan2f(mRocketAngle.x, -mRocketAngle.y); if (mRocketAngleMode == ROT_Unk1 && angle > 0.0f) { @@ -996,17 +993,14 @@ void WorldMap::update(::Game::WorldMap::UpdateArg& arg) mRocketAngle.x = pikmin2_sinf(angle); mRocketAngle.y = -pikmin2_cosf(angle); - // dumb shit here - f32 dist = mRocketAngle.squared(); - if (!mRocketAngle.isZero()) { - f32 mod = sqrtf(dist); - dist = mod / 2 * -(dist * mod - 3.0f); - mRocketAngle.scale(dist); - } - mRocketPosition.add(msVal._04 * mRocketAngle.x * msVal._00, msVal._04 * mRocketAngle.y * msVal._00); + mRocketAngle.normalize(); - f32 zero = 0.0f; - if (mRocketAngle.x * zero + mRocketAngle.y * -1.0f > 0.95f) { + mRocketPosition.x += msVal._04 * (mRocketAngle.x * msVal._00); + mRocketPosition.y += msVal._04 * (mRocketAngle.y * msVal._00); + + JGeometry::TVec2f vec(0.0f, -1.0f); + f32 downComponent = vec.x * mRocketAngle.x + vec.y * mRocketAngle.y; + if (downComponent > 0.95f) { if (!isFlag(WMAPFLAG_Unk1)) { setFlag(WMAPFLAG_Unk1 | WMAPFLAG_Unk2); } else if (!isFlag(WMAPFLAG_Unk2)) { @@ -1019,8 +1013,7 @@ void WorldMap::update(::Game::WorldMap::UpdateArg& arg) mScreenInfo->search('Nlwin')->show(); if (!mInitArg.mDoNewEntriesEfx) { - Vector2f efxPos2(getPaneCenterX(target) + msVal._50[0].x, getPaneCenterY(target) + msVal._50[0].y); - efx2d::Arg arg(efxPos2); + efx2d::Arg arg(Vector2f(getPaneCenterX(target) + msVal._50[0].x, getPaneCenterY(target) + msVal._50[0].y)); efx2d::T2DChangesmoke efx; efx.create(&arg); } @@ -1031,16 +1024,16 @@ void WorldMap::update(::Game::WorldMap::UpdateArg& arg) mScreenInfo->search('Nrwin')->show(); if (!mInitArg.mDoNewEntriesEfx) { - Vector2f efxPos2(getPaneCenterX(target) + msVal._50[0].x, getPaneCenterY(target) + msVal._50[0].y); - efx2d::Arg arg(efxPos2); + // Vector2f efxPos2(getPaneCenterX(target) + msVal._50[0].x, getPaneCenterY(target) + msVal._50[0].y); + efx2d::Arg arg(Vector2f(getPaneCenterX(target) + msVal._50[1].x, getPaneCenterY(target) + msVal._50[1].y)); efx2d::T2DChangesmoke efx; efx.create(&arg); } } if (mInitArg.mHasNewPiklopediaEntries || mInitArg.mHasNewTreasureHoardEntries) { khUtilColorAnm* anm = mColorAnim2; - anm->mColor = anm->mColorList[0]; - anm->mFrame = 0; + mColorAnim2->reset(); + if (!mInitArg.mDoNewEntriesEfx) { mScaleMgr->up(); PSSystem::spSysIF->playSystemSe(PSSE_SY_WMAP_ZUKAN_NEW, 0); @@ -1060,7 +1053,7 @@ void WorldMap::update(::Game::WorldMap::UpdateArg& arg) for (int i = 0; i < mOnyonCount; i++) { mOnyonArray[i].mOnyonPane->setOffset(1000.0f, 0.0f); } - if (mRocketMoveCounter++ > 5) { + if (++mRocketMoveCounter > 5) { mCurrentCourseIndex = mInitArg.mInitialCourseIndex; if (mCurrentCourseIndex < 0) { mCurrentCourseIndex = 0; @@ -1071,13 +1064,15 @@ void WorldMap::update(::Game::WorldMap::UpdateArg& arg) mRocketPosition = Vector2f(getPaneCenterX(cPointPane), getPaneCenterY(cPointPane)); mRocketScale = 0.01f; paneRocket->setOffset(mRocketPosition.x, mRocketPosition.y); - paneRocket->setAngle(TODEGREES(JMAAtan2Radian(-mRocketAngle.x, -mRocketAngle.y))); + f32 atanVal = JMAAtan2Radian(-mRocketAngle.x, -mRocketAngle.y) * JMath::TAngleConstant_::RADIAN_TO_DEGREE_FACTOR(); + paneRocket->setAngle(atanVal); paneRocket->updateScale(mRocketScale); for (int i = 0; i < mOnyonCount; i++) { mOnyonArray[i].mOffset = mRocketPosition; mOnyonArray[i].mAngle.set(mRocketAngle); mOnyonArray[i].mOnyonPane->setOffset(mRocketPosition.x, mRocketPosition.y); - mOnyonArray[i].mOnyonPane->setAngle(TODEGREES(JMAAtan2Radian(-mRocketAngle.x, -mRocketAngle.y))); + f32 atanVal = JMAAtan2Radian(-mRocketAngle.x, -mRocketAngle.y) * JMath::TAngleConstant_::RADIAN_TO_DEGREE_FACTOR(); + mOnyonArray[i].mOnyonPane->setAngle(atanVal); mOnyonArray[i].mOnyonPane->updateScale(mRocketScale); } mRocketMoveCounter = 0; @@ -3246,15 +3241,13 @@ f32 WorldMap::rocketMove(J2DPane* pane, bool flag) angle.x = mRocketAngle.x; angle.y = mRocketAngle.y; JGeometry::TVec2f pos(getPaneCenterX(pane) - mRocketPosition.x, getPaneCenterY(pane) - mRocketPosition.y); - f32 otherFactor = msVal._4C; + f32 dist = pos.x * pos.x + pos.y * pos.y; f32 factor = msVal._08; - int num = (mRocketMoveCounter - 86) / 5; - f32 dist = pos.squared(); + f32 otherFactor = msVal._4C; - if (mRocketMoveCounter > 90) { - for (int i = mRocketMoveCounter; i < 90; i++) { - factor *= 0.99f; - } + // something weird going on here + for (int i = mRocketMoveCounter; i > 90; i--) { + factor *= 0.99f; } pos.normalize(); @@ -3278,8 +3271,9 @@ f32 WorldMap::rocketMove(J2DPane* pane, bool flag) val2 += TAU; } + f32 phi; f32 theta = val3 * otherFactor + (val1 * factor + (val2 * (1.0f - factor))); - f32 phi = theta - val1; + phi = theta - val1; _B4.set(pikmin2_sinf(phi), -pikmin2_cosf(phi)); @@ -3550,8 +3544,7 @@ void WorldMap::rocketUpdate(J2DPane* pane) shipPane->setOffset(mRocketPosition.x, mRocketPosition.y); shipPane->setAngle(TODEGREES(JMAAtan2Radian(-mRocketAngle.x, -mRocketAngle.y))); - f32 scale = tag2num(pane->mMessageID); - mRocketScale *= msVal._08 + (1.0f - msVal._08) * scale; + mRocketScale = mRocketScale * msVal._08 + (1.0f - msVal._08) * tag2num(pane->mMessageID); f32 scale2 = msVal._1C[mOpenCourses] * mRocketScale; shipPane->updateScale(scale2); @@ -3569,13 +3562,13 @@ void WorldMap::rocketUpdate(J2DPane* pane) mEffectDir.x = -mRocketAngle.x; mEffectDir.y = -mRocketAngle.y; - efx2d::WorldMap::ArgDirScale arg(mEffectPos, mEffectDir, scale); + efx2d::WorldMap::ArgDirScale arg(mEffectPos, mEffectDir, scale2); efx2d::WorldMap::T2DRocketA efx; efx.mResMgrId = 1; efx.mGroup = 3; efx.create(&arg); - mEfxRocketSparks->setGlobalParticleScale(scale); - mEfxRocketGlow->setGlobalParticleScale(scale); + mEfxRocketSparks->setGlobalParticleScale(scale2); + mEfxRocketGlow->setGlobalParticleScale(scale2); /* stwu r1, -0x100(r1) @@ -4199,7 +4192,7 @@ void WorldMap::changeInfo() u64 tags2[4] = { '8396_01', '8398_01', '8401_01', '8410_01' }; // "Hole of Beasts" "White Flower Garden" "Bulblax Kingdom" "Snagret Hole" u64 tags3[4] = { '8397_01', '8402_01', '8403_01', - '8411_01' }; // "Citadel of Spiders" "Glutton's Kitchen" "Shower Room" "Submerged Castle" + '8411_01' }; // "Citadel of Spiders" "Glutton's Kitchen" "Shower Room" "Submerged Castle" u64 tags4[4] = { '8412_01', '8413_01', '8414_01', 'no_data' }; // "Cavern of Chaos" "Hole of Heroes" "Dream Den" u64* caveTags[4] = { tags1, tags2, tags3, tags4 };