2019-09-02 16:03:57 +00:00
|
|
|
using JsonPrettyPrinterPlus;
|
2019-10-17 06:17:44 +00:00
|
|
|
using LibHac.FsSystem;
|
2019-02-11 12:00:32 +00:00
|
|
|
using OpenTK.Input;
|
|
|
|
using Ryujinx.Common;
|
|
|
|
using Ryujinx.Common.Logging;
|
|
|
|
using Ryujinx.HLE;
|
|
|
|
using Ryujinx.HLE.HOS.SystemState;
|
2019-04-15 23:22:55 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services;
|
2019-02-11 12:00:32 +00:00
|
|
|
using Ryujinx.HLE.Input;
|
2019-11-29 04:32:51 +00:00
|
|
|
using Ryujinx.Ui;
|
|
|
|
using Ryujinx.Ui.Input;
|
2019-02-11 12:00:32 +00:00
|
|
|
using System;
|
2019-09-02 16:03:57 +00:00
|
|
|
using System.Collections.Generic;
|
2019-02-11 12:00:32 +00:00
|
|
|
using System.IO;
|
2019-09-02 16:03:57 +00:00
|
|
|
using System.Text;
|
2019-02-11 12:00:32 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Utf8Json;
|
|
|
|
using Utf8Json.Resolvers;
|
|
|
|
|
|
|
|
namespace Ryujinx
|
|
|
|
{
|
|
|
|
public class Configuration
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The default configuration instance
|
|
|
|
/// </summary>
|
|
|
|
public static Configuration Instance { get; private set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Dumps shaders in this local directory
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public string GraphicsShadersDumpPath { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enables printing debug log messages
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool LoggingEnableDebug { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enables printing stub log messages
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool LoggingEnableStub { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enables printing info log messages
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool LoggingEnableInfo { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enables printing warning log messages
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool LoggingEnableWarn { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enables printing error log messages
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool LoggingEnableError { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
2019-06-16 01:31:18 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Enables printing guest log messages
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool LoggingEnableGuest { get; set; }
|
2019-06-16 01:31:18 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enables printing FS access log messages
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool LoggingEnableFsAccessLog { get; set; }
|
2019-06-16 01:31:18 +00:00
|
|
|
|
2019-02-11 12:00:32 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Controls which log messages are written to the log targets
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public LogClass[] LoggingFilteredClasses { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enables or disables logging to a file on disk
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool EnableFileLog { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Change System Language
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public SystemLanguage SystemLanguage { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enables or disables Docked Mode
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool DockedMode { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
2019-05-30 20:27:43 +00:00
|
|
|
/// <summary>
|
2019-07-02 02:39:22 +00:00
|
|
|
/// Enables or disables Discord Rich Presence
|
2019-05-30 20:27:43 +00:00
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool EnableDiscordIntegration { get; set; }
|
2019-05-30 20:27:43 +00:00
|
|
|
|
2019-02-11 12:00:32 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Enables or disables Vertical Sync
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool EnableVsync { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enables or disables multi-core scheduling of threads
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool EnableMulticoreScheduling { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enables integrity checks on Game content files
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool EnableFsIntegrityChecks { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
2019-06-16 01:31:18 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Enables FS access log output to the console. Possible modes are 0-3
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public int FsGlobalAccessLogMode { get; set; }
|
2019-06-16 01:31:18 +00:00
|
|
|
|
2019-04-15 23:22:55 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Enable or disable ignoring missing services
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool IgnoreMissingServices { get; set; }
|
2019-04-15 23:22:55 +00:00
|
|
|
|
2019-02-11 12:00:32 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The primary controller's type
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public ControllerStatus ControllerType { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Used to toggle columns in the GUI
|
|
|
|
/// </summary>
|
2019-11-29 04:32:51 +00:00
|
|
|
public GuiColumns GuiColumns { get; set; }
|
2019-09-02 16:03:57 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A list of directories containing games to be used to load games into the games list
|
|
|
|
/// </summary>
|
|
|
|
public List<string> GameDirs { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enable or disable custom themes in the GUI
|
|
|
|
/// </summary>
|
|
|
|
public bool EnableCustomTheme { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Path to custom GUI theme
|
|
|
|
/// </summary>
|
|
|
|
public string CustomThemePath { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
2019-05-02 23:29:01 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Enable or disable keyboard support (Independent from controllers binding)
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public bool EnableKeyboard { get; set; }
|
2019-05-02 23:29:01 +00:00
|
|
|
|
2019-02-11 12:00:32 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Keyboard control bindings
|
|
|
|
/// </summary>
|
2019-09-02 16:03:57 +00:00
|
|
|
public NpadKeyboard KeyboardControls { get; set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Controller control bindings
|
|
|
|
/// </summary>
|
2019-11-29 04:32:51 +00:00
|
|
|
public Ui.Input.NpadController JoystickControls { get; private set; }
|
2019-02-11 12:00:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Loads a configuration file from disk
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path">The path to the JSON configuration file</param>
|
|
|
|
public static void Load(string path)
|
|
|
|
{
|
|
|
|
var resolver = CompositeResolver.Create(
|
|
|
|
new[] { new ConfigurationEnumFormatter<Key>() },
|
|
|
|
new[] { StandardResolver.AllowPrivateSnakeCase }
|
|
|
|
);
|
|
|
|
|
|
|
|
using (Stream stream = File.OpenRead(path))
|
|
|
|
{
|
|
|
|
Instance = JsonSerializer.Deserialize<Configuration>(stream, resolver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Loads a configuration file asynchronously from disk
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path">The path to the JSON configuration file</param>
|
|
|
|
public static async Task LoadAsync(string path)
|
|
|
|
{
|
2019-09-02 16:03:57 +00:00
|
|
|
IJsonFormatterResolver resolver = CompositeResolver.Create(
|
|
|
|
new[] { new ConfigurationEnumFormatter<Key>() },
|
2019-02-11 12:00:32 +00:00
|
|
|
new[] { StandardResolver.AllowPrivateSnakeCase }
|
|
|
|
);
|
|
|
|
|
|
|
|
using (Stream stream = File.OpenRead(path))
|
|
|
|
{
|
|
|
|
Instance = await JsonSerializer.DeserializeAsync<Configuration>(stream, resolver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-02 16:03:57 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Save a configuration file to disk
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path">The path to the JSON configuration file</param>
|
|
|
|
public static void SaveConfig(Configuration config, string path)
|
|
|
|
{
|
|
|
|
IJsonFormatterResolver resolver = CompositeResolver.Create(
|
|
|
|
new[] { new ConfigurationEnumFormatter<Key>() },
|
|
|
|
new[] { StandardResolver.AllowPrivateSnakeCase }
|
|
|
|
);
|
|
|
|
|
|
|
|
byte[] data = JsonSerializer.Serialize(config, resolver);
|
|
|
|
File.WriteAllText(path, Encoding.UTF8.GetString(data, 0, data.Length).PrettyPrintJson());
|
|
|
|
}
|
|
|
|
|
2019-02-11 12:00:32 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Configures a <see cref="Switch"/> instance
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="device">The instance to configure</param>
|
2019-09-02 16:03:57 +00:00
|
|
|
public static void InitialConfigure(Switch device)
|
2019-02-11 12:00:32 +00:00
|
|
|
{
|
|
|
|
if (Instance == null)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException("Configuration has not been loaded yet.");
|
|
|
|
}
|
|
|
|
|
2019-09-02 16:03:57 +00:00
|
|
|
SwitchSettings.ConfigureSettings(Instance);
|
2019-02-11 12:00:32 +00:00
|
|
|
|
|
|
|
Logger.AddTarget(new AsyncLogTargetWrapper(
|
|
|
|
new ConsoleLogTarget(),
|
|
|
|
1000,
|
|
|
|
AsyncLogTargetOverflowAction.Block
|
|
|
|
));
|
|
|
|
|
|
|
|
if (Instance.EnableFileLog)
|
|
|
|
{
|
|
|
|
Logger.AddTarget(new AsyncLogTargetWrapper(
|
2019-09-02 16:03:57 +00:00
|
|
|
new FileLogTarget(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Ryujinx.log")),
|
2019-02-11 12:00:32 +00:00
|
|
|
1000,
|
|
|
|
AsyncLogTargetOverflowAction.Block
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2019-09-02 16:03:57 +00:00
|
|
|
Configure(device, Instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Configure(Switch device, Configuration SwitchConfig)
|
|
|
|
{
|
|
|
|
GraphicsConfig.ShadersDumpPath = SwitchConfig.GraphicsShadersDumpPath;
|
|
|
|
|
|
|
|
Logger.SetEnable(LogLevel.Debug, SwitchConfig.LoggingEnableDebug );
|
|
|
|
Logger.SetEnable(LogLevel.Stub, SwitchConfig.LoggingEnableStub );
|
|
|
|
Logger.SetEnable(LogLevel.Info, SwitchConfig.LoggingEnableInfo );
|
|
|
|
Logger.SetEnable(LogLevel.Warning, SwitchConfig.LoggingEnableWarn );
|
|
|
|
Logger.SetEnable(LogLevel.Error, SwitchConfig.LoggingEnableError );
|
|
|
|
Logger.SetEnable(LogLevel.Guest, SwitchConfig.LoggingEnableGuest );
|
|
|
|
Logger.SetEnable(LogLevel.AccessLog, SwitchConfig.LoggingEnableFsAccessLog);
|
2019-02-11 12:00:32 +00:00
|
|
|
|
2019-09-02 16:03:57 +00:00
|
|
|
if (SwitchConfig.LoggingFilteredClasses.Length > 0)
|
2019-02-11 12:00:32 +00:00
|
|
|
{
|
|
|
|
foreach (var logClass in EnumExtensions.GetValues<LogClass>())
|
|
|
|
{
|
|
|
|
Logger.SetEnable(logClass, false);
|
|
|
|
}
|
|
|
|
|
2019-09-02 16:03:57 +00:00
|
|
|
foreach (var logClass in SwitchConfig.LoggingFilteredClasses)
|
2019-02-11 12:00:32 +00:00
|
|
|
{
|
|
|
|
Logger.SetEnable(logClass, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-02 16:03:57 +00:00
|
|
|
MainWindow.DiscordIntegrationEnabled = SwitchConfig.EnableDiscordIntegration;
|
2019-05-30 20:27:43 +00:00
|
|
|
|
2019-09-02 16:03:57 +00:00
|
|
|
device.EnableDeviceVsync = SwitchConfig.EnableVsync;
|
2019-02-11 12:00:32 +00:00
|
|
|
|
2019-09-02 16:03:57 +00:00
|
|
|
device.System.State.DockedMode = SwitchConfig.DockedMode;
|
2019-02-11 12:00:32 +00:00
|
|
|
|
2019-09-02 16:03:57 +00:00
|
|
|
device.System.State.SetLanguage(SwitchConfig.SystemLanguage);
|
2019-02-11 12:00:32 +00:00
|
|
|
|
2019-09-02 16:03:57 +00:00
|
|
|
if (SwitchConfig.EnableMulticoreScheduling)
|
2019-02-11 12:00:32 +00:00
|
|
|
{
|
|
|
|
device.System.EnableMultiCoreScheduling();
|
|
|
|
}
|
|
|
|
|
2019-09-02 16:03:57 +00:00
|
|
|
device.System.FsIntegrityCheckLevel = SwitchConfig.EnableFsIntegrityChecks
|
2019-02-11 12:00:32 +00:00
|
|
|
? IntegrityCheckLevel.ErrorOnInvalid
|
|
|
|
: IntegrityCheckLevel.None;
|
|
|
|
|
2019-09-02 16:03:57 +00:00
|
|
|
device.System.GlobalAccessLogMode = SwitchConfig.FsGlobalAccessLogMode;
|
2019-06-16 01:31:18 +00:00
|
|
|
|
2019-09-02 16:03:57 +00:00
|
|
|
ServiceConfiguration.IgnoreMissingServices = SwitchConfig.IgnoreMissingServices;
|
|
|
|
}
|
2019-10-31 18:09:03 +00:00
|
|
|
|
|
|
|
public static void ConfigureHid(Switch device, Configuration SwitchConfig)
|
|
|
|
{
|
2019-09-02 16:03:57 +00:00
|
|
|
if (SwitchConfig.JoystickControls.Enabled)
|
2019-02-11 12:00:32 +00:00
|
|
|
{
|
2019-09-02 16:03:57 +00:00
|
|
|
if (!Joystick.GetState(SwitchConfig.JoystickControls.Index).IsConnected)
|
2019-02-11 12:00:32 +00:00
|
|
|
{
|
2019-09-02 16:03:57 +00:00
|
|
|
SwitchConfig.JoystickControls.SetEnabled(false);
|
2019-02-11 12:00:32 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-02 16:03:57 +00:00
|
|
|
device.Hid.InitializePrimaryController(SwitchConfig.ControllerType);
|
2019-07-02 02:39:22 +00:00
|
|
|
device.Hid.InitializeKeyboard();
|
2019-02-11 12:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private class ConfigurationEnumFormatter<T> : IJsonFormatter<T>
|
|
|
|
where T : struct
|
|
|
|
{
|
|
|
|
public void Serialize(ref JsonWriter writer, T value, IJsonFormatterResolver formatterResolver)
|
|
|
|
{
|
|
|
|
formatterResolver.GetFormatterWithVerify<string>()
|
|
|
|
.Serialize(ref writer, value.ToString(), formatterResolver);
|
|
|
|
}
|
|
|
|
|
|
|
|
public T Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
|
|
|
|
{
|
|
|
|
if (reader.ReadIsNull())
|
|
|
|
{
|
|
|
|
return default(T);
|
|
|
|
}
|
|
|
|
|
2019-07-02 02:39:22 +00:00
|
|
|
string enumName = formatterResolver.GetFormatterWithVerify<string>()
|
|
|
|
.Deserialize(ref reader, formatterResolver);
|
2019-02-11 12:00:32 +00:00
|
|
|
|
2019-07-02 02:39:22 +00:00
|
|
|
if (Enum.TryParse<T>(enumName, out T result))
|
2019-02-11 12:00:32 +00:00
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return default(T);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|