Skip to content

Commit

Permalink
poc: display a warning if a titlekey can't be located after starting …
Browse files Browse the repository at this point in the history
…a NSP dump.

Also, what the heck was I thinking last night with that NcmContentMetaType_Patch...?

I'm degenerating.
  • Loading branch information
DarkMatterCore committed Nov 3, 2023
1 parent e1df86f commit b14ccf2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ jobs:
- name: Upload artifact to prerelease
uses: ncipollo/release-action@v1
with:
# Only update attachments on "rewrite-prerelease" tag. Make sure to update the commit referenced by the tag as well by using the branch name.
# Only update attachments on "rewrite-prerelease" tag.
prerelease: True
tag: "rewrite-prerelease"
commit: "rewrite"
updateOnlyUnreleased: True
# Remove old artifacts and replace with new ones.
removeArtifacts: True
Expand Down
41 changes: 27 additions & 14 deletions code_templates/nxdt_rw_poc.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ typedef struct {
static void utilsScanPads(void);
static u64 utilsGetButtonsDown(void);
static u64 utilsGetButtonsHeld(void);
static void utilsWaitForButtonPress(u64 flag);
static u64 utilsWaitForButtonPress(u64 flag);

static void consolePrint(const char *text, ...);
static void consolePrintReversedColors(const char *text, ...);
Expand Down Expand Up @@ -1420,20 +1420,24 @@ static u64 utilsGetButtonsHeld(void)
return padGetButtons(&g_padState);
}

static void utilsWaitForButtonPress(u64 flag)
static u64 utilsWaitForButtonPress(u64 flag)
{
/* Don't consider stick movement as button inputs. */
if (!flag) flag = ~(HidNpadButton_StickLLeft | HidNpadButton_StickLRight | HidNpadButton_StickLUp | HidNpadButton_StickLDown | HidNpadButton_StickRLeft | HidNpadButton_StickRRight | \
HidNpadButton_StickRUp | HidNpadButton_StickRDown);

consoleRefresh();

u64 btn_down = 0;

while(appletMainLoop())
{
utilsScanPads();
if (utilsGetButtonsDown() & flag) break;
if ((btn_down = utilsGetButtonsDown()) & flag) break;
utilsAppletLoopDelay();
}

return btn_down;
}

static void consolePrint(const char *text, ...)
Expand Down Expand Up @@ -3214,12 +3218,6 @@ static bool saveNintendoContentArchiveFsSection(void *userdata)

/* Use a matching NCA FS section entry. */
base_patch_nca_fs_ctx = &(base_patch_nca_ctx->fs_ctx[nca_fs_ctx->section_idx]);
} else
if (title_type != NcmContentMetaType_Patch)
{
/* Handles edge cases where a specific NCA from an update has no matching equivalent by type/ID offset in its base title (e.g. Fall Guys' HtmlDocument NCA). */
consolePrint("unable to find content with type %s and id offset %u in selected base/patch title!\n", titleGetNcmContentTypeName(content_type), nca_ctx->id_offset);
goto end;
}

if (section_type == NcaFsSectionType_PartitionFs)
Expand Down Expand Up @@ -4785,7 +4783,7 @@ static void nspThreadFunc(void *arg)
bool patch_video_capture = (bool)getNspEnableVideoCaptureOption();
bool patch_hdcp = (bool)getNspDisableHdcpOption();
bool generate_authoringtool_data = (bool)getNspGenerateAuthoringToolDataOption();
bool success = false;
bool success = false, no_titlekey_confirmation = false;

u64 free_space = 0;
u32 dev_idx = g_storageMenuElementOption.selected;
Expand Down Expand Up @@ -4924,11 +4922,26 @@ static void nspThreadFunc(void *arg)
consolePrint("%s #%u initialize nca ctx succeeded\n", titleGetNcmContentTypeName(content_info->content_type), content_info->id_offset);

// don't go any further with this nca if we can't access its fs data because it's pointless
// TODO: add preload warning
if (cur_nca_ctx->rights_id_available && !cur_nca_ctx->titlekey_retrieved)
if (cur_nca_ctx->rights_id_available && !cur_nca_ctx->titlekey_retrieved && !no_titlekey_confirmation)
{
j++;
continue;
consolePrintReversedColors("\nunable to retrieve titlekey for the selected title");
consolePrintReversedColors("\nif you proceed, nca modifications will be disabled, and content decryption");
consolePrintReversedColors("\nwill not be possible for external tools (e.g. emulators, etc.)\n");

consolePrintReversedColors("\nif this is a shared game and you wish to fix this, exit the application and");
consolePrintReversedColors("\ntry running it at least once, then come back and try again\n");

consolePrintReversedColors("\npress a to proceed anyway, or b to cancel\n\n");

u64 btn_down = utilsWaitForButtonPress(HidNpadButton_A | HidNpadButton_B);
if (btn_down & HidNpadButton_A)
{
j++;
no_titlekey_confirmation = true;
continue;
}

goto end;
}

// set download distribution type
Expand Down

0 comments on commit b14ccf2

Please sign in to comment.