Add Command Line Parameter to Override Mods #499

Closed
TheMetalStorm wants to merge 4 commits from cli-mods into master
5 changed files with 63 additions and 7 deletions
Showing only changes of commit ae364d1436 - Show all commits

View File

@ -32,6 +32,7 @@ namespace Ryujinx.Common.Configuration
public static string KeysDirPathUser { get; }
public static string LogsDirPath { get; private set; }
public static string[] CommandLineArgMods { get; private set; }
public const string DefaultNandDir = "bis";
public const string DefaultSdcardDir = "sdcard";
@ -47,8 +48,9 @@ namespace Ryujinx.Common.Configuration
KeysDirPathUser = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".switch");
}
public static void Initialize(string baseDirPath)
public static void Initialize(string baseDirPath, string[] commandLineArgMods)
{
CommandLineArgMods = commandLineArgMods;
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
if (appDataPath.Length == 0)

View File

@ -41,11 +41,11 @@ namespace Ryujinx.HLE.HOS
private static readonly ModMetadataJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions());
public readonly struct Mod<T> where T : FileSystemInfo
public struct Mod<T> where T : FileSystemInfo
{
public readonly string Name;
public readonly T Path;
public readonly bool Enabled;
public bool Enabled;
public Mod(string name, T path, bool enabled)
{
@ -169,7 +169,16 @@ namespace Ryujinx.HLE.HOS
if (StrEquals(RomfsDir, modDir.Name))
{
var modData = modMetadata.Mods.FirstOrDefault(x => modDir.FullName.Contains(x.Path));
var enabled = modData?.Enabled ?? true;
bool enabled;
if (AppDataManager.CommandLineArgMods.Length == 0)
{
enabled = modData?.Enabled ?? true;
}
else
{
enabled = AppDataManager.CommandLineArgMods.Contains(modData.Name);
}
mods.RomfsDirs.Add(mod = new Mod<DirectoryInfo>(dir.Name, modDir, enabled));
types.Append('R');
@ -177,7 +186,16 @@ namespace Ryujinx.HLE.HOS
else if (StrEquals(ExefsDir, modDir.Name))
{
var modData = modMetadata.Mods.FirstOrDefault(x => modDir.FullName.Contains(x.Path));
var enabled = modData?.Enabled ?? true;
bool enabled;
if (AppDataManager.CommandLineArgMods.Length == 0)
{
enabled = modData?.Enabled ?? true;
}
else
{
enabled = AppDataManager.CommandLineArgMods.Contains(modData.Name);
}
mods.ExefsDirs.Add(mod = new Mod<DirectoryInfo>(dir.Name, modDir, enabled));
types.Append('E');

View File

@ -147,7 +147,7 @@ namespace Ryujinx.Headless
option.InheritMainConfig(originalArgs, ConfigurationState.Instance, out useLastUsedProfile);
}
AppDataManager.Initialize(option.BaseDataDir);
AppDataManager.Initialize(option.BaseDataDir, []);
if (useLastUsedProfile && AccountSaveDataManager.GetLastUsedUser().TryGet(out var profile))
option.UserProfile = profile.Name;

View File

@ -114,7 +114,7 @@ namespace Ryujinx.Ava
AppDomain.CurrentDomain.ProcessExit += (_, _) => Exit();
// Setup base data directory.
AppDataManager.Initialize(CommandLineState.BaseDirPathArg);
AppDataManager.Initialize(CommandLineState.BaseDirPathArg, CommandLineState.Mods);
// Initialize the configuration.
ConfigurationState.Initialize();

View File

@ -6,6 +6,7 @@ namespace Ryujinx.Ava.Utilities
public static class CommandLineState
{
public static string[] Arguments { get; private set; }
public static string[] Mods { get; private set; }
public static bool? OverrideDockedMode { get; private set; }
public static bool? OverrideHardwareAcceleration { get; private set; }
@ -21,6 +22,7 @@ namespace Ryujinx.Ava.Utilities
public static void ParseArguments(string[] args)
{
List<string> arguments = new();
List<string> mods = new();
// Parse Arguments.
for (int i = 0; i < args.Length; ++i)
@ -78,6 +80,39 @@ namespace Ryujinx.Ava.Utilities
case "--application-id":
LaunchApplicationId = args[++i];
break;
case "-m":
case "--mod":
int numMods;
if (i + 1 >= args.Length)
{
Logger.Error?.Print(LogClass.Application, $"Argument '{arg}' expects a number of mods as next argument");
continue;
}
if (!int.TryParse(args[++i], out numMods))
{
i--;
Logger.Error?.Print(LogClass.Application, $"Expected number of mods, got '{arg}'");
continue;
}
if (i + numMods >= args.Length)
{
Logger.Error?.Print(LogClass.Application, $"The number of expected mods exceeds the number of command line arguments left");
continue;
}
for (int j = i + 1; j <= i + numMods; j++)
{
mods.Add(args[j]);
Logger.Info?.Print(LogClass.Application, $"Enabled mod '{args[j]}' through cli");
}
i += numMods;
break;
case "--docked-mode":
OverrideDockedMode = true;
break;
@ -107,6 +142,7 @@ namespace Ryujinx.Ava.Utilities
}
Arguments = arguments.ToArray();
Mods = mods.ToArray();
}
}
}