ConfigurationState.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. using Ryujinx.Ava.Utilities.Configuration.System;
  2. using Ryujinx.Ava.Utilities.Configuration.UI;
  3. using Ryujinx.Common.Configuration;
  4. using Ryujinx.Common.Configuration.Hid;
  5. using Ryujinx.Common.Configuration.Hid.Keyboard;
  6. using Ryujinx.Common.Configuration.Multiplayer;
  7. using Ryujinx.Graphics.Vulkan;
  8. using Ryujinx.HLE;
  9. using System;
  10. using System.Linq;
  11. namespace Ryujinx.Ava.Utilities.Configuration
  12. {
  13. public partial class ConfigurationState
  14. {
  15. public static void Initialize()
  16. {
  17. if (Instance != null)
  18. {
  19. throw new InvalidOperationException("Configuration is already initialized");
  20. }
  21. Instance = new ConfigurationState();
  22. }
  23. public ConfigurationFileFormat ToFileFormat()
  24. {
  25. ConfigurationFileFormat configurationFile = new()
  26. {
  27. Version = ConfigurationFileFormat.CurrentVersion,
  28. BackendThreading = Graphics.BackendThreading,
  29. EnableFileLog = Logger.EnableFileLog,
  30. ResScale = Graphics.ResScale,
  31. ResScaleCustom = Graphics.ResScaleCustom,
  32. MaxAnisotropy = Graphics.MaxAnisotropy,
  33. AspectRatio = Graphics.AspectRatio,
  34. AntiAliasing = Graphics.AntiAliasing,
  35. ScalingFilter = Graphics.ScalingFilter,
  36. ScalingFilterLevel = Graphics.ScalingFilterLevel,
  37. GraphicsShadersDumpPath = Graphics.ShadersDumpPath,
  38. LoggingEnableDebug = Logger.EnableDebug,
  39. LoggingEnableStub = Logger.EnableStub,
  40. LoggingEnableInfo = Logger.EnableInfo,
  41. LoggingEnableWarn = Logger.EnableWarn,
  42. LoggingEnableError = Logger.EnableError,
  43. LoggingEnableTrace = Logger.EnableTrace,
  44. LoggingEnableGuest = Logger.EnableGuest,
  45. LoggingEnableFsAccessLog = Logger.EnableFsAccessLog,
  46. LoggingEnableAvalonia = Logger.EnableAvaloniaLog,
  47. LoggingFilteredClasses = Logger.FilteredClasses,
  48. LoggingGraphicsDebugLevel = Logger.GraphicsDebugLevel,
  49. SystemLanguage = System.Language,
  50. SystemRegion = System.Region,
  51. SystemTimeZone = System.TimeZone,
  52. SystemTimeOffset = System.SystemTimeOffset,
  53. DockedMode = System.EnableDockedMode,
  54. EnableDiscordIntegration = EnableDiscordIntegration,
  55. CheckUpdatesOnStart = CheckUpdatesOnStart,
  56. UpdateCheckerType = UpdateCheckerType,
  57. FocusLostActionType = FocusLostActionType,
  58. ShowConfirmExit = ShowConfirmExit,
  59. RememberWindowState = RememberWindowState,
  60. ShowTitleBar = ShowTitleBar,
  61. EnableHardwareAcceleration = EnableHardwareAcceleration,
  62. HideCursor = HideCursor,
  63. VSyncMode = Graphics.VSyncMode,
  64. EnableCustomVSyncInterval = Graphics.EnableCustomVSyncInterval,
  65. CustomVSyncInterval = Graphics.CustomVSyncInterval,
  66. EnableShaderCache = Graphics.EnableShaderCache,
  67. EnableTextureRecompression = Graphics.EnableTextureRecompression,
  68. EnableMacroHLE = Graphics.EnableMacroHLE,
  69. EnableColorSpacePassthrough = Graphics.EnableColorSpacePassthrough,
  70. EnablePtc = System.EnablePtc,
  71. EnableLowPowerPtc = System.EnableLowPowerPtc,
  72. EnableInternetAccess = System.EnableInternetAccess,
  73. EnableFsIntegrityChecks = System.EnableFsIntegrityChecks,
  74. FsGlobalAccessLogMode = System.FsGlobalAccessLogMode,
  75. AudioBackend = System.AudioBackend,
  76. AudioVolume = System.AudioVolume,
  77. MemoryManagerMode = System.MemoryManagerMode,
  78. DramSize = System.DramSize,
  79. IgnoreMissingServices = System.IgnoreMissingServices,
  80. IgnoreApplet = System.IgnoreApplet,
  81. UseHypervisor = System.UseHypervisor,
  82. GuiColumns = new GuiColumns
  83. {
  84. FavColumn = UI.GuiColumns.FavColumn,
  85. IconColumn = UI.GuiColumns.IconColumn,
  86. AppColumn = UI.GuiColumns.AppColumn,
  87. DevColumn = UI.GuiColumns.DevColumn,
  88. VersionColumn = UI.GuiColumns.VersionColumn,
  89. LdnInfoColumn = UI.GuiColumns.LdnInfoColumn,
  90. TimePlayedColumn = UI.GuiColumns.TimePlayedColumn,
  91. LastPlayedColumn = UI.GuiColumns.LastPlayedColumn,
  92. FileExtColumn = UI.GuiColumns.FileExtColumn,
  93. FileSizeColumn = UI.GuiColumns.FileSizeColumn,
  94. PathColumn = UI.GuiColumns.PathColumn,
  95. },
  96. ColumnSort = new ColumnSort
  97. {
  98. SortColumnId = UI.ColumnSort.SortColumnId,
  99. SortAscending = UI.ColumnSort.SortAscending,
  100. },
  101. GameDirs = UI.GameDirs,
  102. AutoloadDirs = UI.AutoloadDirs,
  103. ShownFileTypes = new ShownFileTypes
  104. {
  105. NSP = UI.ShownFileTypes.NSP,
  106. PFS0 = UI.ShownFileTypes.PFS0,
  107. XCI = UI.ShownFileTypes.XCI,
  108. NCA = UI.ShownFileTypes.NCA,
  109. NRO = UI.ShownFileTypes.NRO,
  110. NSO = UI.ShownFileTypes.NSO,
  111. },
  112. WindowStartup = new WindowStartup
  113. {
  114. WindowSizeWidth = UI.WindowStartup.WindowSizeWidth,
  115. WindowSizeHeight = UI.WindowStartup.WindowSizeHeight,
  116. WindowPositionX = UI.WindowStartup.WindowPositionX,
  117. WindowPositionY = UI.WindowStartup.WindowPositionY,
  118. WindowMaximized = UI.WindowStartup.WindowMaximized,
  119. },
  120. LanguageCode = UI.LanguageCode,
  121. BaseStyle = UI.BaseStyle,
  122. GameListViewMode = UI.GameListViewMode,
  123. ShowNames = UI.ShowNames,
  124. GridSize = UI.GridSize,
  125. ApplicationSort = UI.ApplicationSort,
  126. IsAscendingOrder = UI.IsAscendingOrder,
  127. StartFullscreen = UI.StartFullscreen,
  128. StartNoUI = UI.StartNoUI,
  129. ShowConsole = UI.ShowConsole,
  130. EnableKeyboard = Hid.EnableKeyboard,
  131. EnableMouse = Hid.EnableMouse,
  132. DisableInputWhenOutOfFocus = Hid.DisableInputWhenOutOfFocus,
  133. Hotkeys = Hid.Hotkeys,
  134. InputConfig = Hid.InputConfig,
  135. RainbowSpeed = Hid.RainbowSpeed,
  136. GraphicsBackend = Graphics.GraphicsBackend,
  137. PreferredGpu = Graphics.PreferredGpu,
  138. MultiplayerLanInterfaceId = Multiplayer.LanInterfaceId,
  139. MultiplayerMode = Multiplayer.Mode,
  140. MultiplayerDisableP2p = Multiplayer.DisableP2p,
  141. MultiplayerLdnPassphrase = Multiplayer.LdnPassphrase,
  142. LdnServer = Multiplayer.LdnServer,
  143. ShowDirtyHacks = Hacks.ShowDirtyHacks,
  144. DirtyHacks = Hacks.EnabledHacks.Select(it => it.Pack()).ToArray(),
  145. };
  146. return configurationFile;
  147. }
  148. public void LoadDefault()
  149. {
  150. Logger.EnableFileLog.Value = true;
  151. Graphics.BackendThreading.Value = BackendThreading.Auto;
  152. Graphics.ResScale.Value = 1;
  153. Graphics.ResScaleCustom.Value = 1.0f;
  154. Graphics.MaxAnisotropy.Value = -1.0f;
  155. Graphics.AspectRatio.Value = AspectRatio.Fixed16x9;
  156. Graphics.GraphicsBackend.Value = DefaultGraphicsBackend();
  157. Graphics.PreferredGpu.Value = string.Empty;
  158. Graphics.ShadersDumpPath.Value = string.Empty;
  159. Logger.EnableDebug.Value = false;
  160. Logger.EnableStub.Value = true;
  161. Logger.EnableInfo.Value = true;
  162. Logger.EnableWarn.Value = true;
  163. Logger.EnableError.Value = true;
  164. Logger.EnableTrace.Value = false;
  165. Logger.EnableGuest.Value = true;
  166. Logger.EnableFsAccessLog.Value = false;
  167. Logger.EnableAvaloniaLog.Value = false;
  168. Logger.FilteredClasses.Value = [];
  169. Logger.GraphicsDebugLevel.Value = GraphicsDebugLevel.None;
  170. System.Language.Value = Language.AmericanEnglish;
  171. System.Region.Value = Region.USA;
  172. System.TimeZone.Value = "UTC";
  173. System.SystemTimeOffset.Value = 0;
  174. System.EnableDockedMode.Value = true;
  175. EnableDiscordIntegration.Value = true;
  176. UpdateCheckerType.Value = UpdaterType.PromptAtStartup;
  177. FocusLostActionType.Value = FocusLostType.DoNothing;
  178. ShowConfirmExit.Value = true;
  179. RememberWindowState.Value = true;
  180. ShowTitleBar.Value = !OperatingSystem.IsWindows();
  181. EnableHardwareAcceleration.Value = true;
  182. HideCursor.Value = HideCursorMode.OnIdle;
  183. Graphics.VSyncMode.Value = VSyncMode.Switch;
  184. Graphics.CustomVSyncInterval.Value = 120;
  185. Graphics.EnableCustomVSyncInterval.Value = false;
  186. Graphics.EnableShaderCache.Value = true;
  187. Graphics.EnableTextureRecompression.Value = false;
  188. Graphics.EnableMacroHLE.Value = true;
  189. Graphics.EnableColorSpacePassthrough.Value = false;
  190. Graphics.AntiAliasing.Value = AntiAliasing.None;
  191. Graphics.ScalingFilter.Value = ScalingFilter.Bilinear;
  192. Graphics.ScalingFilterLevel.Value = 80;
  193. System.EnablePtc.Value = true;
  194. System.EnableInternetAccess.Value = false;
  195. System.EnableFsIntegrityChecks.Value = true;
  196. System.FsGlobalAccessLogMode.Value = 0;
  197. System.AudioBackend.Value = AudioBackend.SDL2;
  198. System.AudioVolume.Value = 1;
  199. System.MemoryManagerMode.Value = MemoryManagerMode.HostMappedUnsafe;
  200. System.DramSize.Value = MemoryConfiguration.MemoryConfiguration4GiB;
  201. System.IgnoreMissingServices.Value = false;
  202. System.IgnoreApplet.Value = false;
  203. System.UseHypervisor.Value = true;
  204. Multiplayer.LanInterfaceId.Value = "0";
  205. Multiplayer.Mode.Value = MultiplayerMode.Disabled;
  206. Multiplayer.DisableP2p.Value = false;
  207. Multiplayer.LdnPassphrase.Value = string.Empty;
  208. Multiplayer.LdnServer.Value = string.Empty;
  209. UI.GuiColumns.FavColumn.Value = true;
  210. UI.GuiColumns.IconColumn.Value = true;
  211. UI.GuiColumns.AppColumn.Value = true;
  212. UI.GuiColumns.DevColumn.Value = true;
  213. UI.GuiColumns.VersionColumn.Value = true;
  214. UI.GuiColumns.TimePlayedColumn.Value = true;
  215. UI.GuiColumns.LastPlayedColumn.Value = true;
  216. UI.GuiColumns.FileExtColumn.Value = true;
  217. UI.GuiColumns.FileSizeColumn.Value = true;
  218. UI.GuiColumns.PathColumn.Value = true;
  219. UI.ColumnSort.SortColumnId.Value = 0;
  220. UI.ColumnSort.SortAscending.Value = false;
  221. UI.GameDirs.Value = [];
  222. UI.AutoloadDirs.Value = [];
  223. UI.ShownFileTypes.NSP.Value = true;
  224. UI.ShownFileTypes.PFS0.Value = true;
  225. UI.ShownFileTypes.XCI.Value = true;
  226. UI.ShownFileTypes.NCA.Value = true;
  227. UI.ShownFileTypes.NRO.Value = true;
  228. UI.ShownFileTypes.NSO.Value = true;
  229. UI.LanguageCode.Value = "en_US";
  230. UI.BaseStyle.Value = "Dark";
  231. UI.GameListViewMode.Value = 0;
  232. UI.ShowNames.Value = true;
  233. UI.GridSize.Value = 2;
  234. UI.ApplicationSort.Value = 0;
  235. UI.IsAscendingOrder.Value = true;
  236. UI.StartFullscreen.Value = false;
  237. UI.StartNoUI.Value = false;
  238. UI.ShowConsole.Value = true;
  239. UI.WindowStartup.WindowSizeWidth.Value = 1280;
  240. UI.WindowStartup.WindowSizeHeight.Value = 760;
  241. UI.WindowStartup.WindowPositionX.Value = 0;
  242. UI.WindowStartup.WindowPositionY.Value = 0;
  243. UI.WindowStartup.WindowMaximized.Value = false;
  244. Hid.EnableKeyboard.Value = false;
  245. Hid.EnableMouse.Value = false;
  246. Hid.DisableInputWhenOutOfFocus.Value = false;
  247. Hid.Hotkeys.Value = new KeyboardHotkeys
  248. {
  249. ToggleVSyncMode = Key.F1,
  250. ToggleMute = Key.F2,
  251. Screenshot = Key.F8,
  252. ShowUI = Key.F4,
  253. Pause = Key.F5,
  254. ResScaleUp = Key.Unbound,
  255. ResScaleDown = Key.Unbound,
  256. VolumeUp = Key.Unbound,
  257. VolumeDown = Key.Unbound,
  258. };
  259. Hid.RainbowSpeed.Value = 1f;
  260. Hid.InputConfig.Value =
  261. [
  262. new StandardKeyboardInputConfig
  263. {
  264. Version = InputConfig.CurrentVersion,
  265. Backend = InputBackendType.WindowKeyboard,
  266. Id = "0",
  267. PlayerIndex = PlayerIndex.Player1,
  268. ControllerType = ControllerType.ProController,
  269. LeftJoycon = new LeftJoyconCommonConfig<Key>
  270. {
  271. DpadUp = Key.Up,
  272. DpadDown = Key.Down,
  273. DpadLeft = Key.Left,
  274. DpadRight = Key.Right,
  275. ButtonMinus = Key.Minus,
  276. ButtonL = Key.E,
  277. ButtonZl = Key.Q,
  278. ButtonSl = Key.Unbound,
  279. ButtonSr = Key.Unbound,
  280. },
  281. LeftJoyconStick = new JoyconConfigKeyboardStick<Key>
  282. {
  283. StickUp = Key.W,
  284. StickDown = Key.S,
  285. StickLeft = Key.A,
  286. StickRight = Key.D,
  287. StickButton = Key.F,
  288. },
  289. RightJoycon = new RightJoyconCommonConfig<Key>
  290. {
  291. ButtonA = Key.Z,
  292. ButtonB = Key.X,
  293. ButtonX = Key.C,
  294. ButtonY = Key.V,
  295. ButtonPlus = Key.Plus,
  296. ButtonR = Key.U,
  297. ButtonZr = Key.O,
  298. ButtonSl = Key.Unbound,
  299. ButtonSr = Key.Unbound,
  300. },
  301. RightJoyconStick = new JoyconConfigKeyboardStick<Key>
  302. {
  303. StickUp = Key.I,
  304. StickDown = Key.K,
  305. StickLeft = Key.J,
  306. StickRight = Key.L,
  307. StickButton = Key.H,
  308. },
  309. }
  310. ];
  311. }
  312. private static GraphicsBackend DefaultGraphicsBackend()
  313. {
  314. // Any system running macOS should default to auto, so it uses Vulkan everywhere and Metal in games where it works well.
  315. if (OperatingSystem.IsMacOS())
  316. return GraphicsBackend.Auto;
  317. // Any system returning any amount of valid Vulkan devices should default to Vulkan.
  318. // Checks for if the Vulkan version and featureset is compatible should be performed within VulkanRenderer.
  319. return VulkanRenderer.GetPhysicalDevices().Length > 0
  320. ? GraphicsBackend.Vulkan
  321. : GraphicsBackend.OpenGl;
  322. }
  323. }
  324. }