ConfigurationState.cs 50 KB

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