resource: Add AchievementHolder

This commit is contained in:
MonsterDruide1 2021-10-23 23:52:19 +02:00
parent 4065262ee8
commit 73c9da076d
7 changed files with 279 additions and 14 deletions

View File

@ -22412,17 +22412,17 @@ Address,Quality,Size,Name
0x0000007100378258,U,000012,_ZN11TimeBalloon15isBalloonIdNoneEm
0x0000007100378264,O,000012,_ZN11AchievementC2EPK15AchievementInfo
0x0000007100378270,O,000036,_ZNK11Achievement5isGetE22GameDataHolderAccessor
0x0000007100378294,U,000012,_ZN17AchievementHolderC2Ev
0x00000071003782a0,U,000216,_ZN17AchievementHolder4initERKN2al13ActorInitInfoE
0x0000007100378378,U,000216,_ZN17AchievementHolder4initEv
0x0000007100378450,U,000040,_ZNK17AchievementHolder9isGetMoonEi22GameDataHolderAccessor
0x0000007100378478,U,000060,_ZNK17AchievementHolder9isAchieveEi22GameDataHolderAccessor
0x00000071003784b4,U,000200,_ZNK17AchievementHolder29getAchievementProgressCurrentEi22GameDataHolderAccessor
0x000000710037857c,U,000020,_ZNK17AchievementHolder25getAchievementProgressMaxEi22GameDataHolderAccessor
0x0000007100378590,U,001868,_ZNK17AchievementHolder32getAchievementProgressCurrentRowEi22GameDataHolderAccessor
0x0000007100378cdc,U,000128,_ZNK17AchievementHolder19calcAchieveTotalNumE22GameDataHolderAccessor
0x0000007100378d5c,U,000132,_ZNK17AchievementHolder19calcMoonGetTotalNumE22GameDataHolderAccessor
0x0000007100378de0,U,000184,_ZNK17AchievementHolder20tryGetNewAchievementE22GameDataHolderAccessor
0x0000007100378294,O,000012,_ZN17AchievementHolderC1Ev
0x00000071003782a0,O,000216,_ZN17AchievementHolder4initERKN2al13ActorInitInfoE
0x0000007100378378,O,000216,_ZN17AchievementHolder4initEv
0x0000007100378450,O,000040,_ZNK17AchievementHolder9isGetMoonEi22GameDataHolderAccessor
0x0000007100378478,O,000060,_ZNK17AchievementHolder9isAchieveEi22GameDataHolderAccessor
0x00000071003784b4,O,000200,_ZNK17AchievementHolder29getAchievementProgressCurrentEi22GameDataHolderAccessor
0x000000710037857c,O,000020,_ZNK17AchievementHolder25getAchievementProgressMaxEi22GameDataHolderAccessor
0x0000007100378590,O,001868,_ZNK17AchievementHolder32getAchievementProgressCurrentRowEi22GameDataHolderAccessor
0x0000007100378cdc,O,000128,_ZNK17AchievementHolder19calcAchieveTotalNumE22GameDataHolderAccessor
0x0000007100378d5c,O,000132,_ZNK17AchievementHolder19calcMoonGetTotalNumE22GameDataHolderAccessor
0x0000007100378de0,m,000184,_ZNK17AchievementHolder20tryGetNewAchievementE22GameDataHolderAccessor
0x0000007100378e98,O,000008,_ZN21AchievementInfoReaderC2Ev
0x0000007100378ea0,m,000508,_ZN21AchievementInfoReader4initEv
0x000000710037909c,O,000120,_ZNK21AchievementInfoReader18tryFindIndexByNameEPKc

Can't render this file because it is too large.

View File

@ -0,0 +1,31 @@
#pragma once
#include <basis/seadTypes.h>
#include <container/seadPtrArray.h>
#include "al/resource/GameDataHolderAccessor.h"
namespace al {
class ActorInitInfo;
}
class Achievement;
class AchievementInfoReader;
class AchievementHolder {
public:
AchievementHolder();
void init(const al::ActorInitInfo&);
void init();
bool isGetMoon(int, GameDataHolderAccessor) const;
bool isAchieve(int, GameDataHolderAccessor) const;
int getAchievementProgressCurrent(int, GameDataHolderAccessor) const;
int getAchievementProgressMax(int, GameDataHolderAccessor) const;
int getAchievementProgressCurrentRow(int, GameDataHolderAccessor) const;
int calcAchieveTotalNum(GameDataHolderAccessor) const;
int calcMoonGetTotalNum(GameDataHolderAccessor) const;
Achievement* tryGetNewAchievement(GameDataHolderAccessor) const;
private:
sead::PtrArray<Achievement> mArray;
AchievementInfoReader* mAchievementInfoReader = nullptr;
};

