Program.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. using ARMeilleure.Translation;
  2. using CommandLine;
  3. using LibHac.Tools.FsSystem;
  4. using Ryujinx.Audio.Backends.SDL2;
  5. using Ryujinx.Common;
  6. using Ryujinx.Common.Configuration;
  7. using Ryujinx.Common.Configuration.Hid;
  8. using Ryujinx.Common.Configuration.Hid.Controller;
  9. using Ryujinx.Common.Configuration.Hid.Controller.Motion;
  10. using Ryujinx.Common.Configuration.Hid.Keyboard;
  11. using Ryujinx.Common.Logging;
  12. using Ryujinx.Common.SystemInterop;
  13. using Ryujinx.Common.Utilities;
  14. using Ryujinx.Cpu;
  15. using Ryujinx.Graphics.GAL;
  16. using Ryujinx.Graphics.GAL.Multithreading;
  17. using Ryujinx.Graphics.Gpu;
  18. using Ryujinx.Graphics.Gpu.Shader;
  19. using Ryujinx.Graphics.OpenGL;
  20. using Ryujinx.Graphics.Vulkan;
  21. using Ryujinx.Headless.SDL2.OpenGL;
  22. using Ryujinx.Headless.SDL2.Vulkan;
  23. using Ryujinx.HLE;
  24. using Ryujinx.HLE.FileSystem;
  25. using Ryujinx.HLE.HOS;
  26. using Ryujinx.HLE.HOS.Services.Account.Acc;
  27. using Ryujinx.Input;
  28. using Ryujinx.Input.HLE;
  29. using Ryujinx.Input.SDL2;
  30. using Silk.NET.Vulkan;
  31. using System;
  32. using System.Collections.Generic;
  33. using System.IO;
  34. using System.Text.Json;
  35. using System.Threading;
  36. using ConfigGamepadInputId = Ryujinx.Common.Configuration.Hid.Controller.GamepadInputId;
  37. using ConfigStickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;
  38. using Key = Ryujinx.Common.Configuration.Hid.Key;
  39. namespace Ryujinx.Headless.SDL2
  40. {
  41. class Program
  42. {
  43. public static string Version { get; private set; }
  44. private static VirtualFileSystem _virtualFileSystem;
  45. private static ContentManager _contentManager;
  46. private static AccountManager _accountManager;
  47. private static LibHacHorizonManager _libHacHorizonManager;
  48. private static UserChannelPersistence _userChannelPersistence;
  49. private static InputManager _inputManager;
  50. private static Switch _emulationContext;
  51. private static WindowBase _window;
  52. private static WindowsMultimediaTimerResolution _windowsMultimediaTimerResolution;
  53. private static List<InputConfig> _inputConfiguration;
  54. private static bool _enableKeyboard;
  55. private static bool _enableMouse;
  56. static void Main(string[] args)
  57. {
  58. Version = ReleaseInformation.GetVersion();
  59. Console.Title = $"Ryujinx Console {Version} (Headless SDL2)";
  60. if (OperatingSystem.IsMacOS() || OperatingSystem.IsLinux())
  61. {
  62. AutoResetEvent invoked = new AutoResetEvent(false);
  63. // MacOS must perform SDL polls from the main thread.
  64. Ryujinx.SDL2.Common.SDL2Driver.MainThreadDispatcher = (Action action) =>
  65. {
  66. invoked.Reset();
  67. WindowBase.QueueMainThreadAction(() =>
  68. {
  69. action();
  70. invoked.Set();
  71. });
  72. invoked.WaitOne();
  73. };
  74. }
  75. Parser.Default.ParseArguments<Options>(args)
  76. .WithParsed(Load)
  77. .WithNotParsed(errors => errors.Output());
  78. }
  79. private static InputConfig HandlePlayerConfiguration(string inputProfileName, string inputId, PlayerIndex index)
  80. {
  81. if (inputId == null)
  82. {
  83. if (index == PlayerIndex.Player1)
  84. {
  85. Logger.Info?.Print(LogClass.Application, $"{index} not configured, defaulting to default keyboard.");
  86. // Default to keyboard
  87. inputId = "0";
  88. }
  89. else
  90. {
  91. Logger.Info?.Print(LogClass.Application, $"{index} not configured");
  92. return null;
  93. }
  94. }
  95. IGamepad gamepad;
  96. bool isKeyboard = true;
  97. gamepad = _inputManager.KeyboardDriver.GetGamepad(inputId);
  98. if (gamepad == null)
  99. {
  100. gamepad = _inputManager.GamepadDriver.GetGamepad(inputId);
  101. isKeyboard = false;
  102. if (gamepad == null)
  103. {
  104. Logger.Error?.Print(LogClass.Application, $"{index} gamepad not found (\"{inputId}\")");
  105. return null;
  106. }
  107. }
  108. string gamepadName = gamepad.Name;
  109. gamepad.Dispose();
  110. InputConfig config;
  111. if (inputProfileName == null || inputProfileName.Equals("default"))
  112. {
  113. if (isKeyboard)
  114. {
  115. config = new StandardKeyboardInputConfig
  116. {
  117. Version = InputConfig.CurrentVersion,
  118. Backend = InputBackendType.WindowKeyboard,
  119. Id = null,
  120. ControllerType = ControllerType.JoyconPair,
  121. LeftJoycon = new LeftJoyconCommonConfig<Key>
  122. {
  123. DpadUp = Key.Up,
  124. DpadDown = Key.Down,
  125. DpadLeft = Key.Left,
  126. DpadRight = Key.Right,
  127. ButtonMinus = Key.Minus,
  128. ButtonL = Key.E,
  129. ButtonZl = Key.Q,
  130. ButtonSl = Key.Unbound,
  131. ButtonSr = Key.Unbound
  132. },
  133. LeftJoyconStick = new JoyconConfigKeyboardStick<Key>
  134. {
  135. StickUp = Key.W,
  136. StickDown = Key.S,
  137. StickLeft = Key.A,
  138. StickRight = Key.D,
  139. StickButton = Key.F,
  140. },
  141. RightJoycon = new RightJoyconCommonConfig<Key>
  142. {
  143. ButtonA = Key.Z,
  144. ButtonB = Key.X,
  145. ButtonX = Key.C,
  146. ButtonY = Key.V,
  147. ButtonPlus = Key.Plus,
  148. ButtonR = Key.U,
  149. ButtonZr = Key.O,
  150. ButtonSl = Key.Unbound,
  151. ButtonSr = Key.Unbound
  152. },
  153. RightJoyconStick = new JoyconConfigKeyboardStick<Key>
  154. {
  155. StickUp = Key.I,
  156. StickDown = Key.K,
  157. StickLeft = Key.J,
  158. StickRight = Key.L,
  159. StickButton = Key.H,
  160. }
  161. };
  162. }
  163. else
  164. {
  165. bool isNintendoStyle = gamepadName.Contains("Nintendo");
  166. config = new StandardControllerInputConfig
  167. {
  168. Version = InputConfig.CurrentVersion,
  169. Backend = InputBackendType.GamepadSDL2,
  170. Id = null,
  171. ControllerType = ControllerType.JoyconPair,
  172. DeadzoneLeft = 0.1f,
  173. DeadzoneRight = 0.1f,
  174. RangeLeft = 1.0f,
  175. RangeRight = 1.0f,
  176. TriggerThreshold = 0.5f,
  177. LeftJoycon = new LeftJoyconCommonConfig<ConfigGamepadInputId>
  178. {
  179. DpadUp = ConfigGamepadInputId.DpadUp,
  180. DpadDown = ConfigGamepadInputId.DpadDown,
  181. DpadLeft = ConfigGamepadInputId.DpadLeft,
  182. DpadRight = ConfigGamepadInputId.DpadRight,
  183. ButtonMinus = ConfigGamepadInputId.Minus,
  184. ButtonL = ConfigGamepadInputId.LeftShoulder,
  185. ButtonZl = ConfigGamepadInputId.LeftTrigger,
  186. ButtonSl = ConfigGamepadInputId.Unbound,
  187. ButtonSr = ConfigGamepadInputId.Unbound,
  188. },
  189. LeftJoyconStick = new JoyconConfigControllerStick<ConfigGamepadInputId, ConfigStickInputId>
  190. {
  191. Joystick = ConfigStickInputId.Left,
  192. StickButton = ConfigGamepadInputId.LeftStick,
  193. InvertStickX = false,
  194. InvertStickY = false,
  195. Rotate90CW = false,
  196. },
  197. RightJoycon = new RightJoyconCommonConfig<ConfigGamepadInputId>
  198. {
  199. ButtonA = isNintendoStyle ? ConfigGamepadInputId.A : ConfigGamepadInputId.B,
  200. ButtonB = isNintendoStyle ? ConfigGamepadInputId.B : ConfigGamepadInputId.A,
  201. ButtonX = isNintendoStyle ? ConfigGamepadInputId.X : ConfigGamepadInputId.Y,
  202. ButtonY = isNintendoStyle ? ConfigGamepadInputId.Y : ConfigGamepadInputId.X,
  203. ButtonPlus = ConfigGamepadInputId.Plus,
  204. ButtonR = ConfigGamepadInputId.RightShoulder,
  205. ButtonZr = ConfigGamepadInputId.RightTrigger,
  206. ButtonSl = ConfigGamepadInputId.Unbound,
  207. ButtonSr = ConfigGamepadInputId.Unbound,
  208. },
  209. RightJoyconStick = new JoyconConfigControllerStick<ConfigGamepadInputId, ConfigStickInputId>
  210. {
  211. Joystick = ConfigStickInputId.Right,
  212. StickButton = ConfigGamepadInputId.RightStick,
  213. InvertStickX = false,
  214. InvertStickY = false,
  215. Rotate90CW = false,
  216. },
  217. Motion = new StandardMotionConfigController
  218. {
  219. MotionBackend = MotionInputBackendType.GamepadDriver,
  220. EnableMotion = true,
  221. Sensitivity = 100,
  222. GyroDeadzone = 1,
  223. },
  224. Rumble = new RumbleConfigController
  225. {
  226. StrongRumble = 1f,
  227. WeakRumble = 1f,
  228. EnableRumble = false
  229. }
  230. };
  231. }
  232. }
  233. else
  234. {
  235. string profileBasePath;
  236. if (isKeyboard)
  237. {
  238. profileBasePath = Path.Combine(AppDataManager.ProfilesDirPath, "keyboard");
  239. }
  240. else
  241. {
  242. profileBasePath = Path.Combine(AppDataManager.ProfilesDirPath, "controller");
  243. }
  244. string path = Path.Combine(profileBasePath, inputProfileName + ".json");
  245. if (!File.Exists(path))
  246. {
  247. Logger.Error?.Print(LogClass.Application, $"Input profile \"{inputProfileName}\" not found for \"{inputId}\"");
  248. return null;
  249. }
  250. try
  251. {
  252. using (Stream stream = File.OpenRead(path))
  253. {
  254. config = JsonHelper.Deserialize<InputConfig>(stream);
  255. }
  256. }
  257. catch (JsonException)
  258. {
  259. Logger.Error?.Print(LogClass.Application, $"Input profile \"{inputProfileName}\" parsing failed for \"{inputId}\"");
  260. return null;
  261. }
  262. }
  263. config.Id = inputId;
  264. config.PlayerIndex = index;
  265. string inputTypeName = isKeyboard ? "Keyboard" : "Gamepad";
  266. Logger.Info?.Print(LogClass.Application, $"{config.PlayerIndex} configured with {inputTypeName} \"{config.Id}\"");
  267. // If both stick ranges are 0 (usually indicative of an outdated profile load) then both sticks will be set to 1.0.
  268. if (config is StandardControllerInputConfig controllerConfig)
  269. {
  270. if (controllerConfig.RangeLeft <= 0.0f && controllerConfig.RangeRight <= 0.0f)
  271. {
  272. controllerConfig.RangeLeft = 1.0f;
  273. controllerConfig.RangeRight = 1.0f;
  274. Logger.Info?.Print(LogClass.Application, $"{config.PlayerIndex} stick range reset. Save the profile now to update your configuration");
  275. }
  276. }
  277. return config;
  278. }
  279. static void Load(Options option)
  280. {
  281. AppDataManager.Initialize(option.BaseDataDir);
  282. _virtualFileSystem = VirtualFileSystem.CreateInstance();
  283. _libHacHorizonManager = new LibHacHorizonManager();
  284. _libHacHorizonManager.InitializeFsServer(_virtualFileSystem);
  285. _libHacHorizonManager.InitializeArpServer();
  286. _libHacHorizonManager.InitializeBcatServer();
  287. _libHacHorizonManager.InitializeSystemClients();
  288. _contentManager = new ContentManager(_virtualFileSystem);
  289. _accountManager = new AccountManager(_libHacHorizonManager.RyujinxClient, option.UserProfile);
  290. _userChannelPersistence = new UserChannelPersistence();
  291. _inputManager = new InputManager(new SDL2KeyboardDriver(), new SDL2GamepadDriver());
  292. GraphicsConfig.EnableShaderCache = true;
  293. IGamepad gamepad;
  294. if (option.ListInputIds)
  295. {
  296. Logger.Info?.Print(LogClass.Application, "Input Ids:");
  297. foreach (string id in _inputManager.KeyboardDriver.GamepadsIds)
  298. {
  299. gamepad = _inputManager.KeyboardDriver.GetGamepad(id);
  300. Logger.Info?.Print(LogClass.Application, $"- {id} (\"{gamepad.Name}\")");
  301. gamepad.Dispose();
  302. }
  303. foreach (string id in _inputManager.GamepadDriver.GamepadsIds)
  304. {
  305. gamepad = _inputManager.GamepadDriver.GetGamepad(id);
  306. Logger.Info?.Print(LogClass.Application, $"- {id} (\"{gamepad.Name}\")");
  307. gamepad.Dispose();
  308. }
  309. return;
  310. }
  311. if (option.InputPath == null)
  312. {
  313. Logger.Error?.Print(LogClass.Application, "Please provide a file to load");
  314. return;
  315. }
  316. _inputConfiguration = new List<InputConfig>();
  317. _enableKeyboard = option.EnableKeyboard;
  318. _enableMouse = option.EnableMouse;
  319. void LoadPlayerConfiguration(string inputProfileName, string inputId, PlayerIndex index)
  320. {
  321. InputConfig inputConfig = HandlePlayerConfiguration(inputProfileName, inputId, index);
  322. if (inputConfig != null)
  323. {
  324. _inputConfiguration.Add(inputConfig);
  325. }
  326. }
  327. LoadPlayerConfiguration(option.InputProfile1Name, option.InputId1, PlayerIndex.Player1);
  328. LoadPlayerConfiguration(option.InputProfile2Name, option.InputId2, PlayerIndex.Player2);
  329. LoadPlayerConfiguration(option.InputProfile3Name, option.InputId3, PlayerIndex.Player3);
  330. LoadPlayerConfiguration(option.InputProfile4Name, option.InputId4, PlayerIndex.Player4);
  331. LoadPlayerConfiguration(option.InputProfile5Name, option.InputId5, PlayerIndex.Player5);
  332. LoadPlayerConfiguration(option.InputProfile6Name, option.InputId6, PlayerIndex.Player6);
  333. LoadPlayerConfiguration(option.InputProfile7Name, option.InputId7, PlayerIndex.Player7);
  334. LoadPlayerConfiguration(option.InputProfile8Name, option.InputId8, PlayerIndex.Player8);
  335. LoadPlayerConfiguration(option.InputProfileHandheldName, option.InputIdHandheld, PlayerIndex.Handheld);
  336. if (_inputConfiguration.Count == 0)
  337. {
  338. return;
  339. }
  340. // Setup logging level
  341. Logger.SetEnable(LogLevel.Debug, option.LoggingEnableDebug);
  342. Logger.SetEnable(LogLevel.Stub, !option.LoggingDisableStub);
  343. Logger.SetEnable(LogLevel.Info, !option.LoggingDisableInfo);
  344. Logger.SetEnable(LogLevel.Warning, !option.LoggingDisableWarning);
  345. Logger.SetEnable(LogLevel.Error, option.LoggingEnableError);
  346. Logger.SetEnable(LogLevel.Trace, option.LoggingEnableTrace);
  347. Logger.SetEnable(LogLevel.Guest, !option.LoggingDisableGuest);
  348. Logger.SetEnable(LogLevel.AccessLog, option.LoggingEnableFsAccessLog);
  349. if (!option.DisableFileLog)
  350. {
  351. Logger.AddTarget(new AsyncLogTargetWrapper(
  352. new FileLogTarget(ReleaseInformation.GetBaseApplicationDirectory(), "file"),
  353. 1000,
  354. AsyncLogTargetOverflowAction.Block
  355. ));
  356. }
  357. // Setup graphics configuration
  358. GraphicsConfig.EnableShaderCache = !option.DisableShaderCache;
  359. GraphicsConfig.EnableTextureRecompression = option.EnableTextureRecompression;
  360. GraphicsConfig.ResScale = option.ResScale;
  361. GraphicsConfig.MaxAnisotropy = option.MaxAnisotropy;
  362. GraphicsConfig.ShadersDumpPath = option.GraphicsShadersDumpPath;
  363. GraphicsConfig.EnableMacroHLE = !option.DisableMacroHLE;
  364. while (true)
  365. {
  366. LoadApplication(option);
  367. if (_userChannelPersistence.PreviousIndex == -1 || !_userChannelPersistence.ShouldRestart)
  368. {
  369. break;
  370. }
  371. _userChannelPersistence.ShouldRestart = false;
  372. }
  373. _inputManager.Dispose();
  374. }
  375. private static void SetupProgressHandler()
  376. {
  377. if (_emulationContext.Application.DiskCacheLoadState != null)
  378. {
  379. _emulationContext.Application.DiskCacheLoadState.StateChanged -= ProgressHandler;
  380. _emulationContext.Application.DiskCacheLoadState.StateChanged += ProgressHandler;
  381. }
  382. _emulationContext.Gpu.ShaderCacheStateChanged -= ProgressHandler;
  383. _emulationContext.Gpu.ShaderCacheStateChanged += ProgressHandler;
  384. }
  385. private static void ProgressHandler<T>(T state, int current, int total) where T : Enum
  386. {
  387. string label;
  388. switch (state)
  389. {
  390. case LoadState ptcState:
  391. label = $"PTC : {current}/{total}";
  392. break;
  393. case ShaderCacheState shaderCacheState:
  394. label = $"Shaders : {current}/{total}";
  395. break;
  396. default:
  397. throw new ArgumentException($"Unknown Progress Handler type {typeof(T)}");
  398. }
  399. Logger.Info?.Print(LogClass.Application, label);
  400. }
  401. private static WindowBase CreateWindow(Options options)
  402. {
  403. return options.GraphicsBackend == GraphicsBackend.Vulkan
  404. ? new VulkanWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableMouse, options.HideCursor)
  405. : new OpenGLWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableMouse, options.HideCursor);
  406. }
  407. private static IRenderer CreateRenderer(Options options, WindowBase window)
  408. {
  409. if (options.GraphicsBackend == GraphicsBackend.Vulkan && window is VulkanWindow vulkanWindow)
  410. {
  411. string preferredGpuId = string.Empty;
  412. if (!string.IsNullOrEmpty(options.PreferredGpuVendor))
  413. {
  414. string preferredGpuVendor = options.PreferredGpuVendor.ToLowerInvariant();
  415. var devices = VulkanRenderer.GetPhysicalDevices();
  416. foreach (var device in devices)
  417. {
  418. if (device.Vendor.ToLowerInvariant() == preferredGpuVendor)
  419. {
  420. preferredGpuId = device.Id;
  421. break;
  422. }
  423. }
  424. }
  425. return new VulkanRenderer(
  426. (instance, vk) => new SurfaceKHR((ulong)(vulkanWindow.CreateWindowSurface(instance.Handle))),
  427. vulkanWindow.GetRequiredInstanceExtensions,
  428. preferredGpuId);
  429. }
  430. else
  431. {
  432. return new OpenGLRenderer();
  433. }
  434. }
  435. private static Switch InitializeEmulationContext(WindowBase window, IRenderer renderer, Options options)
  436. {
  437. BackendThreading threadingMode = options.BackendThreading;
  438. bool threadedGAL = threadingMode == BackendThreading.On || (threadingMode == BackendThreading.Auto && renderer.PreferThreading);
  439. if (threadedGAL)
  440. {
  441. renderer = new ThreadedRenderer(renderer);
  442. }
  443. HLEConfiguration configuration = new HLEConfiguration(_virtualFileSystem,
  444. _libHacHorizonManager,
  445. _contentManager,
  446. _accountManager,
  447. _userChannelPersistence,
  448. renderer,
  449. new SDL2HardwareDeviceDriver(),
  450. options.ExpandRam ? MemoryConfiguration.MemoryConfiguration6GiB : MemoryConfiguration.MemoryConfiguration4GiB,
  451. window,
  452. options.SystemLanguage,
  453. options.SystemRegion,
  454. !options.DisableVsync,
  455. !options.DisableDockedMode,
  456. !options.DisablePtc,
  457. options.EnableInternetAccess,
  458. !options.DisableFsIntegrityChecks ? IntegrityCheckLevel.ErrorOnInvalid : IntegrityCheckLevel.None,
  459. options.FsGlobalAccessLogMode,
  460. options.SystemTimeOffset,
  461. options.SystemTimeZone,
  462. options.MemoryManagerMode,
  463. options.IgnoreMissingServices,
  464. options.AspectRatio,
  465. options.AudioVolume);
  466. return new Switch(configuration);
  467. }
  468. private static void ExecutionEntrypoint()
  469. {
  470. if (OperatingSystem.IsWindows())
  471. {
  472. _windowsMultimediaTimerResolution = new WindowsMultimediaTimerResolution(1);
  473. }
  474. DisplaySleep.Prevent();
  475. _window.Initialize(_emulationContext, _inputConfiguration, _enableKeyboard, _enableMouse);
  476. _window.Execute();
  477. _emulationContext.Dispose();
  478. _window.Dispose();
  479. if (OperatingSystem.IsWindows())
  480. {
  481. _windowsMultimediaTimerResolution?.Dispose();
  482. _windowsMultimediaTimerResolution = null;
  483. }
  484. }
  485. private static bool LoadApplication(Options options)
  486. {
  487. string path = options.InputPath;
  488. Logger.RestartTime();
  489. WindowBase window = CreateWindow(options);
  490. IRenderer renderer = CreateRenderer(options, window);
  491. _window = window;
  492. _emulationContext = InitializeEmulationContext(window, renderer, options);
  493. SetupProgressHandler();
  494. SystemVersion firmwareVersion = _contentManager.GetCurrentFirmwareVersion();
  495. Logger.Notice.Print(LogClass.Application, $"Using Firmware Version: {firmwareVersion?.VersionString}");
  496. if (Directory.Exists(path))
  497. {
  498. string[] romFsFiles = Directory.GetFiles(path, "*.istorage");
  499. if (romFsFiles.Length == 0)
  500. {
  501. romFsFiles = Directory.GetFiles(path, "*.romfs");
  502. }
  503. if (romFsFiles.Length > 0)
  504. {
  505. Logger.Info?.Print(LogClass.Application, "Loading as cart with RomFS.");
  506. _emulationContext.LoadCart(path, romFsFiles[0]);
  507. }
  508. else
  509. {
  510. Logger.Info?.Print(LogClass.Application, "Loading as cart WITHOUT RomFS.");
  511. _emulationContext.LoadCart(path);
  512. }
  513. }
  514. else if (File.Exists(path))
  515. {
  516. switch (Path.GetExtension(path).ToLowerInvariant())
  517. {
  518. case ".xci":
  519. Logger.Info?.Print(LogClass.Application, "Loading as XCI.");
  520. _emulationContext.LoadXci(path);
  521. break;
  522. case ".nca":
  523. Logger.Info?.Print(LogClass.Application, "Loading as NCA.");
  524. _emulationContext.LoadNca(path);
  525. break;
  526. case ".nsp":
  527. case ".pfs0":
  528. Logger.Info?.Print(LogClass.Application, "Loading as NSP.");
  529. _emulationContext.LoadNsp(path);
  530. break;
  531. default:
  532. Logger.Info?.Print(LogClass.Application, "Loading as Homebrew.");
  533. try
  534. {
  535. _emulationContext.LoadProgram(path);
  536. }
  537. catch (ArgumentOutOfRangeException)
  538. {
  539. Logger.Error?.Print(LogClass.Application, "The specified file is not supported by Ryujinx.");
  540. return false;
  541. }
  542. break;
  543. }
  544. }
  545. else
  546. {
  547. Logger.Warning?.Print(LogClass.Application, $"Couldn't load '{options.InputPath}'. Please specify a valid XCI/NCA/NSP/PFS0/NRO file.");
  548. _emulationContext.Dispose();
  549. return false;
  550. }
  551. Translator.IsReadyForTranslation.Reset();
  552. ExecutionEntrypoint();
  553. return true;
  554. }
  555. }
  556. }