Program.cs 26 KB

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