View File

@ -6,12 +6,12 @@
class AchievementInfo {
public:
AchievementInfo(const char* name, const char* note, int num, int level) : mName(name), mNote(note), mNum(num), mLevel(level) {}
AchievementInfo(const char* name, int num, int level, const char* note) : mName(name), mNum(num), mLevel(level), mNote(note) {}
const char* mName;
const char* mNote;
int mNum;
int mLevel;
const char* mNote;
};
class AchievementInfoReader {
@ -21,6 +21,16 @@ public:
void init();
int tryFindIndexByName(const char*) const;
AchievementInfo* get(int index) {
return array[index];
}
int size() {
return array.size();
}
int capacity() {
return array.capacity();
}
private:
sead::PtrArray<AchievementInfo> array;

View File

@ -14,5 +14,51 @@ namespace rs {
bool checkGetAchievement(GameDataHolderAccessor, const char*);
int calcClearWorldNum(GameDataHolderAccessor);
int calcBuyItemNumForCoinCollectByWorld(GameDataHolderAccessor);
int calcGetShineNumDot(GameDataHolderAccessor);
int calcGetShineNumTreasureBox(GameDataHolderAccessor);
int calcGetShineNumNoteObj(GameDataHolderAccessor);
int calcGetShineNumTimerAthletic(GameDataHolderAccessor);
int calcGetShineNumKinopioBrigade(GameDataHolderAccessor);
int calcGetShineNumWorldTravelingPeach(GameDataHolderAccessor);
int calcGetShineNumCollectAnimal(GameDataHolderAccessor);
int calcGetShineNumKuriboGirl(GameDataHolderAccessor);
int calcGetShineNumJugemFish(GameDataHolderAccessor);
int calcGetShineNumGrowPlant(GameDataHolderAccessor);
int calcGetShineNumRabbit(GameDataHolderAccessor);
int calcGetShineNumDigPoint(GameDataHolderAccessor);
int calcGetShineNumCapHanger(GameDataHolderAccessor);
int calcGetShineNumBird(GameDataHolderAccessor);
int calcGetShineNumCostumeRoom(GameDataHolderAccessor);
int calcGetShineNumSlot(GameDataHolderAccessor);
int calcGetShineNumHideAndSeekCapMan(GameDataHolderAccessor);
int calcGetShineNumCollectedBgm(GameDataHolderAccessor);
int calcGetShineNumHintPhoto(GameDataHolderAccessor);
int calcGetShineNumRace(GameDataHolderAccessor);
int calcGetShineNumFigureWalking(GameDataHolderAccessor);
int calcSphinxQuizCompleteNum(GameDataHolderAccessor);
int calcHaveStickerNum(GameDataHolderAccessor);
int calcHaveGiftNum(GameDataHolderAccessor);
int calcHackObjNum(GameDataHolderAccessor);
int calcHaveCapNum(GameDataHolderAccessor);
int calcHaveClothNum(GameDataHolderAccessor);
int calcUnlockMoonRockNum(GameDataHolderAccessor);
int calcWorldWarpHoleThroughNum(GameDataHolderAccessor);
int calcGetCheckpointNum(GameDataHolderAccessor);
int getTotalCoinNum(GameDataHolderAccessor);
int getPlayerJumpCount(GameDataHolderAccessor);
int getPlayerThrowCapCount(GameDataHolderAccessor);
}
//FIXME this is absolutely wrong here and should be made its own class, not a namespace
//used in resource/AchievementHolder.cpp
namespace GameDataFunction {
int getTotalShineNum(GameDataHolderAccessor, int);
}

View File

@ -0,0 +1,177 @@
#include "al/resource/AchievementHolder.h"
#include "al/resource/Achievement.h"
#include "al/resource/AchievementInfoReader.h"
#include "al/util/ResourceUtil.h"
#include "al/util/StringUtil.h"
AchievementHolder::AchievementHolder() = default;
void AchievementHolder::init(const al::ActorInitInfo&) {
mAchievementInfoReader = new AchievementInfoReader();
mAchievementInfoReader->init();
mArray.allocBuffer(mAchievementInfoReader->size(), nullptr);
for(int i=0;i<mArray.capacity();i++) {
mArray.pushBack(new Achievement(mAchievementInfoReader->get(i)));
}
}
void AchievementHolder::init() {
mAchievementInfoReader = new AchievementInfoReader();
mAchievementInfoReader->init();
mArray.allocBuffer(mAchievementInfoReader->size(), nullptr);
for(int i=0;i<mArray.capacity();i++) {
mArray.pushBack(new Achievement(mAchievementInfoReader->get(i)));
}
}
bool AchievementHolder::isGetMoon(int index, GameDataHolderAccessor accessor) const {
return mArray[index]->isGet(accessor);
}
bool AchievementHolder::isAchieve(int index, GameDataHolderAccessor accessor) const {
return getAchievementProgressCurrent(index, accessor) >= mAchievementInfoReader->get(index)->mNum;
}
int AchievementHolder::getAchievementProgressCurrent(int index, GameDataHolderAccessor accessor) const {
int progressCurrentRow = getAchievementProgressCurrentRow(index, accessor);
auto* infoItem = mAchievementInfoReader->get(index);
const char** name = infoItem ? &infoItem->mName : nullptr;
if(al::isEqualSubString(*name, "Shine_")) {
int max = 999;
if(progressCurrentRow <= 999)
max = progressCurrentRow;
return progressCurrentRow < 0 ? 0 : max;
}
if(!al::isEqualSubString(*name, "Other_Coin_") &&
!al::isEqualString(*name, "Other_Jump") &&
!al::isEqualString(*name, "Other_CapThrow")) {
return progressCurrentRow;
}
int max = 999999999;
if(progressCurrentRow <= max)
max = progressCurrentRow;
return progressCurrentRow < 0 ? 0 : max;
}
int AchievementHolder::getAchievementProgressMax(int index, GameDataHolderAccessor) const {
return mAchievementInfoReader->get(index)->mNum;
}
int AchievementHolder::getAchievementProgressCurrentRow(int index, GameDataHolderAccessor accessor) const {
auto* infoItem = mAchievementInfoReader->get(index);
const char** name = infoItem ? &infoItem->mName : nullptr;
if(al::isEqualString(*name, "Scenario_Ending"))
return 1;
if(al::isEqualString(*name, "Scenario_WorldAll"))
return rs::calcClearWorldNum(accessor);
if(al::isEqualString(*name, "Shine_Gather_1") || al::isEqualString(*name, "Shine_Gather_2") || al::isEqualString(*name, "Shine_Gather_3"))
return GameDataFunction::getTotalShineNum(accessor, -1);
if(al::isEqualString(*name, "Shine_CollectCoinShop"))
return rs::calcBuyItemNumForCoinCollectByWorld(accessor);
if(al::isEqualString(*name, "Shine_Shine2D_1") || al::isEqualString(*name, "Shine_Shine2D_2"))
return rs::calcGetShineNumDot(accessor);
if(al::isEqualString(*name, "Shine_TreasureBox_1") || al::isEqualString(*name, "Shine_TreasureBox_2"))
return rs::calcGetShineNumTreasureBox(accessor);
if(al::isEqualString(*name, "Shine_MusicNote_1") || al::isEqualString(*name, "Shine_MusicNote_2"))
return rs::calcGetShineNumNoteObj(accessor);
if(al::isEqualString(*name, "Shine_TimerAthretic_1") || al::isEqualString(*name, "Shine_TimerAthretic_2"))
return rs::calcGetShineNumTimerAthletic(accessor);
if(al::isEqualString(*name, "Shine_CaptainKinopio_1") || al::isEqualString(*name, "Shine_CaptainKinopio_2"))
return rs::calcGetShineNumKinopioBrigade(accessor);
if(al::isEqualString(*name, "Shine_TravelingPeach_1") || al::isEqualString(*name, "Shine_TravelingPeach_2"))
return rs::calcGetShineNumWorldTravelingPeach(accessor);
if(al::isEqualString(*name, "Shine_CollectAnimalAll"))
return rs::calcGetShineNumCollectAnimal(accessor);
if(al::isEqualString(*name, "Shine_KuriboGirl"))
return rs::calcGetShineNumKuriboGirl(accessor);
if(al::isEqualString(*name, "Shine_Jugem"))
return rs::calcGetShineNumJugemFish(accessor);
if(al::isEqualString(*name, "Shine_Seed_1") || al::isEqualString(*name, "Shine_Seed_2"))
return rs::calcGetShineNumGrowPlant(accessor);
if(al::isEqualString(*name, "Shine_Rabbit_1") || al::isEqualString(*name, "Shine_Rabbit_2"))
return rs::calcGetShineNumRabbit(accessor);
if(al::isEqualString(*name, "Shine_DigPoint_1") || al::isEqualString(*name, "Shine_DigPoint_2"))
return rs::calcGetShineNumDigPoint(accessor);
if(al::isEqualString(*name, "Shine_CapHanger_1") || al::isEqualString(*name, "Shine_CapHanger_2"))
return rs::calcGetShineNumCapHanger(accessor);
if(al::isEqualString(*name, "Shine_Bird"))
return rs::calcGetShineNumBird(accessor);
if(al::isEqualString(*name, "Shine_CostumeRoom_1") || al::isEqualString(*name, "Shine_CostumeRoom_2") || al::isEqualString(*name, "Shine_CostumeRoom_3"))
return rs::calcGetShineNumCostumeRoom(accessor);
if(al::isEqualString(*name, "Shine_CapThrottle"))
return rs::calcGetShineNumSlot(accessor);
if(al::isEqualString(*name, "Shine_HideAndSeekCapMan"))
return rs::calcGetShineNumHideAndSeekCapMan(accessor);
if(al::isEqualString(*name, "Shine_CollectBgm"))
return rs::calcGetShineNumCollectedBgm(accessor);
if(al::isEqualString(*name, "Shine_HintPhoto_1") || al::isEqualString(*name, "Shine_HintPhoto_2"))
return rs::calcGetShineNumHintPhoto(accessor);
if(al::isEqualString(*name, "MiniGame_RaceMan_1") || al::isEqualString(*name, "MiniGame_RaceMan_2"))
return rs::calcGetShineNumRace(accessor);
if(al::isEqualString(*name, "MiniGame_FigureWalker"))
return rs::calcGetShineNumFigureWalking(accessor);
if(al::isEqualString(*name, "MiniGame_SphinxQuiz"))
return rs::calcSphinxQuizCompleteNum(accessor);
if(al::isEqualString(*name, "Souvenir_Count_1") || al::isEqualString(*name, "Souvenir_Count_2") || al::isEqualString(*name, "Souvenir_Count_3"))
return rs::calcHaveStickerNum(accessor) + rs::calcHaveGiftNum(accessor);
if(al::isEqualString(*name, "Capture_Count_1") || al::isEqualString(*name, "Capture_Count_2") || al::isEqualString(*name, "Capture_Count_3"))
return rs::calcHackObjNum(accessor);
if(al::isEqualString(*name, "Costume_Cap_1") || al::isEqualString(*name, "Costume_Cap_2"))
return rs::calcHaveCapNum(accessor);
if(al::isEqualString(*name, "Costume_Clothes_1") || al::isEqualString(*name, "Costume_Clothes_2"))
return rs::calcHaveClothNum(accessor);
if(al::isEqualString(*name, "Other_MoonStoneAll"))
return rs::calcUnlockMoonRockNum(accessor);
if(al::isEqualString(*name, "Other_WorldWarpHoleAll"))
return rs::calcWorldWarpHoleThroughNum(accessor);
if(al::isEqualString(*name, "Other_CheckPoint_1") || al::isEqualString(*name, "Other_CheckPoint_2"))
return rs::calcGetCheckpointNum(accessor);
if(al::isEqualString(*name, "Other_Coin_1") || al::isEqualString(*name, "Other_Coin_2") || al::isEqualString(*name, "Other_Coin_3"))
return rs::getTotalCoinNum(accessor);
if(al::isEqualString(*name, "Other_Jump"))
return rs::getPlayerJumpCount(accessor);
if(al::isEqualString(*name, "Other_CapThrow"))
return rs::getPlayerThrowCapCount(accessor);
return 0;
}
int AchievementHolder::calcAchieveTotalNum(GameDataHolderAccessor accessor) const {
int count = 0;
for(int i=0; i<mArray.capacity();i++) {
if(getAchievementProgressCurrent(i, accessor) >= mAchievementInfoReader->get(i)->mNum)
count++;
}
return count;
}
int AchievementHolder::calcMoonGetTotalNum(GameDataHolderAccessor accessor) const {
int count = 0;
for(int i=0; i<mArray.capacity();i++) {
if(mArray[i]->isGet(accessor))
count++;
}
return count;
}
Achievement* AchievementHolder::tryGetNewAchievement(GameDataHolderAccessor accessor) const { //TODO mismatch
int i=0;
for(; i<mArray.capacity(); i++) {
if(!mArray[i]->isGet(accessor) && getAchievementProgressCurrent(i, accessor) >= mAchievementInfoReader->get(i)->mNum)
break;
}
return mArray[i];
}

View File

@ -31,7 +31,7 @@ void AchievementInfoReader::init() { //TODO minor mismatches during loop
int level = -1;
iter.tryGetIntByKey(&level, "Level");
array.pushBack(new AchievementInfo(name, note, num, level));
array.pushBack(new AchievementInfo(name, num, level, note));
}
}
}

View File

@ -1,5 +1,6 @@
target_sources(odyssey PRIVATE
Achievement.cpp
AchievementHolder.cpp
AchievementInfoReader.cpp
GameDataHolderAccessor.cpp
Resource.cpp