예제 #1
0
        /// <summary>
        /// Configures a <see cref="Switch"/> instance
        /// </summary>
        /// <param name="device">The instance to configure</param>
        public static void Configure(Switch device)
        {
            if (Instance == null)
            {
                throw new InvalidOperationException("Configuration has not been loaded yet.");
            }

            GraphicsConfig.ShadersDumpPath = Instance.GraphicsShadersDumpPath;

            Logger.AddTarget(new AsyncLogTargetWrapper(
                                 new ConsoleLogTarget(),
                                 1000,
                                 AsyncLogTargetOverflowAction.Block
                                 ));

            if (Instance.EnableFileLog)
            {
                Logger.AddTarget(new AsyncLogTargetWrapper(
                                     new FileLogTarget(Path.Combine(Program.ApplicationDirectory, "Ryujinx.log")),
                                     1000,
                                     AsyncLogTargetOverflowAction.Block
                                     ));
            }

            Logger.SetEnable(LogLevel.Debug, Instance.LoggingEnableDebug);
            Logger.SetEnable(LogLevel.Stub, Instance.LoggingEnableStub);
            Logger.SetEnable(LogLevel.Info, Instance.LoggingEnableInfo);
            Logger.SetEnable(LogLevel.Warning, Instance.LoggingEnableWarn);
            Logger.SetEnable(LogLevel.Error, Instance.LoggingEnableError);
            Logger.SetEnable(LogLevel.Guest, Instance.LoggingEnableGuest);
            Logger.SetEnable(LogLevel.AccessLog, Instance.LoggingEnableFsAccessLog);

            if (Instance.LoggingFilteredClasses.Length > 0)
            {
                foreach (var logClass in EnumExtensions.GetValues <LogClass>())
                {
                    Logger.SetEnable(logClass, false);
                }

                foreach (var logClass in Instance.LoggingFilteredClasses)
                {
                    Logger.SetEnable(logClass, true);
                }
            }

            device.System.State.DiscordIntegrationEnabled = Instance.EnableDiscordIntegration;

            device.EnableDeviceVsync = Instance.EnableVsync;

            device.System.State.DockedMode = Instance.DockedMode;

            device.System.State.SetLanguage(Instance.SystemLanguage);

            if (Instance.EnableMulticoreScheduling)
            {
                device.System.EnableMultiCoreScheduling();
            }

            device.System.FsIntegrityCheckLevel = Instance.EnableFsIntegrityChecks
                ? IntegrityCheckLevel.ErrorOnInvalid
                : IntegrityCheckLevel.None;

            device.System.GlobalAccessLogMode = Instance.FsGlobalAccessLogMode;

            if (Instance.EnableAggressiveCpuOpts)
            {
                Optimizations.AssumeStrictAbiCompliance = true;
            }

            ServiceConfiguration.IgnoreMissingServices = Instance.IgnoreMissingServices;

            if (Instance.GamepadControls.Enabled)
            {
                if (GamePad.GetName(Instance.GamepadControls.Index) == "Unmapped Controller")
                {
                    Instance.GamepadControls.SetEnabled(false);
                }
            }

            device.Hid.InitializePrimaryController(Instance.ControllerType);
            device.Hid.InitializeKeyboard();
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.Title = "Ryujinx Console";

            IGalRenderer renderer = new OglRenderer();

            IAalOutput audioOut = InitializeAudioEngine();

            Switch device = new Switch(renderer, audioOut);

            Configuration.Load(Path.Combine(ApplicationDirectory, "Config.jsonc"));
            Configuration.Configure(device);

            Profile.Initialize();

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.ProcessExit        += CurrentDomain_ProcessExit;

            if (device.System.State.DiscordIntegrationEnabled)
            {
                DiscordClient   = new DiscordRpcClient("568815339807309834");
                DiscordPresence = new RichPresence
                {
                    Assets = new Assets
                    {
                        LargeImageKey  = "ryujinx",
                        LargeImageText = "Ryujinx is an emulator for the Nintendo Switch"
                    }
                };

                DiscordClient.Initialize();
                DiscordClient.SetPresence(DiscordPresence);
            }

            if (args.Length == 1)
            {
                if (Directory.Exists(args[0]))
                {
                    string[] romFsFiles = Directory.GetFiles(args[0], "*.istorage");

                    if (romFsFiles.Length == 0)
                    {
                        romFsFiles = Directory.GetFiles(args[0], "*.romfs");
                    }

                    if (romFsFiles.Length > 0)
                    {
                        Logger.PrintInfo(LogClass.Application, "Loading as cart with RomFS.");
                        device.LoadCart(args[0], romFsFiles[0]);
                    }
                    else
                    {
                        Logger.PrintInfo(LogClass.Application, "Loading as cart WITHOUT RomFS.");
                        device.LoadCart(args[0]);
                    }
                }
                else if (File.Exists(args[0]))
                {
                    switch (Path.GetExtension(args[0]).ToLowerInvariant())
                    {
                    case ".xci":
                        Logger.PrintInfo(LogClass.Application, "Loading as XCI.");
                        device.LoadXci(args[0]);
                        break;

                    case ".nca":
                        Logger.PrintInfo(LogClass.Application, "Loading as NCA.");
                        device.LoadNca(args[0]);
                        break;

                    case ".nsp":
                    case ".pfs0":
                        Logger.PrintInfo(LogClass.Application, "Loading as NSP.");
                        device.LoadNsp(args[0]);
                        break;

                    default:
                        Logger.PrintInfo(LogClass.Application, "Loading as homebrew.");
                        device.LoadProgram(args[0]);
                        break;
                    }
                }
                else
                {
                    Logger.PrintWarning(LogClass.Application, "Please specify a valid XCI/NCA/NSP/PFS0/NRO file");
                }
            }
            else
            {
                Logger.PrintWarning(LogClass.Application, "Please specify the folder with the NSOs/IStorage or a NSO/NRO.");
            }

            if (device.System.State.DiscordIntegrationEnabled)
            {
                if (File.ReadAllLines(Path.Combine(ApplicationDirectory, "RPsupported.dat")).Contains(device.System.TitleID))
                {
                    DiscordPresence.Assets.LargeImageKey = device.System.TitleID;
                }

                string state = device.System.TitleID;

                if (state == null)
                {
                    state = "Ryujinx";
                }
                else
                {
                    state = state.ToUpper();
                }

                string details = "Idling";

                if (device.System.TitleName != null)
                {
                    details = $"Playing {device.System.TitleName}";
                }

                DiscordPresence.Details = details;
                DiscordPresence.State   = state;
                DiscordPresence.Assets.LargeImageText = device.System.TitleName;
                DiscordPresence.Assets.SmallImageKey  = "ryujinx";
                DiscordPresence.Assets.SmallImageText = "Ryujinx is an emulator for the Nintendo Switch";
                DiscordPresence.Timestamps            = new Timestamps(DateTime.UtcNow);

                DiscordClient.SetPresence(DiscordPresence);
            }

            using (GlScreen screen = new GlScreen(device, renderer))
            {
                screen.MainLoop();

                Profile.FinishProfiling();

                device.Dispose();
            }

            audioOut.Dispose();

            Logger.Shutdown();

            DiscordClient.Dispose();
        }
