From d5ddde4909e906180d857eadc97ff3df9b3ffd0a Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sat, 30 Jun 2018 14:15:55 -0500 Subject: [PATCH] Read nacp display name and version --- hactoolnet/Program.cs | 2 +- libhac/Nacp.cs | 41 +++++++++++++++++++++++++++++++++++++++++ libhac/SdFs.cs | 14 +++++++++++++- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 libhac/Nacp.cs diff --git a/hactoolnet/Program.cs b/hactoolnet/Program.cs index c9c01066..377c98b8 100644 --- a/hactoolnet/Program.cs +++ b/hactoolnet/Program.cs @@ -129,7 +129,7 @@ namespace hactoolnet { foreach (var title in sdfs.Titles.Values.OrderBy(x => x.Id)) { - Console.WriteLine(title.Name); + Console.WriteLine($"{title.Name} {title.Control?.Version}"); Console.WriteLine($"{title.Id:X16} v{title.Version.Version} ({title.Version}) {title.Metadata.Type}"); foreach (var content in title.Metadata.ContentEntries) diff --git a/libhac/Nacp.cs b/libhac/Nacp.cs new file mode 100644 index 00000000..71f392b5 --- /dev/null +++ b/libhac/Nacp.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace libhac +{ + public class Nacp + { + public NacpLang[] Languages { get; } = new NacpLang[0x10]; + public string Version { get; } + + public Nacp(BinaryReader reader) + { + var start = reader.BaseStream.Position; + + for (int i = 0; i < 16; i++) + { + Languages[i] = new NacpLang(reader); + } + + reader.BaseStream.Position = start + 0x3060; + Version = reader.ReadUtf8Z(); + } + } + + public class NacpLang + { + public string Title { get; } + public string Developer { get; } + + public NacpLang(BinaryReader reader) + { + var start = reader.BaseStream.Position; + Title = reader.ReadUtf8Z(); + reader.BaseStream.Position = start + 0x200; + Developer = reader.ReadUtf8Z(); + reader.BaseStream.Position = start + 0x300; + } + } +} diff --git a/libhac/SdFs.cs b/libhac/SdFs.cs index 0224d625..8196bf92 100644 --- a/libhac/SdFs.cs +++ b/libhac/SdFs.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; @@ -108,7 +109,16 @@ namespace libhac File.WriteAllBytes($"control/{title.Id:X16}.nacp", control); var reader = new BinaryReader(new MemoryStream(control)); - title.Name = reader.ReadUtf8Z(); + title.Control = new Nacp(reader); + + foreach (var lang in title.Control.Languages) + { + if (!string.IsNullOrWhiteSpace(lang.Title)) + { + title.Name = lang.Title; + break; + } + } } } @@ -131,6 +141,7 @@ namespace libhac } } + [DebuggerDisplay("{" + nameof(Name) + "}")] public class Title { public ulong Id { get; internal set; } @@ -139,6 +150,7 @@ namespace libhac public Cnmt Metadata { get; internal set; } 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 ControlNca { get; internal set; }