ConfigurationState.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. using Ryujinx.Common;
  2. using Ryujinx.Common.Configuration;
  3. using Ryujinx.Common.Configuration.Hid;
  4. using Ryujinx.Common.Configuration.Hid.Controller;
  5. using Ryujinx.Common.Configuration.Hid.Keyboard;
  6. using Ryujinx.Common.Logging;
  7. using Ryujinx.Configuration.System;
  8. using Ryujinx.Configuration.Ui;
  9. using System;
  10. using System.Collections.Generic;
  11. namespace Ryujinx.Configuration
  12. {
  13. public class ConfigurationState
  14. {
  15. /// <summary>
  16. /// UI configuration section
  17. /// </summary>
  18. public class UiSection
  19. {
  20. public class Columns
  21. {
  22. public ReactiveObject<bool> FavColumn { get; private set; }
  23. public ReactiveObject<bool> IconColumn { get; private set; }
  24. public ReactiveObject<bool> AppColumn { get; private set; }
  25. public ReactiveObject<bool> DevColumn { get; private set; }
  26. public ReactiveObject<bool> VersionColumn { get; private set; }
  27. public ReactiveObject<bool> TimePlayedColumn { get; private set; }
  28. public ReactiveObject<bool> LastPlayedColumn { get; private set; }
  29. public ReactiveObject<bool> FileExtColumn { get; private set; }
  30. public ReactiveObject<bool> FileSizeColumn { get; private set; }
  31. public ReactiveObject<bool> PathColumn { get; private set; }
  32. public Columns()
  33. {
  34. FavColumn = new ReactiveObject<bool>();
  35. IconColumn = new ReactiveObject<bool>();
  36. AppColumn = new ReactiveObject<bool>();
  37. DevColumn = new ReactiveObject<bool>();
  38. VersionColumn = new ReactiveObject<bool>();
  39. TimePlayedColumn = new ReactiveObject<bool>();
  40. LastPlayedColumn = new ReactiveObject<bool>();
  41. FileExtColumn = new ReactiveObject<bool>();
  42. FileSizeColumn = new ReactiveObject<bool>();
  43. PathColumn = new ReactiveObject<bool>();
  44. }
  45. }
  46. public class ColumnSortSettings
  47. {
  48. public ReactiveObject<int> SortColumnId { get; private set; }
  49. public ReactiveObject<bool> SortAscending { get; private set; }
  50. public ColumnSortSettings()
  51. {
  52. SortColumnId = new ReactiveObject<int>();
  53. SortAscending = new ReactiveObject<bool>();
  54. }
  55. }
  56. /// <summary>
  57. /// Used to toggle columns in the GUI
  58. /// </summary>
  59. public Columns GuiColumns { get; private set; }
  60. /// <summary>
  61. /// Used to configure column sort settings in the GUI
  62. /// </summary>
  63. public ColumnSortSettings ColumnSort { get; private set; }
  64. /// <summary>
  65. /// A list of directories containing games to be used to load games into the games list
  66. /// </summary>
  67. public ReactiveObject<List<string>> GameDirs { get; private set; }
  68. /// <summary>
  69. /// Enable or disable custom themes in the GUI
  70. /// </summary>
  71. public ReactiveObject<bool> EnableCustomTheme { get; private set; }
  72. /// <summary>
  73. /// Path to custom GUI theme
  74. /// </summary>
  75. public ReactiveObject<string> CustomThemePath { get; private set; }
  76. /// <summary>
  77. /// Start games in fullscreen mode
  78. /// </summary>
  79. public ReactiveObject<bool> StartFullscreen { get; private set; }
  80. public UiSection()
  81. {
  82. GuiColumns = new Columns();
  83. ColumnSort = new ColumnSortSettings();
  84. GameDirs = new ReactiveObject<List<string>>();
  85. EnableCustomTheme = new ReactiveObject<bool>();
  86. CustomThemePath = new ReactiveObject<string>();
  87. StartFullscreen = new ReactiveObject<bool>();
  88. }
  89. }
  90. /// <summary>
  91. /// Logger configuration section
  92. /// </summary>
  93. public class LoggerSection
  94. {
  95. /// <summary>
  96. /// Enables printing debug log messages
  97. /// </summary>
  98. public ReactiveObject<bool> EnableDebug { get; private set; }
  99. /// <summary>
  100. /// Enables printing stub log messages
  101. /// </summary>
  102. public ReactiveObject<bool> EnableStub { get; private set; }
  103. /// <summary>
  104. /// Enables printing info log messages
  105. /// </summary>
  106. public ReactiveObject<bool> EnableInfo { get; private set; }
  107. /// <summary>
  108. /// Enables printing warning log messages
  109. /// </summary>
  110. public ReactiveObject<bool> EnableWarn { get; private set; }
  111. /// <summary>
  112. /// Enables printing error log messages
  113. /// </summary>
  114. public ReactiveObject<bool> EnableError { get; private set; }
  115. /// <summary>
  116. /// Enables printing guest log messages
  117. /// </summary>
  118. public ReactiveObject<bool> EnableGuest { get; private set; }
  119. /// <summary>
  120. /// Enables printing FS access log messages
  121. /// </summary>
  122. public ReactiveObject<bool> EnableFsAccessLog { get; private set; }
  123. /// <summary>
  124. /// Controls which log messages are written to the log targets
  125. /// </summary>
  126. public ReactiveObject<LogClass[]> FilteredClasses { get; private set; }
  127. /// <summary>
  128. /// Enables or disables logging to a file on disk
  129. /// </summary>
  130. public ReactiveObject<bool> EnableFileLog { get; private set; }
  131. /// <summary>
  132. /// Controls which OpenGL log messages are recorded in the log
  133. /// </summary>
  134. public ReactiveObject<GraphicsDebugLevel> GraphicsDebugLevel { get; private set; }
  135. public LoggerSection()
  136. {
  137. EnableDebug = new ReactiveObject<bool>();
  138. EnableStub = new ReactiveObject<bool>();
  139. EnableInfo = new ReactiveObject<bool>();
  140. EnableWarn = new ReactiveObject<bool>();
  141. EnableError = new ReactiveObject<bool>();
  142. EnableGuest = new ReactiveObject<bool>();
  143. EnableFsAccessLog = new ReactiveObject<bool>();
  144. FilteredClasses = new ReactiveObject<LogClass[]>();
  145. EnableFileLog = new ReactiveObject<bool>();
  146. EnableFileLog.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableFileLog));
  147. GraphicsDebugLevel = new ReactiveObject<GraphicsDebugLevel>();
  148. }
  149. }
  150. /// <summary>
  151. /// System configuration section
  152. /// </summary>
  153. public class SystemSection
  154. {
  155. /// <summary>
  156. /// Change System Language
  157. /// </summary>
  158. public ReactiveObject<Language> Language { get; private set; }
  159. /// <summary>
  160. /// Change System Region
  161. /// </summary>
  162. public ReactiveObject<Region> Region { get; private set; }
  163. /// <summary>
  164. /// Change System TimeZone
  165. /// </summary>
  166. public ReactiveObject<string> TimeZone { get; private set; }
  167. /// <summary>
  168. /// System Time Offset in Seconds
  169. /// </summary>
  170. public ReactiveObject<long> SystemTimeOffset { get; private set; }
  171. /// <summary>
  172. /// Enables or disables Docked Mode
  173. /// </summary>
  174. public ReactiveObject<bool> EnableDockedMode { get; private set; }
  175. /// <summary>
  176. /// Enables or disables profiled translation cache persistency
  177. /// </summary>
  178. public ReactiveObject<bool> EnablePtc { get; private set; }
  179. /// <summary>
  180. /// Enables integrity checks on Game content files
  181. /// </summary>
  182. public ReactiveObject<bool> EnableFsIntegrityChecks { get; private set; }
  183. /// <summary>
  184. /// Enables FS access log output to the console. Possible modes are 0-3
  185. /// </summary>
  186. public ReactiveObject<int> FsGlobalAccessLogMode { get; private set; }
  187. /// <summary>
  188. /// The selected audio backend
  189. /// </summary>
  190. public ReactiveObject<AudioBackend> AudioBackend { get; private set; }
  191. /// <summary>
  192. /// The audio backend volume
  193. /// </summary>
  194. public ReactiveObject<float> AudioVolume { get; private set; }
  195. /// <summary>
  196. /// The selected memory manager mode
  197. /// </summary>
  198. public ReactiveObject<MemoryManagerMode> MemoryManagerMode { get; private set; }
  199. /// <summary>
  200. /// Defines the amount of RAM available on the emulated system, and how it is distributed
  201. /// </summary>
  202. public ReactiveObject<bool> ExpandRam { get; private set; }
  203. /// <summary>
  204. /// Enable or disable ignoring missing services
  205. /// </summary>
  206. public ReactiveObject<bool> IgnoreMissingServices { get; private set; }
  207. public SystemSection()
  208. {
  209. Language = new ReactiveObject<Language>();
  210. Region = new ReactiveObject<Region>();
  211. TimeZone = new ReactiveObject<string>();
  212. SystemTimeOffset = new ReactiveObject<long>();
  213. EnableDockedMode = new ReactiveObject<bool>();
  214. EnableDockedMode.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableDockedMode));
  215. EnablePtc = new ReactiveObject<bool>();
  216. EnablePtc.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnablePtc));
  217. EnableFsIntegrityChecks = new ReactiveObject<bool>();
  218. EnableFsIntegrityChecks.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableFsIntegrityChecks));
  219. FsGlobalAccessLogMode = new ReactiveObject<int>();
  220. FsGlobalAccessLogMode.Event += static (sender, e) => LogValueChange(sender, e, nameof(FsGlobalAccessLogMode));
  221. AudioBackend = new ReactiveObject<AudioBackend>();
  222. AudioBackend.Event += static (sender, e) => LogValueChange(sender, e, nameof(AudioBackend));
  223. MemoryManagerMode = new ReactiveObject<MemoryManagerMode>();
  224. MemoryManagerMode.Event += static (sender, e) => LogValueChange(sender, e, nameof(MemoryManagerMode));
  225. ExpandRam = new ReactiveObject<bool>();
  226. ExpandRam.Event += static (sender, e) => LogValueChange(sender, e, nameof(ExpandRam));
  227. IgnoreMissingServices = new ReactiveObject<bool>();
  228. IgnoreMissingServices.Event += static (sender, e) => LogValueChange(sender, e, nameof(IgnoreMissingServices));
  229. AudioVolume = new ReactiveObject<float>();
  230. AudioVolume.Event += static (sender, e) => LogValueChange(sender, e, nameof(AudioVolume));
  231. }
  232. }
  233. /// <summary>
  234. /// Hid configuration section
  235. /// </summary>
  236. public class HidSection
  237. {
  238. /// <summary>
  239. /// Enable or disable keyboard support (Independent from controllers binding)
  240. /// </summary>
  241. public ReactiveObject<bool> EnableKeyboard { get; private set; }
  242. /// <summary>
  243. /// Enable or disable mouse support (Independent from controllers binding)
  244. /// </summary>
  245. public ReactiveObject<bool> EnableMouse { get; private set; }
  246. /// <summary>
  247. /// Hotkey Keyboard Bindings
  248. /// </summary>
  249. public ReactiveObject<KeyboardHotkeys> Hotkeys { get; private set; }
  250. /// <summary>
  251. /// Input device configuration.
  252. /// NOTE: This ReactiveObject won't issue an event when the List has elements added or removed.
  253. /// TODO: Implement a ReactiveList class.
  254. /// </summary>
  255. public ReactiveObject<List<InputConfig>> InputConfig { get; private set; }
  256. public HidSection()
  257. {
  258. EnableKeyboard = new ReactiveObject<bool>();
  259. EnableMouse = new ReactiveObject<bool>();
  260. Hotkeys = new ReactiveObject<KeyboardHotkeys>();
  261. InputConfig = new ReactiveObject<List<InputConfig>>();
  262. }
  263. }
  264. /// <summary>
  265. /// Graphics configuration section
  266. /// </summary>
  267. public class GraphicsSection
  268. {
  269. /// <summary>
  270. /// Whether or not backend threading is enabled. The "Auto" setting will determine whether threading should be enabled at runtime.
  271. /// </summary>
  272. public ReactiveObject<BackendThreading> BackendThreading { get; private set; }
  273. /// <summary>
  274. /// Max Anisotropy. Values range from 0 - 16. Set to -1 to let the game decide.
  275. /// </summary>
  276. public ReactiveObject<float> MaxAnisotropy { get; private set; }
  277. /// <summary>
  278. /// Aspect Ratio applied to the renderer window.
  279. /// </summary>
  280. public ReactiveObject<AspectRatio> AspectRatio { get; private set; }
  281. /// <summary>
  282. /// Resolution Scale. An integer scale applied to applicable render targets. Values 1-4, or -1 to use a custom floating point scale instead.
  283. /// </summary>
  284. public ReactiveObject<int> ResScale { get; private set; }
  285. /// <summary>
  286. /// Custom Resolution Scale. A custom floating point scale applied to applicable render targets. Only active when Resolution Scale is -1.
  287. /// </summary>
  288. public ReactiveObject<float> ResScaleCustom { get; private set; }
  289. /// <summary>
  290. /// Dumps shaders in this local directory
  291. /// </summary>
  292. public ReactiveObject<string> ShadersDumpPath { get; private set; }
  293. /// <summary>
  294. /// Enables or disables Vertical Sync
  295. /// </summary>
  296. public ReactiveObject<bool> EnableVsync { get; private set; }
  297. /// <summary>
  298. /// Enables or disables Shader cache
  299. /// </summary>
  300. public ReactiveObject<bool> EnableShaderCache { get; private set; }
  301. public GraphicsSection()
  302. {
  303. BackendThreading = new ReactiveObject<BackendThreading>();
  304. BackendThreading.Event += static (sender, e) => LogValueChange(sender, e, nameof(BackendThreading));
  305. ResScale = new ReactiveObject<int>();
  306. ResScale.Event += static (sender, e) => LogValueChange(sender, e, nameof(ResScale));
  307. ResScaleCustom = new ReactiveObject<float>();
  308. ResScaleCustom.Event += static (sender, e) => LogValueChange(sender, e, nameof(ResScaleCustom));
  309. MaxAnisotropy = new ReactiveObject<float>();
  310. MaxAnisotropy.Event += static (sender, e) => LogValueChange(sender, e, nameof(MaxAnisotropy));
  311. AspectRatio = new ReactiveObject<AspectRatio>();
  312. AspectRatio.Event += static (sender, e) => LogValueChange(sender, e, nameof(AspectRatio));
  313. ShadersDumpPath = new ReactiveObject<string>();
  314. EnableVsync = new ReactiveObject<bool>();
  315. EnableVsync.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableVsync));
  316. EnableShaderCache = new ReactiveObject<bool>();
  317. EnableShaderCache.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableShaderCache));
  318. }
  319. }
  320. /// <summary>
  321. /// The default configuration instance
  322. /// </summary>
  323. public static ConfigurationState Instance { get; private set; }
  324. /// <summary>
  325. /// The Ui section
  326. /// </summary>
  327. public UiSection Ui { get; private set; }
  328. /// <summary>
  329. /// The Logger section
  330. /// </summary>
  331. public LoggerSection Logger { get; private set; }
  332. /// <summary>
  333. /// The System section
  334. /// </summary>
  335. public SystemSection System { get; private set; }
  336. /// <summary>
  337. /// The Graphics section
  338. /// </summary>
  339. public GraphicsSection Graphics { get; private set; }
  340. /// <summary>
  341. /// The Hid section
  342. /// </summary>
  343. public HidSection Hid { get; private set; }
  344. /// <summary>
  345. /// Enables or disables Discord Rich Presence
  346. /// </summary>
  347. public ReactiveObject<bool> EnableDiscordIntegration { get; private set; }
  348. /// <summary>
  349. /// Checks for updates when Ryujinx starts when enabled
  350. /// </summary>
  351. public ReactiveObject<bool> CheckUpdatesOnStart { get; private set; }
  352. /// <summary>
  353. /// Show "Confirm Exit" Dialog
  354. /// </summary>
  355. public ReactiveObject<bool> ShowConfirmExit { get; private set; }
  356. /// <summary>
  357. /// Hide Cursor on Idle
  358. /// </summary>
  359. public ReactiveObject<bool> HideCursorOnIdle { get; private set; }
  360. private ConfigurationState()
  361. {
  362. Ui = new UiSection();
  363. Logger = new LoggerSection();
  364. System = new SystemSection();
  365. Graphics = new GraphicsSection();
  366. Hid = new HidSection();
  367. EnableDiscordIntegration = new ReactiveObject<bool>();
  368. CheckUpdatesOnStart = new ReactiveObject<bool>();
  369. ShowConfirmExit = new ReactiveObject<bool>();
  370. HideCursorOnIdle = new ReactiveObject<bool>();
  371. }
  372. public ConfigurationFileFormat ToFileFormat()
  373. {
  374. ConfigurationFileFormat configurationFile = new ConfigurationFileFormat
  375. {
  376. Version = ConfigurationFileFormat.CurrentVersion,
  377. EnableFileLog = Logger.EnableFileLog,
  378. BackendThreading = Graphics.BackendThreading,
  379. ResScale = Graphics.ResScale,
  380. ResScaleCustom = Graphics.ResScaleCustom,
  381. MaxAnisotropy = Graphics.MaxAnisotropy,
  382. AspectRatio = Graphics.AspectRatio,
  383. GraphicsShadersDumpPath = Graphics.ShadersDumpPath,
  384. LoggingEnableDebug = Logger.EnableDebug,
  385. LoggingEnableStub = Logger.EnableStub,
  386. LoggingEnableInfo = Logger.EnableInfo,
  387. LoggingEnableWarn = Logger.EnableWarn,
  388. LoggingEnableError = Logger.EnableError,
  389. LoggingEnableGuest = Logger.EnableGuest,
  390. LoggingEnableFsAccessLog = Logger.EnableFsAccessLog,
  391. LoggingFilteredClasses = Logger.FilteredClasses,
  392. LoggingGraphicsDebugLevel = Logger.GraphicsDebugLevel,
  393. SystemLanguage = System.Language,
  394. SystemRegion = System.Region,
  395. SystemTimeZone = System.TimeZone,
  396. SystemTimeOffset = System.SystemTimeOffset,
  397. DockedMode = System.EnableDockedMode,
  398. EnableDiscordIntegration = EnableDiscordIntegration,
  399. CheckUpdatesOnStart = CheckUpdatesOnStart,
  400. ShowConfirmExit = ShowConfirmExit,
  401. HideCursorOnIdle = HideCursorOnIdle,
  402. EnableVsync = Graphics.EnableVsync,
  403. EnableShaderCache = Graphics.EnableShaderCache,
  404. EnablePtc = System.EnablePtc,
  405. EnableFsIntegrityChecks = System.EnableFsIntegrityChecks,
  406. FsGlobalAccessLogMode = System.FsGlobalAccessLogMode,
  407. AudioBackend = System.AudioBackend,
  408. AudioVolume = System.AudioVolume,
  409. MemoryManagerMode = System.MemoryManagerMode,
  410. ExpandRam = System.ExpandRam,
  411. IgnoreMissingServices = System.IgnoreMissingServices,
  412. GuiColumns = new GuiColumns
  413. {
  414. FavColumn = Ui.GuiColumns.FavColumn,
  415. IconColumn = Ui.GuiColumns.IconColumn,
  416. AppColumn = Ui.GuiColumns.AppColumn,
  417. DevColumn = Ui.GuiColumns.DevColumn,
  418. VersionColumn = Ui.GuiColumns.VersionColumn,
  419. TimePlayedColumn = Ui.GuiColumns.TimePlayedColumn,
  420. LastPlayedColumn = Ui.GuiColumns.LastPlayedColumn,
  421. FileExtColumn = Ui.GuiColumns.FileExtColumn,
  422. FileSizeColumn = Ui.GuiColumns.FileSizeColumn,
  423. PathColumn = Ui.GuiColumns.PathColumn,
  424. },
  425. ColumnSort = new ColumnSort
  426. {
  427. SortColumnId = Ui.ColumnSort.SortColumnId,
  428. SortAscending = Ui.ColumnSort.SortAscending
  429. },
  430. GameDirs = Ui.GameDirs,
  431. EnableCustomTheme = Ui.EnableCustomTheme,
  432. CustomThemePath = Ui.CustomThemePath,
  433. StartFullscreen = Ui.StartFullscreen,
  434. EnableKeyboard = Hid.EnableKeyboard,
  435. EnableMouse = Hid.EnableMouse,
  436. Hotkeys = Hid.Hotkeys,
  437. KeyboardConfig = new List<object>(),
  438. ControllerConfig = new List<object>(),
  439. InputConfig = Hid.InputConfig,
  440. };
  441. return configurationFile;
  442. }
  443. public void LoadDefault()
  444. {
  445. Logger.EnableFileLog.Value = true;
  446. Graphics.BackendThreading.Value = BackendThreading.Auto;
  447. Graphics.ResScale.Value = 1;
  448. Graphics.ResScaleCustom.Value = 1.0f;
  449. Graphics.MaxAnisotropy.Value = -1.0f;
  450. Graphics.AspectRatio.Value = AspectRatio.Fixed16x9;
  451. Graphics.ShadersDumpPath.Value = "";
  452. Logger.EnableDebug.Value = false;
  453. Logger.EnableStub.Value = true;
  454. Logger.EnableInfo.Value = true;
  455. Logger.EnableWarn.Value = true;
  456. Logger.EnableError.Value = true;
  457. Logger.EnableGuest.Value = true;
  458. Logger.EnableFsAccessLog.Value = false;
  459. Logger.FilteredClasses.Value = Array.Empty<LogClass>();
  460. Logger.GraphicsDebugLevel.Value = GraphicsDebugLevel.None;
  461. System.Language.Value = Language.AmericanEnglish;
  462. System.Region.Value = Region.USA;
  463. System.TimeZone.Value = "UTC";
  464. System.SystemTimeOffset.Value = 0;
  465. System.EnableDockedMode.Value = true;
  466. EnableDiscordIntegration.Value = true;
  467. CheckUpdatesOnStart.Value = true;
  468. ShowConfirmExit.Value = true;
  469. HideCursorOnIdle.Value = false;
  470. Graphics.EnableVsync.Value = true;
  471. Graphics.EnableShaderCache.Value = true;
  472. System.EnablePtc.Value = true;
  473. System.EnableFsIntegrityChecks.Value = true;
  474. System.FsGlobalAccessLogMode.Value = 0;
  475. System.AudioBackend.Value = AudioBackend.SDL2;
  476. System.MemoryManagerMode.Value = MemoryManagerMode.HostMappedUnsafe;
  477. System.ExpandRam.Value = false;
  478. System.IgnoreMissingServices.Value = false;
  479. Ui.GuiColumns.FavColumn.Value = true;
  480. Ui.GuiColumns.IconColumn.Value = true;
  481. Ui.GuiColumns.AppColumn.Value = true;
  482. Ui.GuiColumns.DevColumn.Value = true;
  483. Ui.GuiColumns.VersionColumn.Value = true;
  484. Ui.GuiColumns.TimePlayedColumn.Value = true;
  485. Ui.GuiColumns.LastPlayedColumn.Value = true;
  486. Ui.GuiColumns.FileExtColumn.Value = true;
  487. Ui.GuiColumns.FileSizeColumn.Value = true;
  488. Ui.GuiColumns.PathColumn.Value = true;
  489. Ui.ColumnSort.SortColumnId.Value = 0;
  490. Ui.ColumnSort.SortAscending.Value = false;
  491. Ui.GameDirs.Value = new List<string>();
  492. Ui.EnableCustomTheme.Value = false;
  493. Ui.CustomThemePath.Value = "";
  494. Ui.StartFullscreen.Value = false;
  495. Hid.EnableKeyboard.Value = false;
  496. Hid.EnableMouse.Value = false;
  497. Hid.Hotkeys.Value = new KeyboardHotkeys
  498. {
  499. ToggleVsync = Key.Tab,
  500. ToggleMute = Key.F2,
  501. Screenshot = Key.F8,
  502. ShowUi = Key.F4,
  503. Pause = Key.F5
  504. };
  505. Hid.InputConfig.Value = new List<InputConfig>
  506. {
  507. new StandardKeyboardInputConfig
  508. {
  509. Version = InputConfig.CurrentVersion,
  510. Backend = InputBackendType.WindowKeyboard,
  511. Id = "0",
  512. PlayerIndex = PlayerIndex.Player1,
  513. ControllerType = ControllerType.JoyconPair,
  514. LeftJoycon = new LeftJoyconCommonConfig<Key>
  515. {
  516. DpadUp = Key.Up,
  517. DpadDown = Key.Down,
  518. DpadLeft = Key.Left,
  519. DpadRight = Key.Right,
  520. ButtonMinus = Key.Minus,
  521. ButtonL = Key.E,
  522. ButtonZl = Key.Q,
  523. ButtonSl = Key.Unbound,
  524. ButtonSr = Key.Unbound
  525. },
  526. LeftJoyconStick = new JoyconConfigKeyboardStick<Key>
  527. {
  528. StickUp = Key.W,
  529. StickDown = Key.S,
  530. StickLeft = Key.A,
  531. StickRight = Key.D,
  532. StickButton = Key.F,
  533. },
  534. RightJoycon = new RightJoyconCommonConfig<Key>
  535. {
  536. ButtonA = Key.Z,
  537. ButtonB = Key.X,
  538. ButtonX = Key.C,
  539. ButtonY = Key.V,
  540. ButtonPlus = Key.Plus,
  541. ButtonR = Key.U,
  542. ButtonZr = Key.O,
  543. ButtonSl = Key.Unbound,
  544. ButtonSr = Key.Unbound
  545. },
  546. RightJoyconStick = new JoyconConfigKeyboardStick<Key>
  547. {
  548. StickUp = Key.I,
  549. StickDown = Key.K,
  550. StickLeft = Key.J,
  551. StickRight = Key.L,
  552. StickButton = Key.H,
  553. }
  554. }
  555. };
  556. }
  557. public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath)
  558. {
  559. bool configurationFileUpdated = false;
  560. if (configurationFileFormat.Version < 0 || configurationFileFormat.Version > ConfigurationFileFormat.CurrentVersion)
  561. {
  562. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Unsupported configuration version {configurationFileFormat.Version}, loading default.");
  563. LoadDefault();
  564. return;
  565. }
  566. if (configurationFileFormat.Version < 2)
  567. {
  568. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 2.");
  569. configurationFileFormat.SystemRegion = Region.USA;
  570. configurationFileUpdated = true;
  571. }
  572. if (configurationFileFormat.Version < 3)
  573. {
  574. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 3.");
  575. configurationFileFormat.SystemTimeZone = "UTC";
  576. configurationFileUpdated = true;
  577. }
  578. if (configurationFileFormat.Version < 4)
  579. {
  580. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 4.");
  581. configurationFileFormat.MaxAnisotropy = -1;
  582. configurationFileUpdated = true;
  583. }
  584. if (configurationFileFormat.Version < 5)
  585. {
  586. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 5.");
  587. configurationFileFormat.SystemTimeOffset = 0;
  588. configurationFileUpdated = true;
  589. }
  590. if (configurationFileFormat.Version < 8)
  591. {
  592. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 8.");
  593. configurationFileFormat.EnablePtc = true;
  594. configurationFileUpdated = true;
  595. }
  596. if (configurationFileFormat.Version < 9)
  597. {
  598. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 9.");
  599. configurationFileFormat.ColumnSort = new ColumnSort
  600. {
  601. SortColumnId = 0,
  602. SortAscending = false
  603. };
  604. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  605. {
  606. ToggleVsync = Key.Tab
  607. };
  608. configurationFileUpdated = true;
  609. }
  610. if (configurationFileFormat.Version < 10)
  611. {
  612. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 10.");
  613. configurationFileFormat.AudioBackend = AudioBackend.OpenAl;
  614. configurationFileUpdated = true;
  615. }
  616. if (configurationFileFormat.Version < 11)
  617. {
  618. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 11.");
  619. configurationFileFormat.ResScale = 1;
  620. configurationFileFormat.ResScaleCustom = 1.0f;
  621. configurationFileUpdated = true;
  622. }
  623. if (configurationFileFormat.Version < 12)
  624. {
  625. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 12.");
  626. configurationFileFormat.LoggingGraphicsDebugLevel = GraphicsDebugLevel.None;
  627. configurationFileUpdated = true;
  628. }
  629. if (configurationFileFormat.Version < 14)
  630. {
  631. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 14.");
  632. configurationFileFormat.CheckUpdatesOnStart = true;
  633. configurationFileUpdated = true;
  634. }
  635. if (configurationFileFormat.Version < 16)
  636. {
  637. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 16.");
  638. configurationFileFormat.EnableShaderCache = true;
  639. configurationFileUpdated = true;
  640. }
  641. if (configurationFileFormat.Version < 17)
  642. {
  643. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 17.");
  644. configurationFileFormat.StartFullscreen = false;
  645. configurationFileUpdated = true;
  646. }
  647. if (configurationFileFormat.Version < 18)
  648. {
  649. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 18.");
  650. configurationFileFormat.AspectRatio = AspectRatio.Fixed16x9;
  651. configurationFileUpdated = true;
  652. }
  653. if (configurationFileFormat.Version < 20)
  654. {
  655. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 20.");
  656. configurationFileFormat.ShowConfirmExit = true;
  657. configurationFileUpdated = true;
  658. }
  659. if (configurationFileFormat.Version < 22)
  660. {
  661. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 22.");
  662. configurationFileFormat.HideCursorOnIdle = false;
  663. configurationFileUpdated = true;
  664. }
  665. if (configurationFileFormat.Version < 24)
  666. {
  667. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 24.");
  668. configurationFileFormat.InputConfig = new List<InputConfig>
  669. {
  670. new StandardKeyboardInputConfig
  671. {
  672. Version = InputConfig.CurrentVersion,
  673. Backend = InputBackendType.WindowKeyboard,
  674. Id = "0",
  675. PlayerIndex = PlayerIndex.Player1,
  676. ControllerType = ControllerType.JoyconPair,
  677. LeftJoycon = new LeftJoyconCommonConfig<Key>
  678. {
  679. DpadUp = Key.Up,
  680. DpadDown = Key.Down,
  681. DpadLeft = Key.Left,
  682. DpadRight = Key.Right,
  683. ButtonMinus = Key.Minus,
  684. ButtonL = Key.E,
  685. ButtonZl = Key.Q,
  686. ButtonSl = Key.Unbound,
  687. ButtonSr = Key.Unbound
  688. },
  689. LeftJoyconStick = new JoyconConfigKeyboardStick<Key>
  690. {
  691. StickUp = Key.W,
  692. StickDown = Key.S,
  693. StickLeft = Key.A,
  694. StickRight = Key.D,
  695. StickButton = Key.F,
  696. },
  697. RightJoycon = new RightJoyconCommonConfig<Key>
  698. {
  699. ButtonA = Key.Z,
  700. ButtonB = Key.X,
  701. ButtonX = Key.C,
  702. ButtonY = Key.V,
  703. ButtonPlus = Key.Plus,
  704. ButtonR = Key.U,
  705. ButtonZr = Key.O,
  706. ButtonSl = Key.Unbound,
  707. ButtonSr = Key.Unbound
  708. },
  709. RightJoyconStick = new JoyconConfigKeyboardStick<Key>
  710. {
  711. StickUp = Key.I,
  712. StickDown = Key.K,
  713. StickLeft = Key.J,
  714. StickRight = Key.L,
  715. StickButton = Key.H,
  716. }
  717. }
  718. };
  719. configurationFileUpdated = true;
  720. }
  721. if (configurationFileFormat.Version < 25)
  722. {
  723. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 25.");
  724. configurationFileUpdated = true;
  725. }
  726. if (configurationFileFormat.Version < 26)
  727. {
  728. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 26.");
  729. configurationFileFormat.MemoryManagerMode = MemoryManagerMode.HostMappedUnsafe;
  730. configurationFileUpdated = true;
  731. }
  732. if (configurationFileFormat.Version < 27)
  733. {
  734. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 27.");
  735. configurationFileFormat.EnableMouse = false;
  736. configurationFileUpdated = true;
  737. }
  738. if (configurationFileFormat.Version < 28)
  739. {
  740. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 28.");
  741. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  742. {
  743. ToggleVsync = Key.Tab,
  744. Screenshot = Key.F8
  745. };
  746. configurationFileUpdated = true;
  747. }
  748. if (configurationFileFormat.Version < 29)
  749. {
  750. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 29.");
  751. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  752. {
  753. ToggleVsync = Key.Tab,
  754. Screenshot = Key.F8,
  755. ShowUi = Key.F4
  756. };
  757. configurationFileUpdated = true;
  758. }
  759. if (configurationFileFormat.Version < 30)
  760. {
  761. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 30.");
  762. foreach (InputConfig config in configurationFileFormat.InputConfig)
  763. {
  764. if (config is StandardControllerInputConfig controllerConfig)
  765. {
  766. controllerConfig.Rumble = new RumbleConfigController
  767. {
  768. EnableRumble = false,
  769. StrongRumble = 1f,
  770. WeakRumble = 1f
  771. };
  772. }
  773. }
  774. configurationFileUpdated = true;
  775. }
  776. if (configurationFileFormat.Version < 31)
  777. {
  778. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 31.");
  779. configurationFileFormat.BackendThreading = BackendThreading.Auto;
  780. configurationFileUpdated = true;
  781. }
  782. if (configurationFileFormat.Version < 32)
  783. {
  784. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 32.");
  785. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  786. {
  787. ToggleVsync = configurationFileFormat.Hotkeys.ToggleVsync,
  788. Screenshot = configurationFileFormat.Hotkeys.Screenshot,
  789. ShowUi = configurationFileFormat.Hotkeys.ShowUi,
  790. Pause = Key.F5
  791. };
  792. configurationFileUpdated = true;
  793. }
  794. if (configurationFileFormat.Version < 33)
  795. {
  796. Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 33.");
  797. configurationFileFormat.Hotkeys = new KeyboardHotkeys
  798. {
  799. ToggleVsync = configurationFileFormat.Hotkeys.ToggleVsync,
  800. Screenshot = configurationFileFormat.Hotkeys.Screenshot,
  801. ShowUi = configurationFileFormat.Hotkeys.ShowUi,
  802. Pause = configurationFileFormat.Hotkeys.Pause,
  803. ToggleMute = Key.F2
  804. };
  805. configurationFileFormat.AudioVolume = 1;
  806. configurationFileUpdated = true;
  807. }
  808. Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog;
  809. Graphics.BackendThreading.Value = configurationFileFormat.BackendThreading;
  810. Graphics.ResScale.Value = configurationFileFormat.ResScale;
  811. Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom;
  812. Graphics.MaxAnisotropy.Value = configurationFileFormat.MaxAnisotropy;
  813. Graphics.AspectRatio.Value = configurationFileFormat.AspectRatio;
  814. Graphics.ShadersDumpPath.Value = configurationFileFormat.GraphicsShadersDumpPath;
  815. Logger.EnableDebug.Value = configurationFileFormat.LoggingEnableDebug;
  816. Logger.EnableStub.Value = configurationFileFormat.LoggingEnableStub;
  817. Logger.EnableInfo.Value = configurationFileFormat.LoggingEnableInfo;
  818. Logger.EnableWarn.Value = configurationFileFormat.LoggingEnableWarn;
  819. Logger.EnableError.Value = configurationFileFormat.LoggingEnableError;
  820. Logger.EnableGuest.Value = configurationFileFormat.LoggingEnableGuest;
  821. Logger.EnableFsAccessLog.Value = configurationFileFormat.LoggingEnableFsAccessLog;
  822. Logger.FilteredClasses.Value = configurationFileFormat.LoggingFilteredClasses;
  823. Logger.GraphicsDebugLevel.Value = configurationFileFormat.LoggingGraphicsDebugLevel;
  824. System.Language.Value = configurationFileFormat.SystemLanguage;
  825. System.Region.Value = configurationFileFormat.SystemRegion;
  826. System.TimeZone.Value = configurationFileFormat.SystemTimeZone;
  827. System.SystemTimeOffset.Value = configurationFileFormat.SystemTimeOffset;
  828. System.EnableDockedMode.Value = configurationFileFormat.DockedMode;
  829. EnableDiscordIntegration.Value = configurationFileFormat.EnableDiscordIntegration;
  830. CheckUpdatesOnStart.Value = configurationFileFormat.CheckUpdatesOnStart;
  831. ShowConfirmExit.Value = configurationFileFormat.ShowConfirmExit;
  832. HideCursorOnIdle.Value = configurationFileFormat.HideCursorOnIdle;
  833. Graphics.EnableVsync.Value = configurationFileFormat.EnableVsync;
  834. Graphics.EnableShaderCache.Value = configurationFileFormat.EnableShaderCache;
  835. System.EnablePtc.Value = configurationFileFormat.EnablePtc;
  836. System.EnableFsIntegrityChecks.Value = configurationFileFormat.EnableFsIntegrityChecks;
  837. System.FsGlobalAccessLogMode.Value = configurationFileFormat.FsGlobalAccessLogMode;
  838. System.AudioBackend.Value = configurationFileFormat.AudioBackend;
  839. System.AudioVolume.Value = configurationFileFormat.AudioVolume;
  840. System.MemoryManagerMode.Value = configurationFileFormat.MemoryManagerMode;
  841. System.ExpandRam.Value = configurationFileFormat.ExpandRam;
  842. System.IgnoreMissingServices.Value = configurationFileFormat.IgnoreMissingServices;
  843. Ui.GuiColumns.FavColumn.Value = configurationFileFormat.GuiColumns.FavColumn;
  844. Ui.GuiColumns.IconColumn.Value = configurationFileFormat.GuiColumns.IconColumn;
  845. Ui.GuiColumns.AppColumn.Value = configurationFileFormat.GuiColumns.AppColumn;
  846. Ui.GuiColumns.DevColumn.Value = configurationFileFormat.GuiColumns.DevColumn;
  847. Ui.GuiColumns.VersionColumn.Value = configurationFileFormat.GuiColumns.VersionColumn;
  848. Ui.GuiColumns.TimePlayedColumn.Value = configurationFileFormat.GuiColumns.TimePlayedColumn;
  849. Ui.GuiColumns.LastPlayedColumn.Value = configurationFileFormat.GuiColumns.LastPlayedColumn;
  850. Ui.GuiColumns.FileExtColumn.Value = configurationFileFormat.GuiColumns.FileExtColumn;
  851. Ui.GuiColumns.FileSizeColumn.Value = configurationFileFormat.GuiColumns.FileSizeColumn;
  852. Ui.GuiColumns.PathColumn.Value = configurationFileFormat.GuiColumns.PathColumn;
  853. Ui.ColumnSort.SortColumnId.Value = configurationFileFormat.ColumnSort.SortColumnId;
  854. Ui.ColumnSort.SortAscending.Value = configurationFileFormat.ColumnSort.SortAscending;
  855. Ui.GameDirs.Value = configurationFileFormat.GameDirs;
  856. Ui.EnableCustomTheme.Value = configurationFileFormat.EnableCustomTheme;
  857. Ui.CustomThemePath.Value = configurationFileFormat.CustomThemePath;
  858. Ui.StartFullscreen.Value = configurationFileFormat.StartFullscreen;
  859. Hid.EnableKeyboard.Value = configurationFileFormat.EnableKeyboard;
  860. Hid.EnableMouse.Value = configurationFileFormat.EnableMouse;
  861. Hid.Hotkeys.Value = configurationFileFormat.Hotkeys;
  862. Hid.InputConfig.Value = configurationFileFormat.InputConfig;
  863. if (Hid.InputConfig.Value == null)
  864. {
  865. Hid.InputConfig.Value = new List<InputConfig>();
  866. }
  867. if (configurationFileUpdated)
  868. {
  869. ToFileFormat().SaveConfig(configurationFilePath);
  870. Common.Logging.Logger.Notice.Print(LogClass.Application, $"Configuration file updated to version {ConfigurationFileFormat.CurrentVersion}");
  871. }
  872. }
  873. private static void LogValueChange<T>(object sender, ReactiveEventArgs<T> eventArgs, string valueName)
  874. {
  875. Common.Logging.Logger.Info?.Print(LogClass.Configuration, $"{valueName} set to: {eventArgs.NewValue}");
  876. }
  877. public static void Initialize()
  878. {
  879. if (Instance != null)
  880. {
  881. throw new InvalidOperationException("Configuration is already initialized");
  882. }
  883. Instance = new ConfigurationState();
  884. }
  885. }
  886. }