mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Net control
This commit is contained in:
parent
b19db45c6c
commit
86b8a2ee8e
2 changed files with 82 additions and 4 deletions
|
@ -74,14 +74,44 @@ namespace Net
|
|||
return null;
|
||||
}
|
||||
|
||||
public Nacp GetControl(ulong titleId, int version)
|
||||
{
|
||||
var cnmt = GetCnmt(titleId, version);
|
||||
var controlEntry = cnmt.ContentEntries.FirstOrDefault(x => x.Type == CnmtContentType.Control);
|
||||
if (controlEntry == null) return null;
|
||||
|
||||
var controlNca = GetNcaFile(titleId, version, controlEntry.NcaId.ToHexString());
|
||||
var nca = new Nca(ToolCtx.Keyset, controlNca, true);
|
||||
var romfs = new Romfs(nca.OpenSection(0, false));
|
||||
var controlNacp = romfs.GetFile("/control.nacp");
|
||||
|
||||
var reader = new BinaryReader(new MemoryStream(controlNacp));
|
||||
var control = new Nacp(reader);
|
||||
return control;
|
||||
}
|
||||
|
||||
public Stream GetNcaFile(ulong titleId, int version, string ncaId)
|
||||
{
|
||||
string titleDir = GetTitleDir(titleId, version);
|
||||
var filePath = Path.Combine(titleDir, $"{ncaId.ToLower()}.nca");
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
DownloadFile(GetContentUrl(ncaId), filePath);
|
||||
}
|
||||
|
||||
if (!File.Exists(filePath)) return null;
|
||||
|
||||
return new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
}
|
||||
|
||||
private void DownloadCnmt(ulong titleId, int version)
|
||||
{
|
||||
var titleDir = GetTitleDir(titleId, version);
|
||||
|
||||
var ncaId = GetMetadataNcaId(titleId, version);
|
||||
var filename = $"{ncaId}.cnmt.nca";
|
||||
var filename = $"{ncaId.ToLower()}.cnmt.nca";
|
||||
var filePath = Path.Combine(titleDir, filename);
|
||||
DownloadFile(GetContentUrl(ncaId), filePath);
|
||||
DownloadFile(GetMetaUrl(ncaId), filePath);
|
||||
}
|
||||
|
||||
public void DownloadFile(string url, string filePath)
|
||||
|
@ -103,9 +133,15 @@ namespace Net
|
|||
return titleDir;
|
||||
}
|
||||
|
||||
public string GetMetaUrl(string ncaId)
|
||||
{
|
||||
string url = $"{GetAtumUrl()}/c/a/{ncaId.ToLower()}";
|
||||
return url;
|
||||
}
|
||||
|
||||
public string GetContentUrl(string ncaId)
|
||||
{
|
||||
string url = $"{GetAtumUrl()}/c/a/{ncaId}";
|
||||
string url = $"{GetAtumUrl()}/c/c/{ncaId.ToLower()}";
|
||||
return url;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using libhac;
|
||||
|
@ -24,17 +26,37 @@ namespace Net
|
|||
|
||||
private static void ProcessNet(Context ctx)
|
||||
{
|
||||
|
||||
if (ctx.Options.DeviceId == 0)
|
||||
{
|
||||
CliParser.PrintWithUsage("A non-zero Device ID must be set.");
|
||||
return;
|
||||
}
|
||||
|
||||
var tid = ctx.Options.TitleId;
|
||||
var ver = ctx.Options.Version;
|
||||
|
||||
var net = new NetContext(ctx);
|
||||
var cnmt = net.GetCnmt(ctx.Options.TitleId, ctx.Options.Version);
|
||||
//GetControls(net);
|
||||
|
||||
var cnmt = net.GetCnmt(tid, ver);
|
||||
foreach (var entry in cnmt.ContentEntries)
|
||||
{
|
||||
Console.WriteLine($"{entry.NcaId.ToHexString()} {entry.Type}");
|
||||
net.GetNcaFile(tid, ver, entry.NcaId.ToHexString());
|
||||
}
|
||||
|
||||
var control = net.GetControl(tid, ver);
|
||||
;
|
||||
}
|
||||
|
||||
private static void GetControls(NetContext net)
|
||||
{
|
||||
var titles = GetTitleIds("titles.txt");
|
||||
|
||||
foreach (var title in titles)
|
||||
{
|
||||
var control = net.GetControl(title, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,5 +87,25 @@ namespace Net
|
|||
|
||||
ctx.Keyset = ExternalKeys.ReadKeyFile(keyFile, titleKeyFile, consoleKeyFile, ctx.Logger);
|
||||
}
|
||||
|
||||
private static List<ulong> GetTitleIds(string filename)
|
||||
{
|
||||
var titles = new List<ulong>();
|
||||
|
||||
using (var reader = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read)))
|
||||
{
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
if (ulong.TryParse(line, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var id))
|
||||
{
|
||||
titles.Add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return titles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue