From 57103c0e0b1f928284e39725297c30d48b6b76bc Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Thu, 5 Jul 2018 21:37:46 -0500 Subject: [PATCH] Improve finding a title's main RomFS --- hactoolnet/Program.cs | 28 ++++++++++++++++++---------- libhac/NcaStructs.cs | 2 +- libhac/SdFs.cs | 5 +++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/hactoolnet/Program.cs b/hactoolnet/Program.cs index d155c0cc..b94c2e84 100644 --- a/hactoolnet/Program.cs +++ b/hactoolnet/Program.cs @@ -16,17 +16,17 @@ namespace hactoolnet ctx.Options = CliParser.Parse(args); if (ctx.Options == null) return; - if (ctx.Options.RunCustom) - { - CustomTask(ctx); - return; - } - using (var logger = new ProgressBar()) { ctx.Logger = logger; OpenKeyset(ctx); + if (ctx.Options.RunCustom) + { + CustomTask(ctx); + return; + } + switch (ctx.Options.InFileType) { case FileType.Nca: @@ -120,13 +120,21 @@ namespace hactoolnet return; } - if (title.ProgramNca == null) + if (title.MainNca == null) { - ctx.Logger.LogMessage($"Could not find main program data for title {id:X16}"); + ctx.Logger.LogMessage($"Could not find main data for title {id:X16}"); return; } - var romfs = new Romfs(title.ProgramNca.OpenSection(1, false)); + var section = title.MainNca.Sections.FirstOrDefault(x => x.Type == SectionType.Romfs); + + if (section == null) + { + ctx.Logger.LogMessage($"Main NCA for title {id:X16} has no Rom FS section"); + return; + } + + var romfs = new Romfs(title.MainNca.OpenSection(section.SectionNum, false)); romfs.Extract(ctx.Options.RomfsOutDir, ctx.Logger); } @@ -189,7 +197,7 @@ namespace hactoolnet { var sdfs = LoadSdFs(args); var title = sdfs.Titles[0x0100E95004038000]; - var nca = title.ProgramNca; + var nca = title.MainNca; var romfsStream = nca.OpenSection(1, false); var romfs = new Romfs(romfsStream); var file = romfs.OpenFile("/stream/voice/us/127/127390101.nop"); diff --git a/libhac/NcaStructs.cs b/libhac/NcaStructs.cs index dda42dc8..7c7e08fa 100644 --- a/libhac/NcaStructs.cs +++ b/libhac/NcaStructs.cs @@ -275,7 +275,7 @@ namespace libhac Control, Manual, Data, - Unknown + AocData } public enum DistributionType diff --git a/libhac/SdFs.cs b/libhac/SdFs.cs index 9aa1dc82..c2d6afa0 100644 --- a/libhac/SdFs.cs +++ b/libhac/SdFs.cs @@ -111,7 +111,8 @@ namespace libhac switch (content.Type) { case CnmtContentType.Program: - title.ProgramNca = contentNca; + case CnmtContentType.Data: + title.MainNca = contentNca; break; case CnmtContentType.Control: title.ControlNca = contentNca; @@ -227,7 +228,7 @@ namespace libhac public string Name { get; internal set; } public Nacp Control { get; internal set; } public Nca MetaNca { get; internal set; } - public Nca ProgramNca { get; internal set; } + public Nca MainNca { get; internal set; } public Nca ControlNca { get; internal set; } public long GetSize()