示例#1
0
        public override PadToKey SetupCustomPadToKeyMapping(PadToKey mapping)
        {
            if (string.IsNullOrEmpty(_exename))
            {
                return(mapping);
            }

            if (Program.Controllers.Count(c => c.Config != null && c.Config.DeviceName != "Keyboard") == 0)
            {
                return(mapping);
            }

            if (mapping == null)
            {
                mapping = new PadToKeyboard.PadToKey();
            }

            var app = new PadToKeyApp();

            app.Name = _exename;

            PadToKeyInput mouseInput = new PadToKeyInput();

            mouseInput.Name = InputKey.hotkey | InputKey.start;
            mouseInput.Type = PadToKeyType.Keyboard;
            mouseInput.Key  = "(%{KILL})";
            app.Input.Add(mouseInput);
            mapping.Applications.Add(app);

            return(mapping);
        }
示例#2
0
        private static PadToKey LoadGamePadToKeyMapping(ProcessStartInfo path, PadToKey mapping)
        {
            string filePath = SystemConfig["rom"] + (Directory.Exists(SystemConfig["rom"]) ? "\\padto.keys" : ".keys");

            EvMapyKeysFile gameMapping = EvMapyKeysFile.TryLoad(filePath);

            if (gameMapping == null && SystemConfig["system"] != null)
            {
                var systemMapping = Path.Combine(Program.LocalPath, ".emulationstation", "padtokey", SystemConfig["system"] + ".keys");
                if (!File.Exists(systemMapping))
                {
                    systemMapping = Path.Combine(Program.AppConfig.GetFullPath("padtokey"), SystemConfig["system"] + ".keys");
                }

                if (File.Exists(systemMapping))
                {
                    gameMapping = EvMapyKeysFile.TryLoad(systemMapping);
                }
            }

            if (gameMapping == null || gameMapping.All(c => c == null))
            {
                return(mapping);
            }

            PadToKeyApp app = new PadToKeyApp();

            app.Name = Path.GetFileNameWithoutExtension(path.FileName).ToLower();

            int controllerIndex = 0;

            foreach (var player in gameMapping)
            {
                if (player == null)
                {
                    controllerIndex++;
                    continue;
                }

                foreach (var action in player)
                {
                    if (action.type == "mouse")
                    {
                        if (action.Triggers == null || action.Triggers.Length == 0)
                        {
                            continue;
                        }

                        if (action.Triggers.FirstOrDefault() == "joystick1")
                        {
                            PadToKeyInput mouseInput = new PadToKeyInput();
                            mouseInput.Name = InputKey.leftanalogleft;
                            mouseInput.Type = PadToKeyType.Mouse;
                            mouseInput.Code = "X";
                            app.Input.Add(mouseInput);

                            mouseInput      = new PadToKeyInput();
                            mouseInput.Name = InputKey.leftanalogup;
                            mouseInput.Type = PadToKeyType.Mouse;
                            mouseInput.Code = "Y";
                            app.Input.Add(mouseInput);
                        }
                        else if (action.Triggers.FirstOrDefault() == "joystick2")
                        {
                            PadToKeyInput mouseInput = new PadToKeyInput();
                            mouseInput.Name = InputKey.rightanalogleft;
                            mouseInput.Type = PadToKeyType.Mouse;
                            mouseInput.Code = "X";
                            app.Input.Add(mouseInput);

                            mouseInput      = new PadToKeyInput();
                            mouseInput.Name = InputKey.rightanalogup;
                            mouseInput.Type = PadToKeyType.Mouse;
                            mouseInput.Code = "Y";
                            app.Input.Add(mouseInput);
                        }

                        continue;
                    }

                    if (action.type != "key")
                    {
                        continue;
                    }

                    InputKey k;
                    if (!Enum.TryParse <InputKey>(string.Join(", ", action.Triggers.ToArray()).ToLower(), out k))
                    {
                        continue;
                    }

                    PadToKeyInput input = new PadToKeyInput();
                    input.Name            = k;
                    input.ControllerIndex = controllerIndex;

                    foreach (var target in action.Targets)
                    {
                        LinuxScanCode sc;
                        if (!Enum.TryParse <LinuxScanCode>(target.ToUpper(), out sc))
                        {
                            continue;
                        }

                        input.SetScanCode((uint)sc);
                    }

                    if (input.ScanCodes.Length > 0)
                    {
                        app.Input.Add(input);
                    }
                }

                controllerIndex++;
            }

            if (app.Input.Count > 0)
            {
                if (mapping == null)
                {
                    mapping = new PadToKey();
                }

                var existingApp = mapping.Applications.FirstOrDefault(a => a.Name == app.Name);
                if (existingApp != null)
                {
                    // Merge with existing by replacing inputs
                    foreach (var input in app.Input)
                    {
                        existingApp.Input.RemoveAll(i => i.Name == input.Name);
                        existingApp.Input.Add(input);
                    }
                }
                else
                {
                    mapping.Applications.Add(app);
                }
            }

            return(mapping);
        }
