/ src / Ryujinx.HLE / Loaders / Processes / Extensions / MetaLoaderExtensions.cs
MetaLoaderExtensions.cs
 1  using LibHac.Common;
 2  using LibHac.Fs;
 3  using LibHac.Fs.Fsa;
 4  using LibHac.Loader;
 5  using LibHac.Util;
 6  using Ryujinx.Common;
 7  using System;
 8  
 9  namespace Ryujinx.HLE.Loaders.Processes.Extensions
10  {
11      public static class MetaLoaderExtensions
12      {
13          public static ulong GetProgramId(this MetaLoader metaLoader)
14          {
15              metaLoader.GetNpdm(out var npdm).ThrowIfFailure();
16  
17              return npdm.Aci.ProgramId.Value;
18          }
19  
20          public static string GetProgramName(this MetaLoader metaLoader)
21          {
22              metaLoader.GetNpdm(out var npdm).ThrowIfFailure();
23  
24              return StringUtils.Utf8ZToString(npdm.Meta.ProgramName);
25          }
26  
27          public static bool IsProgram64Bit(this MetaLoader metaLoader)
28          {
29              metaLoader.GetNpdm(out var npdm).ThrowIfFailure();
30  
31              return (npdm.Meta.Flags & 1) != 0;
32          }
33  
34          public static void LoadDefault(this MetaLoader metaLoader)
35          {
36              byte[] npdmBuffer = EmbeddedResources.Read("Ryujinx.HLE/Homebrew.npdm");
37  
38              metaLoader.Load(npdmBuffer).ThrowIfFailure();
39          }
40  
41          public static void LoadFromFile(this MetaLoader metaLoader, IFileSystem fileSystem, string path = "")
42          {
43              if (string.IsNullOrEmpty(path))
44              {
45                  path = ProcessConst.MainNpdmPath;
46              }
47  
48              using var npdmFile = new UniqueRef<IFile>();
49  
50              fileSystem.OpenFile(ref npdmFile.Ref, path.ToU8Span(), OpenMode.Read).ThrowIfFailure();
51  
52              npdmFile.Get.GetSize(out long fileSize).ThrowIfFailure();
53  
54              Span<byte> npdmBuffer = new byte[fileSize];
55  
56              npdmFile.Get.Read(out _, 0, npdmBuffer).ThrowIfFailure();
57  
58              metaLoader.Load(npdmBuffer).ThrowIfFailure();
59          }
60      }
61  }