Program.cs 27 KB

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