mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Read title names
This commit is contained in:
parent
d24028f34d
commit
1df1ce7bcc
4 changed files with 51 additions and 18 deletions
|
@ -10,7 +10,8 @@ namespace hactoolnet
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
FileReadTest(args);
|
ListSdfs(args);
|
||||||
|
//FileReadTest(args);
|
||||||
//ReadNca();
|
//ReadNca();
|
||||||
//ListSdfs(args);
|
//ListSdfs(args);
|
||||||
//ReadNcaSdfs(args);
|
//ReadNcaSdfs(args);
|
||||||
|
@ -36,17 +37,12 @@ namespace hactoolnet
|
||||||
var title = sdfs.Titles[0x0100E95004038000];
|
var title = sdfs.Titles[0x0100E95004038000];
|
||||||
var nca = title.ProgramNca;
|
var nca = title.ProgramNca;
|
||||||
var romfsStream = nca.OpenSection(1, false);
|
var romfsStream = nca.OpenSection(1, false);
|
||||||
|
|
||||||
var romfs = new Romfs(romfsStream);
|
var romfs = new Romfs(romfsStream);
|
||||||
var file = romfs.OpenFile("/bf2.ard");
|
var file = romfs.OpenFile("/stream/voice/us/127/127390101.nop");
|
||||||
|
|
||||||
using (var progress = new ProgressBar())
|
using (var output = new FileStream("127390101.nop", FileMode.Create))
|
||||||
using (var output = new FileStream("bf2.ard", FileMode.Create))
|
|
||||||
{
|
{
|
||||||
var watch = Stopwatch.StartNew();
|
file.CopyTo(output);
|
||||||
file.CopyStream(output, file.Length / 100, progress);
|
|
||||||
watch.Stop();
|
|
||||||
progress.LogMessage(watch.Elapsed.TotalSeconds.ToString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +129,7 @@ namespace hactoolnet
|
||||||
{
|
{
|
||||||
foreach (var title in sdfs.Titles.Values.OrderBy(x => x.Id))
|
foreach (var title in sdfs.Titles.Values.OrderBy(x => x.Id))
|
||||||
{
|
{
|
||||||
|
Console.WriteLine(title.Name);
|
||||||
Console.WriteLine($"{title.Id:X16} v{title.Version.Version} ({title.Version}) {title.Metadata.Type}");
|
Console.WriteLine($"{title.Id:X16} v{title.Version.Version} ({title.Version}) {title.Metadata.Type}");
|
||||||
|
|
||||||
foreach (var content in title.Metadata.ContentEntries)
|
foreach (var content in title.Metadata.ContentEntries)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -20,8 +19,6 @@ namespace libhac
|
||||||
|
|
||||||
public Romfs(Stream stream)
|
public Romfs(Stream stream)
|
||||||
{
|
{
|
||||||
var watch = Stopwatch.StartNew();
|
|
||||||
|
|
||||||
byte[] dirMetaTable;
|
byte[] dirMetaTable;
|
||||||
byte[] fileMetaTable;
|
byte[] fileMetaTable;
|
||||||
using (var reader = new BinaryReader(stream, Encoding.Default, true))
|
using (var reader = new BinaryReader(stream, Encoding.Default, true))
|
||||||
|
@ -61,10 +58,6 @@ namespace libhac
|
||||||
ResolveFilenames();
|
ResolveFilenames();
|
||||||
FileDict = Files.ToDictionary(x => x.FullPath, x => x);
|
FileDict = Files.ToDictionary(x => x.FullPath, x => x);
|
||||||
Stream = stream;
|
Stream = stream;
|
||||||
|
|
||||||
watch.Stop();
|
|
||||||
Console.WriteLine(watch.Elapsed.TotalMilliseconds);
|
|
||||||
Console.WriteLine(Files.Count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream OpenFile(string filename)
|
public Stream OpenFile(string filename)
|
||||||
|
@ -78,6 +71,18 @@ namespace libhac
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] GetFile(string filename)
|
||||||
|
{
|
||||||
|
var stream = OpenFile(filename);
|
||||||
|
var file = new byte[stream.Length];
|
||||||
|
using (var ms = new MemoryStream(file))
|
||||||
|
{
|
||||||
|
stream.CopyTo(ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
public bool FileExists(string filename) => FileDict.ContainsKey(filename);
|
public bool FileExists(string filename) => FileDict.ContainsKey(filename);
|
||||||
|
|
||||||
private void SetReferences()
|
private void SetReferences()
|
||||||
|
|
|
@ -29,6 +29,7 @@ namespace libhac
|
||||||
Files = Directory.GetFiles(ContentsDir, "00", SearchOption.AllDirectories).Select(Path.GetDirectoryName).ToArray();
|
Files = Directory.GetFiles(ContentsDir, "00", SearchOption.AllDirectories).Select(Path.GetDirectoryName).ToArray();
|
||||||
OpenAllNcas();
|
OpenAllNcas();
|
||||||
ReadTitles();
|
ReadTitles();
|
||||||
|
ReadControls();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpenAllNcas()
|
private void OpenAllNcas()
|
||||||
|
@ -97,6 +98,20 @@ namespace libhac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ReadControls()
|
||||||
|
{
|
||||||
|
foreach (var title in Titles.Values.Where(x => x.ControlNca != null))
|
||||||
|
{
|
||||||
|
var romfs = new Romfs(title.ControlNca.OpenSection(0, false));
|
||||||
|
var control = romfs.GetFile("/control.nacp");
|
||||||
|
Directory.CreateDirectory("control");
|
||||||
|
File.WriteAllBytes($"control/{title.Id:X16}.nacp", control);
|
||||||
|
|
||||||
|
var reader = new BinaryReader(new MemoryStream(control));
|
||||||
|
title.Name = reader.ReadUtf8Z();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void DisposeNcas()
|
private void DisposeNcas()
|
||||||
{
|
{
|
||||||
foreach (Nca nca in Ncas.Values)
|
foreach (Nca nca in Ncas.Values)
|
||||||
|
@ -123,6 +138,7 @@ namespace libhac
|
||||||
public List<Nca> Ncas { get; } = new List<Nca>();
|
public List<Nca> Ncas { get; } = new List<Nca>();
|
||||||
public Cnmt Metadata { get; internal set; }
|
public Cnmt Metadata { get; internal set; }
|
||||||
|
|
||||||
|
public string Name { get; internal set; }
|
||||||
public Nca MetaNca { get; internal set; }
|
public Nca MetaNca { get; internal set; }
|
||||||
public Nca ProgramNca { get; internal set; }
|
public Nca ProgramNca { get; internal set; }
|
||||||
public Nca ControlNca { get; internal set; }
|
public Nca ControlNca { get; internal set; }
|
||||||
|
|
|
@ -93,6 +93,21 @@ namespace libhac
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ReadUtf8Z(this BinaryReader reader)
|
||||||
|
{
|
||||||
|
var start = reader.BaseStream.Position;
|
||||||
|
|
||||||
|
// Read until we hit the end of the stream (-1) or a zero
|
||||||
|
while (reader.BaseStream.ReadByte() - 1 > 0) { }
|
||||||
|
|
||||||
|
int size = (int)(reader.BaseStream.Position - start - 1);
|
||||||
|
reader.BaseStream.Position = start;
|
||||||
|
|
||||||
|
string text = reader.ReadUtf8(size);
|
||||||
|
reader.BaseStream.Position++; // Skip the null byte
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
public static string ReadAscii(this BinaryReader reader, int size)
|
public static string ReadAscii(this BinaryReader reader, int size)
|
||||||
{
|
{
|
||||||
return Encoding.ASCII.GetString(reader.ReadBytes(size), 0, size);
|
return Encoding.ASCII.GetString(reader.ReadBytes(size), 0, size);
|
||||||
|
|
Loading…
Reference in a new issue