Options.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. using CommandLine;
  2. using Gommon;
  3. using Ryujinx.Ava.Utilities.Configuration;
  4. using Ryujinx.Common.Configuration;
  5. using Ryujinx.Common.Configuration.Hid;
  6. using Ryujinx.HLE;
  7. using Ryujinx.HLE.HOS.SystemState;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Reflection;
  12. namespace Ryujinx.Headless
  13. {
  14. public class Options
  15. {
  16. public void InheritMainConfig(string[] originalArgs, ConfigurationState configurationState, out bool needsProfileSet)
  17. {
  18. needsProfileSet = NeedsOverride(nameof(UserProfile));
  19. if (NeedsOverride(nameof(IsFullscreen)))
  20. IsFullscreen = configurationState.UI.StartFullscreen;
  21. if (NeedsOverride(nameof(EnableKeyboard)))
  22. EnableKeyboard = configurationState.Hid.EnableKeyboard;
  23. if (NeedsOverride(nameof(EnableMouse)))
  24. EnableMouse = configurationState.Hid.EnableMouse;
  25. if (NeedsOverride(nameof(HideCursorMode)))
  26. HideCursorMode = configurationState.HideCursor;
  27. if (NeedsOverride(nameof(DisablePTC)))
  28. DisablePTC = !configurationState.System.EnablePtc;
  29. if (NeedsOverride(nameof(EnableInternetAccess)))
  30. EnableInternetAccess = configurationState.System.EnableInternetAccess;
  31. if (NeedsOverride(nameof(DisableFsIntegrityChecks)))
  32. DisableFsIntegrityChecks = configurationState.System.EnableFsIntegrityChecks;
  33. if (NeedsOverride(nameof(FsGlobalAccessLogMode)))
  34. FsGlobalAccessLogMode = configurationState.System.FsGlobalAccessLogMode;
  35. if (NeedsOverride(nameof(VSyncMode)))
  36. VSyncMode = configurationState.Graphics.VSyncMode;
  37. if (NeedsOverride(nameof(CustomVSyncInterval)))
  38. CustomVSyncInterval = configurationState.Graphics.CustomVSyncInterval;
  39. if (NeedsOverride(nameof(DisableShaderCache)))
  40. DisableShaderCache = !configurationState.Graphics.EnableShaderCache;
  41. if (NeedsOverride(nameof(EnableTextureRecompression)))
  42. EnableTextureRecompression = configurationState.Graphics.EnableTextureRecompression;
  43. if (NeedsOverride(nameof(DisableDockedMode)))
  44. DisableDockedMode = !configurationState.System.EnableDockedMode;
  45. if (NeedsOverride(nameof(SystemLanguage)))
  46. SystemLanguage = (SystemLanguage)(int)configurationState.System.Language.Value;
  47. if (NeedsOverride(nameof(SystemRegion)))
  48. SystemRegion = (RegionCode)(int)configurationState.System.Region.Value;
  49. if (NeedsOverride(nameof(SystemTimeZone)))
  50. SystemTimeZone = configurationState.System.TimeZone;
  51. if (NeedsOverride(nameof(SystemTimeOffset)))
  52. SystemTimeOffset = configurationState.System.SystemTimeOffset;
  53. if (NeedsOverride(nameof(MemoryManagerMode)))
  54. MemoryManagerMode = configurationState.System.MemoryManagerMode;
  55. if (NeedsOverride(nameof(AudioVolume)))
  56. AudioVolume = configurationState.System.AudioVolume;
  57. if (NeedsOverride(nameof(UseHypervisor)) && OperatingSystem.IsMacOS())
  58. UseHypervisor = configurationState.System.UseHypervisor;
  59. if (NeedsOverride(nameof(MultiplayerLanInterfaceId)))
  60. MultiplayerLanInterfaceId = configurationState.Multiplayer.LanInterfaceId;
  61. if (NeedsOverride(nameof(DisableFileLog)))
  62. DisableFileLog = !configurationState.Logger.EnableFileLog;
  63. if (NeedsOverride(nameof(LoggingEnableDebug)))
  64. LoggingEnableDebug = configurationState.Logger.EnableDebug;
  65. if (NeedsOverride(nameof(LoggingDisableStub)))
  66. LoggingDisableStub = !configurationState.Logger.EnableStub;
  67. if (NeedsOverride(nameof(LoggingDisableInfo)))
  68. LoggingDisableInfo = !configurationState.Logger.EnableInfo;
  69. if (NeedsOverride(nameof(LoggingDisableWarning)))
  70. LoggingDisableWarning = !configurationState.Logger.EnableWarn;
  71. if (NeedsOverride(nameof(LoggingDisableError)))
  72. LoggingDisableError = !configurationState.Logger.EnableError;
  73. if (NeedsOverride(nameof(LoggingEnableTrace)))
  74. LoggingEnableTrace = configurationState.Logger.EnableTrace;
  75. if (NeedsOverride(nameof(LoggingDisableGuest)))
  76. LoggingDisableGuest = !configurationState.Logger.EnableGuest;
  77. if (NeedsOverride(nameof(LoggingEnableFsAccessLog)))
  78. LoggingEnableFsAccessLog = configurationState.Logger.EnableFsAccessLog;
  79. if (NeedsOverride(nameof(LoggingGraphicsDebugLevel)))
  80. LoggingGraphicsDebugLevel = configurationState.Logger.GraphicsDebugLevel;
  81. if (NeedsOverride(nameof(ResScale)))
  82. ResScale = configurationState.Graphics.ResScale;
  83. if (NeedsOverride(nameof(MaxAnisotropy)))
  84. MaxAnisotropy = configurationState.Graphics.MaxAnisotropy;
  85. if (NeedsOverride(nameof(AspectRatio)))
  86. AspectRatio = configurationState.Graphics.AspectRatio;
  87. if (NeedsOverride(nameof(BackendThreading)))
  88. BackendThreading = configurationState.Graphics.BackendThreading;
  89. if (NeedsOverride(nameof(DisableMacroHLE)))
  90. DisableMacroHLE = !configurationState.Graphics.EnableMacroHLE;
  91. if (NeedsOverride(nameof(GraphicsShadersDumpPath)))
  92. GraphicsShadersDumpPath = configurationState.Graphics.ShadersDumpPath;
  93. if (NeedsOverride(nameof(GraphicsBackend)))
  94. GraphicsBackend = configurationState.Graphics.GraphicsBackend;
  95. if (NeedsOverride(nameof(AntiAliasing)))
  96. AntiAliasing = configurationState.Graphics.AntiAliasing;
  97. if (NeedsOverride(nameof(ScalingFilter)))
  98. ScalingFilter = configurationState.Graphics.ScalingFilter;
  99. if (NeedsOverride(nameof(ScalingFilterLevel)))
  100. ScalingFilterLevel = configurationState.Graphics.ScalingFilterLevel;
  101. if (NeedsOverride(nameof(DramSize)))
  102. DramSize = configurationState.System.DramSize;
  103. if (NeedsOverride(nameof(IgnoreMissingServices)))
  104. IgnoreMissingServices = configurationState.System.IgnoreMissingServices;
  105. if (NeedsOverride(nameof(IgnoreControllerApplet)))
  106. IgnoreControllerApplet = configurationState.System.IgnoreControllerApplet;
  107. return;
  108. bool NeedsOverride(string argKey) => originalArgs.None(arg => arg.TrimStart('-').EqualsIgnoreCase(OptionName(argKey)));
  109. }
  110. public void InheritMainConfigInput(string[] originalArgs, ConfigurationState configurationState)
  111. {
  112. Dictionary<PlayerIndex, (string InputId, string InputProfileName)> indicesToProperties = new()
  113. {
  114. { PlayerIndex.Handheld, (nameof(InputIdHandheld), nameof(InputProfileHandheldName)) },
  115. { PlayerIndex.Player1, (nameof(InputId1), nameof(InputProfile1Name)) },
  116. { PlayerIndex.Player2, (nameof(InputId2), nameof(InputProfile2Name)) },
  117. { PlayerIndex.Player3, (nameof(InputId3), nameof(InputProfile3Name)) },
  118. { PlayerIndex.Player4, (nameof(InputId4), nameof(InputProfile4Name)) },
  119. { PlayerIndex.Player5, (nameof(InputId5), nameof(InputProfile5Name)) },
  120. { PlayerIndex.Player6, (nameof(InputId6), nameof(InputProfile6Name)) },
  121. { PlayerIndex.Player7, (nameof(InputId7), nameof(InputProfile7Name)) },
  122. { PlayerIndex.Player8, (nameof(InputId8), nameof(InputProfile8Name)) }
  123. };
  124. foreach ((PlayerIndex playerIndex, _) in indicesToProperties
  125. .Where(it => NeedsOverride(it.Value.InputId) && NeedsOverride(it.Value.InputProfileName)))
  126. {
  127. configurationState.Hid.InputConfig.Value.FindFirst(x => x.PlayerIndex == playerIndex)
  128. .IfPresent(ic => InheritedInputConfigs[playerIndex] = ic);
  129. }
  130. return;
  131. bool NeedsOverride(string argKey) => originalArgs.None(arg => arg.TrimStart('-').EqualsIgnoreCase(OptionName(argKey)));
  132. }
  133. private static string OptionName(string propertyName) =>
  134. typeof(Options)!.GetProperty(propertyName)!.GetCustomAttribute<OptionAttribute>()!.LongName;
  135. // General
  136. [Option("use-main-config", Required = false, Default = false, HelpText = "Use the settings from what was configured via the UI.")]
  137. public bool InheritConfig { get; set; }
  138. [Option("root-data-dir", Required = false, HelpText = "Set the custom folder path for Ryujinx data.")]
  139. public string BaseDataDir { get; set; }
  140. [Option("profile", Required = false, HelpText = "Set the user profile to launch the game with.")]
  141. public string UserProfile { get; set; }
  142. [Option("display-id", Required = false, Default = 0, HelpText = "Set the display to use - especially helpful for fullscreen mode. [0-n]")]
  143. public int DisplayId { get; set; }
  144. [Option("fullscreen", Required = false, Default = false, HelpText = "Launch the game in fullscreen mode.")]
  145. public bool IsFullscreen { get; set; }
  146. [Option("exclusive-fullscreen", Required = false, Default = false, HelpText = "Launch the game in exclusive fullscreen mode.")]
  147. public bool IsExclusiveFullscreen { get; set; }
  148. [Option("exclusive-fullscreen-width", Required = false, Default = 1920, HelpText = "Set horizontal resolution for exclusive fullscreen mode.")]
  149. public int ExclusiveFullscreenWidth { get; set; }
  150. [Option("exclusive-fullscreen-height", Required = false, Default = 1080, HelpText = "Set vertical resolution for exclusive fullscreen mode.")]
  151. public int ExclusiveFullscreenHeight { get; set; }
  152. // Input
  153. [Option("input-profile-1", Required = false, HelpText = "Set the input profile in use for Player 1.")]
  154. public string InputProfile1Name { get; set; }
  155. [Option("input-profile-2", Required = false, HelpText = "Set the input profile in use for Player 2.")]
  156. public string InputProfile2Name { get; set; }
  157. [Option("input-profile-3", Required = false, HelpText = "Set the input profile in use for Player 3.")]
  158. public string InputProfile3Name { get; set; }
  159. [Option("input-profile-4", Required = false, HelpText = "Set the input profile in use for Player 4.")]
  160. public string InputProfile4Name { get; set; }
  161. [Option("input-profile-5", Required = false, HelpText = "Set the input profile in use for Player 5.")]
  162. public string InputProfile5Name { get; set; }
  163. [Option("input-profile-6", Required = false, HelpText = "Set the input profile in use for Player 6.")]
  164. public string InputProfile6Name { get; set; }
  165. [Option("input-profile-7", Required = false, HelpText = "Set the input profile in use for Player 7.")]
  166. public string InputProfile7Name { get; set; }
  167. [Option("input-profile-8", Required = false, HelpText = "Set the input profile in use for Player 8.")]
  168. public string InputProfile8Name { get; set; }
  169. [Option("input-profile-handheld", Required = false, HelpText = "Set the input profile in use for the Handheld Player.")]
  170. public string InputProfileHandheldName { get; set; }
  171. [Option("input-id-1", Required = false, HelpText = "Set the input id in use for Player 1.")]
  172. public string InputId1 { get; set; }
  173. [Option("input-id-2", Required = false, HelpText = "Set the input id in use for Player 2.")]
  174. public string InputId2 { get; set; }
  175. [Option("input-id-3", Required = false, HelpText = "Set the input id in use for Player 3.")]
  176. public string InputId3 { get; set; }
  177. [Option("input-id-4", Required = false, HelpText = "Set the input id in use for Player 4.")]
  178. public string InputId4 { get; set; }
  179. [Option("input-id-5", Required = false, HelpText = "Set the input id in use for Player 5.")]
  180. public string InputId5 { get; set; }
  181. [Option("input-id-6", Required = false, HelpText = "Set the input id in use for Player 6.")]
  182. public string InputId6 { get; set; }
  183. [Option("input-id-7", Required = false, HelpText = "Set the input id in use for Player 7.")]
  184. public string InputId7 { get; set; }
  185. [Option("input-id-8", Required = false, HelpText = "Set the input id in use for Player 8.")]
  186. public string InputId8 { get; set; }
  187. [Option("input-id-handheld", Required = false, HelpText = "Set the input id in use for the Handheld Player.")]
  188. public string InputIdHandheld { get; set; }
  189. [Option("enable-keyboard", Required = false, Default = false, HelpText = "Enable or disable keyboard support (Independent from controllers binding).")]
  190. public bool EnableKeyboard { get; set; }
  191. [Option("enable-mouse", Required = false, Default = false, HelpText = "Enable or disable mouse support.")]
  192. public bool EnableMouse { get; set; }
  193. [Option("hide-cursor", Required = false, Default = HideCursorMode.OnIdle, HelpText = "Change when the cursor gets hidden.")]
  194. public HideCursorMode HideCursorMode { get; set; }
  195. [Option("list-input-profiles", Required = false, HelpText = "List input profiles.")]
  196. public bool ListInputProfiles { get; set; }
  197. [Option("list-input-ids", Required = false, HelpText = "List input IDs.")]
  198. public bool ListInputIds { get; set; }
  199. // System
  200. [Option("disable-ptc", Required = false, HelpText = "Disables profiled persistent translation cache.")]
  201. public bool DisablePTC { get; set; }
  202. [Option("enable-internet-connection", Required = false, Default = false, HelpText = "Enables guest Internet connection.")]
  203. public bool EnableInternetAccess { get; set; }
  204. [Option("disable-fs-integrity-checks", Required = false, HelpText = "Disables integrity checks on Game content files.")]
  205. public bool DisableFsIntegrityChecks { get; set; }
  206. [Option("fs-global-access-log-mode", Required = false, Default = 0, HelpText = "Enables FS access log output to the console.")]
  207. public int FsGlobalAccessLogMode { get; set; }
  208. [Option("vsync-mode", Required = false, Default = VSyncMode.Switch, HelpText = "Sets the emulated VSync mode (Switch, Unbounded, or Custom).")]
  209. public VSyncMode VSyncMode { get; set; }
  210. [Option("custom-refresh-rate", Required = false, Default = 90, HelpText = "Sets the custom refresh rate target value (integer).")]
  211. public int CustomVSyncInterval { get; set; }
  212. [Option("disable-shader-cache", Required = false, HelpText = "Disables Shader cache.")]
  213. public bool DisableShaderCache { get; set; }
  214. [Option("enable-texture-recompression", Required = false, Default = false, HelpText = "Enables Texture recompression.")]
  215. public bool EnableTextureRecompression { get; set; }
  216. [Option("disable-docked-mode", Required = false, HelpText = "Disables Docked Mode.")]
  217. public bool DisableDockedMode { get; set; }
  218. [Option("system-language", Required = false, Default = SystemLanguage.AmericanEnglish, HelpText = "Change System Language.")]
  219. public SystemLanguage SystemLanguage { get; set; }
  220. [Option("system-region", Required = false, Default = RegionCode.USA, HelpText = "Change System Region.")]
  221. public RegionCode SystemRegion { get; set; }
  222. [Option("system-timezone", Required = false, Default = "UTC", HelpText = "Change System TimeZone.")]
  223. public string SystemTimeZone { get; set; }
  224. [Option("system-time-offset", Required = false, Default = 0, HelpText = "Change System Time Offset in seconds.")]
  225. public long SystemTimeOffset { get; set; }
  226. [Option("memory-manager-mode", Required = false, Default = MemoryManagerMode.HostMappedUnsafe, HelpText = "The selected memory manager mode.")]
  227. public MemoryManagerMode MemoryManagerMode { get; set; }
  228. [Option("audio-volume", Required = false, Default = 1.0f, HelpText = "The audio level (0 to 1).")]
  229. public float AudioVolume { get; set; }
  230. [Option("use-hypervisor", Required = false, Default = true, HelpText = "Uses Hypervisor over JIT if available.")]
  231. public bool? UseHypervisor { get; set; }
  232. [Option("lan-interface-id", Required = false, Default = "0", HelpText = "GUID for the network interface used by LAN.")]
  233. public string MultiplayerLanInterfaceId { get; set; }
  234. // Logging
  235. [Option("disable-file-logging", Required = false, Default = false, HelpText = "Disables logging to a file on disk.")]
  236. public bool DisableFileLog { get; set; }
  237. [Option("enable-debug-logs", Required = false, Default = false, HelpText = "Enables printing debug log messages.")]
  238. public bool LoggingEnableDebug { get; set; }
  239. [Option("disable-stub-logs", Required = false, HelpText = "Disables printing stub log messages.")]
  240. public bool LoggingDisableStub { get; set; }
  241. [Option("disable-info-logs", Required = false, HelpText = "Disables printing info log messages.")]
  242. public bool LoggingDisableInfo { get; set; }
  243. [Option("disable-warning-logs", Required = false, HelpText = "Disables printing warning log messages.")]
  244. public bool LoggingDisableWarning { get; set; }
  245. [Option("disable-error-logs", Required = false, HelpText = "Disables printing error log messages.")]
  246. public bool LoggingDisableError { get; set; }
  247. [Option("enable-trace-logs", Required = false, Default = false, HelpText = "Enables printing trace log messages.")]
  248. public bool LoggingEnableTrace { get; set; }
  249. [Option("disable-guest-logs", Required = false, HelpText = "Disables printing guest log messages.")]
  250. public bool LoggingDisableGuest { get; set; }
  251. [Option("enable-fs-access-logs", Required = false, Default = false, HelpText = "Enables printing FS access log messages.")]
  252. public bool LoggingEnableFsAccessLog { get; set; }
  253. [Option("graphics-debug-level", Required = false, Default = GraphicsDebugLevel.None, HelpText = "Change Graphics API debug log level.")]
  254. public GraphicsDebugLevel LoggingGraphicsDebugLevel { get; set; }
  255. // Graphics
  256. [Option("resolution-scale", Required = false, Default = 1, HelpText = "Resolution Scale. A floating point scale applied to applicable render targets.")]
  257. public float ResScale { get; set; }
  258. [Option("max-anisotropy", Required = false, Default = -1, HelpText = "Max Anisotropy. Values range from 0 - 16. Set to -1 to let the game decide.")]
  259. public float MaxAnisotropy { get; set; }
  260. [Option("aspect-ratio", Required = false, Default = AspectRatio.Fixed16x9, HelpText = "Aspect Ratio applied to the renderer window.")]
  261. public AspectRatio AspectRatio { get; set; }
  262. [Option("backend-threading", Required = false, Default = BackendThreading.Auto, HelpText = "Whether or not backend threading is enabled. The \"Auto\" setting will determine whether threading should be enabled at runtime.")]
  263. public BackendThreading BackendThreading { get; set; }
  264. [Option("disable-macro-hle", Required = false, HelpText = "Disables high-level emulation of Macro code. Leaving this enabled improves performance but may cause graphical glitches in some games.")]
  265. public bool DisableMacroHLE { get; set; }
  266. [Option("graphics-shaders-dump-path", Required = false, HelpText = "Dumps shaders in this local directory. (Developer only)")]
  267. public string GraphicsShadersDumpPath { get; set; }
  268. [Option("graphics-backend", Required = false, Default = GraphicsBackend.Vulkan, HelpText = "Change Graphics Backend to use.")]
  269. public GraphicsBackend GraphicsBackend { get; set; }
  270. [Option("preferred-gpu-vendor", Required = false, Default = "", HelpText = "When using the Vulkan backend, prefer using the GPU from the specified vendor.")]
  271. public string PreferredGPUVendor { get; set; }
  272. [Option("anti-aliasing", Required = false, Default = AntiAliasing.None, HelpText = "Set the type of anti aliasing being used. [None|Fxaa|SmaaLow|SmaaMedium|SmaaHigh|SmaaUltra]")]
  273. public AntiAliasing AntiAliasing { get; set; }
  274. [Option("scaling-filter", Required = false, Default = ScalingFilter.Bilinear, HelpText = "Set the scaling filter. [Bilinear|Nearest|Fsr|Area]")]
  275. public ScalingFilter ScalingFilter { get; set; }
  276. [Option("scaling-filter-level", Required = false, Default = 0, HelpText = "Set the scaling filter intensity (currently only applies to FSR). [0-100]")]
  277. public int ScalingFilterLevel { get; set; }
  278. // Hacks
  279. [Option("dram-size", Required = false, Default = MemoryConfiguration.MemoryConfiguration4GiB, HelpText = "Set the RAM amount on the emulated system.")]
  280. public MemoryConfiguration DramSize { get; set; }
  281. [Option("ignore-missing-services", Required = false, Default = false, HelpText = "Enable ignoring missing services.")]
  282. public bool IgnoreMissingServices { get; set; }
  283. [Option("ignore-controller-applet", Required = false, Default = false, HelpText = "Enable ignoring the controller applet when your game loses connection to your controller.")]
  284. public bool IgnoreControllerApplet { get; set; }
  285. // Values
  286. [Value(0, MetaName = "input", HelpText = "Input to load.", Required = true)]
  287. public string InputPath { get; set; }
  288. public SafeDictionary<PlayerIndex, InputConfig> InheritedInputConfigs = new();
  289. }
  290. }