aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE
diff options
context:
space:
mode:
authormageven <62494521+mageven@users.noreply.github.com>2021-02-20 05:55:01 +0530
committerGitHub <noreply@github.com>2021-02-20 01:25:01 +0100
commit65eb9901f17f210aab467eabfc090c872c08755a (patch)
tree16d4522ea84fd5cc69d889bc6f12a50874811f0b /Ryujinx.HLE
parentd9b3f3fa3aa3816f8c136ca5a5c7139331b9cbd7 (diff)
Allow modding AddOnContent RomFS (#2024)
Simplify some misc logic
Diffstat (limited to 'Ryujinx.HLE')
-rw-r--r--Ryujinx.HLE/HOS/ApplicationLoader.cs7
-rw-r--r--Ryujinx.HLE/HOS/ModLoader.cs60
-rw-r--r--Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxy.cs2
3 files changed, 35 insertions, 34 deletions
diff --git a/Ryujinx.HLE/HOS/ApplicationLoader.cs b/Ryujinx.HLE/HOS/ApplicationLoader.cs
index cc9b25fb..fb2b9770 100644
--- a/Ryujinx.HLE/HOS/ApplicationLoader.cs
+++ b/Ryujinx.HLE/HOS/ApplicationLoader.cs
@@ -72,9 +72,6 @@ namespace Ryujinx.HLE.HOS
_fileSystem = fileSystem;
_controlData = new BlitStruct<ApplicationControlProperty>(1);
-
- // Clear Mods cache
- _fileSystem.ModLoader.Clear();
}
public void LoadCart(string exeFsDir, string romFsFile = null)
@@ -88,7 +85,7 @@ namespace Ryujinx.HLE.HOS
Npdm metaData = ReadNpdm(codeFs);
- _fileSystem.ModLoader.CollectMods(TitleId, _fileSystem.ModLoader.GetModsBasePath());
+ _fileSystem.ModLoader.CollectMods(new[] { TitleId }, _fileSystem.ModLoader.GetModsBasePath());
if (TitleId != 0)
{
@@ -377,7 +374,7 @@ namespace Ryujinx.HLE.HOS
Npdm metaData = ReadNpdm(codeFs);
- _fileSystem.ModLoader.CollectMods(TitleId, _fileSystem.ModLoader.GetModsBasePath());
+ _fileSystem.ModLoader.CollectMods(_contentManager.GetAocTitleIds().Prepend(TitleId), _fileSystem.ModLoader.GetModsBasePath());
if (controlNca != null)
{
diff --git a/Ryujinx.HLE/HOS/ModLoader.cs b/Ryujinx.HLE/HOS/ModLoader.cs
index 7aba0fc7..1558ac76 100644
--- a/Ryujinx.HLE/HOS/ModLoader.cs
+++ b/Ryujinx.HLE/HOS/ModLoader.cs
@@ -66,7 +66,7 @@ namespace Ryujinx.HLE.HOS
public List<Mod<DirectoryInfo>> NroPatches { get; }
public List<Mod<DirectoryInfo>> KipPatches { get; }
- public HashSet<string> SearchedDirs { get; }
+ internal bool Initialized { get; set; }
public PatchCache()
{
@@ -74,7 +74,7 @@ namespace Ryujinx.HLE.HOS
NroPatches = new List<Mod<DirectoryInfo>>();
KipPatches = new List<Mod<DirectoryInfo>>();
- SearchedDirs = new HashSet<string>();
+ Initialized = false;
}
}
@@ -140,9 +140,9 @@ namespace Ryujinx.HLE.HOS
}
// Static Query Methods
- public static void QueryPatchDirs(PatchCache cache, DirectoryInfo patchDir, DirectoryInfo searchDir)
+ public static void QueryPatchDirs(PatchCache cache, DirectoryInfo patchDir)
{
- if (!patchDir.Exists || cache.SearchedDirs.Contains(searchDir.FullName)) return;
+ if (cache.Initialized || !patchDir.Exists) return;
var patches = cache.KipPatches;
string type = null;
@@ -216,7 +216,7 @@ namespace Ryujinx.HLE.HOS
{
if (!contentsDir.Exists) return;
- Logger.Info?.Print(LogClass.ModLoader, $"Searching mods for Title {titleId:X16}");
+ Logger.Info?.Print(LogClass.ModLoader, $"Searching mods for {((titleId & 0x1000) != 0 ? "DLC" : "Title")} {titleId:X16}");
var titleDir = FindTitleDir(contentsDir, $"{titleId:x16}");
@@ -226,26 +226,29 @@ namespace Ryujinx.HLE.HOS
}
}
- public static void CollectMods(ModCache mods, PatchCache patches, ulong? titleId, params string[] searchDirPaths)
+ // Assumes searchDirPaths don't overlap
+ public static void CollectMods(Dictionary<ulong, ModCache> modCaches, PatchCache patches, params string[] searchDirPaths)
{
static bool IsPatchesDir(string name) => StrEquals(AmsNsoPatchDir, name) ||
StrEquals(AmsNroPatchDir, name) ||
StrEquals(AmsKipPatchDir, name);
- static bool TryQuery(ModCache mods, PatchCache patches, ulong? titleId, DirectoryInfo dir, DirectoryInfo searchDir)
+ static bool IsContentsDir(string name) => StrEquals(AmsContentsDir, name);
+
+ static bool TryQuery(DirectoryInfo searchDir, PatchCache patches, Dictionary<ulong, ModCache> modCaches)
{
- if (StrEquals(AmsContentsDir, dir.Name))
+ if (IsContentsDir(searchDir.Name))
{
- if (titleId.HasValue)
+ foreach (var (titleId, cache) in modCaches)
{
- QueryContentsDir(mods, dir, (ulong)titleId);
-
- return true;
+ QueryContentsDir(cache, searchDir, titleId);
}
+
+ return true;
}
- else if (IsPatchesDir(dir.Name))
+ else if (IsPatchesDir(searchDir.Name))
{
- QueryPatchDirs(patches, dir, searchDir);
+ QueryPatchDirs(patches, searchDir);
return true;
}
@@ -255,34 +258,35 @@ namespace Ryujinx.HLE.HOS
foreach (var path in searchDirPaths)
{
- var dir = new DirectoryInfo(path);
- if (!dir.Exists)
+ var searchDir = new DirectoryInfo(path);
+ if (!searchDir.Exists)
{
- Logger.Warning?.Print(LogClass.ModLoader, $"Mod Search Dir '{dir.FullName}' doesn't exist");
+ Logger.Warning?.Print(LogClass.ModLoader, $"Mod Search Dir '{searchDir.FullName}' doesn't exist");
continue;
}
- if (!TryQuery(mods, patches, titleId, dir, dir))
+ if (!TryQuery(searchDir, patches, modCaches))
{
- foreach (var subdir in dir.EnumerateDirectories())
+ foreach (var subdir in searchDir.EnumerateDirectories())
{
- TryQuery(mods, patches, titleId, subdir, dir);
+ TryQuery(subdir, patches, modCaches);
}
}
-
- patches.SearchedDirs.Add(dir.FullName);
}
+
+ patches.Initialized = true;
}
- public void CollectMods(ulong titleId, params string[] searchDirPaths)
+ public void CollectMods(IEnumerable<ulong> titles, params string[] searchDirPaths)
{
- if (!AppMods.TryGetValue(titleId, out ModCache mods))
+ Clear();
+
+ foreach (ulong titleId in titles)
{
- mods = new ModCache();
- AppMods[titleId] = mods;
+ AppMods[titleId] = new ModCache();
}
- CollectMods(mods, Patches, titleId, searchDirPaths);
+ CollectMods(AppMods, Patches, searchDirPaths);
}
internal IStorage ApplyRomFsMods(ulong titleId, IStorage baseStorage)
@@ -448,7 +452,7 @@ namespace Ryujinx.HLE.HOS
}
modLoadResult.Npdm = new Npdm(npdmFile.OpenRead());
-
+
Logger.Info?.Print(LogClass.ModLoader, $"main.npdm replaced");
}
}
diff --git a/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxy.cs b/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxy.cs
index e29a040f..d108f95a 100644
--- a/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxy.cs
+++ b/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxy.cs
@@ -400,7 +400,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
{
Logger.Info?.Print(LogClass.Loader, $"Opened AddOnContent Data TitleID={titleId:X16}");
- MakeObject(context, new FileSystemProxy.IStorage(aocStorage));
+ MakeObject(context, new FileSystemProxy.IStorage(context.Device.FileSystem.ModLoader.ApplyRomFsMods((ulong)titleId, aocStorage)));
return ResultCode.Success;
}