From 0167bf034c7d32c27fdf5ac2f887a98eaf9dabdc Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Wed, 14 May 2025 00:04:47 +0100 Subject: [PATCH] gc menu now tries to load control data from ns cache before manually loading. on fw 19 and below, loading from cache takes ~5ms, whereas manually loading takes ~20ms. manually loading is still faster than relying on ns to load control from storage (~50ms). --- sphaira/source/ui/menus/gc_menu.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/sphaira/source/ui/menus/gc_menu.cpp b/sphaira/source/ui/menus/gc_menu.cpp index c2d2c63..2c78b0d 100644 --- a/sphaira/source/ui/menus/gc_menu.cpp +++ b/sphaira/source/ui/menus/gc_menu.cpp @@ -182,6 +182,7 @@ Menu::Menu() : MenuBase{"GameCard"_i18n} { const Vec2 pad{0, 125 - v.h}; m_list = std::make_unique(1, 3, m_pos, v, pad); + nsInitialize(); fsOpenDeviceOperator(std::addressof(m_dev_op)); fsOpenGameCardDetectionEventNotifier(std::addressof(m_event_notifier)); fsEventNotifierGetEventHandle(std::addressof(m_event_notifier), std::addressof(m_event), true); @@ -494,6 +495,31 @@ void Menu::OnChangeIndex(s64 new_index) { const auto index = m_entries.empty() ? 0 : m_entry_index + 1; this->SetSubHeading(std::to_string(index) + " / " + std::to_string(m_entries.size())); + const auto id = m_entries[m_entry_index].app_id; + + if (hosversionBefore(20,0,0)) { + TimeStamp ts; + auto control = std::make_unique(); + u64 control_size; + + if (R_SUCCEEDED(nsGetApplicationControlData(NsApplicationControlSource_CacheOnly, id, control.get(), sizeof(NsApplicationControlData), &control_size))) { + log_write("\t\t[ns control cache] time taken: %.2fs %zums\n", ts.GetSecondsD(), ts.GetMs()); + + NacpLanguageEntry* lang_entry{}; + nacpGetLanguageEntry(&control->nacp, &lang_entry); + + if (lang_entry) { + m_lang_entry = *lang_entry; + } + + const auto jpeg_size = control_size - sizeof(NacpStruct); + m_icon = nvgCreateImageMem(App::GetVg(), 0, control->icon, jpeg_size); + if (m_icon > 0) { + return; + } + } + } + // nsGetApplicationControlData() will fail if it's the first time // mounting a gamecard if the image is not already cached. // waiting 1-2s after mount, then calling seems to work. @@ -506,7 +532,7 @@ void Menu::OnChangeIndex(s64 new_index) { std::vector icon; const auto path = BuildGcPath(collection.name.c_str(), &m_handle); - u64 program_id = m_entries[m_entry_index].app_id | collection.id_offset; + u64 program_id = id | collection.id_offset; if (hosversionAtLeast(17, 0, 0)) { fsGetProgramId(&program_id, path, FsContentAttributes_All); }