コード例 #1
0
        private void btnSaveInput_Click(object sender, EventArgs e)
        {
            string launcherText = File.ReadAllText(Launcher.rootDir + "launcher.cfg");

            string[] launcherCfgLines = File.ReadAllLines(Launcher.rootDir + "launcher.cfg");
            string   cfgText          = File.ReadAllText(Launcher.rootDir + "nulldc-1-0-4-en-win\\nullDC.cfg");

            string[] cfgLines = File.ReadAllLines(Launcher.rootDir + "nulldc-1-0-4-en-win\\nullDC.cfg");

            if (chkCustomCFG.Checked)
            {
                if (!launcherText.Contains("custom_cfg"))
                {
                    launcherText += "custom_cfg=1" + Environment.NewLine;
                }
                else
                {
                    launcherText = launcherText.Replace("custom_cfg=0", "custom_cfg=1");
                }
            }
            else
            {
                if (!launcherText.Contains("custom_cfg"))
                {
                    launcherText += "custom_cfg=0" + Environment.NewLine;
                }
                else
                {
                    launcherText = launcherText.Replace("custom_cfg=1", "custom_cfg=0");
                }
            }


            if (chkEnableMapper.Checked)
            {
                launcherText = launcherText.Replace("enable_mapper=0", "enable_mapper=1");
                launcherText = launcherText.Replace("player1=joy1", "player1=keyboard");

                var player1_old = cfgLines.Where(s => s.Contains("player1=")).ToList().First();
                cfgText = cfgText.Replace(player1_old, "player1=keyboard");

                foreach (GamePadMapping mapping in Launcher.mappings.GamePadMappings)
                {
                    mapping.Default = false;
                }

                ((GamePadMapping)cboGamePadMappings.SelectedValue).Default = true;

                Launcher.ActiveGamePadMapping = (GamePadMapping)cboGamePadMappings.SelectedValue;

                var path = Launcher.rootDir + "//GamePadMappingList.xml";
                System.Xml.Serialization.XmlSerializer serializer =
                    new System.Xml.Serialization.XmlSerializer(typeof(GamePadMappingList));
                StreamWriter writer = new StreamWriter(path);
                serializer.Serialize(writer.BaseStream, Launcher.mappings);
                writer.Close();

                NetplayLaunchForm.StopMapper(true);
                NetplayLaunchForm.StartMapper();
            }
            else
            {
                launcherText = launcherText.Replace("enable_mapper=1", "enable_mapper=0");
                if (cboPlayer1.SelectedValue.ToString() == "joy1")
                {
                    launcherText = launcherText.Replace("player1=keyboard", "player1=joy1");
                }
                var player1_old = cfgLines.Where(s => s.Contains("player1=")).ToList().First();
                cfgText = cfgText.Replace(player1_old, "player1=joy1");

                NetplayLaunchForm.StopMapper();
            }

            String p1_val = $"{cboPlayer1.SelectedValue}";

            if (p1_val.Length == 0)
            {
                p1_val = "NULL";
            }

            var    region_old = launcherCfgLines.Where(s => s.Contains("region=")).ToList().First();
            String region_val = $"{cboRegion.SelectedValue}";

            cfgText      = cfgText.Replace(player1_old, "player1=" + p1_val);
            launcherText = launcherText.Replace(player1_old, "player1=" + p1_val);
            launcherText = launcherText.Replace(region_old, "region=" + region_val);
            File.WriteAllText(Launcher.rootDir + "nulldc-1-0-4-en-win\\nullDC.cfg", cfgText);
            File.WriteAllText(Launcher.rootDir + "launcher.cfg", launcherText);

            // reload from file
            cfgLines    = File.ReadAllLines(Launcher.rootDir + "nulldc-1-0-4-en-win\\nullDC.cfg");
            player1_old = cfgLines.Where(s => s.Contains("player1=")).ToList().First();
            backup_old  = cfgLines.Where(s => s.Contains("backup=")).ToList().First();
            player2_old = cfgLines.Where(s => s.Contains("player2=")).ToList().First();

            Launcher.LoadRegionSettings();
            Launcher.RestoreFiles();

            MessageBox.Show("Main Settings Successfully Saved");
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Launcher.RestoreLauncherCfg();

            if (args.Length > 0 && args[0].StartsWith("--"))
            {
                ShowConsoleWindow();
                Dictionary <string, string> arguments = new Dictionary <string, string>();
                bool              hosting             = false;
                bool              offline             = false;
                string            hostCode;
                Launcher.HostInfo hostInfo = new Launcher.HostInfo();
                hostInfo.Method = "0";
                string romPath = "";

                if (args.Length == 1 && args[0] == "--help")
                {
                    Array.Resize(ref args, args.Length + 1);
                    args[1] = "1";
                }

                for (int index = 0; index < args.Length - 1; index += 2)
                {
                    string arg = args[index].Replace("--", "");
                    if (arg == "help")
                    {
                        arguments[arg] = "1";
                    }
                    else
                    {
                        arguments[arg] = args[index + 1];
                    }
                }

                if (arguments.ContainsKey("help"))
                {
                    Console.WriteLine("--root-dir <distribution root directory>");
                    Console.WriteLine("--lst-path <path to lst file>");
                    Console.WriteLine("--gameid <game id according to games.json>");
                    Console.WriteLine("");
                    Console.WriteLine("--host-fps <max fps, 0 for uncapped>");
                    Console.WriteLine("--guest-fps <max fps, 0 for uncapped>");
                    Console.WriteLine("");
                    Console.WriteLine("--offline <0/1>");
                    Console.WriteLine("--delay <frame delay>");
                    Console.WriteLine("--host-code <code>");
                    Console.WriteLine("--hosting <0/1>");
                    Console.WriteLine("--ip <ip address>");
                    Console.WriteLine("--port <port number>");
                    Console.WriteLine("");
                    Console.WriteLine("--audio-sync (only for host)");
                    Console.WriteLine("--frame-limit (only for host)");
                    Console.WriteLine("");
                    Console.WriteLine("--controller-setup 1");
                    return;
                }

                if (arguments.ContainsKey("root-dir"))
                {
                    Launcher.rootDir = Regex.Replace(arguments["root-dir"], @"\s+", string.Empty) + "\\";
                }

                if (arguments.ContainsKey("controller-setup"))
                {
                    LoadController();
                    return;
                }

                Launcher.RestoreFiles();

                if (!arguments.ContainsKey("offline") &&
                    !arguments.ContainsKey("ip") &&
                    !arguments.ContainsKey("host-code"))
                {
                    LoadInteractive();
                    return;
                }

                if (arguments.ContainsKey("lst-path"))
                {
                    romPath = arguments["lst-path"];
                }
                else if (arguments.ContainsKey("gameid"))
                {
                    if (File.Exists(Launcher.rootDir + "games.json"))
                    {
                        // disables usa bios for fightcade launching to ensure same region on both sides
                        // will add region command line option soon
                        var us_bios_path = Path.Combine(Launcher.rootDir, "nulldc-1-0-4-en-win", "data", "naomi_boot.bin");
                        if (File.Exists(us_bios_path))
                        {
                            if (File.Exists($"{us_bios_path}.inactive"))
                            {
                                File.Delete($"{us_bios_path}.inactive");
                            }
                            File.Move(us_bios_path, $"{us_bios_path}.inactive");
                        }

                        romPath = Launcher.GetRomPathFromGameId(arguments["gameid"]);
                        if (string.IsNullOrEmpty(romPath))
                        {
                            MessageBox.Show($"Game ID '{arguments["gameid"]}' not found.\n\nPlease check your ROM directory and make sure your files match the provided games.json file.");
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please provide a valid games.json file to use the launcher from command line.");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Please enter a valid LST path (--lst-path) or Game ID (--gameid) to continue.");
                    return;
                }

                if (arguments.ContainsKey("host-fps") || arguments.ContainsKey("guest-fps"))
                {
                    string launcherCfgPath  = Launcher.rootDir + "launcher.cfg";
                    var    launcherCfgLines = File.ReadAllLines(launcherCfgPath);

                    var host_fps_old  = launcherCfgLines.Where(s => s.Contains("host_fps=")).ToList().First();
                    var guest_fps_old = launcherCfgLines.Where(s => s.Contains("guest_fps=")).ToList().First();

                    var hostFpsEntry  = host_fps_old.Split('=')[1];
                    var guestFpsEntry = guest_fps_old.Split('=')[1];

                    int host_fps  = Convert.ToInt32(hostFpsEntry);
                    int guest_fps = Convert.ToInt32(guestFpsEntry);
                    if (arguments.ContainsKey("host-fps"))
                    {
                        host_fps = Convert.ToInt32(arguments["host-fps"]);
                    }

                    if (arguments.ContainsKey("guest-fps"))
                    {
                        guest_fps = Convert.ToInt32(arguments["guest-fps"]);
                    }
                    Launcher.SaveFpsSettings(host_fps, guest_fps);
                }

                if (arguments.ContainsKey("offline"))
                {
                    offline = arguments["offline"] == "1";
                    hosting = false;

                    Launcher.CleanMalformedQjcFiles();

                    Launcher.UpdateCFGFile(
                        netplayEnabled: !offline,
                        isHost: hosting);

                    Launcher.LaunchNullDC(
                        RomPath: romPath,
                        isHost: hosting);
                }
                else
                {
                    if (arguments.ContainsKey("hosting"))
                    {
                        hosting = arguments["hosting"] == "1";
                    }

                    if (arguments.ContainsKey("audio-sync"))
                    {
                        hostInfo.Method = "1";
                        Console.WriteLine("audio sync");
                    }

                    if (arguments.ContainsKey("guess-ip"))
                    {
                        hostInfo.Delay = Launcher.GuessDelay(arguments["guess-ip"]).ToString();
                        Console.WriteLine($"Delay is set to {hostInfo.Delay}");
                    }
                    else if (arguments.ContainsKey("delay"))
                    {
                        hostInfo.Delay = arguments["delay"];
                    }
                    else if (arguments.ContainsKey("host-code"))
                    {
                        hostCode = arguments["host-code"];
                        hostInfo = Launcher.DecodeHostCode(hostCode);
                        Console.WriteLine($"Delay is set to {hostInfo.Delay}");
                    }
                    else
                    {
                        MessageBox.Show("No delay entered.");
                        return;
                    }

                    if (arguments.ContainsKey("ip"))
                    {
                        hostInfo.IP = arguments["ip"];
                    }
                    if (arguments.ContainsKey("port"))
                    {
                        hostInfo.Port = arguments["port"];
                    }

                    if (hosting)
                    {
                        var genHost = Launcher.GenerateHostCode(hostInfo.IP, hostInfo.Port, hostInfo.Delay, hostInfo.Method);
                        Console.WriteLine($"Generated Host Code: {genHost}");
                    }

                    Launcher.CleanMalformedQjcFiles();

                    Launcher.UpdateCFGFile(
                        netplayEnabled: !offline,
                        isHost: hosting,
                        hostAddress: hostInfo.IP,
                        hostPort: hostInfo.Port,
                        frameDelay: hostInfo.Delay,
                        frameMethod: hostInfo.Method);

                    Launcher.LaunchNullDC(
                        RomPath: romPath,
                        isHost: hosting);
                }

                LoadInteractive(tray: true);
            }
            else
            {
                LoadInteractive();
            }
        }
コード例 #3
0
        public NetplayLaunchForm(bool tray = false, bool controllerSetup = false)
        {
            controller = new ControllerEngine();

            launcher = new Launcher();
            presets  = ConnectionPreset.ReadPresetsFile();

            StartTray = tray;

            string launcherCfgText = "";

            try
            {
                var launcherCfgUri = new System.Uri(Path.Combine(Launcher.rootDir, @"launcher.cfg"));
                launcherCfgText = File.ReadAllText(launcherCfgUri.LocalPath);
            }
            catch (System.IO.DirectoryNotFoundException)
            {
                MessageBox.Show("launcher.cfg not found. Please enter a valid root directory.");
                System.Environment.Exit(1);
            }


            if (launcherCfgText.Contains("enable_mapper=1"))
            {
                StartMapper();
            }

            if (controllerSetup)
            {
                LaunchControllerSetup(true);
            }
            else
            {
                if (!StartTray)
                {
                    try
                    {
                        launcher.UpdateLauncher(true);
                    }
                    catch { }
                    if (!Launcher.FilesRestored)
                    {
                        Launcher.RestoreFiles();
                    }
                }

                InitializeComponent(StartTray);
                //InitializeComponent();

                if (StartTray)
                {
                    this.WindowState = FormWindowState.Minimized;
                }

                ReloadRomList();
                Launcher.LoadRegionSettings();


                if (StartTray)
                {
                    Process[] processes = Process.GetProcessesByName("nullDC_Win32_Release-NoTrace");
                    if (processes.Length > 0)
                    {
                        Process nulldcProcess = processes[0];
                        nulldcProcess.EnableRaisingEvents = true;

                        nulldcProcess.Exited += (sender, e) =>
                        {
                            Application.Exit();
                        };
                    }
                }
            }
        }