From cdebcad4fe9416ddc487494a69de6d0c5dade8f7 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Wed, 1 Jan 2025 17:34:54 +0000 Subject: [PATCH 1/4] correctly path npdm kc flags on ams 1.7.1 or greater fixes #67 --- sphaira/source/owo.cpp | 75 +++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/sphaira/source/owo.cpp b/sphaira/source/owo.cpp index c46d437..85135bc 100644 --- a/sphaira/source/owo.cpp +++ b/sphaira/source/owo.cpp @@ -12,6 +12,7 @@ #include "app.hpp" #include "ui/progress_box.hpp" #include "i18n.hpp" +#include "log.hpp" namespace sphaira { namespace { @@ -191,10 +192,30 @@ struct NpdmMeta { u32 acid_size; }; +struct NpdmAcid { + u8 rsa_sig[0x100]; + u8 rsa_pub[0x100]; + u32 magic; // "ACID" + u32 size; + u8 version; + u8 _0x209[0x1]; + u8 _0x20A[0x2]; + u32 flags; + u64 program_id_min; + u64 program_id_max; + u32 fac_offset; + u32 fac_size; + u32 sac_offset; + u32 sac_size; + u32 kac_offset; + u32 kac_size; + u8 _0x238[0x8]; +}; + struct NpdmAci0 { u32 magic; // "ACI0" u8 _0x4[0xC]; - u32 program_id; + u64 program_id; u8 _0x18[0x8]; u32 fac_offset; u32 fac_size; @@ -592,25 +613,41 @@ auto romfs_build(const FileEntries& entries, u64 *out_size) -> std::vector { return buf.buf; } +auto npdm_patch_kc(std::vector& npdm, u32 off, u32 size, u32 bitmask, u32 value) -> bool { + const u32 pattern = BIT(bitmask) - 1; + const u32 mask = BIT(bitmask) | pattern; + + for (u32 i = 0; i < size; i += 4) { + u32 cup; + std::memcpy(&cup, npdm.data() + off + i, sizeof(cup)); + if ((cup & mask) == pattern) { + cup = value | pattern; + std::memcpy(npdm.data() + off + i, &cup, sizeof(cup)); + return true; + } + } + + return false; +} + // todo: manually build npdm void patch_npdm(std::vector& npdm, const NpdmPatch& patch) { NpdmMeta meta{}; NpdmAci0 aci0{}; + NpdmAcid acid{}; std::memcpy(&meta, npdm.data(), sizeof(meta)); std::memcpy(&aci0, npdm.data() + meta.aci0_offset, sizeof(aci0)); + std::memcpy(&acid, npdm.data() + meta.acid_offset, sizeof(acid)); // apply patch - std::memcpy(npdm.data() + 0x20, &patch.title_name, sizeof(patch.title_name)); - std::memcpy(npdm.data() + 0x30, &patch.product_code, sizeof(patch.product_code)); - std::memcpy(npdm.data() + meta.aci0_offset + 0x10, &patch.tid, sizeof(patch.tid)); - std::memcpy(npdm.data() + meta.acid_offset + 0x210, &patch.tid, sizeof(patch.tid)); - std::memcpy(npdm.data() + meta.acid_offset + 0x218, &patch.tid, sizeof(patch.tid)); + std::memcpy(meta.title_name, &patch.title_name, sizeof(meta.title_name)); + std::memcpy(meta.product_code, &patch.product_code, sizeof(patch.product_code)); + aci0.program_id = patch.tid; + acid.program_id_min = patch.tid; + acid.program_id_max = patch.tid; // patch debug flags based on ams version // SEE: https://github.com/ITotalJustice/sphaira/issues/67 - // disabled as it doesn't seem to launch with ForceDebug set. - // todo: look into ams and figure out why. - #if 0 u64 ver{}; splInitialize(); ON_SCOPE_EXIT(splExit()); @@ -618,20 +655,14 @@ void patch_npdm(std::vector& npdm, const NpdmPatch& patch) { splGetConfig(SplConfigItem_ExosphereVersion, &ver); ver >>= 40; - const auto kac_offset = meta.aci0_offset + sizeof(aci0) + aci0.kac_offset; - - for (u32 i = 0; i < aci0.kac_size; i += 4) { - u32 cup; - std::memcpy(&cup, npdm.data() + kac_offset + i, sizeof(cup)); - if ((cup & 0x1FFFF) == 0xFFFF) { - if (ver >= MAKEHOSVERSION(1,7,1) && hosversionAtLeast(1, 9, 0)) { - cup = BIT(19) | 0xFFFF; // ForceDebug - } - std::memcpy(npdm.data() + kac_offset + i, &cup, sizeof(cup)); - break; - } + if (ver >= MAKEHOSVERSION(1,7,1)) { + npdm_patch_kc(npdm, meta.aci0_offset + aci0.kac_offset, aci0.kac_size, 16, BIT(19)); + npdm_patch_kc(npdm, meta.acid_offset + acid.kac_offset, acid.kac_size, 16, BIT(19)); } - #endif + + std::memcpy(npdm.data(), &meta, sizeof(meta)); + std::memcpy(npdm.data() + meta.aci0_offset, &aci0, sizeof(aci0)); + std::memcpy(npdm.data() + meta.acid_offset, &acid, sizeof(acid)); } void patch_nacp(NacpStruct& nacp, const NcapPatch& patch) { From 1614c8e2e48ca4e248172f245a6dc3c5d0d716f1 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Wed, 1 Jan 2025 17:38:07 +0000 Subject: [PATCH 2/4] remove debug code in homebrew menu --- sphaira/source/ui/menus/homebrew.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphaira/source/ui/menus/homebrew.cpp b/sphaira/source/ui/menus/homebrew.cpp index 5ec0f1e..51607c5 100644 --- a/sphaira/source/ui/menus/homebrew.cpp +++ b/sphaira/source/ui/menus/homebrew.cpp @@ -268,7 +268,7 @@ void Menu::SetIndex(std::size_t index) { // log_write("name: %s hbini.ts: %lu file.ts: %lu smaller: %s\n", e.GetName(), e.hbini.timestamp, e.timestamp.modified, e.hbini.timestamp < e.timestamp.modified ? "true" : "false"); SetTitleSubHeading(m_entries[m_index].path); - this->SetSubHeading(std::to_string(m_index + 1) + " / " + std::to_string(m_entries.size()) + " " + std::to_string(m_start)); + this->SetSubHeading(std::to_string(m_index + 1) + " / " + std::to_string(m_entries.size())); } void Menu::InstallHomebrew() { From 6dbf48d73ca4ff9acdf066f68ca2ba648be51549 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Wed, 1 Jan 2025 17:42:07 +0000 Subject: [PATCH 3/4] fix badly formatted string for i18n fixes #68 --- sphaira/source/app.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphaira/source/app.cpp b/sphaira/source/app.cpp index b8c702e..754ab89 100644 --- a/sphaira/source/app.cpp +++ b/sphaira/source/app.cpp @@ -503,8 +503,8 @@ void App::SetReplaceHbmenuEnable(bool enable) { NacpStruct actual_hbmenu_nacp; if (R_FAILED(nro_get_nacp("/switch/hbmenu.nro", actual_hbmenu_nacp))) { App::Push(std::make_shared( - "Failed to find /switch/hbmenu.nro\n\ - Use the Appstore to re-install hbmenu"_i18n, + "Failed to find /switch/hbmenu.nro\n" + "Use the Appstore to re-install hbmenu"_i18n, "OK"_i18n )); return; From cf95128f0b35c7ffdbe9271b83ba08a629ad5834 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Wed, 1 Jan 2025 17:50:08 +0000 Subject: [PATCH 4/4] allow for github actions to run on all branches --- .github/workflows/build_presets.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/build_presets.yml b/.github/workflows/build_presets.yml index fbfd84c..22dd0b8 100644 --- a/.github/workflows/build_presets.yml +++ b/.github/workflows/build_presets.yml @@ -1,10 +1,6 @@ name: build -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] +on: [push, pull_request] jobs: build: