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