예제 #3
0
        public static void Read(Switch device)
        {
            string iniFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            string iniPath = Path.Combine(iniFolder, "Ryujinx.conf");

            IniParser parser = new IniParser(iniPath);

            GraphicsConfig.ShadersDumpPath = parser.Value("Graphics_Shaders_Dump_Path");

            Logger.SetEnable(LogLevel.Debug, Convert.ToBoolean(parser.Value("Logging_Enable_Debug")));
            Logger.SetEnable(LogLevel.Stub, Convert.ToBoolean(parser.Value("Logging_Enable_Stub")));
            Logger.SetEnable(LogLevel.Info, Convert.ToBoolean(parser.Value("Logging_Enable_Info")));
            Logger.SetEnable(LogLevel.Warning, Convert.ToBoolean(parser.Value("Logging_Enable_Warn")));
            Logger.SetEnable(LogLevel.Error, Convert.ToBoolean(parser.Value("Logging_Enable_Error")));

            string[] filteredLogClasses = parser.Value("Logging_Filtered_Classes").Split(',', StringSplitOptions.RemoveEmptyEntries);

            //When the classes are specified on the list, we only
            //enable the classes that are on the list.
            //So, first disable everything, then enable
            //the classes that the user added to the list.
            if (filteredLogClasses.Length > 0)
            {
                foreach (LogClass Class in Enum.GetValues(typeof(LogClass)))
                {
                    Logger.SetEnable(Class, false);
                }
            }

            foreach (string logClass in filteredLogClasses)
            {
                if (!string.IsNullOrEmpty(logClass.Trim()))
                {
                    foreach (LogClass Class in Enum.GetValues(typeof(LogClass)))
                    {
                        if (Class.ToString().ToLower().Contains(logClass.Trim().ToLower()))
                        {
                            Logger.SetEnable(Class, true);
                        }
                    }
                }
            }

            device.System.State.DockedMode = Convert.ToBoolean(parser.Value("Docked_Mode"));

            device.EnableDeviceVsync = Convert.ToBoolean(parser.Value("Enable_Vsync"));

            if (Convert.ToBoolean(parser.Value("Enable_MultiCore_Scheduling")))
            {
                device.System.EnableMultiCoreScheduling();
            }

            device.System.FsIntegrityCheckLevel = Convert.ToBoolean(parser.Value("Enable_FS_Integrity_Checks"))
                ? IntegrityCheckLevel.ErrorOnInvalid
                : IntegrityCheckLevel.None;

            HidControllerType ControllerType = Enum.Parse <HidControllerType>(parser.Value("Controller_Type"));

            device.Hid.InitilizePrimaryController(ControllerType);

            NpadKeyboard = new NpadKeyboard(

                new NpadKeyboardLeft
            {
                StickUp     = Convert.ToInt16(parser.Value("Controls_Left_JoyConKeyboard_Stick_Up")),
                StickDown   = Convert.ToInt16(parser.Value("Controls_Left_JoyConKeyboard_Stick_Down")),
                StickLeft   = Convert.ToInt16(parser.Value("Controls_Left_JoyConKeyboard_Stick_Left")),
                StickRight  = Convert.ToInt16(parser.Value("Controls_Left_JoyConKeyboard_Stick_Right")),
                StickButton = Convert.ToInt16(parser.Value("Controls_Left_JoyConKeyboard_Stick_Button")),
                DPadUp      = Convert.ToInt16(parser.Value("Controls_Left_JoyConKeyboard_DPad_Up")),
                DPadDown    = Convert.ToInt16(parser.Value("Controls_Left_JoyConKeyboard_DPad_Down")),
                DPadLeft    = Convert.ToInt16(parser.Value("Controls_Left_JoyConKeyboard_DPad_Left")),
                DPadRight   = Convert.ToInt16(parser.Value("Controls_Left_JoyConKeyboard_DPad_Right")),
                ButtonMinus = Convert.ToInt16(parser.Value("Controls_Left_JoyConKeyboard_Button_Minus")),
                ButtonL     = Convert.ToInt16(parser.Value("Controls_Left_JoyConKeyboard_Button_L")),
                ButtonZl    = Convert.ToInt16(parser.Value("Controls_Left_JoyConKeyboard_Button_ZL"))
            },

                new NpadKeyboardRight
            {
                StickUp     = Convert.ToInt16(parser.Value("Controls_Right_JoyConKeyboard_Stick_Up")),
                StickDown   = Convert.ToInt16(parser.Value("Controls_Right_JoyConKeyboard_Stick_Down")),
                StickLeft   = Convert.ToInt16(parser.Value("Controls_Right_JoyConKeyboard_Stick_Left")),
                StickRight  = Convert.ToInt16(parser.Value("Controls_Right_JoyConKeyboard_Stick_Right")),
                StickButton = Convert.ToInt16(parser.Value("Controls_Right_JoyConKeyboard_Stick_Button")),
                ButtonA     = Convert.ToInt16(parser.Value("Controls_Right_JoyConKeyboard_Button_A")),
                ButtonB     = Convert.ToInt16(parser.Value("Controls_Right_JoyConKeyboard_Button_B")),
                ButtonX     = Convert.ToInt16(parser.Value("Controls_Right_JoyConKeyboard_Button_X")),
                ButtonY     = Convert.ToInt16(parser.Value("Controls_Right_JoyConKeyboard_Button_Y")),
                ButtonPlus  = Convert.ToInt16(parser.Value("Controls_Right_JoyConKeyboard_Button_Plus")),
                ButtonR     = Convert.ToInt16(parser.Value("Controls_Right_JoyConKeyboard_Button_R")),
                ButtonZr    = Convert.ToInt16(parser.Value("Controls_Right_JoyConKeyboard_Button_ZR"))
            });

            NpadController = new NpadController(

                Convert.ToBoolean(parser.Value("GamePad_Enable")),
                Convert.ToInt32(parser.Value("GamePad_Index")),
                (float)Convert.ToDouble(parser.Value("GamePad_Deadzone"), CultureInfo.InvariantCulture),
                (float)Convert.ToDouble(parser.Value("GamePad_Trigger_Threshold"), CultureInfo.InvariantCulture),

                new NpadControllerLeft
            {
                Stick       = ToId(parser.Value("Controls_Left_JoyConController_Stick")),
                StickButton = ToId(parser.Value("Controls_Left_JoyConController_Stick_Button")),
                DPadUp      = ToId(parser.Value("Controls_Left_JoyConController_DPad_Up")),
                DPadDown    = ToId(parser.Value("Controls_Left_JoyConController_DPad_Down")),
                DPadLeft    = ToId(parser.Value("Controls_Left_JoyConController_DPad_Left")),
                DPadRight   = ToId(parser.Value("Controls_Left_JoyConController_DPad_Right")),
                ButtonMinus = ToId(parser.Value("Controls_Left_JoyConController_Button_Minus")),
                ButtonL     = ToId(parser.Value("Controls_Left_JoyConController_Button_L")),
                ButtonZl    = ToId(parser.Value("Controls_Left_JoyConController_Button_ZL"))
            },

                new NpadControllerRight
            {
                Stick       = ToId(parser.Value("Controls_Right_JoyConController_Stick")),
                StickButton = ToId(parser.Value("Controls_Right_JoyConController_Stick_Button")),
                ButtonA     = ToId(parser.Value("Controls_Right_JoyConController_Button_A")),
                ButtonB     = ToId(parser.Value("Controls_Right_JoyConController_Button_B")),
                ButtonX     = ToId(parser.Value("Controls_Right_JoyConController_Button_X")),
                ButtonY     = ToId(parser.Value("Controls_Right_JoyConController_Button_Y")),
                ButtonPlus  = ToId(parser.Value("Controls_Right_JoyConController_Button_Plus")),
                ButtonR     = ToId(parser.Value("Controls_Right_JoyConController_Button_R")),
                ButtonZr    = ToId(parser.Value("Controls_Right_JoyConController_Button_ZR"))
            });
        }