示例#3
0
        static void Main(string[] args)
        {
            SimpleLogger.Instance.Info("--------------------------------------------------------------");
            SimpleLogger.Instance.Info(Environment.CommandLine);

            try { SetProcessDPIAware(); }
            catch { }

            LocalPath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
            AppConfig = ConfigFile.FromFile(Path.Combine(LocalPath, "emulatorLauncher.cfg"));
            AppConfig.ImportOverrides(ConfigFile.FromArguments(args));

            SystemConfig = ConfigFile.LoadEmulationStationSettings(Path.Combine(Program.AppConfig.GetFullPath("home"), "es_settings.cfg"));
            SystemConfig.ImportOverrides(ConfigFile.FromArguments(args));
            SystemConfig.ImportOverrides(SystemConfig.LoadAll("global"));
            SystemConfig.ImportOverrides(SystemConfig.LoadAll(SystemConfig["system"]));
            SystemConfig.ImportOverrides(SystemConfig.LoadAll(SystemConfig["system"] + "[\"" + Path.GetFileName(SystemConfig["rom"]) + "\"]"));
            SystemConfig.ImportOverrides(ConfigFile.FromArguments(args));

            LoadControllerConfiguration(args);
            ImportShaderOverrides();

            if (!SystemConfig.isOptSet("rom"))
            {
                SimpleLogger.Instance.Error("rom not set");
                return;
            }

            if (!File.Exists(SystemConfig.GetFullPath("rom")) && !Directory.Exists(SystemConfig.GetFullPath("rom")))
            {
                SimpleLogger.Instance.Error("rom does not exist");
                return;
            }

            if (!SystemConfig.isOptSet("system"))
            {
                SimpleLogger.Instance.Error("system not set");
                return;
            }

            if (string.IsNullOrEmpty(SystemConfig["emulator"]))
            {
                SystemConfig["emulator"] = SystemDefaults.GetDefaultEmulator(SystemConfig["system"]);
            }

            if (string.IsNullOrEmpty(SystemConfig["core"]))
            {
                SystemConfig["core"] = SystemDefaults.GetDefaultCore(SystemConfig["system"]);
            }

            if (string.IsNullOrEmpty(SystemConfig["emulator"]))
            {
                SystemConfig["emulator"] = SystemConfig["system"];
            }

            Generator generator = generators.Where(g => g.Key == SystemConfig["emulator"]).Select(g => g.Value()).FirstOrDefault();

            if (generator == null && !string.IsNullOrEmpty(SystemConfig["emulator"]) && SystemConfig["emulator"].StartsWith("lr-"))
            {
                generator = new LibRetroGenerator();
            }
            if (generator == null)
            {
                generator = generators.Where(g => g.Key == SystemConfig["system"]).Select(g => g.Value()).FirstOrDefault();
            }

            if (generator != null)
            {
                using (var screenResolution = ScreenResolution.Parse(SystemConfig["videomode"]))
                {
                    ProcessStartInfo path = generator.Generate(SystemConfig["system"], SystemConfig["emulator"], SystemConfig["core"], SystemConfig["rom"], null, screenResolution);
                    if (path != null)
                    {
                        if (path.Arguments != null)
                        {
                            SimpleLogger.Instance.Info("->  " + path.FileName + " " + path.Arguments);
                        }
                        else
                        {
                            SimpleLogger.Instance.Info("->  " + path.FileName);
                        }

                        path.UseShellExecute = true;

                        if (screenResolution != null && generator.DependsOnDesktopResolution)
                        {
                            screenResolution.Apply();
                        }

                        Cursor.Position = new System.Drawing.Point(Screen.PrimaryScreen.Bounds.Right, Screen.PrimaryScreen.Bounds.Bottom / 2);

                        PadToKey mapping = null;
                        if (generator.UsePadToKey)
                        {
                            mapping = PadToKey.Load(Path.Combine(Program.AppConfig.GetFullPath("home"), "es_padtokey.cfg"));
                        }

                        mapping = LoadGamePadToKeyMapping(path, mapping);
                        mapping = generator.SetupCustomPadToKeyMapping(mapping);

                        using (new HighPerformancePowerScheme())
                            using (new JoystickListener(Controllers.Where(c => c.Config.DeviceName != "Keyboard").ToArray(), mapping))
                                generator.RunAndWait(path);
                    }
                    else
                    {
                        SimpleLogger.Instance.Error("generator failed");
                    }
                }

                generator.Cleanup();
            }
            else
            {
                SimpleLogger.Instance.Error("Can't find generator");
            }
        }