From c2321b7b8ad755ed441f3ba191ee4ad6f916464a Mon Sep 17 00:00:00 2001 From: Pistonight Date: Wed, 7 Aug 2024 18:28:23 -0700 Subject: [PATCH] LayoutResourceMgr functions + update NintendoSDK. --- .github/workflows/lint_pr.yml | 7 +- data/data_symbols.csv | 31 +- data/uking_functions.csv | 50 ++-- lib/NintendoSDK | 2 +- src/KingSystem/System/CMakeLists.txt | 5 + src/KingSystem/System/UI/ArcResource.h | 33 +++ src/KingSystem/System/UI/ArcResourceMgr.h | 34 +++ .../System/UI/LayoutResourceMgr.cpp | 268 ++++++++++++++++++ src/KingSystem/System/UI/LayoutResourceMgr.h | 97 +++++++ src/KingSystem/ksys.cpp | 20 ++ src/KingSystem/ksys.h | 7 + tools/format_data_symbols.py | 26 ++ 12 files changed, 537 insertions(+), 43 deletions(-) create mode 100644 src/KingSystem/System/UI/ArcResource.h create mode 100644 src/KingSystem/System/UI/ArcResourceMgr.h create mode 100644 src/KingSystem/System/UI/LayoutResourceMgr.cpp create mode 100644 src/KingSystem/System/UI/LayoutResourceMgr.h create mode 100644 tools/format_data_symbols.py diff --git a/.github/workflows/lint_pr.yml b/.github/workflows/lint_pr.yml index 559a626c8..3408f5fe2 100644 --- a/.github/workflows/lint_pr.yml +++ b/.github/workflows/lint_pr.yml @@ -4,8 +4,11 @@ jobs: clang-format: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: DoozyX/clang-format-lint-action@v0.12 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + - uses: DoozyX/clang-format-lint-action@v0.18 with: source: 'src' exclude: 'lib' diff --git a/data/data_symbols.csv b/data/data_symbols.csv index 8d8bb29dd..610d12488 100644 --- a/data/data_symbols.csv +++ b/data/data_symbols.csv @@ -1,6 +1,6 @@ -0x0000007101e9fe68,_ZN4sead8Matrix34IfE5identE -0x0000007101e9ff18,_ZN4sead7Vector3IfE4zeroE -0x0000007101e9ff48,_ZN4sead7Vector3IfE4onesE +0x0000007101E9FE68,_ZN4sead8Matrix34IfE5identE +0x0000007101E9FF18,_ZN4sead7Vector3IfE4zeroE +0x0000007101E9FF48,_ZN4sead7Vector3IfE4onesE 0x00000071023556B0,_ZTVN4sead14SafeStringBaseIcEE 0x0000007102356AF0,_ZTVN4sead22BufferedSafeStringBaseIcEE 0x000000710246F9E0,_ZN4ksys3gdt6detail13sCommonFlags0E @@ -20,6 +20,9 @@ 0x00000071024C1600,_ZTVN3agl3utl9ParameterIN4sead15FixedSafeStringILi64EEEEE 0x00000071024C16A0,_ZTVN3agl3utl9ParameterIN4sead15FixedSafeStringILi256EEEEE 0x00000071024C1740,_ZTVN3agl3utl9ParameterIN4sead14SafeStringBaseIcEEEE +0x00000071024C6600,_ZN6xlink216ContainerCreator17sContainerSizeMaxE +0x00000071024C68A8,_ZN6xlink215sMinAddressHighE +0x00000071024C68B0,_ZN6xlink214sMinAddressLowE 0x00000071024D8D58,_ZTVN4ksys3act2ai10ActionBaseE 0x00000071025129E0,_ZTVN4ksys3act2ai6ActionE 0x0000007102513268,_ZTVN4ksys3act2ai2AiE @@ -500,17 +503,15 @@ 0x00000071025F8480,pfnc_nvnEventSignal 0x00000071025F8488,pfnc_nvnCommandBufferWaitEvent 0x00000071025F8490,pfnc_nvnCommandBufferSignalEvent -0x0000007102606910,_ZN4ksys12SystemTimers9sInstanceE -0x0000007102650608,_ZN4ksys3act11BaseProcMgr9sInstanceE 0x00000071025F9CB0,_ZN3agl6driver17GraphicsDriverMgr18SingletonDisposer_15sStaticDisposerE 0x00000071025F9CB8,_ZN3agl6driver17GraphicsDriverMgr9sInstanceE -0x00000071024c6600,_ZN6xlink216ContainerCreator17sContainerSizeMaxE -0x00000071024c68a8,_ZN6xlink215sMinAddressHighE -0x00000071024c68b0,_ZN6xlink214sMinAddressLowE -0x00000071025fb508,_ZN3aal6System9sInstanceE -0x00000071025fc7f0,_ZN6xlink211SystemSLink9sInstanceE -0x00000071025fc7f8,_ZN6xlink211SystemSLink10sLockProxyE -0x00000071025fc878,_ZZNK6xlink214ResourceBuffer18getEmptyUserHeaderEvE6sDummy -0x00000071025fc8b0,_ZZNK6xlink214ResourceBuffer24getEmptyRomResourceParamEvE6sDummy -0x00000071025fc948,_ZZNK6xlink214ResourceBuffer24getEmptyRomResourceParamEvE6sDummy -0x00000071025fc950,_ZN6xlink27Locator16sDataLoadedCountE \ No newline at end of file +0x00000071025FB508,_ZN3aal6System9sInstanceE +0x00000071025FC7F0,_ZN6xlink211SystemSLink9sInstanceE +0x00000071025FC7F8,_ZN6xlink211SystemSLink10sLockProxyE +0x00000071025FC878,_ZZNK6xlink214ResourceBuffer18getEmptyUserHeaderEvE6sDummy +0x00000071025FC8B0,_ZZNK6xlink214ResourceBuffer24getEmptyRomResourceParamEvE6sDummy +0x00000071025FC948,_ZZNK6xlink214ResourceBuffer24getEmptyRomResourceParamEvE6sDummy +0x00000071025FC950,_ZN6xlink27Locator16sDataLoadedCountE +0x0000007102606910,_ZN4ksys12SystemTimers9sInstanceE +0x000000710261EB90,_ZN4ksys2ui17LayoutResourceMgr9sInstanceE +0x0000007102650608,_ZN4ksys3act11BaseProcMgr9sInstanceE diff --git a/data/uking_functions.csv b/data/uking_functions.csv index f0689c44e..3fe48dc16 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -81790,7 +81790,7 @@ Address,Quality,Size,Name 0x0000007100f3a528,U,000016, 0x0000007100f3a538,U,000756,ui::init 0x0000007100f3a82c,U,000172,createRegionLanguageMgr -0x0000007100f3a8d8,U,002276,ksys::PreInitializeApp +0x0000007100f3a8d8,W,002276,_ZN4ksys16preInitializeAppEPNS_10InitParamsE 0x0000007100f3b1bc,U,000132,checkPreInitializeResourcesStillLoading 0x0000007100f3b240,U,007612,ksys::InitializeApp 0x0000007100f3cffc,O,000388,_ZN4ksys15initBaseProcMgrEPN4sead4HeapE @@ -88328,31 +88328,31 @@ Address,Quality,Size,Name 0x00000071010a2294,U,000008, 0x00000071010a229c,U,000040, 0x00000071010a22c4,U,000372, -0x00000071010a2438,U,000112, -0x00000071010a24a8,U,000120, -0x00000071010a2520,U,000284,LayoutResourceMgr::createInstance -0x00000071010a263c,U,000268,LayoutResourceMgr::init -0x00000071010a2748,U,000424,LayoutResourceMgr::loadMsgPack -0x00000071010a28f0,U,000384,LayoutResourceMgr::__auto2 -0x00000071010a2a70,U,000260,LayoutResourceMgr::loadLangFont -0x00000071010a2b74,U,000388,LayoutResourceMgr::__auto0 -0x00000071010a2cf8,U,000680,LayoutResourceMgr::loadFonts -0x00000071010a2fa0,U,000188,LayoutResourceMgr::ready -0x00000071010a305c,U,000136,LayoutResourceMgr::ready_0 -0x00000071010a30e4,U,000136,LayoutResourceMgr::loadVersion -0x00000071010a316c,U,000372,LayoutResourceMgr::ready_1 -0x00000071010a32e0,U,001584, +0x00000071010a2438,O,000112,_ZN4ksys2ui17LayoutResourceMgr18SingletonDisposer_D1Ev +0x00000071010a24a8,O,000120,_ZN4ksys2ui17LayoutResourceMgr18SingletonDisposer_D0Ev +0x00000071010a2520,O,000284,_ZN4ksys2ui17LayoutResourceMgr14createInstanceEPN4sead4HeapE +0x00000071010a263c,O,000268,_ZN4ksys2ui17LayoutResourceMgr4initEPN4sead4HeapE +0x00000071010a2748,O,000424,_ZN4ksys2ui17LayoutResourceMgr11loadMsgPackEPj +0x00000071010a28f0,U,000384,LayoutResourceMgr::loadGrammarArticleMaxLen +0x00000071010a2a70,O,000260,_ZN4ksys2ui17LayoutResourceMgr12loadLangFontEPN4sead4HeapE +0x00000071010a2b74,U,000388,LayoutResourceMgr::initializeFontMgr +0x00000071010a2cf8,O,000680,_ZN4ksys2ui17LayoutResourceMgr18loadExtraLangFontsEPN4sead4HeapE +0x00000071010a2fa0,O,000188,_ZN4ksys2ui17LayoutResourceMgr18checkLangFontReadyEv +0x00000071010a305c,O,000136,_ZNK4ksys2ui17LayoutResourceMgr24checkExtraLangFontsReadyEv +0x00000071010a30e4,O,000136,_ZN4ksys2ui17LayoutResourceMgr11loadVersionEv +0x00000071010a316c,O,000372,_ZN4ksys2ui17LayoutResourceMgr17checkVersionReadyEv +0x00000071010a32e0,U,001584,LayoutResourceMgr::doSomethingWithFontTextureCache 0x00000071010a3910,W,000064,_ZN4sead12PerfJobQueue13measureEndRunEv -0x00000071010a3950,U,000072,LayoutResourceMgr::loadLayoutCommonArchive -0x00000071010a3998,U,000288,LayoutResourceMgr::loadArcResource -0x00000071010a3ab8,U,000104, -0x00000071010a3b20,U,000208, -0x00000071010a3bf0,U,000016, -0x00000071010a3c00,U,000104, -0x00000071010a3c68,U,000264,LayoutResourceMgr::x -0x00000071010a3d70,U,000076, -0x00000071010a3dbc,U,000068, -0x00000071010a3e00,U,000168, +0x00000071010a3950,O,000072,_ZN4ksys2ui17LayoutResourceMgr23loadCommonLayoutArchiveEPN4sead7ExpHeapE +0x00000071010a3998,O,000288,_ZN4ksys2ui17LayoutResourceMgr15loadArcResourceERNS1_7ArchiveEPKc +0x00000071010a3ab8,O,000104,_ZN4ksys2ui17LayoutResourceMgr8unloadA8Ev +0x00000071010a3b20,O,000208,_ZN4ksys2ui17LayoutResourceMgr15loadTitleLayoutEPN4sead4HeapE +0x00000071010a3bf0,O,000016,_ZN4ksys2ui17LayoutResourceMgr23loadTitleLayoutResourceEv +0x00000071010a3c00,O,000104,_ZN4ksys2ui17LayoutResourceMgr17unloadTitleLayoutEv +0x00000071010a3c68,O,000264,_ZN4ksys2ui17LayoutResourceMgr15loadHorseLayoutEPN4sead4HeapE +0x00000071010a3d70,O,000076,_ZN4ksys2ui17LayoutResourceMgr23loadHorseLayoutResourceEv +0x00000071010a3dbc,O,000068,_ZNK4ksys2ui17LayoutResourceMgr25hasHorseLayoutLoadFailureEv +0x00000071010a3e00,O,000168,_ZN4ksys2ui17LayoutResourceMgr17unloadHorseLayoutEv 0x00000071010a3ea8,U,000104,ScreenLoadSaveIcon::ctor 0x00000071010a3f10,U,000044, 0x00000071010a3f3c,U,000048, diff --git a/lib/NintendoSDK b/lib/NintendoSDK index a7a1e2b71..cc73cdf46 160000 --- a/lib/NintendoSDK +++ b/lib/NintendoSDK @@ -1 +1 @@ -Subproject commit a7a1e2b715cbafbbe50264a6157da8388a390776 +Subproject commit cc73cdf466e31794669757352a434d240f79c9f4 diff --git a/src/KingSystem/System/CMakeLists.txt b/src/KingSystem/System/CMakeLists.txt index 4f907b819..ee6b48f05 100644 --- a/src/KingSystem/System/CMakeLists.txt +++ b/src/KingSystem/System/CMakeLists.txt @@ -1,4 +1,9 @@ target_sources(uking PRIVATE + UI/ArcResource.h + UI/ArcResourceMgr.h + UI/LayoutResourceMgr.cpp + UI/LayoutResourceMgr.h + Account.cpp Account.h AutoDim.cpp diff --git a/src/KingSystem/System/UI/ArcResource.h b/src/KingSystem/System/UI/ArcResource.h new file mode 100644 index 000000000..1bc55f07c --- /dev/null +++ b/src/KingSystem/System/UI/ArcResource.h @@ -0,0 +1,33 @@ +#pragma once + +#include +#include +#include "KingSystem/Utils/Types.h" + +namespace ksys { +namespace res { +class Handle; +} +namespace ui { + +class ArcResourceMgr; + +class ArcResource : public sead::IDisposer { +public: + ArcResource() = default; + + void init(ArcResourceMgr* mgr, const sead::SafeString& name, u8* data, res::Handle* handle); + +private: + void* _20; + void* _28; + ArcResourceMgr* mArcResourceMgr; + sead::FixedSafeString<0x40> mName; + u8* mData; + void* mFile; + res::Handle* mHandle; +}; +KSYS_CHECK_SIZE_NX150(ArcResource, 0xA8); + +} // namespace ui +} // namespace ksys diff --git a/src/KingSystem/System/UI/ArcResourceMgr.h b/src/KingSystem/System/UI/ArcResourceMgr.h new file mode 100644 index 000000000..1882e3bfc --- /dev/null +++ b/src/KingSystem/System/UI/ArcResourceMgr.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include "KingSystem/System/UI/ArcResource.h" +#include "KingSystem/Utils/Types.h" + +namespace sead { +class ExpHeap; +} + +namespace ksys::ui { + +class ArcResourceMgr { +public: + ArcResourceMgr() = default; + virtual ~ArcResourceMgr(); + + virtual void sub_10(); + virtual void loadArchive(sead::Heap* heap, const sead::SafeString& path); + virtual void sub_20(); + virtual void sub_28(); + virtual void addArchive(ArcResource* archive); + +private: + // TODO: fields + /* sead::TList */ + char list[0x10]; + int _18 = 0; + int _1c = 0x20; +}; +KSYS_CHECK_SIZE_NX150(ArcResourceMgr, 0x20); + +} // namespace ksys::ui diff --git a/src/KingSystem/System/UI/LayoutResourceMgr.cpp b/src/KingSystem/System/UI/LayoutResourceMgr.cpp new file mode 100644 index 000000000..fa1d9dc2b --- /dev/null +++ b/src/KingSystem/System/UI/LayoutResourceMgr.cpp @@ -0,0 +1,268 @@ +#include +#include +#include + +#include "KingSystem/Resource/resLoadRequest.h" +#include "KingSystem/System/StarterPackMgr.h" +#include "KingSystem/System/UI/ArcResource.h" +#include "KingSystem/System/UI/LayoutResourceMgr.h" + +namespace ksys::ui { + +SEAD_SINGLETON_DISPOSER_IMPL(LayoutResourceMgr) + +void LayoutResourceMgr::init(sead::Heap* heap) { + mMsgPackHandle = new (heap) res::Handle; + mLangFontHandle = new (heap) res::Handle; + mVersionHandle = new (heap) res::Handle; + + int count; + switch (sead::EnvUtil::getRegionLanguage().value()) { + case sead::RegionLanguageID::KRko: + case sead::RegionLanguageID::CNzh: + case sead::RegionLanguageID::TWzh: + count = cExtraLangFontCount; + break; + default: + count = 0; + break; + } + for (int i = 0; i < count; i++) { + mExtraLangFontHandles.pushBack(new (heap) res::Handle); + } + if (count > 0) { + mZeldaGlyphHandle = new (heap) res::Handle; + } +} + +u8* LayoutResourceMgr::loadMsgPack(u32* size) { + mMsgPackHandle->resetUnitFlag20000IfSuccess(); + mMsgPackHandle->unload(); + + res::LoadRequest req; + req.mRequester = "LayoutResourceMgr"; + req._22 = true; + req._21 = true; + req.mLoadDataAlignment = 0x80; + req._26 = false; + req.mPackHandle = StarterPackMgr::instance()->getBootupLangPack(); + + sead::FixedSafeString<0x20> path; + path.format("Message/Msg_%s.product.sarc", sead::EnvUtil::getRegionLanguage().text()); + + res::Handle::Status status; + auto* resource = + sead::DynamicCast(mMsgPackHandle->load(path, &req, &status)); + + *size = resource->getRawSize(); + return resource->getRawData(); +} + +void LayoutResourceMgr::loadLangFont(sead::Heap* heap) { + mLangFontHandle->resetUnitFlag20000IfSuccess(); + mLangFontHandle->unload(); + mLangFontResource = nullptr; + + res::LoadRequest req; + req.mRequester = "LayoutResourceMgr"; + req._22 = true; + req.mLoadDataAlignment = 0x1000; + req._26 = false; + + sead::FixedSafeString<0x20> path; + path.format("Font/Font_%s.bfarc", sead::EnvUtil::getRegion().text()); + + mLangFontHandle->requestLoad(path, &req, nullptr); +} + +constexpr const char* sExtraLangFontFiles[LayoutResourceMgr::cExtraLangCount * + LayoutResourceMgr::cExtraLangFontCount] = { + "AsiaKCUBE-R", "AsiaKDREAM2R", "AsiaKDREAM4R", "AsiaKDREAM7R", "DFP_GBZY9", "DFP_GB_H3", + "DFP_GB_H5", "DFHEI5A", "DFT_ZY9", "DFT_B3", "DFT_B5", "DFT_B9"}; + +void LayoutResourceMgr::loadExtraLangFonts(sead::Heap* heap) { + sead::RegionLanguageID lang_id = sead::EnvUtil::getRegionLanguage(); + auto* fonts = sExtraLangFontFiles; + for (int i = 0; i <= cExtraLangCount; i++) { + if (lang_id.value() == sead::RegionLanguageID::KRko + i) { + break; + } + if (i == cExtraLangCount - 1) { + return; + } + fonts += cExtraLangFontCount; + } + + res::LoadRequest req; + req.mRequester = "ui::LayoutResourceMgr"; + req._26 = false; + + res::Handle::Status status = res::Handle::Status::NoFile; + for (int i = 0; i < cExtraLangFontCount; ++i) { + auto* handle = mExtraLangFontHandles[i]; + sead::FixedSafeString<0x20> path; +#ifdef MATCHING_HACK_NX_CLANG + asm(""); +#endif + path.format("Font/%s.bfttf", fonts[i]); + handle->requestLoad(path, &req, &status); + } + + mZeldaGlyphHandle->requestLoad("Font/ZeldaGlyphs-v2-Deco.bfotf", &req, &status); + nn::pl::RequestSharedFontLoad(nn::pl::SharedFontType::STANDARD); +} + +bool LayoutResourceMgr::checkLangFontReady() { + if (mLangFontResource) { + return true; + } + if (!mLangFontHandle->isReady()) { + return false; + } + mLangFontResource = sead::DynamicCast(mLangFontHandle->getResource()); + return true; +} + +bool LayoutResourceMgr::checkExtraLangFontsReady() const { + switch (sead::EnvUtil::getRegionLanguage().value()) { + case sead::RegionLanguageID::KRko: + case sead::RegionLanguageID::CNzh: + case sead::RegionLanguageID::TWzh: + break; + default: + return true; + } + for (const auto& handle : mExtraLangFontHandles) { + if (!handle.isReady()) { + return false; + } + } + if (!mZeldaGlyphHandle || mZeldaGlyphHandle->isReady()) { + return nn::pl::GetSharedFontLoadState(nn::pl::SharedFontType::STANDARD) == + nn::pl::LoadState::LOADED; + } + return false; +} + +void LayoutResourceMgr::loadVersion() { + res::LoadRequest req; + req.mRequester = "LayoutResourceMgr"; + req._26 = false; + + mVersionHandle->requestLoad("System/Version.txt", &req, nullptr); +} + +bool LayoutResourceMgr::checkVersionReady() { + if (!mVersionHandle) { + return true; + } + if (mVersionHandle->isReady()) { + auto* resource = sead::DynamicCast(mVersionHandle->getResource()); + instance()->mVersionString.copy(reinterpret_cast(resource->getRawData()), + static_cast(resource->getRawSize())); + delete mVersionHandle; + mVersionHandle = nullptr; + return true; + } + return false; +} + +void LayoutResourceMgr::loadCommonLayoutArchive(sead::ExpHeap* heap) { + mArcResourceMgr->loadArchive(heap, "Layout/Common.sblarc"); +} + +void LayoutResourceMgr::loadTitleLayout(sead::Heap* heap) { + mTitleLayout.allocate(heap); + + res::LoadRequest req; + req.mRequester = "ui::LayoutResourceMgr"; + req.mLoadDataAlignment = 0x1000; + req._22 = false; + req._26 = false; + req._c = 2; + + res::Handle::Status status = res::Handle::Status::NoFile; + mTitleLayout.getHandle()->requestLoad("Layout/Title.blarc", &req, &status); +} + +bool LayoutResourceMgr::loadTitleLayoutResource() { + return loadArcResource(mTitleLayout, "Title"); +} + +void LayoutResourceMgr::unloadTitleLayout() { + mTitleLayout.deallocate(); +} + +bool LayoutResourceMgr::loadHorseLayout(sead::Heap* heap) { + const auto lock = sead::makeScopedLock(mCriticalSection); + + if (mHorseLayoutLoadCount++) { + return false; + } + + mHorseLayout.allocate(heap); + + res::LoadRequest req; + req.mRequester = "ui::LayoutResourceMgr"; + req.mLoadDataAlignment = 0x1000; + req._22 = false; + req._26 = true; + req._c = 2; + + res::Handle::Status status = res::Handle::Status::NoFile; + mHorseLayout.getHandle()->requestLoad("Layout/Horse.blarc", &req, &status); + + return true; +} + +bool LayoutResourceMgr::loadHorseLayoutResource() { + const auto lock = sead::makeScopedLock(mCriticalSection); + return loadArcResource(mHorseLayout, "Horse"); +} + +bool LayoutResourceMgr::hasHorseLayoutLoadFailure() const { + if (mHorseLayout.getHandle()) { + if (mHorseLayout.getHandle()->isReady() && !mHorseLayout.getHandle()->isSuccess()) { + return true; + } + } + return false; +} + +bool LayoutResourceMgr::unloadHorseLayout() { + const auto lock = sead::makeScopedLock(mCriticalSection); + int old_count = mHorseLayoutLoadCount--; + + if (mHorseLayoutLoadCount == 0) { + mHorseLayout.deallocate(); + return true; + } + + return old_count < 2; +} + +bool LayoutResourceMgr::loadArcResource(Archive& archive, const char* name) { + if (archive.getResource()) { + return true; + } + if (!archive.getHandle()->isReady()) { + return false; + } + if (archive.getHandle()->isSuccess()) { + auto* resource = + sead::DynamicCast(archive.getHandle()->getResource()); + if (resource) { + auto* arc_resource = reinterpret_cast(archive.mResourceStorage); + arc_resource->init(mArcResourceMgr, name, resource->getRawData(), archive.mHandle); + archive.mResource = arc_resource; + mArcResourceMgr->addArchive(archive.getResource()); + } + } + return true; +} + +void LayoutResourceMgr::unloadA8() { + _a8.deallocate(); +} + +} // namespace ksys::ui diff --git a/src/KingSystem/System/UI/LayoutResourceMgr.h b/src/KingSystem/System/UI/LayoutResourceMgr.h new file mode 100644 index 000000000..64378496d --- /dev/null +++ b/src/KingSystem/System/UI/LayoutResourceMgr.h @@ -0,0 +1,97 @@ +#pragma once + +#include +#include +#include +#include +#include +#include "KingSystem/Resource/resHandle.h" +#include "KingSystem/System/UI/ArcResource.h" +#include "KingSystem/System/UI/ArcResourceMgr.h" +#include "KingSystem/Utils/Types.h" + +namespace ksys::ui { + +class LayoutResourceMgr final : public sead::hostio::Node { + SEAD_SINGLETON_DISPOSER(LayoutResourceMgr) + LayoutResourceMgr() = default; + ~LayoutResourceMgr() = default; + +public: + static constexpr int cExtraLangFontCount = 4; + static constexpr int cExtraLangCount = 3; + +private: + class Archive { + friend class LayoutResourceMgr; + + public: + void allocate(sead::Heap* heap) { + mHandle = new (heap) res::Handle; + mResourceStorage = new (heap) u8[sizeof(ArcResource)]; + } + void deallocate() { + if (mResource) { + delete mResource; + mResource = nullptr; + } else { + delete mHandle; + delete[] mResourceStorage; + } + mHandle = nullptr; + mResourceStorage = nullptr; + } + + res::Handle* getHandle() { return mHandle; } + const res::Handle* getHandle() const { return mHandle; } + ArcResource* getResource() { return mResource; } + const ArcResource* getResource() const { return mResource; } + + private: + res::Handle* mHandle = nullptr; + ArcResource* mResource = nullptr; + u8* mResourceStorage = nullptr; + }; + +public: + void init(sead::Heap* heap); + u8* loadMsgPack(u32* size); + void loadLangFont(sead::Heap* heap); + void loadExtraLangFonts(sead::Heap* heap); + bool checkLangFontReady(); + bool checkExtraLangFontsReady() const; + void loadVersion(); + bool checkVersionReady(); + void loadCommonLayoutArchive(sead::ExpHeap* heap); + void loadTitleLayout(sead::Heap* heap); + bool loadTitleLayoutResource(); + void unloadTitleLayout(); + bool loadHorseLayout(sead::Heap* heap); + bool loadHorseLayoutResource(); + bool hasHorseLayoutLoadFailure() const; + bool unloadHorseLayout(); + void unloadA8(); + void doSomethingWithFontTextureCache(void* texture_cache); + + bool loadArcResource(Archive& archive, const char* name); + +private: + res::Handle* mMsgPackHandle = nullptr; + res::Handle* mLangFontHandle = nullptr; + res::Handle* mVersionHandle = nullptr; + sead::FixedPtrArray mExtraLangFontHandles; + res::Handle* mZeldaGlyphHandle = nullptr; + ArcResourceMgr* mArcResourceMgr = nullptr; + sead::DirectResource* mLangFontResource = nullptr; + Archive _a8; + Archive mTitleLayout; + Archive mHorseLayout; + u16 mMaxDefArtLen = 0; + u16 mMaxIndefArtLen = 0; + sead::FixedSafeString<16> mVersionString; + int mHorseLayoutLoadCount = 0; + sead::CriticalSection mCriticalSection; +}; +KSYS_CHECK_SIZE_NX150(LayoutResourceMgr, 0x168); + +} // namespace ksys::ui diff --git a/src/KingSystem/ksys.cpp b/src/KingSystem/ksys.cpp index e370b0038..de4c6bdd6 100644 --- a/src/KingSystem/ksys.cpp +++ b/src/KingSystem/ksys.cpp @@ -4,7 +4,9 @@ #include "KingSystem/ActorSystem/actBaseProcCreateTaskSelector.h" #include "KingSystem/ActorSystem/actBaseProcInitializer.h" #include "KingSystem/ActorSystem/actBaseProcMgr.h" +#include "KingSystem/System/BasicProfiler.h" #include "KingSystem/System/HavokWorkerMgr.h" +#include "KingSystem/System/UI/LayoutResourceMgr.h" namespace ksys { @@ -29,4 +31,22 @@ void initBaseProcMgr(sead::Heap* heap) { act::BaseProcMgr::sConstant4 = u32(act::JobType::Calc4); } +void preInitializeApp(InitParams* params) { + ksys::BasicProfiler::push("ksys::PreInitializeApp"); + + // TODO - other parts + + ksys::BasicProfiler::push("RequestFontLoad"); + // TODO: FontMgr::createInstance() + ui::LayoutResourceMgr::createInstance(params->king_sys_heap); + ui::LayoutResourceMgr::instance()->init(params->king_sys_heap); + ui::LayoutResourceMgr::instance()->loadLangFont(params->king_sys_heap); + ui::LayoutResourceMgr::instance()->loadExtraLangFonts(params->king_sys_heap); + ksys::BasicProfiler::pop("RequestFontLoad"); + + // TODO - other parts + + ksys::BasicProfiler::pop("ksys::PreInitializeApp"); +} + } // namespace ksys diff --git a/src/KingSystem/ksys.h b/src/KingSystem/ksys.h index 4775ea4f4..4c5285819 100644 --- a/src/KingSystem/ksys.h +++ b/src/KingSystem/ksys.h @@ -6,6 +6,10 @@ class Heap; namespace ksys { +struct InitParams { + sead::Heap* king_sys_heap; +}; + // 0x0000007100f3a4e4 bool isGameOver(); // 0x0000007100f3a4f0 @@ -13,4 +17,7 @@ void setIsGameOver(bool is_game_over); void initBaseProcMgr(sead::Heap* heap); +// 0x0000007100f3a8d8 +void preInitializeApp(InitParams* params); + } // namespace ksys diff --git a/tools/format_data_symbols.py b/tools/format_data_symbols.py new file mode 100644 index 000000000..ec85166ad --- /dev/null +++ b/tools/format_data_symbols.py @@ -0,0 +1,26 @@ +import os +import csv + +DATA_SYMBOLS = os.path.join(os.path.dirname(__file__), '../data/data_symbols.csv') + +if __name__ == "__main__": + addr2symbol = {} + + with open(DATA_SYMBOLS, "r", encoding="utf-8") as f: + reader = csv.reader(f) + # doesn't come with header + for row in reader: + if not row: # skip empty + continue + addr = int(row[0].strip(), 16) + name = "" + if len(row) > 1: + name = row[1].strip() + addr2symbol[addr] = name + + with open(DATA_SYMBOLS, "w", encoding="utf-8") as f: + writer = csv.writer(f, lineterminator="\n") + for hex in sorted(addr2symbol): + writer.writerow([f"0x{hex:016X}", addr2symbol[hex]]) + print("data_symbols.csv updated") +