예제 #4
0
        static void Main(string[] args)
        {
            Console.Title = "Ryujinx Console";

            IGalRenderer Renderer = new OpenGLRenderer();

            IAalOutput AudioOut = new OpenALAudioOut();

            Switch Ns = new Switch(Renderer, AudioOut);

            Config.Read(Ns.Log);

            Ns.Log.Updated += ConsoleLog.PrintLog;

            if (args.Length == 1)
            {
                if (Directory.Exists(args[0]))
                {
                    string[] RomFsFiles = Directory.GetFiles(args[0], "*.istorage");

                    if (RomFsFiles.Length == 0)
                    {
                        RomFsFiles = Directory.GetFiles(args[0], "*.romfs");
                    }

                    if (RomFsFiles.Length > 0)
                    {
                        Console.WriteLine("Loading as cart with RomFS.");

                        Ns.LoadCart(args[0], RomFsFiles[0]);
                    }
                    else
                    {
                        Console.WriteLine("Loading as cart WITHOUT RomFS.");

                        Ns.LoadCart(args[0]);
                    }
                }
                else if (File.Exists(args[0]))
                {
                    Console.WriteLine("Loading as homebrew.");

                    Ns.LoadProgram(args[0]);
                }
            }
            else
            {
                Console.WriteLine("Please specify the folder with the NSOs/IStorage or a NSO/NRO.");
            }

            using (GLScreen Screen = new GLScreen(Ns, Renderer))
            {
                Ns.Finish += (Sender, Args) =>
                {
                    Screen.Exit();
                };

                Screen.Run(60.0);
            }

            Environment.Exit(0);
        }
