mirror of
https://git.743378673.xyz/MeloNX/MeloNX.git
synced 2025-07-25 07:57:11 +02:00
add steam based loaders
This commit is contained in:
parent
56a6ac2a65
commit
07caf24936
4 changed files with 172 additions and 23 deletions
|
@ -20,7 +20,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
|
|||
private static readonly DownloadableContentJsonSerializerContext _contentSerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
|
||||
private static readonly TitleUpdateMetadataJsonSerializerContext _titleSerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
|
||||
|
||||
internal static (bool, ProcessResult) TryLoad<TMetaData, TFormat, THeader, TEntry>(this PartitionFileSystemCore<TMetaData, TFormat, THeader, TEntry> partitionFileSystem, Switch device, string path, out string errorMessage)
|
||||
internal static (bool, ProcessResult) TryLoad<TMetaData, TFormat, THeader, TEntry>(this PartitionFileSystemCore<TMetaData, TFormat, THeader, TEntry> partitionFileSystem, Switch device, , Stream stream, out string errorMessage, string extension)
|
||||
where TMetaData : PartitionFileSystemMetaCore<TFormat, THeader, TEntry>, new()
|
||||
where TFormat : IPartitionFileSystemFormat
|
||||
where THeader : unmanaged, IPartitionFileSystemHeader
|
||||
|
@ -141,7 +141,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
|
|||
// Load contained DownloadableContents.
|
||||
// TODO: If we want to support multi-processes in future, we shouldn't clear AddOnContent data here.
|
||||
device.Configuration.ContentManager.ClearAocData();
|
||||
device.Configuration.ContentManager.AddAocData(partitionFileSystem, path, mainNca.Header.TitleId, device.Configuration.FsIntegrityCheckLevel);
|
||||
device.Configuration.ContentManager.AddAocData(partitionFileSystem, stream, mainNca.Header.TitleId, device.Configuration.FsIntegrityCheckLevel, extension);
|
||||
|
||||
// Load DownloadableContents.
|
||||
string addOnContentMetadataPath = System.IO.Path.Combine(AppDataManager.GamesDirPath, mainNca.Header.TitleId.ToString("x16"), "dlc.json");
|
||||
|
@ -155,7 +155,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
|
|||
{
|
||||
if (File.Exists(downloadableContentContainer.ContainerPath) && downloadableContentNca.Enabled)
|
||||
{
|
||||
device.Configuration.ContentManager.AddAocItem(downloadableContentNca.TitleId, downloadableContentContainer.ContainerPath, downloadableContentNca.FullPath);
|
||||
device.Configuration.ContentManager.AddAocItem(downloadableContentNca.TitleId, stream, downloadableContentNca.FullPath, System.IO.Path.GetExtension(downloadableContentContainer.ContainerPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -35,6 +35,12 @@ namespace Ryujinx.HLE.Loaders.Processes
|
|||
public bool LoadXci(string path)
|
||||
{
|
||||
FileStream stream = new(path, FileMode.Open, FileAccess.Read);
|
||||
|
||||
return LoadXci(stream);
|
||||
}
|
||||
|
||||
public bool LoadXci(Stream stream)
|
||||
{
|
||||
Xci xci = new(_device.Configuration.VirtualFileSystem.KeySet, stream.AsStorage());
|
||||
|
||||
if (!xci.HasPartition(XciPartitionType.Secure))
|
||||
|
@ -44,7 +50,7 @@ namespace Ryujinx.HLE.Loaders.Processes
|
|||
return false;
|
||||
}
|
||||
|
||||
(bool success, ProcessResult processResult) = xci.OpenPartition(XciPartitionType.Secure).TryLoad(_device, path, out string errorMessage);
|
||||
(bool success, ProcessResult processResult) = xci.OpenPartition(XciPartitionType.Secure).TryLoad(_device, stream, out string errorMessage, "xci");
|
||||
|
||||
if (!success)
|
||||
{
|
||||
|
@ -69,10 +75,16 @@ namespace Ryujinx.HLE.Loaders.Processes
|
|||
public bool LoadNsp(string path)
|
||||
{
|
||||
FileStream file = new(path, FileMode.Open, FileAccess.Read);
|
||||
PartitionFileSystem partitionFileSystem = new();
|
||||
partitionFileSystem.Initialize(file.AsStorage()).ThrowIfFailure();
|
||||
|
||||
return LoadNsp(file);
|
||||
}
|
||||
|
||||
(bool success, ProcessResult processResult) = partitionFileSystem.TryLoad(_device, path, out string errorMessage);
|
||||
public bool LoadNsp(Stream stream)
|
||||
{
|
||||
PartitionFileSystem partitionFileSystem = new();
|
||||
partitionFileSystem.Initialize(stream.AsStorage()).ThrowIfFailure();
|
||||
|
||||
(bool success, ProcessResult processResult) = partitionFileSystem.TryLoad(_device, stream, out string errorMessage, "nsp");
|
||||
|
||||
if (processResult.ProcessId == 0)
|
||||
{
|
||||
|
@ -101,7 +113,13 @@ namespace Ryujinx.HLE.Loaders.Processes
|
|||
public bool LoadNca(string path)
|
||||
{
|
||||
FileStream file = new(path, FileMode.Open, FileAccess.Read);
|
||||
Nca nca = new(_device.Configuration.VirtualFileSystem.KeySet, file.AsStorage(false));
|
||||
|
||||
return LoadNca(file);
|
||||
}
|
||||
|
||||
public bool LoadNca(Stream ncaStream)
|
||||
{
|
||||
Nca nca = new(_device.Configuration.VirtualFileSystem.KeySet, ncaStream.AsStorage(false));
|
||||
|
||||
ProcessResult processResult = nca.Load(_device, null, null);
|
||||
|
||||
|
@ -241,5 +259,107 @@ namespace Ryujinx.HLE.Loaders.Processes
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool LoadNxo(Stream stream, bool isNro, string name)
|
||||
{
|
||||
var nacpData = new BlitStruct<ApplicationControlProperty>(1);
|
||||
IFileSystem dummyExeFs = null;
|
||||
Stream romfsStream = null;
|
||||
|
||||
string programName = "";
|
||||
ulong programId = 0000000000000000;
|
||||
|
||||
// Load executable.
|
||||
IExecutable executable;
|
||||
|
||||
if (isNro)
|
||||
{
|
||||
NroExecutable nro = new(stream.AsStorage());
|
||||
|
||||
executable = nro;
|
||||
|
||||
// Open RomFS if exists.
|
||||
IStorage romFsStorage = nro.OpenNroAssetSection(LibHac.Tools.Ro.NroAssetType.RomFs, false);
|
||||
romFsStorage.GetSize(out long romFsSize).ThrowIfFailure();
|
||||
if (romFsSize != 0)
|
||||
{
|
||||
romfsStream = romFsStorage.AsStream();
|
||||
}
|
||||
|
||||
// Load Nacp if exists.
|
||||
IStorage nacpStorage = nro.OpenNroAssetSection(LibHac.Tools.Ro.NroAssetType.Nacp, false);
|
||||
nacpStorage.GetSize(out long nacpSize).ThrowIfFailure();
|
||||
if (nacpSize != 0)
|
||||
{
|
||||
nacpStorage.Read(0, nacpData.ByteSpan);
|
||||
|
||||
programName = nacpData.Value.Title[(int)_device.System.State.DesiredTitleLanguage].NameString.ToString();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(programName))
|
||||
{
|
||||
programName = Array.Find(nacpData.Value.Title.ItemsRo.ToArray(), x => x.Name[0] != 0).NameString.ToString();
|
||||
}
|
||||
|
||||
if (nacpData.Value.PresenceGroupId != 0)
|
||||
{
|
||||
programId = nacpData.Value.PresenceGroupId;
|
||||
}
|
||||
else if (nacpData.Value.SaveDataOwnerId != 0)
|
||||
{
|
||||
programId = nacpData.Value.SaveDataOwnerId;
|
||||
}
|
||||
else if (nacpData.Value.AddOnContentBaseId != 0)
|
||||
{
|
||||
programId = nacpData.Value.AddOnContentBaseId - 0x1000;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add icon maybe ?
|
||||
}
|
||||
else
|
||||
{
|
||||
executable = new NsoExecutable(new LocalStorage(name, FileAccess.Read), programName);
|
||||
}
|
||||
|
||||
// Explicitly null TitleId to disable the shader cache.
|
||||
Graphics.Gpu.GraphicsConfig.TitleId = null;
|
||||
_device.Gpu.HostInitalized.Set();
|
||||
|
||||
ProcessResult processResult = ProcessLoaderHelper.LoadNsos(_device,
|
||||
_device.System.KernelContext,
|
||||
dummyExeFs.GetNpdm(),
|
||||
nacpData,
|
||||
diskCacheEnabled: false,
|
||||
allowCodeMemoryForJit: true,
|
||||
programName,
|
||||
programId,
|
||||
null,
|
||||
executable);
|
||||
|
||||
// Make sure the process id is valid.
|
||||
if (processResult.ProcessId != 0)
|
||||
{
|
||||
// Load RomFS.
|
||||
if (romfsStream != null)
|
||||
{
|
||||
_device.Configuration.VirtualFileSystem.SetRomFs(processResult.ProcessId, romfsStream);
|
||||
}
|
||||
|
||||
// Start process.
|
||||
if (_processesByPid.TryAdd(processResult.ProcessId, processResult))
|
||||
{
|
||||
if (processResult.Start(_device))
|
||||
{
|
||||
_latestPid = processResult.ProcessId;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue