From 3090c9f236e3422b3242c90b9c05f2ac1843b8fd Mon Sep 17 00:00:00 2001 From: emmaus Date: Sun, 17 Jun 2018 10:17:09 +0000 Subject: [PATCH] Add Nacp parsing --- .../Loaders/Archives/ControlArchive.cs | 53 +++++++++++++++++++ Ryujinx.HLE/Loaders/Executables/Nro.cs | 13 ++++- 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 Ryujinx.HLE/Loaders/Archives/ControlArchive.cs diff --git a/Ryujinx.HLE/Loaders/Archives/ControlArchive.cs b/Ryujinx.HLE/Loaders/Archives/ControlArchive.cs new file mode 100644 index 000000000..481b359da --- /dev/null +++ b/Ryujinx.HLE/Loaders/Archives/ControlArchive.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace Ryujinx.HLE.Loaders.Archives +{ + public class ControlArchive + { + public LanguageEntry[] LanguageEntries { get; set; } + public long ApplicationTitleID { get; set; } + public long BaseTitleID { get; set; } + public long ProductCode { get; set; } + public string ApplicationVersion { get; set; } + + public ControlArchive(Stream Input) + { + BinaryReader Reader = new BinaryReader(Input); + + byte[] LanguageEntryData = Reader.ReadBytes(0x3000); + + Input.Seek(0x3060, SeekOrigin.Begin); + ApplicationVersion = Encoding.ASCII.GetString(Reader.ReadBytes(0x10)); + BaseTitleID = Reader.ReadInt64(); + ApplicationTitleID = Reader.ReadInt64(); + + Input.Seek(0x30a8, SeekOrigin.Begin); + ProductCode = Reader.ReadInt64(); + + LanguageEntries = new LanguageEntry[16]; + + using (MemoryStream LanguageStream = new MemoryStream(LanguageEntryData)) + { + BinaryReader LanguageReader = new BinaryReader(LanguageStream); + for (int index = 0; index < 16; index++) + { + LanguageEntries[index] = new LanguageEntry() + { + AplicationName = Encoding.ASCII.GetString(LanguageReader.ReadBytes(0x200)).Trim('\0'), + DeveloperName = Encoding.ASCII.GetString(LanguageReader.ReadBytes(0x100)).Trim('\0') + }; + } + } + } + } + + + public struct LanguageEntry + { + public string AplicationName; + public string DeveloperName; + } +} diff --git a/Ryujinx.HLE/Loaders/Executables/Nro.cs b/Ryujinx.HLE/Loaders/Executables/Nro.cs index 671936c8e..b7712173c 100644 --- a/Ryujinx.HLE/Loaders/Executables/Nro.cs +++ b/Ryujinx.HLE/Loaders/Executables/Nro.cs @@ -2,6 +2,7 @@ using System; using System.Drawing; using System.IO; using System.Text; +using Ryujinx.HLE.Loaders.Archives; namespace Ryujinx.HLE.Loaders.Executables { @@ -14,7 +15,6 @@ namespace Ryujinx.HLE.Loaders.Executables public byte[] Data { get; private set; } public byte[] AssetRomfData { get; set; } public byte[] IconData { get; set; } - public byte[] NCAPData { get; set; } public int Mod0Offset { get; private set; } public int TextOffset { get; private set; } @@ -23,6 +23,10 @@ namespace Ryujinx.HLE.Loaders.Executables public int BssSize { get; private set; } public int AssetOffset { get; set; } + public ControlArchive ControlArchive { get; set; } + + private byte[] NACPData { get; set; } + public Nro(Stream Input, string Name) { this.Name = Name; @@ -88,12 +92,17 @@ namespace Ryujinx.HLE.Loaders.Executables IconData = Reader.ReadBytes((int)IconSize); Input.Seek(AssetOffset + NACPOffset, SeekOrigin.Begin); - NCAPData = Reader.ReadBytes((int)NACPSize); + NACPData = Reader.ReadBytes((int)NACPSize); Input.Seek(AssetOffset + RomfOffset, SeekOrigin.Begin); AssetRomfData = Reader.ReadBytes((int)RomfSize); } } + + using(MemoryStream NACPStream = new MemoryStream(NACPData)) + { + ControlArchive = new ControlArchive(NACPStream); + } } } } \ No newline at end of file