Initial texture replacement implementation

Unmerged PR #5632, originally by @gdkchan

* Add mod manager support - @KeatonTheBot

* Remove redundant code - @KeatonTheBot

* Optimize, modernize code to newer C# standards where appropriate - @KeatonTheBot

Co-authored-by: KeatonTheBot <keaton@ryujinx.app>
This commit is contained in:
gdkchan
2025-12-19 17:49:02 -06:00
committed by KeatonTheBot
co-authored by KeatonTheBot
parent d00bda7e53
commit 812cecd713
27 changed files with 3505 additions and 67 deletions
+34
View File
@@ -9,6 +9,7 @@ using LibHac.Util;
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
using Ryujinx.Common.Utilities;
using Ryujinx.Graphics.Gpu;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.HLE.Loaders.Executables;
using Ryujinx.HLE.Loaders.Mods;
@@ -30,6 +31,7 @@ namespace Ryujinx.HLE.HOS
private const string RomfsDir = "romfs";
private const string ExefsDir = "exefs";
private const string CheatDir = "cheats";
private const string TexturesDir = "textures";
private const string RomfsContainer = "romfs.bin";
private const string ExefsContainer = "exefs.nsp";
private const string StubExtension = ".stub";
@@ -83,6 +85,7 @@ namespace Ryujinx.HLE.HOS
public List<Mod<DirectoryInfo>> RomfsDirs { get; }
public List<Mod<DirectoryInfo>> ExefsDirs { get; }
public List<Mod<DirectoryInfo>> TextureDirs { get; }
public List<Cheat> Cheats { get; }
@@ -92,6 +95,7 @@ namespace Ryujinx.HLE.HOS
ExefsContainers = [];
RomfsDirs = [];
ExefsDirs = [];
TextureDirs = [];
Cheats = [];
}
}
@@ -189,6 +193,14 @@ namespace Ryujinx.HLE.HOS
mods.ExefsDirs.Add(mod = new Mod<DirectoryInfo>(dir.Name, modDir, enabled));
types.Append('E');
}
else if (StrEquals(TexturesDir, modDir.Name) && modDir.Parent != null)
{
var modData = modMetadata.Mods.FirstOrDefault(x => modDir.Parent.FullName.Equals(x.Path));
var enabled = modData?.Enabled ?? true;
mods.TextureDirs.Add(mod = new Mod<DirectoryInfo>(dir.Name, modDir, enabled));
types.Append('T');
}
else if (StrEquals(CheatDir, modDir.Name))
{
types.Append('C', QueryCheatsDir(mods, modDir));
@@ -731,6 +743,28 @@ namespace Ryujinx.HLE.HOS
return ApplyProgramPatches(nsoMods, 0x100, programs);
}
internal void ApplyTextureMods(ulong applicationId, GpuContext gpuContext)
{
if (!_appMods.TryGetValue(applicationId, out ModCache mods) || mods.TextureDirs.Count == 0)
{
return;
}
var textureMods = mods.TextureDirs;
foreach (var mod in textureMods)
{
if (!mod.Enabled)
{
continue;
}
gpuContext.DiskTextureStorage.AddInputDirectory(mod.Path.FullName);
Logger.Info?.Print(LogClass.ModLoader, $"Found texture replacements on mod '{mod.Name}'");
}
}
internal void LoadCheats(ulong applicationId, ProcessTamperInfo tamperInfo, TamperMachine tamperMachine)
{
if (tamperInfo?.BuildIds == null || tamperInfo.CodeAddresses == null)