From f3f4cb78a4789ff4b3fe1d7ecb1b48bfe573412a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 4 Apr 2021 16:30:31 +0200 Subject: [PATCH] ksys/gdt: Implement Manager::loadShopGameDataInfo --- data/uking_functions.csv | 2 +- src/KingSystem/GameData/gdtManager.cpp | 36 ++++++++++++++++++++++++++ src/KingSystem/GameData/gdtManager.h | 4 +-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 75adf6ac..515e5e7b 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -76019,7 +76019,7 @@ 0x0000007100dcf6b4,sub_7100DCF6B4,704,_ZN4ksys3gdt7Manager14IncreaseLoggerC2Ev 0x0000007100dcf974,EntryFactoryBgdata::dtor,68,_ZN4ksys3res12EntryFactoryINS0_8GameDataEED2Ev 0x0000007100dcf9b8,GameDataMgr::loadGameDataFromArc,1692, -0x0000007100dd0054,GameDataMgr::loadShopGameDataInfo,600, +0x0000007100dd0054,GameDataMgr::loadShopGameDataInfo,600,_ZN4ksys3gdt7Manager20loadShopGameDataInfoERKN4sead14SafeStringBaseIcEE 0x0000007100dd02ac,GameDataMgr::unloadResources,288,_ZN4ksys3gdt7Manager15unloadResourcesEv 0x0000007100dd03cc,GameDataMgr::calc,896, 0x0000007100dd074c,GameDataMgr::calc0,548, diff --git a/src/KingSystem/GameData/gdtManager.cpp b/src/KingSystem/GameData/gdtManager.cpp index 7597cc49..8258bd56 100644 --- a/src/KingSystem/GameData/gdtManager.cpp +++ b/src/KingSystem/GameData/gdtManager.cpp @@ -13,9 +13,13 @@ #include "KingSystem/GameData/gdtTriggerParam.h" #include "KingSystem/Map/mapMubinIter.h" #include "KingSystem/Resource/resEntryFactory.h" +#include "KingSystem/Resource/resLoadRequest.h" #include "KingSystem/Resource/resResourceGameData.h" #include "KingSystem/Resource/resSystem.h" #include "KingSystem/System/OverlayArenaSystem.h" +#include "KingSystem/Utils/Byaml/Byaml.h" +#include "KingSystem/Utils/Byaml/ByamlArrayIter.h" +#include "KingSystem/Utils/Debug.h" #include "KingSystem/Utils/HeapUtil.h" #include "KingSystem/Utils/InitTimeInfo.h" #include "KingSystem/Utils/SafeDelete.h" @@ -134,6 +138,38 @@ void Manager::init(sead::Heap* heap, sead::Framework* framework) { mNumFlagsToReset = 0; } +void Manager::loadShopGameDataInfo(const sead::SafeString& path) { + res::LoadRequest req; + req.mRequester = "gdtManager"; + req._26 = false; + if (!sead::DynamicCast(mShopGameDataInfoHandle.load(path, &req))) + return; + + auto* res = sead::DynamicCast(mShopGameDataInfoHandle.getResource()); + if (!res) + return; + + al::ByamlIter root{res->getRawData()}; + al::ByamlIter iter; + al::ByamlIter hashes; + + if (root.tryGetIterByKey(&iter, "ShopAreaInfo")) { + iter.tryGetIterByKey(&mShopAreaInfoValues, "Values"); + if (iter.tryGetIterByKey(&hashes, "Hashes")) { + mShopAreaInfoHashes = al::ByamlArrayIter(hashes.getRootNode()).getDataTable(); + } + } + util::PrintDebugFmt("ShopAreaInfo: %d %d", mShopAreaInfoValues.getSize(), hashes.getSize()); + + if (root.tryGetIterByKey(&iter, "SoldOutInfo")) { + iter.tryGetIterByKey(&mShopSoldOutInfoValues, "Values"); + if (iter.tryGetIterByKey(&hashes, "Hashes")) { + mShopSoldOutInfoHashes = al::ByamlArrayIter(hashes.getRootNode()).getDataTable(); + } + } + util::PrintDebugFmt("SoldOutInfo: %d %d", mShopSoldOutInfoValues.getSize(), hashes.getSize()); +} + void Manager::unloadResources() { for (s32 i = 0; i < mBgdataHandles.size(); ++i) mBgdataHandles[i].requestUnload(); diff --git a/src/KingSystem/GameData/gdtManager.h b/src/KingSystem/GameData/gdtManager.h index 01a80926..555f8a01 100644 --- a/src/KingSystem/GameData/gdtManager.h +++ b/src/KingSystem/GameData/gdtManager.h @@ -624,9 +624,9 @@ private: res::Handle mShopGameDataInfoHandle; al::ByamlIter mShopAreaInfoValues; - const u8* mShopAreaInfoHashes = nullptr; + const u32* mShopAreaInfoHashes = nullptr; al::ByamlIter mShopSoldOutInfoValues; - const u8* mShopSoldOutInfoHashes = nullptr; + const u32* mShopSoldOutInfoHashes = nullptr; TriggerParamRef mParamBypassPerm{&mFlagBuffer1, &mFlagBuffer, false, false, false}; TriggerParamRef mParam{&mFlagBuffer1, &mFlagBuffer, true, false, false};