Update to LibHac 0.2.0 (#549)
* Update to LibHac 0.2.0 * Changes based on feedback
This commit is contained in:
parent
cf147f1e49
commit
290f5e812e
9 changed files with 110 additions and 120 deletions
|
@ -1,4 +1,5 @@
|
||||||
using LibHac;
|
using LibHac;
|
||||||
|
using LibHac.IO;
|
||||||
using Ryujinx.HLE.Utilities;
|
using Ryujinx.HLE.Utilities;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -73,7 +74,7 @@ namespace Ryujinx.HLE.FileSystem.Content
|
||||||
|
|
||||||
using (FileStream ncaFile = new FileStream(Directory.GetFiles(directoryPath)[0], FileMode.Open, FileAccess.Read))
|
using (FileStream ncaFile = new FileStream(Directory.GetFiles(directoryPath)[0], FileMode.Open, FileAccess.Read))
|
||||||
{
|
{
|
||||||
Nca nca = new Nca(_device.System.KeySet, ncaFile, false);
|
Nca nca = new Nca(_device.System.KeySet, ncaFile.AsStorage(), false);
|
||||||
|
|
||||||
string switchPath = Path.Combine(contentPathString + ":",
|
string switchPath = Path.Combine(contentPathString + ":",
|
||||||
ncaFile.Name.Replace(contentDirectory, string.Empty).TrimStart('\\'));
|
ncaFile.Name.Replace(contentDirectory, string.Empty).TrimStart('\\'));
|
||||||
|
@ -89,10 +90,6 @@ namespace Ryujinx.HLE.FileSystem.Content
|
||||||
AddEntry(entry);
|
AddEntry(entry);
|
||||||
|
|
||||||
_contentDictionary.Add((nca.Header.TitleId, nca.Header.ContentType), ncaName);
|
_contentDictionary.Add((nca.Header.TitleId, nca.Header.ContentType), ncaName);
|
||||||
|
|
||||||
ncaFile.Close();
|
|
||||||
nca.Dispose();
|
|
||||||
ncaFile.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,7 +102,7 @@ namespace Ryujinx.HLE.FileSystem.Content
|
||||||
|
|
||||||
using (FileStream ncaFile = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
using (FileStream ncaFile = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
||||||
{
|
{
|
||||||
Nca nca = new Nca(_device.System.KeySet, ncaFile, false);
|
Nca nca = new Nca(_device.System.KeySet, ncaFile.AsStorage(), false);
|
||||||
|
|
||||||
string switchPath = Path.Combine(contentPathString + ":",
|
string switchPath = Path.Combine(contentPathString + ":",
|
||||||
filePath.Replace(contentDirectory, string.Empty).TrimStart('\\'));
|
filePath.Replace(contentDirectory, string.Empty).TrimStart('\\'));
|
||||||
|
@ -121,10 +118,6 @@ namespace Ryujinx.HLE.FileSystem.Content
|
||||||
AddEntry(entry);
|
AddEntry(entry);
|
||||||
|
|
||||||
_contentDictionary.Add((nca.Header.TitleId, nca.Header.ContentType), ncaName);
|
_contentDictionary.Add((nca.Header.TitleId, nca.Header.ContentType), ncaName);
|
||||||
|
|
||||||
ncaFile.Close();
|
|
||||||
nca.Dispose();
|
|
||||||
ncaFile.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,16 +228,15 @@ namespace Ryujinx.HLE.FileSystem.Content
|
||||||
{
|
{
|
||||||
if (File.Exists(installedPath))
|
if (File.Exists(installedPath))
|
||||||
{
|
{
|
||||||
FileStream file = new FileStream(installedPath, FileMode.Open, FileAccess.Read);
|
using (FileStream file = new FileStream(installedPath, FileMode.Open, FileAccess.Read))
|
||||||
Nca nca = new Nca(_device.System.KeySet, file, false);
|
{
|
||||||
|
Nca nca = new Nca(_device.System.KeySet, file.AsStorage(), false);
|
||||||
bool contentCheck = nca.Header.ContentType == contentType;
|
bool contentCheck = nca.Header.ContentType == contentType;
|
||||||
|
|
||||||
nca.Dispose();
|
|
||||||
file.Dispose();
|
|
||||||
|
|
||||||
return contentCheck;
|
return contentCheck;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using LibHac;
|
using LibHac;
|
||||||
|
using LibHac.IO;
|
||||||
using Ryujinx.HLE.HOS;
|
using Ryujinx.HLE.HOS;
|
||||||
using Ryujinx.HLE.HOS.Services.FspSrv;
|
using Ryujinx.HLE.HOS.Services.FspSrv;
|
||||||
using System;
|
using System;
|
||||||
|
@ -117,7 +118,7 @@ namespace Ryujinx.HLE.FileSystem
|
||||||
|
|
||||||
if (_pfs.FileExists(name))
|
if (_pfs.FileExists(name))
|
||||||
{
|
{
|
||||||
Stream stream = _pfs.OpenFile(name);
|
Stream stream = _pfs.OpenFile(name).AsStream();
|
||||||
fileInterface = new IFile(stream, name);
|
fileInterface = new IFile(stream, name);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using LibHac;
|
using LibHac;
|
||||||
|
using LibHac.IO;
|
||||||
using Ryujinx.HLE.HOS;
|
using Ryujinx.HLE.HOS;
|
||||||
using Ryujinx.HLE.HOS.Services.FspSrv;
|
using Ryujinx.HLE.HOS.Services.FspSrv;
|
||||||
using System;
|
using System;
|
||||||
|
@ -14,9 +15,9 @@ namespace Ryujinx.HLE.FileSystem
|
||||||
{
|
{
|
||||||
private Romfs _romFs;
|
private Romfs _romFs;
|
||||||
|
|
||||||
public RomFsProvider(Stream storageStream)
|
public RomFsProvider(LibHac.IO.IStorage storage)
|
||||||
{
|
{
|
||||||
_romFs = new Romfs(storageStream);
|
_romFs = new Romfs(storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long CreateDirectory(string name)
|
public long CreateDirectory(string name)
|
||||||
|
@ -133,7 +134,7 @@ namespace Ryujinx.HLE.FileSystem
|
||||||
{
|
{
|
||||||
if (_romFs.FileExists(name))
|
if (_romFs.FileExists(name))
|
||||||
{
|
{
|
||||||
Stream stream = _romFs.OpenFile(name);
|
Stream stream = _romFs.OpenFile(name).AsStream();
|
||||||
|
|
||||||
fileInterface = new IFile(stream, name);
|
fileInterface = new IFile(stream, name);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using LibHac;
|
using LibHac;
|
||||||
|
using LibHac.IO;
|
||||||
using Ryujinx.HLE.FileSystem;
|
using Ryujinx.HLE.FileSystem;
|
||||||
using Ryujinx.HLE.FileSystem.Content;
|
using Ryujinx.HLE.FileSystem.Content;
|
||||||
using Ryujinx.HLE.Resource;
|
using Ryujinx.HLE.Resource;
|
||||||
|
@ -67,13 +68,17 @@ namespace Ryujinx.HLE.HOS.Font
|
||||||
fileIndex = 1;
|
fileIndex = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileStream ncaFileStream = new FileStream(fontPath, FileMode.Open, FileAccess.Read);
|
byte[] data;
|
||||||
Nca nca = new Nca(_device.System.KeySet, ncaFileStream, false);
|
|
||||||
NcaSection romfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
|
|
||||||
Romfs romfs = new Romfs(nca.OpenSection(romfsSection.SectionNum, false, _device.System.FsIntegrityCheckLevel));
|
|
||||||
Stream fontFile = romfs.OpenFile(romfs.Files[fileIndex]);
|
|
||||||
|
|
||||||
byte[] data = DecryptFont(fontFile);
|
using (FileStream ncaFileStream = new FileStream(fontPath, FileMode.Open, FileAccess.Read))
|
||||||
|
{
|
||||||
|
Nca nca = new Nca(_device.System.KeySet, ncaFileStream.AsStorage(), false);
|
||||||
|
NcaSection romfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
|
||||||
|
Romfs romfs = new Romfs(nca.OpenSection(romfsSection.SectionNum, false, _device.System.FsIntegrityCheckLevel, false));
|
||||||
|
Stream fontFile = romfs.OpenFile(romfs.Files[fileIndex]).AsStream();
|
||||||
|
|
||||||
|
data = DecryptFont(fontFile);
|
||||||
|
}
|
||||||
|
|
||||||
FontInfo info = new FontInfo((int)fontOffset, data.Length);
|
FontInfo info = new FontInfo((int)fontOffset, data.Length);
|
||||||
|
|
||||||
|
@ -88,9 +93,6 @@ namespace Ryujinx.HLE.HOS.Font
|
||||||
_device.Memory.WriteByte(_physicalAddress + fontOffset, data[fontOffset - start]);
|
_device.Memory.WriteByte(_physicalAddress + fontOffset, data[fontOffset - start]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ncaFileStream.Dispose();
|
|
||||||
nca.Dispose();
|
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using LibHac;
|
using LibHac;
|
||||||
|
using LibHac.IO;
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
using Ryujinx.HLE.FileSystem.Content;
|
using Ryujinx.HLE.FileSystem.Content;
|
||||||
using Ryujinx.HLE.HOS.Font;
|
using Ryujinx.HLE.HOS.Font;
|
||||||
|
@ -242,7 +243,7 @@ namespace Ryujinx.HLE.HOS
|
||||||
{
|
{
|
||||||
FileStream file = new FileStream(xciFile, FileMode.Open, FileAccess.Read);
|
FileStream file = new FileStream(xciFile, FileMode.Open, FileAccess.Read);
|
||||||
|
|
||||||
Xci xci = new Xci(KeySet, file);
|
Xci xci = new Xci(KeySet, file.AsStorage());
|
||||||
|
|
||||||
(Nca mainNca, Nca controlNca) = GetXciGameData(xci);
|
(Nca mainNca, Nca controlNca) = GetXciGameData(xci);
|
||||||
|
|
||||||
|
@ -271,7 +272,7 @@ namespace Ryujinx.HLE.HOS
|
||||||
|
|
||||||
foreach (PfsFileEntry ticketEntry in xci.SecurePartition.Files.Where(x => x.Name.EndsWith(".tik")))
|
foreach (PfsFileEntry ticketEntry in xci.SecurePartition.Files.Where(x => x.Name.EndsWith(".tik")))
|
||||||
{
|
{
|
||||||
Ticket ticket = new Ticket(xci.SecurePartition.OpenFile(ticketEntry));
|
Ticket ticket = new Ticket(xci.SecurePartition.OpenFile(ticketEntry).AsStream());
|
||||||
|
|
||||||
if (!KeySet.TitleKeys.ContainsKey(ticket.RightsId))
|
if (!KeySet.TitleKeys.ContainsKey(ticket.RightsId))
|
||||||
{
|
{
|
||||||
|
@ -281,9 +282,9 @@ namespace Ryujinx.HLE.HOS
|
||||||
|
|
||||||
foreach (PfsFileEntry fileEntry in xci.SecurePartition.Files.Where(x => x.Name.EndsWith(".nca")))
|
foreach (PfsFileEntry fileEntry in xci.SecurePartition.Files.Where(x => x.Name.EndsWith(".nca")))
|
||||||
{
|
{
|
||||||
Stream ncaStream = xci.SecurePartition.OpenFile(fileEntry);
|
IStorage ncaStorage = xci.SecurePartition.OpenFile(fileEntry);
|
||||||
|
|
||||||
Nca nca = new Nca(KeySet, ncaStream, true);
|
Nca nca = new Nca(KeySet, ncaStorage, true);
|
||||||
|
|
||||||
if (nca.Header.ContentType == ContentType.Program)
|
if (nca.Header.ContentType == ContentType.Program)
|
||||||
{
|
{
|
||||||
|
@ -326,20 +327,18 @@ namespace Ryujinx.HLE.HOS
|
||||||
|
|
||||||
public void ReadControlData(Nca controlNca)
|
public void ReadControlData(Nca controlNca)
|
||||||
{
|
{
|
||||||
Romfs controlRomfs = new Romfs(controlNca.OpenSection(0, false, FsIntegrityCheckLevel));
|
Romfs controlRomfs = new Romfs(controlNca.OpenSection(0, false, FsIntegrityCheckLevel, true));
|
||||||
|
|
||||||
byte[] controlFile = controlRomfs.GetFile("/control.nacp");
|
IStorage controlFile = controlRomfs.OpenFile("/control.nacp");
|
||||||
|
|
||||||
BinaryReader reader = new BinaryReader(new MemoryStream(controlFile));
|
ControlData = new Nacp(controlFile.AsStream());
|
||||||
|
|
||||||
ControlData = new Nacp(reader);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadNca(string ncaFile)
|
public void LoadNca(string ncaFile)
|
||||||
{
|
{
|
||||||
FileStream file = new FileStream(ncaFile, FileMode.Open, FileAccess.Read);
|
FileStream file = new FileStream(ncaFile, FileMode.Open, FileAccess.Read);
|
||||||
|
|
||||||
Nca nca = new Nca(KeySet, file, true);
|
Nca nca = new Nca(KeySet, file.AsStorage(false), false);
|
||||||
|
|
||||||
LoadNca(nca, null);
|
LoadNca(nca, null);
|
||||||
}
|
}
|
||||||
|
@ -348,16 +347,16 @@ namespace Ryujinx.HLE.HOS
|
||||||
{
|
{
|
||||||
FileStream file = new FileStream(nspFile, FileMode.Open, FileAccess.Read);
|
FileStream file = new FileStream(nspFile, FileMode.Open, FileAccess.Read);
|
||||||
|
|
||||||
Pfs nsp = new Pfs(file);
|
Pfs nsp = new Pfs(file.AsStorage(false));
|
||||||
|
|
||||||
PfsFileEntry ticketFile = nsp.Files.FirstOrDefault(x => x.Name.EndsWith(".tik"));
|
foreach (PfsFileEntry ticketEntry in nsp.Files.Where(x => x.Name.EndsWith(".tik")))
|
||||||
|
|
||||||
// Load title key from the NSP's ticket in case the user doesn't have a title key file
|
|
||||||
if (ticketFile != null)
|
|
||||||
{
|
{
|
||||||
Ticket ticket = new Ticket(nsp.OpenFile(ticketFile));
|
Ticket ticket = new Ticket(nsp.OpenFile(ticketEntry).AsStream());
|
||||||
|
|
||||||
KeySet.TitleKeys[ticket.RightsId] = ticket.GetTitleKey(KeySet);
|
if (!KeySet.TitleKeys.ContainsKey(ticket.RightsId))
|
||||||
|
{
|
||||||
|
KeySet.TitleKeys.Add(ticket.RightsId, ticket.GetTitleKey(KeySet));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Nca mainNca = null;
|
Nca mainNca = null;
|
||||||
|
@ -396,26 +395,26 @@ namespace Ryujinx.HLE.HOS
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream romfsStream = mainNca.OpenSection(ProgramPartitionType.Data, false, FsIntegrityCheckLevel);
|
IStorage romfsStorage = mainNca.OpenSection(ProgramPartitionType.Data, false, FsIntegrityCheckLevel, false);
|
||||||
Stream exefsStream = mainNca.OpenSection(ProgramPartitionType.Code, false, FsIntegrityCheckLevel);
|
IStorage exefsStorage = mainNca.OpenSection(ProgramPartitionType.Code, false, FsIntegrityCheckLevel, true);
|
||||||
|
|
||||||
if (exefsStream == null)
|
if (exefsStorage == null)
|
||||||
{
|
{
|
||||||
Logger.PrintError(LogClass.Loader, "No ExeFS found in NCA");
|
Logger.PrintError(LogClass.Loader, "No ExeFS found in NCA");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (romfsStream == null)
|
if (romfsStorage == null)
|
||||||
{
|
{
|
||||||
Logger.PrintWarning(LogClass.Loader, "No RomFS found in NCA");
|
Logger.PrintWarning(LogClass.Loader, "No RomFS found in NCA");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Device.FileSystem.SetRomFs(romfsStream);
|
Device.FileSystem.SetRomFs(romfsStorage.AsStream(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
Pfs exefs = new Pfs(exefsStream);
|
Pfs exefs = new Pfs(exefsStorage);
|
||||||
|
|
||||||
Npdm metaData = null;
|
Npdm metaData = null;
|
||||||
|
|
||||||
|
@ -423,7 +422,7 @@ namespace Ryujinx.HLE.HOS
|
||||||
{
|
{
|
||||||
Logger.PrintInfo(LogClass.Loader, "Loading main.npdm...");
|
Logger.PrintInfo(LogClass.Loader, "Loading main.npdm...");
|
||||||
|
|
||||||
metaData = new Npdm(exefs.OpenFile("main.npdm"));
|
metaData = new Npdm(exefs.OpenFile("main.npdm").AsStream());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -445,7 +444,7 @@ namespace Ryujinx.HLE.HOS
|
||||||
|
|
||||||
Logger.PrintInfo(LogClass.Loader, $"Loading {filename}...");
|
Logger.PrintInfo(LogClass.Loader, $"Loading {filename}...");
|
||||||
|
|
||||||
NxStaticObject staticObject = new NxStaticObject(exefs.OpenFile(file));
|
NxStaticObject staticObject = new NxStaticObject(exefs.OpenFile(file).AsStream());
|
||||||
|
|
||||||
staticObjects.Add(staticObject);
|
staticObjects.Add(staticObject);
|
||||||
}
|
}
|
||||||
|
@ -453,19 +452,17 @@ namespace Ryujinx.HLE.HOS
|
||||||
|
|
||||||
Nacp ReadControlData()
|
Nacp ReadControlData()
|
||||||
{
|
{
|
||||||
Romfs controlRomfs = new Romfs(controlNca.OpenSection(0, false, FsIntegrityCheckLevel));
|
Romfs controlRomfs = new Romfs(controlNca.OpenSection(0, false, FsIntegrityCheckLevel, true));
|
||||||
|
|
||||||
byte[] controlFile = controlRomfs.GetFile("/control.nacp");
|
IStorage controlFile = controlRomfs.OpenFile("/control.nacp");
|
||||||
|
|
||||||
BinaryReader reader = new BinaryReader(new MemoryStream(controlFile));
|
Nacp controlData = new Nacp(controlFile.AsStream());
|
||||||
|
|
||||||
Nacp controlData = new Nacp(reader);
|
CurrentTitle = controlData.Descriptions[(int)State.DesiredTitleLanguage].Title;
|
||||||
|
|
||||||
CurrentTitle = controlData.Languages[(int)State.DesiredTitleLanguage].Title;
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(CurrentTitle))
|
if (string.IsNullOrWhiteSpace(CurrentTitle))
|
||||||
{
|
{
|
||||||
CurrentTitle = controlData.Languages.ToList().Find(x => !string.IsNullOrWhiteSpace(x.Title)).Title;
|
CurrentTitle = controlData.Descriptions.ToList().Find(x => !string.IsNullOrWhiteSpace(x.Title)).Title;
|
||||||
}
|
}
|
||||||
|
|
||||||
return controlData;
|
return controlData;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using LibHac;
|
using LibHac;
|
||||||
|
using LibHac.IO;
|
||||||
using Ryujinx.HLE.FileSystem;
|
using Ryujinx.HLE.FileSystem;
|
||||||
using Ryujinx.HLE.HOS.Ipc;
|
using Ryujinx.HLE.HOS.Ipc;
|
||||||
using Ryujinx.HLE.Utilities;
|
using Ryujinx.HLE.Utilities;
|
||||||
|
@ -65,7 +66,7 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
|
||||||
|
|
||||||
if (extension == ".nca")
|
if (extension == ".nca")
|
||||||
{
|
{
|
||||||
return OpenNcaFs(context, fullPath, fileStream);
|
return OpenNcaFs(context, fullPath, fileStream.AsStorage());
|
||||||
}
|
}
|
||||||
else if (extension == ".nsp")
|
else if (extension == ".nsp")
|
||||||
{
|
{
|
||||||
|
@ -174,10 +175,10 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
|
||||||
|
|
||||||
if (File.Exists(ncaPath))
|
if (File.Exists(ncaPath))
|
||||||
{
|
{
|
||||||
FileStream ncaStream = new FileStream(ncaPath, FileMode.Open, FileAccess.Read);
|
LibHac.IO.IStorage ncaStorage = new FileStream(ncaPath, FileMode.Open, FileAccess.Read).AsStorage();
|
||||||
Nca nca = new Nca(context.Device.System.KeySet, ncaStream, false);
|
Nca nca = new Nca(context.Device.System.KeySet, ncaStorage, false);
|
||||||
NcaSection romfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
|
NcaSection romfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
|
||||||
Stream romfsStream = nca.OpenSection(romfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel);
|
Stream romfsStream = nca.OpenSection(romfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel, false).AsStream();
|
||||||
|
|
||||||
MakeObject(context, new IStorage(romfsStream));
|
MakeObject(context, new IStorage(romfsStream));
|
||||||
|
|
||||||
|
@ -235,16 +236,10 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
|
||||||
private long OpenNsp(ServiceCtx context, string pfsPath)
|
private long OpenNsp(ServiceCtx context, string pfsPath)
|
||||||
{
|
{
|
||||||
FileStream pfsFile = new FileStream(pfsPath, FileMode.Open, FileAccess.Read);
|
FileStream pfsFile = new FileStream(pfsPath, FileMode.Open, FileAccess.Read);
|
||||||
Pfs nsp = new Pfs(pfsFile);
|
Pfs nsp = new Pfs(pfsFile.AsStorage());
|
||||||
PfsFileEntry ticketFile = nsp.Files.FirstOrDefault(x => x.Name.EndsWith(".tik"));
|
|
||||||
|
|
||||||
if (ticketFile != null)
|
ImportTitleKeysFromNsp(nsp, context.Device.System.KeySet);
|
||||||
{
|
|
||||||
Ticket ticket = new Ticket(nsp.OpenFile(ticketFile));
|
|
||||||
|
|
||||||
context.Device.System.KeySet.TitleKeys[ticket.RightsId] =
|
|
||||||
ticket.GetTitleKey(context.Device.System.KeySet);
|
|
||||||
}
|
|
||||||
|
|
||||||
IFileSystem nspFileSystem = new IFileSystem(pfsPath, new PFsProvider(nsp));
|
IFileSystem nspFileSystem = new IFileSystem(pfsPath, new PFsProvider(nsp));
|
||||||
|
|
||||||
|
@ -253,24 +248,24 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long OpenNcaFs(ServiceCtx context,string ncaPath, Stream ncaStream)
|
private long OpenNcaFs(ServiceCtx context, string ncaPath, LibHac.IO.IStorage ncaStorage)
|
||||||
{
|
{
|
||||||
Nca nca = new Nca(context.Device.System.KeySet, ncaStream, false);
|
Nca nca = new Nca(context.Device.System.KeySet, ncaStorage, false);
|
||||||
|
|
||||||
NcaSection romfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
|
NcaSection romfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
|
||||||
NcaSection pfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Pfs0);
|
NcaSection pfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Pfs0);
|
||||||
|
|
||||||
if (romfsSection != null)
|
if (romfsSection != null)
|
||||||
{
|
{
|
||||||
Stream romfsStream = nca.OpenSection(romfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel);
|
LibHac.IO.IStorage romfsStorage = nca.OpenSection(romfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel, false);
|
||||||
IFileSystem ncaFileSystem = new IFileSystem(ncaPath, new RomFsProvider(romfsStream));
|
IFileSystem ncaFileSystem = new IFileSystem(ncaPath, new RomFsProvider(romfsStorage));
|
||||||
|
|
||||||
MakeObject(context, ncaFileSystem);
|
MakeObject(context, ncaFileSystem);
|
||||||
}
|
}
|
||||||
else if(pfsSection != null)
|
else if(pfsSection != null)
|
||||||
{
|
{
|
||||||
Stream pfsStream = nca.OpenSection(pfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel);
|
LibHac.IO.IStorage pfsStorage = nca.OpenSection(pfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel, false);
|
||||||
Pfs pfs = new Pfs(pfsStream);
|
Pfs pfs = new Pfs(pfsStorage);
|
||||||
IFileSystem ncaFileSystem = new IFileSystem(ncaPath, new PFsProvider(pfs));
|
IFileSystem ncaFileSystem = new IFileSystem(ncaPath, new PFsProvider(pfs));
|
||||||
|
|
||||||
MakeObject(context, ncaFileSystem);
|
MakeObject(context, ncaFileSystem);
|
||||||
|
@ -299,16 +294,9 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
|
||||||
FileMode.Open,
|
FileMode.Open,
|
||||||
FileAccess.Read);
|
FileAccess.Read);
|
||||||
|
|
||||||
Pfs nsp = new Pfs(pfsFile);
|
Pfs nsp = new Pfs(pfsFile.AsStorage());
|
||||||
PfsFileEntry ticketFile = nsp.Files.FirstOrDefault(x => x.Name.EndsWith(".tik"));
|
|
||||||
|
|
||||||
if (ticketFile != null)
|
ImportTitleKeysFromNsp(nsp, context.Device.System.KeySet);
|
||||||
{
|
|
||||||
Ticket ticket = new Ticket(nsp.OpenFile(ticketFile));
|
|
||||||
|
|
||||||
context.Device.System.KeySet.TitleKeys[ticket.RightsId] =
|
|
||||||
ticket.GetTitleKey(context.Device.System.KeySet);
|
|
||||||
}
|
|
||||||
|
|
||||||
string filename = fullPath.Replace(archivePath.FullName, string.Empty).TrimStart('\\');
|
string filename = fullPath.Replace(archivePath.FullName, string.Empty).TrimStart('\\');
|
||||||
|
|
||||||
|
@ -320,5 +308,18 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
|
||||||
|
|
||||||
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ImportTitleKeysFromNsp(Pfs nsp, Keyset keySet)
|
||||||
|
{
|
||||||
|
foreach (PfsFileEntry ticketEntry in nsp.Files.Where(x => x.Name.EndsWith(".tik")))
|
||||||
|
{
|
||||||
|
Ticket ticket = new Ticket(nsp.OpenFile(ticketEntry).AsStream());
|
||||||
|
|
||||||
|
if (!keySet.TitleKeys.ContainsKey(ticket.RightsId))
|
||||||
|
{
|
||||||
|
keySet.TitleKeys.Add(ticket.RightsId, ticket.GetTitleKey(keySet));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,12 +1,13 @@
|
||||||
|
using LibHac;
|
||||||
|
using LibHac.IO;
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
|
using Ryujinx.HLE.FileSystem;
|
||||||
using Ryujinx.HLE.HOS.Ipc;
|
using Ryujinx.HLE.HOS.Ipc;
|
||||||
using Ryujinx.HLE.HOS.SystemState;
|
using Ryujinx.HLE.HOS.SystemState;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using LibHac;
|
|
||||||
using Ryujinx.HLE.FileSystem;
|
|
||||||
|
|
||||||
namespace Ryujinx.HLE.HOS.Services.Set
|
namespace Ryujinx.HLE.HOS.Services.Set
|
||||||
{
|
{
|
||||||
|
@ -173,7 +174,6 @@ namespace Ryujinx.HLE.HOS.Services.Set
|
||||||
|
|
||||||
public static byte[] GetFirmwareData(Switch device)
|
public static byte[] GetFirmwareData(Switch device)
|
||||||
{
|
{
|
||||||
byte[] data = null;
|
|
||||||
long titleId = 0x0100000000000809;
|
long titleId = 0x0100000000000809;
|
||||||
string contentPath = device.System.ContentManager.GetInstalledContentPath(titleId, StorageId.NandSystem, ContentType.Data);
|
string contentPath = device.System.ContentManager.GetInstalledContentPath(titleId, StorageId.NandSystem, ContentType.Data);
|
||||||
|
|
||||||
|
@ -183,31 +183,27 @@ namespace Ryujinx.HLE.HOS.Services.Set
|
||||||
}
|
}
|
||||||
|
|
||||||
string firmwareTitlePath = device.FileSystem.SwitchPathToSystemPath(contentPath);
|
string firmwareTitlePath = device.FileSystem.SwitchPathToSystemPath(contentPath);
|
||||||
FileStream firmwareStream = File.Open(firmwareTitlePath, FileMode.Open, FileAccess.Read);
|
|
||||||
Nca firmwareContent = new Nca(device.System.KeySet, firmwareStream, false);
|
|
||||||
Stream romFsStream = firmwareContent.OpenSection(0, false, device.System.FsIntegrityCheckLevel);
|
|
||||||
|
|
||||||
if(romFsStream == null)
|
using(FileStream firmwareStream = File.Open(firmwareTitlePath, FileMode.Open, FileAccess.Read))
|
||||||
|
{
|
||||||
|
Nca firmwareContent = new Nca(device.System.KeySet, firmwareStream.AsStorage(), false);
|
||||||
|
IStorage romFsStorage = firmwareContent.OpenSection(0, false, device.System.FsIntegrityCheckLevel, false);
|
||||||
|
|
||||||
|
if(romFsStorage == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Romfs firmwareRomFs = new Romfs(romFsStream);
|
Romfs firmwareRomFs = new Romfs(romFsStorage);
|
||||||
|
|
||||||
using(MemoryStream memoryStream = new MemoryStream())
|
IStorage firmwareFile = firmwareRomFs.OpenFile("/file");
|
||||||
{
|
|
||||||
using (Stream firmwareFile = firmwareRomFs.OpenFile("/file"))
|
|
||||||
{
|
|
||||||
firmwareFile.CopyTo(memoryStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
data = memoryStream.ToArray();
|
byte[] data = new byte[firmwareFile.Length];
|
||||||
}
|
|
||||||
|
|
||||||
firmwareContent.Dispose();
|
firmwareFile.Read(data, 0);
|
||||||
firmwareStream.Dispose();
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -28,11 +28,11 @@
|
||||||
<ProjectReference Include="..\Ryujinx.Audio\Ryujinx.Audio.csproj" />
|
<ProjectReference Include="..\Ryujinx.Audio\Ryujinx.Audio.csproj" />
|
||||||
<ProjectReference Include="..\Ryujinx.Common\Ryujinx.Common.csproj" />
|
<ProjectReference Include="..\Ryujinx.Common\Ryujinx.Common.csproj" />
|
||||||
<ProjectReference Include="..\Ryujinx.Graphics\Ryujinx.Graphics.csproj" />
|
<ProjectReference Include="..\Ryujinx.Graphics\Ryujinx.Graphics.csproj" />
|
||||||
<PackageReference Include="LibHac" Version="0.1.3" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Concentus" Version="1.1.7" />
|
<PackageReference Include="Concentus" Version="1.1.7" />
|
||||||
|
<PackageReference Include="LibHac" Version="0.2.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using LibHac;
|
using LibHac.IO;
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
using Ryujinx.HLE;
|
using Ryujinx.HLE;
|
||||||
using Ryujinx.HLE.HOS.SystemState;
|
using Ryujinx.HLE.HOS.SystemState;
|
||||||
|
|
Loading…
Reference in a new issue