diff options
| author | Alex Barney <thealexbarney@gmail.com> | 2021-12-23 09:55:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-23 13:55:50 -0300 |
| commit | aa932a6df1764b7c600ae0ba4e0c7a0ba802f312 (patch) | |
| tree | 24a390cf2330620aeeab1efbd42ae4099f61ca86 /Ryujinx.HLE/HOS/ApplicationLoader.cs | |
| parent | cb43cc7e322014ce2bd0ee73b06d403be62fa8d5 (diff) | |
Update to LibHac v0.14.3 (#2925)
* Update to LibHac v0.14.3
* Fix loading NCAs that don't have a data partition
Diffstat (limited to 'Ryujinx.HLE/HOS/ApplicationLoader.cs')
| -rw-r--r-- | Ryujinx.HLE/HOS/ApplicationLoader.cs | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/Ryujinx.HLE/HOS/ApplicationLoader.cs b/Ryujinx.HLE/HOS/ApplicationLoader.cs index 767496d2..c0798abe 100644 --- a/Ryujinx.HLE/HOS/ApplicationLoader.cs +++ b/Ryujinx.HLE/HOS/ApplicationLoader.cs @@ -25,6 +25,7 @@ using System.Reflection; using static LibHac.Fs.ApplicationSaveDataManagement; using static Ryujinx.HLE.HOS.ModLoader; using ApplicationId = LibHac.Ncm.ApplicationId; +using Path = System.IO.Path; namespace Ryujinx.HLE.HOS { @@ -101,9 +102,11 @@ namespace Ryujinx.HLE.HOS foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca")) { - pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure(); + using var ncaFile = new UniqueRef<IFile>(); - Nca nca = new Nca(fileSystem.KeySet, ncaFile.AsStorage()); + pfs.OpenFile(ref ncaFile.Ref(), fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure(); + + Nca nca = new Nca(fileSystem.KeySet, ncaFile.Release().AsStorage()); int ncaProgramIndex = (int)(nca.Header.TitleId & 0xF); @@ -116,7 +119,7 @@ namespace Ryujinx.HLE.HOS { int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program); - if (nca.Header.GetFsHeader(dataIndex).IsPatchSection()) + if (nca.SectionExists(NcaSectionType.Data) && nca.Header.GetFsHeader(dataIndex).IsPatchSection()) { patchNca = nca; } @@ -143,9 +146,11 @@ namespace Ryujinx.HLE.HOS foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca")) { - pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure(); + using var ncaFile = new UniqueRef<IFile>(); + + pfs.OpenFile(ref ncaFile.Ref(), fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure(); - Nca nca = new Nca(fileSystem.KeySet, ncaFile.AsStorage()); + Nca nca = new Nca(fileSystem.KeySet, ncaFile.Release().AsStorage()); int ncaProgramIndex = (int)(nca.Header.TitleId & 0xF); @@ -429,7 +434,9 @@ namespace Ryujinx.HLE.HOS // Sets TitleId, so be sure to call before using it private MetaLoader ReadNpdm(IFileSystem fs) { - Result result = fs.OpenFile(out IFile npdmFile, "/main.npdm".ToU8Span(), OpenMode.Read); + using var npdmFile = new UniqueRef<IFile>(); + + Result result = fs.OpenFile(ref npdmFile.Ref(), "/main.npdm".ToU8Span(), OpenMode.Read); MetaLoader metaData; @@ -441,10 +448,10 @@ namespace Ryujinx.HLE.HOS } else { - npdmFile.GetSize(out long fileSize).ThrowIfFailure(); + npdmFile.Get.GetSize(out long fileSize).ThrowIfFailure(); var npdmBuffer = new byte[fileSize]; - npdmFile.Read(out _, 0, npdmBuffer).ThrowIfFailure(); + npdmFile.Get.Read(out _, 0, npdmBuffer).ThrowIfFailure(); metaData = new MetaLoader(); metaData.Load(npdmBuffer).ThrowIfFailure(); @@ -461,12 +468,14 @@ namespace Ryujinx.HLE.HOS private static void ReadControlData(Switch device, Nca controlNca, ref BlitStruct<ApplicationControlProperty> controlData, ref string titleName, ref string displayVersion) { + using var controlFile = new UniqueRef<IFile>(); + IFileSystem controlFs = controlNca.OpenFileSystem(NcaSectionType.Data, device.System.FsIntegrityCheckLevel); - Result result = controlFs.OpenFile(out IFile controlFile, "/control.nacp".ToU8Span(), OpenMode.Read); + Result result = controlFs.OpenFile(ref controlFile.Ref(), "/control.nacp".ToU8Span(), OpenMode.Read); if (result.IsSuccess()) { - result = controlFile.Read(out long bytesRead, 0, controlData.ByteSpan, ReadOption.None); + result = controlFile.Get.Read(out long bytesRead, 0, controlData.ByteSpan, ReadOption.None); if (result.IsSuccess() && bytesRead == controlData.ByteSpan.Length) { @@ -508,9 +517,11 @@ namespace Ryujinx.HLE.HOS Logger.Info?.Print(LogClass.Loader, $"Loading {name}..."); - codeFs.OpenFile(out IFile nsoFile, $"/{name}".ToU8Span(), OpenMode.Read).ThrowIfFailure(); + using var nsoFile = new UniqueRef<IFile>(); + + codeFs.OpenFile(ref nsoFile.Ref(), $"/{name}".ToU8Span(), OpenMode.Read).ThrowIfFailure(); - nsos[i] = new NsoExecutable(nsoFile.AsStorage(), name); + nsos[i] = new NsoExecutable(nsoFile.Release().AsStorage(), name); } // ExeFs file replacements @@ -680,9 +691,11 @@ namespace Ryujinx.HLE.HOS foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca")) { - pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure(); + using var ncaFile = new UniqueRef<IFile>(); + + pfs.OpenFile(ref ncaFile.Ref(), fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure(); - Nca nca = new Nca(fileSystem.KeySet, ncaFile.AsStorage()); + Nca nca = new Nca(fileSystem.KeySet, ncaFile.Release().AsStorage()); if (nca.Header.ContentType != NcaContentType.Program) { @@ -691,7 +704,7 @@ namespace Ryujinx.HLE.HOS int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program); - if (nca.Header.GetFsHeader(dataIndex).IsPatchSection()) + if (nca.SectionExists(NcaSectionType.Data) && nca.Header.GetFsHeader(dataIndex).IsPatchSection()) { continue; } |