예제 #5
0
        static void Main(string[] args)
        {
            Console.Title = "Ryujinx Console";

            IGalRenderer renderer = new OGLRenderer();

            IAalOutput audioOut = InitializeAudioEngine();

            Switch device = new Switch(renderer, audioOut);

            Config.Read(device);

            Logger.Updated += ConsoleLog.Log;

            if (args.Length == 1)
            {
                if (Directory.Exists(args[0]))
                {
                    string[] romFsFiles = Directory.GetFiles(args[0], "*.istorage");

                    if (romFsFiles.Length == 0)
                    {
                        romFsFiles = Directory.GetFiles(args[0], "*.romfs");
                    }

                    if (romFsFiles.Length > 0)
                    {
                        Console.WriteLine("Loading as cart with RomFS.");

                        device.LoadCart(args[0], romFsFiles[0]);
                    }
                    else
                    {
                        Console.WriteLine("Loading as cart WITHOUT RomFS.");

                        device.LoadCart(args[0]);
                    }
                }
                else if (File.Exists(args[0]))
                {
                    switch (Path.GetExtension(args[0]).ToLowerInvariant())
                    {
                    case ".xci":
                        Console.WriteLine("Loading as XCI.");
                        device.LoadXci(args[0]);
                        break;

                    case ".nca":
                        Console.WriteLine("Loading as NCA.");
                        device.LoadNca(args[0]);
                        break;

                    case ".nsp":
                        Console.WriteLine("Loading as NSP.");
                        device.LoadNsp(args[0]);
                        break;

                    default:
                        Console.WriteLine("Loading as homebrew.");
                        device.LoadProgram(args[0]);
                        break;
                    }
                }
            }
            else
            {
                Console.WriteLine("Please specify the folder with the NSOs/IStorage or a NSO/NRO.");
            }

            using (GlScreen screen = new GlScreen(device, renderer))
            {
                screen.MainLoop();

                device.Dispose();
            }

            audioOut.Dispose();
        }