Compare commits

...

2 Commits

Author SHA1 Message Date
Alex Barney
56fe2ff535 Fix loading tickets from a Sha256PartitionFileSystem (#5844) 2023-10-24 13:26:25 -03:00
Alex Barney
b1f8f868f6 Fix the AOC manager using incorrect paths (#5840)
* Fix the content manager using incorrect path for some AOC NCAs

* Check Results in a few more places in the content manager
2023-10-23 14:34:31 -03:00
2 changed files with 17 additions and 8 deletions

View File

@@ -198,7 +198,7 @@ namespace Ryujinx.HLE.FileSystem
{ {
using var ncaFile = new UniqueRef<IFile>(); using var ncaFile = new UniqueRef<IFile>();
fs.OpenFile(ref ncaFile.Ref, ncaPath.FullPath.ToU8Span(), OpenMode.Read); fs.OpenFile(ref ncaFile.Ref, ncaPath.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
var nca = new Nca(_virtualFileSystem.KeySet, ncaFile.Get.AsStorage()); var nca = new Nca(_virtualFileSystem.KeySet, ncaFile.Get.AsStorage());
if (nca.Header.ContentType != NcaContentType.Meta) if (nca.Header.ContentType != NcaContentType.Meta)
{ {
@@ -210,7 +210,7 @@ namespace Ryujinx.HLE.FileSystem
using var pfs0 = nca.OpenFileSystem(0, integrityCheckLevel); using var pfs0 = nca.OpenFileSystem(0, integrityCheckLevel);
using var cnmtFile = new UniqueRef<IFile>(); using var cnmtFile = new UniqueRef<IFile>();
pfs0.OpenFile(ref cnmtFile.Ref, pfs0.EnumerateEntries().Single().FullPath.ToU8Span(), OpenMode.Read); pfs0.OpenFile(ref cnmtFile.Ref, pfs0.EnumerateEntries().Single().FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
var cnmt = new Cnmt(cnmtFile.Get.AsStream()); var cnmt = new Cnmt(cnmtFile.Get.AsStream());
if (cnmt.Type != ContentMetaType.AddOnContent || (cnmt.TitleId & 0xFFFFFFFFFFFFE000) != aocBaseId) if (cnmt.Type != ContentMetaType.AddOnContent || (cnmt.TitleId & 0xFFFFFFFFFFFFE000) != aocBaseId)
@@ -220,7 +220,7 @@ namespace Ryujinx.HLE.FileSystem
string ncaId = Convert.ToHexString(cnmt.ContentEntries[0].NcaId).ToLower(); string ncaId = Convert.ToHexString(cnmt.ContentEntries[0].NcaId).ToLower();
AddAocItem(cnmt.TitleId, containerPath, $"{ncaId}.nca", true); AddAocItem(cnmt.TitleId, containerPath, $"/{ncaId}.nca", true);
} }
} }
@@ -265,12 +265,12 @@ namespace Ryujinx.HLE.FileSystem
{ {
case ".xci": case ".xci":
var xci = new Xci(_virtualFileSystem.KeySet, file.AsStorage()).OpenPartition(XciPartitionType.Secure); var xci = new Xci(_virtualFileSystem.KeySet, file.AsStorage()).OpenPartition(XciPartitionType.Secure);
xci.OpenFile(ref ncaFile.Ref, aoc.NcaPath.ToU8Span(), OpenMode.Read); xci.OpenFile(ref ncaFile.Ref, aoc.NcaPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
break; break;
case ".nsp": case ".nsp":
var pfs = new PartitionFileSystem(); var pfs = new PartitionFileSystem();
pfs.Initialize(file.AsStorage()); pfs.Initialize(file.AsStorage());
pfs.OpenFile(ref ncaFile.Ref, aoc.NcaPath.ToU8Span(), OpenMode.Read); pfs.OpenFile(ref ncaFile.Ref, aoc.NcaPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
break; break;
default: default:
return false; // Print error? return false; // Print error?
@@ -607,11 +607,11 @@ namespace Ryujinx.HLE.FileSystem
if (filesystem.FileExists($"{path}/00")) if (filesystem.FileExists($"{path}/00"))
{ {
filesystem.OpenFile(ref file.Ref, $"{path}/00".ToU8Span(), mode); filesystem.OpenFile(ref file.Ref, $"{path}/00".ToU8Span(), mode).ThrowIfFailure();
} }
else else
{ {
filesystem.OpenFile(ref file.Ref, path.ToU8Span(), mode); filesystem.OpenFile(ref file.Ref, path.ToU8Span(), mode).ThrowIfFailure();
} }
return file.Release(); return file.Release();

View File

@@ -264,7 +264,16 @@ namespace Ryujinx.HLE.FileSystem
if (result.IsSuccess()) if (result.IsSuccess())
{ {
Ticket ticket = new(ticketFile.Get.AsStream()); // When reading a file from a Sha256PartitionFileSystem, you can't start a read in the middle
// of the hashed portion (usually the first 0x200 bytes) of the file and end the read after
// the end of the hashed portion, so we read the ticket file using a single read.
byte[] ticketData = new byte[0x2C0];
result = ticketFile.Get.Read(out long bytesRead, 0, ticketData);
if (result.IsFailure() || bytesRead != ticketData.Length)
continue;
Ticket ticket = new(new MemoryStream(ticketData));
var titleKey = ticket.GetTitleKey(KeySet); var titleKey = ticket.GetTitleKey(KeySet);
if (titleKey != null) if (titleKey != null)