ConfigurationState.cs 15 KB

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