mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-06-28 06:46:24 +02:00
PPTC Profiles (#370)
Added functionality that allows ExeFS mods to compile to their own PPTC Profile and therefore store PTC data between sessions. The feature calculates the hash of the currently loaded ExeFS mods and stores the PPTC data in a profile that matches said hash, so you can have multiple ExeFS loadouts without causing issues. This includes different versions of the same mod as their hashes will be different. Using this PR should be seamless as the JIT Sparse PR already laid the groundwork for PPTC Profiles and this PR just allows ExeFS mods to load and store their own profiles besides the `default` profile. ❗❗❗ **WARNING!** ❗❗❗ **This will update your PPTC profile version, which means the PPTC profile will be invalidated if you try to run a PR/Build/Branch that does not include this change!** **This is only relevant for the default PPTC Profile, as any other profiles do not exist to older versions!**
This commit is contained in:
parent
9d28af935d
commit
7085bafa60
11 changed files with 299 additions and 28 deletions
|
@ -20,6 +20,7 @@ namespace Ryujinx.HLE.HOS
|
|||
private readonly string _titleIdText;
|
||||
private readonly string _displayVersion;
|
||||
private readonly bool _diskCacheEnabled;
|
||||
private readonly string _diskCacheSelector;
|
||||
private readonly ulong _codeAddress;
|
||||
private readonly ulong _codeSize;
|
||||
|
||||
|
@ -31,6 +32,7 @@ namespace Ryujinx.HLE.HOS
|
|||
string titleIdText,
|
||||
string displayVersion,
|
||||
bool diskCacheEnabled,
|
||||
string diskCacheSelector,
|
||||
ulong codeAddress,
|
||||
ulong codeSize)
|
||||
{
|
||||
|
@ -39,6 +41,7 @@ namespace Ryujinx.HLE.HOS
|
|||
_titleIdText = titleIdText;
|
||||
_displayVersion = displayVersion;
|
||||
_diskCacheEnabled = diskCacheEnabled;
|
||||
_diskCacheSelector = diskCacheSelector;
|
||||
_codeAddress = codeAddress;
|
||||
_codeSize = codeSize;
|
||||
}
|
||||
|
@ -114,7 +117,7 @@ namespace Ryujinx.HLE.HOS
|
|||
}
|
||||
}
|
||||
|
||||
DiskCacheLoadState = processContext.Initialize(_titleIdText, _displayVersion, _diskCacheEnabled, _codeAddress, _codeSize, "default"); //Ready for exefs profiles
|
||||
DiskCacheLoadState = processContext.Initialize(_titleIdText, _displayVersion, _diskCacheEnabled, _codeAddress, _codeSize, _diskCacheSelector ?? "default");
|
||||
|
||||
return processContext;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ using LibHac.Loader;
|
|||
using LibHac.Tools.Fs;
|
||||
using LibHac.Tools.FsSystem;
|
||||
using LibHac.Tools.FsSystem.RomFs;
|
||||
using LibHac.Util;
|
||||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Common.Utilities;
|
||||
|
@ -19,6 +20,7 @@ using System.Collections.Specialized;
|
|||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using LazyFile = Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy.LazyFile;
|
||||
using Path = System.IO.Path;
|
||||
|
||||
|
@ -581,6 +583,7 @@ namespace Ryujinx.HLE.HOS
|
|||
public BitVector32 Stubs;
|
||||
public BitVector32 Replaces;
|
||||
public MetaLoader Npdm;
|
||||
public string Hash;
|
||||
|
||||
public bool Modified => (Stubs.Data | Replaces.Data) != 0;
|
||||
}
|
||||
|
@ -591,8 +594,11 @@ namespace Ryujinx.HLE.HOS
|
|||
{
|
||||
Stubs = new BitVector32(),
|
||||
Replaces = new BitVector32(),
|
||||
Hash = null,
|
||||
};
|
||||
|
||||
string tempHash = string.Empty;
|
||||
|
||||
if (!_appMods.TryGetValue(applicationId, out ModCache mods) || mods.ExefsDirs.Count == 0)
|
||||
{
|
||||
return modLoadResult;
|
||||
|
@ -628,8 +634,16 @@ namespace Ryujinx.HLE.HOS
|
|||
|
||||
modLoadResult.Replaces[1 << i] = true;
|
||||
|
||||
nsos[i] = new NsoExecutable(nsoFile.OpenRead().AsStorage(), nsoName);
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"NSO '{nsoName}' replaced");
|
||||
using (FileStream stream = nsoFile.OpenRead())
|
||||
{
|
||||
nsos[i] = new NsoExecutable(stream.AsStorage(), nsoName);
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"NSO '{nsoName}' replaced");
|
||||
using (MD5 md5 = MD5.Create())
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
tempHash += BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
modLoadResult.Stubs[1 << i] |= File.Exists(Path.Combine(mod.Path.FullName, nsoName + StubExtension));
|
||||
|
@ -661,6 +675,14 @@ namespace Ryujinx.HLE.HOS
|
|||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(tempHash))
|
||||
{
|
||||
using (MD5 md5 = MD5.Create())
|
||||
{
|
||||
modLoadResult.Hash += BitConverter.ToString(md5.ComputeHash(tempHash.ToBytes())).Replace("-", "").ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
|
||||
return modLoadResult;
|
||||
}
|
||||
|
||||
|
|
|
@ -84,13 +84,6 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
|
|||
// Apply Nsos patches.
|
||||
device.Configuration.VirtualFileSystem.ModLoader.ApplyNsoPatches(programId, nsoExecutables);
|
||||
|
||||
// Don't use PTC if ExeFS files have been replaced.
|
||||
bool enablePtc = device.System.EnablePtc && !modLoadResult.Modified;
|
||||
if (!enablePtc)
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.Ptc, "Detected unsupported ExeFs modifications. PTC disabled.");
|
||||
}
|
||||
|
||||
string programName = string.Empty;
|
||||
|
||||
if (!isHomebrew && programId > 0x010000000000FFFF)
|
||||
|
@ -117,7 +110,8 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
|
|||
device.System.KernelContext,
|
||||
metaLoader,
|
||||
nacpData,
|
||||
enablePtc,
|
||||
device.System.EnablePtc,
|
||||
modLoadResult.Hash,
|
||||
true,
|
||||
programName,
|
||||
metaLoader.GetProgramId(),
|
||||
|
|
|
@ -235,6 +235,7 @@ namespace Ryujinx.HLE.Loaders.Processes
|
|||
dummyExeFs.GetNpdm(),
|
||||
nacpData,
|
||||
diskCacheEnabled: false,
|
||||
diskCacheSelector: null,
|
||||
allowCodeMemoryForJit: true,
|
||||
programName,
|
||||
programId,
|
||||
|
|
|
@ -186,6 +186,7 @@ namespace Ryujinx.HLE.Loaders.Processes
|
|||
string.Empty,
|
||||
string.Empty,
|
||||
false,
|
||||
null,
|
||||
codeAddress,
|
||||
codeSize);
|
||||
|
||||
|
@ -226,6 +227,7 @@ namespace Ryujinx.HLE.Loaders.Processes
|
|||
MetaLoader metaLoader,
|
||||
BlitStruct<ApplicationControlProperty> applicationControlProperties,
|
||||
bool diskCacheEnabled,
|
||||
string diskCacheSelector,
|
||||
bool allowCodeMemoryForJit,
|
||||
string name,
|
||||
ulong programId,
|
||||
|
@ -379,6 +381,7 @@ namespace Ryujinx.HLE.Loaders.Processes
|
|||
$"{programId:x16}",
|
||||
displayVersion,
|
||||
diskCacheEnabled,
|
||||
diskCacheSelector,
|
||||
codeStart,
|
||||
codeSize);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue