| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759 |
- using Avalonia.Collections;
- using Avalonia.Controls;
- using Avalonia.Threading;
- using CommunityToolkit.Mvvm.ComponentModel;
- using CommunityToolkit.Mvvm.Input;
- using LibHac.Tools.FsSystem;
- using Ryujinx.Audio.Backends.OpenAL;
- using Ryujinx.Audio.Backends.SDL2;
- using Ryujinx.Audio.Backends.SoundIo;
- using Ryujinx.Ava.Common.Locale;
- using Ryujinx.Ava.UI.Helpers;
- using Ryujinx.Ava.UI.Models.Input;
- using Ryujinx.Ava.UI.Windows;
- using Ryujinx.Ava.Utilities.Configuration;
- using Ryujinx.Ava.Utilities.Configuration.System;
- using Ryujinx.Ava.Utilities.Configuration.UI;
- using Ryujinx.Common.Configuration;
- using Ryujinx.Common.Configuration.Multiplayer;
- using Ryujinx.Common.GraphicsDriver;
- using Ryujinx.Common.Helper;
- using Ryujinx.Common.Logging;
- using Ryujinx.Graphics.GAL;
- using Ryujinx.Graphics.Vulkan;
- using Ryujinx.HLE;
- using Ryujinx.HLE.FileSystem;
- using Ryujinx.HLE.HOS.Services.Time.TimeZone;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Net.NetworkInformation;
- using System.Threading.Tasks;
- using TimeZone = Ryujinx.Ava.UI.Models.TimeZone;
- namespace Ryujinx.Ava.UI.ViewModels
- {
- public partial class SettingsViewModel : BaseModel
- {
- private readonly VirtualFileSystem _virtualFileSystem;
- private readonly ContentManager _contentManager;
- private TimeZoneContentManager _timeZoneContentManager;
- private readonly List<string> _validTzRegions;
- private readonly Dictionary<string, string> _networkInterfaces;
- private float _customResolutionScale;
- private int _resolutionScale;
- private int _graphicsBackendMultithreadingIndex;
- private float _volume;
- [ObservableProperty] private bool _isVulkanAvailable = true;
- [ObservableProperty] private bool _gameDirectoryChanged;
- [ObservableProperty] private bool _autoloadDirectoryChanged;
- private readonly List<string> _gpuIds = [];
- private int _graphicsBackendIndex;
- private int _scalingFilter;
- private int _scalingFilterLevel;
- private int _customVSyncInterval;
- private bool _enableCustomVSyncInterval;
- private int _customVSyncIntervalPercentageProxy;
- private VSyncMode _vSyncMode;
- public event Action CloseWindow;
- public event Action SaveSettingsEvent;
- private int _networkInterfaceIndex;
- private int _multiplayerModeIndex;
- private string _ldnPassphrase;
- [ObservableProperty] private string _ldnServer;
- public SettingsHacksViewModel DirtyHacks { get; }
- public int ResolutionScale
- {
- get => _resolutionScale;
- set
- {
- _resolutionScale = value;
- OnPropertiesChanged(nameof(CustomResolutionScale), nameof(IsCustomResolutionScaleActive));
- }
- }
- public int GraphicsBackendMultithreadingIndex
- {
- get => _graphicsBackendMultithreadingIndex;
- set
- {
- _graphicsBackendMultithreadingIndex = value;
- if (_graphicsBackendMultithreadingIndex != (int)ConfigurationState.Instance.Graphics.BackendThreading.Value)
- {
- Dispatcher.UIThread.InvokeAsync(() =>
- ContentDialogHelper.CreateInfoDialog(LocaleManager.Instance[LocaleKeys.DialogSettingsBackendThreadingWarningMessage],
- string.Empty,
- string.Empty,
- LocaleManager.Instance[LocaleKeys.InputDialogOk],
- LocaleManager.Instance[LocaleKeys.DialogSettingsBackendThreadingWarningTitle])
- );
- }
- OnPropertyChanged();
- }
- }
- public float CustomResolutionScale
- {
- get => _customResolutionScale;
- set
- {
- _customResolutionScale = MathF.Round(value, 1);
- OnPropertyChanged();
- }
- }
- public bool IsOpenGLAvailable => !OperatingSystem.IsMacOS();
- public bool EnableDiscordIntegration { get; set; }
- public bool CheckUpdatesOnStart { get; set; }
- public bool ShowConfirmExit { get; set; }
- public bool IgnoreApplet { get; set; }
- public bool RememberWindowState { get; set; }
- public bool ShowTitleBar { get; set; }
- public int HideCursor { get; set; }
- public int UpdateCheckerType { get; set; }
- public bool EnableDockedMode { get; set; }
- public bool EnableKeyboard { get; set; }
- public bool EnableMouse { get; set; }
- public bool DisableInputWhenOutOfFocus { get; set; }
-
- public VSyncMode VSyncMode
- {
- get => _vSyncMode;
- set
- {
- if (value is VSyncMode.Custom or VSyncMode.Switch or VSyncMode.Unbounded)
- {
- _vSyncMode = value;
- OnPropertyChanged();
- }
- }
- }
- public int CustomVSyncIntervalPercentageProxy
- {
- get => _customVSyncIntervalPercentageProxy;
- set
- {
- int newInterval = (int)((value / 100f) * 60);
- _customVSyncInterval = newInterval;
- _customVSyncIntervalPercentageProxy = value;
- OnPropertiesChanged(
- nameof(CustomVSyncInterval),
- nameof(CustomVSyncIntervalPercentageText));
- }
- }
- public string CustomVSyncIntervalPercentageText => CustomVSyncIntervalPercentageProxy + "%";
- public bool EnableCustomVSyncInterval
- {
- get => _enableCustomVSyncInterval;
- set
- {
- _enableCustomVSyncInterval = value;
- if (_vSyncMode == VSyncMode.Custom && !value)
- {
- VSyncMode = VSyncMode.Switch;
- }
- else if (value)
- {
- VSyncMode = VSyncMode.Custom;
- }
- OnPropertyChanged();
- }
- }
- public int CustomVSyncInterval
- {
- get => _customVSyncInterval;
- set
- {
- _customVSyncInterval = value;
- int newPercent = (int)((value / 60f) * 100);
- _customVSyncIntervalPercentageProxy = newPercent;
- OnPropertiesChanged(
- nameof(CustomVSyncIntervalPercentageProxy),
- nameof(CustomVSyncIntervalPercentageText));
- OnPropertyChanged();
- }
- }
- public bool EnablePptc { get; set; }
- public bool EnableLowPowerPptc { get; set; }
- public bool EnableInternetAccess { get; set; }
- public bool EnableFsIntegrityChecks { get; set; }
- public bool IgnoreMissingServices { get; set; }
- public MemoryConfiguration DramSize { get; set; }
- public bool EnableShaderCache { get; set; }
- public bool EnableTextureRecompression { get; set; }
- public bool EnableMacroHLE { get; set; }
- public bool EnableColorSpacePassthrough { get; set; }
- public bool ColorSpacePassthroughAvailable => RunningPlatform.IsMacOS;
- public bool EnableFileLog { get; set; }
- public bool EnableStub { get; set; }
- public bool EnableInfo { get; set; }
- public bool EnableWarn { get; set; }
- public bool EnableError { get; set; }
- public bool EnableTrace { get; set; }
- public bool EnableGuest { get; set; }
- public bool EnableFsAccessLog { get; set; }
- public bool EnableAvaloniaLog { get; set; }
- public bool EnableDebug { get; set; }
- public bool IsOpenAlEnabled { get; set; }
- public bool IsSoundIoEnabled { get; set; }
- public bool IsSDL2Enabled { get; set; }
- public bool IsCustomResolutionScaleActive => _resolutionScale == 4;
- public bool IsScalingFilterActive => _scalingFilter == (int)Ryujinx.Common.Configuration.ScalingFilter.Fsr;
- public bool IsVulkanSelected =>
- GraphicsBackendIndex == 1 || (GraphicsBackendIndex == 0 && !OperatingSystem.IsMacOS());
- public bool UseHypervisor { get; set; }
- public bool DisableP2P { get; set; }
- public bool ShowDirtyHacks => ConfigurationState.Instance.Hacks.ShowDirtyHacks;
- public string TimeZone { get; set; }
- public string ShaderDumpPath { get; set; }
- public string LdnPassphrase
- {
- get => _ldnPassphrase;
- set
- {
- _ldnPassphrase = value;
- IsInvalidLdnPassphraseVisible = !ValidateLdnPassphrase(value);
- OnPropertyChanged();
- OnPropertyChanged(nameof(IsInvalidLdnPassphraseVisible));
- }
- }
- public int Language { get; set; }
- public int Region { get; set; }
- public int FsGlobalAccessLogMode { get; set; }
- public int AudioBackend { get; set; }
- public int MaxAnisotropy { get; set; }
- public int AspectRatio { get; set; }
- public int AntiAliasingEffect { get; set; }
- public string ScalingFilterLevelText => ScalingFilterLevel.ToString("0");
- public int ScalingFilterLevel
- {
- get => _scalingFilterLevel;
- set
- {
- _scalingFilterLevel = value;
- OnPropertyChanged();
- OnPropertyChanged(nameof(ScalingFilterLevelText));
- }
- }
- public int OpenglDebugLevel { get; set; }
- public int MemoryMode { get; set; }
- public int BaseStyleIndex { get; set; }
- public int GraphicsBackendIndex
- {
- get => _graphicsBackendIndex;
- set
- {
- _graphicsBackendIndex = value;
- OnPropertyChanged();
- OnPropertyChanged(nameof(IsVulkanSelected));
- }
- }
- public int ScalingFilter
- {
- get => _scalingFilter;
- set
- {
- _scalingFilter = value;
- OnPropertyChanged();
- OnPropertyChanged(nameof(IsScalingFilterActive));
- }
- }
- public int PreferredGpuIndex { get; set; }
- public float Volume
- {
- get => _volume;
- set
- {
- _volume = value;
- ConfigurationState.Instance.System.AudioVolume.Value = _volume / 100;
- OnPropertyChanged();
- }
- }
- [ObservableProperty] private bool _matchSystemTime;
- public DateTimeOffset CurrentDate { get; set; }
- public TimeSpan CurrentTime { get; set; }
- internal AvaloniaList<TimeZone> TimeZones { get; set; }
- public AvaloniaList<string> GameDirectories { get; set; }
- public AvaloniaList<string> AutoloadDirectories { get; set; }
- public ObservableCollection<ComboBoxItem> AvailableGpus { get; set; }
- public AvaloniaList<string> NetworkInterfaceList
- {
- get => new(_networkInterfaces.Keys);
- }
- public HotkeyConfig KeyboardHotkey { get; set; }
- public int NetworkInterfaceIndex
- {
- get => _networkInterfaceIndex;
- set
- {
- _networkInterfaceIndex = value != -1 ? value : 0;
- }
- }
- public int MultiplayerModeIndex
- {
- get => _multiplayerModeIndex;
- set
- {
- _multiplayerModeIndex = value;
- }
- }
- public bool IsInvalidLdnPassphraseVisible { get; set; }
- public SettingsViewModel(VirtualFileSystem virtualFileSystem, ContentManager contentManager) : this()
- {
- _virtualFileSystem = virtualFileSystem;
- _contentManager = contentManager;
-
- if (Program.PreviewerDetached)
- {
- Task.Run(LoadTimeZones);
-
- DirtyHacks = new SettingsHacksViewModel(this);
- }
- }
- public SettingsViewModel()
- {
- GameDirectories = [];
- AutoloadDirectories = [];
- TimeZones = [];
- AvailableGpus = [];
- _validTzRegions = [];
- _networkInterfaces = new Dictionary<string, string>();
- Task.Run(CheckSoundBackends);
- Task.Run(PopulateNetworkInterfaces);
- if (Program.PreviewerDetached)
- {
- Task.Run(LoadAvailableGpus);
- LoadCurrentConfiguration();
- DirtyHacks = new SettingsHacksViewModel(this);
- }
- }
- public async Task CheckSoundBackends()
- {
- IsOpenAlEnabled = OpenALHardwareDeviceDriver.IsSupported;
- IsSoundIoEnabled = SoundIoHardwareDeviceDriver.IsSupported;
- IsSDL2Enabled = SDL2HardwareDeviceDriver.IsSupported;
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- OnPropertyChanged(nameof(IsOpenAlEnabled));
- OnPropertyChanged(nameof(IsSoundIoEnabled));
- OnPropertyChanged(nameof(IsSDL2Enabled));
- });
- }
- private async Task LoadAvailableGpus()
- {
- AvailableGpus.Clear();
- DeviceInfo[] devices = VulkanRenderer.GetPhysicalDevices();
- if (devices.Length == 0)
- {
- IsVulkanAvailable = false;
- GraphicsBackendIndex = 2;
- }
- else
- {
- foreach (DeviceInfo device in devices)
- {
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- _gpuIds.Add(device.Id);
- AvailableGpus.Add(new ComboBoxItem { Content = $"{device.Name} {(device.IsDiscrete ? "(dGPU)" : string.Empty)}" });
- });
- }
- }
- // GPU configuration needs to be loaded during the async method or it will always return 0.
- PreferredGpuIndex = _gpuIds.Contains(ConfigurationState.Instance.Graphics.PreferredGpu) ?
- _gpuIds.IndexOf(ConfigurationState.Instance.Graphics.PreferredGpu) : 0;
- Dispatcher.UIThread.Post(() => OnPropertyChanged(nameof(PreferredGpuIndex)));
- }
- public async Task LoadTimeZones()
- {
- _timeZoneContentManager = new TimeZoneContentManager();
- _timeZoneContentManager.InitializeInstance(_virtualFileSystem, _contentManager, IntegrityCheckLevel.None);
- foreach ((int offset, string location, string abbr) in _timeZoneContentManager.ParseTzOffsets())
- {
- int hours = Math.DivRem(offset, 3600, out int seconds);
- int minutes = Math.Abs(seconds) / 60;
- string abbr2 = abbr.StartsWith('+') || abbr.StartsWith('-') ? string.Empty : abbr;
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- TimeZones.Add(new TimeZone($"UTC{hours:+0#;-0#;+00}:{minutes:D2}", location, abbr2));
- _validTzRegions.Add(location);
- });
- }
- Dispatcher.UIThread.Post(() => OnPropertyChanged(nameof(TimeZone)));
- }
- private async Task PopulateNetworkInterfaces()
- {
- _networkInterfaces.Clear();
- _networkInterfaces.Add(LocaleManager.Instance[LocaleKeys.NetworkInterfaceDefault], "0");
- foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
- {
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- _networkInterfaces.Add(networkInterface.Name, networkInterface.Id);
- });
- }
- // Network interface index needs to be loaded during the async method or it will always return 0.
- NetworkInterfaceIndex = _networkInterfaces.Values.ToList().IndexOf(ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value);
- Dispatcher.UIThread.Post(() => OnPropertyChanged(nameof(NetworkInterfaceIndex)));
- }
- private bool ValidateLdnPassphrase(string passphrase)
- {
- return string.IsNullOrEmpty(passphrase) || (passphrase.Length == 16 && Patterns.LdnPassphrase.IsMatch(passphrase));
- }
- public void ValidateAndSetTimeZone(string location)
- {
- if (_validTzRegions.Contains(location))
- {
- TimeZone = location;
- }
- }
- public void LoadCurrentConfiguration()
- {
- ConfigurationState config = ConfigurationState.Instance;
- // User Interface
- EnableDiscordIntegration = config.EnableDiscordIntegration;
- CheckUpdatesOnStart = config.CheckUpdatesOnStart;
- ShowConfirmExit = config.ShowConfirmExit;
- RememberWindowState = config.RememberWindowState;
- ShowTitleBar = config.ShowTitleBar;
- HideCursor = (int)config.HideCursor.Value;
- UpdateCheckerType = (int)config.UpdateCheckerType.Value;
- GameDirectories.Clear();
- GameDirectories.AddRange(config.UI.GameDirs.Value);
- AutoloadDirectories.Clear();
- AutoloadDirectories.AddRange(config.UI.AutoloadDirs.Value);
- BaseStyleIndex = config.UI.BaseStyle.Value switch
- {
- "Auto" => 0,
- "Light" => 1,
- "Dark" => 2,
- _ => 0
- };
- // Input
- EnableDockedMode = config.System.EnableDockedMode;
- EnableKeyboard = config.Hid.EnableKeyboard;
- EnableMouse = config.Hid.EnableMouse;
- DisableInputWhenOutOfFocus = config.Hid.DisableInputWhenOutOfFocus;
- // Keyboard Hotkeys
- KeyboardHotkey = new HotkeyConfig(config.Hid.Hotkeys.Value);
- // System
- Region = (int)config.System.Region.Value;
- Language = (int)config.System.Language.Value;
- TimeZone = config.System.TimeZone;
- DateTime currentHostDateTime = DateTime.Now;
- TimeSpan systemDateTimeOffset = TimeSpan.FromSeconds(config.System.SystemTimeOffset);
- DateTime currentDateTime = currentHostDateTime.Add(systemDateTimeOffset);
- CurrentDate = currentDateTime.Date;
- CurrentTime = currentDateTime.TimeOfDay;
- MatchSystemTime = config.System.MatchSystemTime;
- EnableCustomVSyncInterval = config.Graphics.EnableCustomVSyncInterval;
- CustomVSyncInterval = config.Graphics.CustomVSyncInterval;
- VSyncMode = config.Graphics.VSyncMode;
- EnableFsIntegrityChecks = config.System.EnableFsIntegrityChecks;
- DramSize = config.System.DramSize;
- IgnoreMissingServices = config.System.IgnoreMissingServices;
- IgnoreApplet = config.System.IgnoreApplet;
- // CPU
- EnablePptc = config.System.EnablePtc;
- EnableLowPowerPptc = config.System.EnableLowPowerPtc;
- MemoryMode = (int)config.System.MemoryManagerMode.Value;
- UseHypervisor = config.System.UseHypervisor;
- // Graphics
- GraphicsBackendIndex = (int)config.Graphics.GraphicsBackend.Value;
- // Physical devices are queried asynchronously hence the preferred index config value is loaded in LoadAvailableGpus().
- EnableShaderCache = config.Graphics.EnableShaderCache;
- EnableTextureRecompression = config.Graphics.EnableTextureRecompression;
- EnableMacroHLE = config.Graphics.EnableMacroHLE;
- EnableColorSpacePassthrough = config.Graphics.EnableColorSpacePassthrough;
- ResolutionScale = config.Graphics.ResScale == -1 ? 4 : config.Graphics.ResScale - 1;
- CustomResolutionScale = config.Graphics.ResScaleCustom;
- MaxAnisotropy = config.Graphics.MaxAnisotropy == -1 ? 0 : (int)MathF.Log2(config.Graphics.MaxAnisotropy);
- AspectRatio = (int)config.Graphics.AspectRatio.Value;
- GraphicsBackendMultithreadingIndex = (int)config.Graphics.BackendThreading.Value;
- ShaderDumpPath = config.Graphics.ShadersDumpPath;
- AntiAliasingEffect = (int)config.Graphics.AntiAliasing.Value;
- ScalingFilter = (int)config.Graphics.ScalingFilter.Value;
- ScalingFilterLevel = config.Graphics.ScalingFilterLevel.Value;
- // Audio
- AudioBackend = (int)config.System.AudioBackend.Value;
- Volume = config.System.AudioVolume * 100;
- // Network
- EnableInternetAccess = config.System.EnableInternetAccess;
- // LAN interface index is loaded asynchronously in PopulateNetworkInterfaces()
- // Logging
- EnableFileLog = config.Logger.EnableFileLog;
- EnableStub = config.Logger.EnableStub;
- EnableInfo = config.Logger.EnableInfo;
- EnableWarn = config.Logger.EnableWarn;
- EnableError = config.Logger.EnableError;
- EnableTrace = config.Logger.EnableTrace;
- EnableGuest = config.Logger.EnableGuest;
- EnableDebug = config.Logger.EnableDebug;
- EnableFsAccessLog = config.Logger.EnableFsAccessLog;
- EnableAvaloniaLog = config.Logger.EnableAvaloniaLog;
- FsGlobalAccessLogMode = config.System.FsGlobalAccessLogMode;
- OpenglDebugLevel = (int)config.Logger.GraphicsDebugLevel.Value;
- MultiplayerModeIndex = (int)config.Multiplayer.Mode.Value;
- DisableP2P = config.Multiplayer.DisableP2p;
- LdnPassphrase = config.Multiplayer.LdnPassphrase;
- LdnServer = config.Multiplayer.LdnServer;
- }
- public void SaveSettings()
- {
- ConfigurationState config = ConfigurationState.Instance;
- // User Interface
- config.EnableDiscordIntegration.Value = EnableDiscordIntegration;
- config.CheckUpdatesOnStart.Value = CheckUpdatesOnStart;
- config.ShowConfirmExit.Value = ShowConfirmExit;
- config.RememberWindowState.Value = RememberWindowState;
- config.ShowTitleBar.Value = ShowTitleBar;
- config.HideCursor.Value = (HideCursorMode)HideCursor;
- config.UpdateCheckerType.Value = (UpdaterType)UpdateCheckerType;
- if (GameDirectoryChanged)
- {
- config.UI.GameDirs.Value = [..GameDirectories];
- }
- if (AutoloadDirectoryChanged)
- {
- config.UI.AutoloadDirs.Value = [..AutoloadDirectories];
- }
- config.UI.BaseStyle.Value = BaseStyleIndex switch
- {
- 0 => "Auto",
- 1 => "Light",
- 2 => "Dark",
- _ => "Auto"
- };
- // Input
- config.System.EnableDockedMode.Value = EnableDockedMode;
- config.Hid.EnableKeyboard.Value = EnableKeyboard;
- config.Hid.EnableMouse.Value = EnableMouse;
- config.Hid.DisableInputWhenOutOfFocus.Value = DisableInputWhenOutOfFocus;
- // Keyboard Hotkeys
- config.Hid.Hotkeys.Value = KeyboardHotkey.GetConfig();
- // System
- config.System.Region.Value = (Region)Region;
- config.System.Language.Value = (Language)Language;
- if (_validTzRegions.Contains(TimeZone))
- {
- config.System.TimeZone.Value = TimeZone;
- }
- config.System.MatchSystemTime.Value = MatchSystemTime;
- config.System.SystemTimeOffset.Value = Convert.ToInt64((CurrentDate.ToUnixTimeSeconds() + CurrentTime.TotalSeconds) - DateTimeOffset.Now.ToUnixTimeSeconds());
- config.System.EnableFsIntegrityChecks.Value = EnableFsIntegrityChecks;
- config.System.DramSize.Value = DramSize;
- config.System.IgnoreMissingServices.Value = IgnoreMissingServices;
- config.System.IgnoreApplet.Value = IgnoreApplet;
- // CPU
- config.System.EnablePtc.Value = EnablePptc;
- config.System.EnableLowPowerPtc.Value = EnableLowPowerPptc;
- config.System.MemoryManagerMode.Value = (MemoryManagerMode)MemoryMode;
- config.System.UseHypervisor.Value = UseHypervisor;
- // Graphics
- config.Graphics.VSyncMode.Value = VSyncMode;
- config.Graphics.EnableCustomVSyncInterval.Value = EnableCustomVSyncInterval;
- config.Graphics.CustomVSyncInterval.Value = CustomVSyncInterval;
- config.Graphics.GraphicsBackend.Value = (GraphicsBackend)GraphicsBackendIndex;
- config.Graphics.PreferredGpu.Value = _gpuIds.ElementAtOrDefault(PreferredGpuIndex);
- config.Graphics.EnableShaderCache.Value = EnableShaderCache;
- config.Graphics.EnableTextureRecompression.Value = EnableTextureRecompression;
- config.Graphics.EnableMacroHLE.Value = EnableMacroHLE;
- config.Graphics.EnableColorSpacePassthrough.Value = EnableColorSpacePassthrough;
- config.Graphics.ResScale.Value = ResolutionScale == 4 ? -1 : ResolutionScale + 1;
- config.Graphics.ResScaleCustom.Value = CustomResolutionScale;
- config.Graphics.MaxAnisotropy.Value = MaxAnisotropy == 0 ? -1 : MathF.Pow(2, MaxAnisotropy);
- config.Graphics.AspectRatio.Value = (AspectRatio)AspectRatio;
- config.Graphics.AntiAliasing.Value = (AntiAliasing)AntiAliasingEffect;
- config.Graphics.ScalingFilter.Value = (ScalingFilter)ScalingFilter;
- config.Graphics.ScalingFilterLevel.Value = ScalingFilterLevel;
- if (ConfigurationState.Instance.Graphics.BackendThreading != (BackendThreading)GraphicsBackendMultithreadingIndex)
- {
- DriverUtilities.ToggleOGLThreading(GraphicsBackendMultithreadingIndex == (int)BackendThreading.Off);
- }
- config.Graphics.BackendThreading.Value = (BackendThreading)GraphicsBackendMultithreadingIndex;
- config.Graphics.ShadersDumpPath.Value = ShaderDumpPath;
- // Audio
- AudioBackend audioBackend = (AudioBackend)AudioBackend;
- if (audioBackend != config.System.AudioBackend.Value)
- {
- config.System.AudioBackend.Value = audioBackend;
- Logger.Info?.Print(LogClass.Application, $"AudioBackend toggled to: {audioBackend}");
- }
- config.System.AudioVolume.Value = Volume / 100;
- // Network
- config.System.EnableInternetAccess.Value = EnableInternetAccess;
- // Logging
- config.Logger.EnableFileLog.Value = EnableFileLog;
- config.Logger.EnableStub.Value = EnableStub;
- config.Logger.EnableInfo.Value = EnableInfo;
- config.Logger.EnableWarn.Value = EnableWarn;
- config.Logger.EnableError.Value = EnableError;
- config.Logger.EnableTrace.Value = EnableTrace;
- config.Logger.EnableGuest.Value = EnableGuest;
- config.Logger.EnableDebug.Value = EnableDebug;
- config.Logger.EnableFsAccessLog.Value = EnableFsAccessLog;
- config.Logger.EnableAvaloniaLog.Value = EnableAvaloniaLog;
- config.System.FsGlobalAccessLogMode.Value = FsGlobalAccessLogMode;
- config.Logger.GraphicsDebugLevel.Value = (GraphicsDebugLevel)OpenglDebugLevel;
- config.Multiplayer.LanInterfaceId.Value = _networkInterfaces[NetworkInterfaceList[NetworkInterfaceIndex]];
- config.Multiplayer.Mode.Value = (MultiplayerMode)MultiplayerModeIndex;
- config.Multiplayer.DisableP2p.Value = DisableP2P;
- config.Multiplayer.LdnPassphrase.Value = LdnPassphrase;
- config.Multiplayer.LdnServer.Value = LdnServer;
-
- // Dirty Hacks
- config.Hacks.Xc2MenuSoftlockFix.Value = DirtyHacks.Xc2MenuSoftlockFix;
- config.Hacks.EnableShaderTranslationDelay.Value = DirtyHacks.ShaderTranslationDelayEnabled;
- config.Hacks.ShaderTranslationDelay.Value = DirtyHacks.ShaderTranslationDelay;
- config.ToFileFormat().SaveConfig(Program.ConfigurationPath);
- MainWindow.UpdateGraphicsConfig();
- RyujinxApp.MainWindow.ViewModel.VSyncModeSettingChanged();
- SaveSettingsEvent?.Invoke();
- GameDirectoryChanged = false;
- AutoloadDirectoryChanged = false;
- }
- private static void RevertIfNotSaved()
- {
- Program.ReloadConfig();
- }
- public void ApplyButton()
- {
- SaveSettings();
- }
- public void OkButton()
- {
- SaveSettings();
- CloseWindow?.Invoke();
- }
- [ObservableProperty] private bool _wantsToReset;
- public AsyncRelayCommand ResetButton => Commands.Create(async () =>
- {
- if (!WantsToReset) return;
-
- CloseWindow?.Invoke();
- ConfigurationState.Instance.LoadDefault();
- ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
- RyujinxApp.MainWindow.LoadApplications();
- await ContentDialogHelper.CreateInfoDialog(
- $"Your {RyujinxApp.FullAppName} configuration has been reset.",
- "",
- string.Empty,
- LocaleManager.Instance[LocaleKeys.SettingsButtonClose],
- "Configuration Reset");
- });
- public void CancelButton()
- {
- RevertIfNotSaved();
- CloseWindow?.Invoke();
- }
- }
- }
|