Пример #1
0
        private void ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length > 0)
            {
                MsgBox.ShowMessage(@"Game is running, you need to close it first!");
                return;
            }

            using (var form = new GameScan())
            {
                form.ShowDialog();
            }
        }
Пример #2
0
        public static async void StartGame(bool isOffline = false)
        {
            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length > 0)
            {
                MsgBox.ShowMessage(@"Game already running!");
                return;
            }

            //QuickGameScan
            if (!isOffline || InternetUtils.IsConnectedToInternet())
            {
                try
                {
                    var gameFilePath = !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath)
                        ? Program.UserConfig.GameFilesPath
                        : GameScannerManager.GetGameFilesRootPath();

                    using (var gameScannner = new GameScannerManager(gameFilePath, Program.UserConfig.IsSteamVersion))
                    {
                        await gameScannner.InitializeFromCelesteManifest();

retry:
                        if (!await gameScannner.Scan(true))
                        {
                            bool success;
                            using (var form =
                                       new MsgBoxYesNo(
                                           @"Error: Your game files are corrupted or outdated. Click ""Yes"" to run a ""Game Scan"" to fix your game files, or ""No"" to ignore the error (not recommended).")
                                   )
                            {
                                var dr = form.ShowDialog();
                                if (dr == DialogResult.OK)
                                {
                                    using (var form2 = new GameScan())
                                    {
                                        form2.ShowDialog();
                                        success = false;
                                    }
                                }
                                else
                                {
                                    success = true;
                                }
                            }
                            if (!success)
                            {
                                goto retry;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MsgBox.ShowMessage(
                        $"Warning: Error during quick scan. Error message: {ex.Message}",
                        @"Celeste Fan Project",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            //isSteam
            if (!Program.UserConfig.IsSteamVersion)
            {
                var steamApiDll = Path.Combine(Program.UserConfig.GameFilesPath, "steam_api.dll");
                if (File.Exists(steamApiDll))
                {
                    File.Delete(steamApiDll);
                }
            }

            //MpSettings
            if (!isOffline && Program.UserConfig.MpSettings != null)
            {
                if (Program.UserConfig.MpSettings.ConnectionType == ConnectionType.Wan)
                {
                    Program.UserConfig.MpSettings.PublicIp = Program.CurrentUser.Ip;

                    if (Program.UserConfig.MpSettings.PortMappingType == PortMappingType.Upnp)
                    {
                        try
                        {
                            await OpenNat.MapPortTask(1000, 1000);
                        }
                        catch (Exception)
                        {
                            Program.UserConfig.MpSettings.PortMappingType = PortMappingType.NatPunch;

                            MsgBox.ShowMessage(
                                "Error: Upnp device not found! \"UPnP Port Mapping\" has been disabled.",
                                @"Celeste Fan Project",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
Пример #3
0
        private async void Btn_Play_Click(object sender, EventArgs e)
        {
            btn_Play.Enabled = false;
            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length > 0)
            {
                MsgBox.ShowMessage(@"Game already running!");
                btn_Play.Enabled = true;
                return;
            }

            //QuickGameScan
            try
            {
                var gameFilePath = !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath)
                    ? Program.UserConfig.GameFilesPath
                    : GameScannnerApi.GetGameFilesRootPath();

                var gameScannner = new GameScannnerApi(gameFilePath, Program.UserConfig.IsSteamVersion,
                                                       Program.UserConfig.IsLegacyXLive);

retry:
                if (!await gameScannner.QuickScan())
                {
                    bool success;
                    using (var form =
                               new MsgBoxYesNo(
                                   @"Error: Your game files are corrupted or outdated. Click ""Yes"" to run a ""Game Scan"" to fix your game files, or ""No"" to ignore the error (not recommended).")
                           )
                    {
                        var dr = form.ShowDialog();
                        if (dr == DialogResult.OK)
                        {
                            using (var form2 = new GameScan())
                            {
                                form2.ShowDialog();
                                success = false;
                            }
                        }
                        else
                        {
                            success = true;
                        }
                    }
                    if (!success)
                    {
                        goto retry;
                    }
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowMessage(
                    $"Warning: Error during quick scan. Error message: {ex.Message}",
                    @"Celeste Fan Project",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            //isSteam
            if (!Program.UserConfig.IsSteamVersion)
            {
                var steamApiDll = $"{Program.UserConfig.GameFilesPath}\\steam_api.dll";
                if (File.Exists(steamApiDll))
                {
                    File.Delete(steamApiDll);
                }
            }

            //MpSettings
            try
            {
                if (Program.UserConfig.MpSettings != null)
                {
                    if (Program.UserConfig.MpSettings.IsOnline)
                    {
                        Program.UserConfig.MpSettings.PublicIp = Program.CurrentUser.Ip;

                        if (Program.UserConfig.MpSettings.AutoPortMapping)
                        {
                            var mapPortTask = OpenNat.MapPortTask(1000, 1000);
                            try
                            {
                                await mapPortTask;
                                NatDiscoverer.TraceSource.Close();
                            }
                            catch (AggregateException ex)
                            {
                                NatDiscoverer.TraceSource.Close();

                                if (!(ex.InnerException is NatDeviceNotFoundException))
                                {
                                    throw;
                                }

                                MsgBox.ShowMessage(
                                    "Error: Upnp device not found! Set \"Port mapping\" to manual in \"Mp Settings\" and configure your router.",
                                    @"Celeste Fan Project",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);

                                btn_Play.Enabled = true;

                                return;
                            }
                        }
                    }
                }
            }
            catch
            {
                MsgBox.ShowMessage(
                    "Error: Upnp device not found! Set \"Port mapping\" to manual in \"Mp Settings\" and configure your router.",
                    @"Celeste Fan Project",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);

                btn_Play.Enabled = true;

                return;
            }

            try
            {
                //Save UserConfig
                Program.UserConfig.Save(Program.UserConfigFilePath);
            }
            catch
            {
                //
            }

            try
            {
                //Launch Game
                var path = !string.IsNullOrEmpty(Program.UserConfig.GameFilesPath)
                    ? Program.UserConfig.GameFilesPath
                    : GameScannnerApi.GetGameFilesRootPath();

                if (!path.EndsWith(Path.DirectorySeparatorChar.ToString()))
                {
                    path += Path.DirectorySeparatorChar;
                }

                var spartanPath = Path.Combine(path, "Spartan.exe");

                if (!File.Exists(spartanPath))
                {
                    throw new FileNotFoundException("Spartan.exe not found!", spartanPath);
                }

                string lang;
                switch (Program.UserConfig.GameLanguage)
                {
                case GameLanguage.deDE:
                    lang = "de-DE";
                    break;

                case GameLanguage.enUS:
                    lang = "en-US";
                    break;

                case GameLanguage.esES:
                    lang = "es-ES";
                    break;

                case GameLanguage.frFR:
                    lang = "fr-FR";
                    break;

                case GameLanguage.itIT:
                    lang = "it-IT";
                    break;

                case GameLanguage.zhCHT:
                    lang = "zh-CHT";
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                try
                {
                    if (Program.UserConfig.IsDiagnosticMode)
                    {
                        var       procdumpFileName   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "procdump.exe");
                        const int maxNumOfCrashDumps = 30;
                        if (!File.Exists(procdumpFileName))
                        {
                            throw new FileNotFoundException("Diagonstic Mode requires procdump.exe (File not Found)",
                                                            procdumpFileName);
                        }

                        // First ensure that all directories are set
                        var pathToCrashDumpFolder =
                            Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                         @"Spartan\MiniDumps");

                        if (!Directory.Exists(pathToCrashDumpFolder))
                        {
                            Directory.CreateDirectory(pathToCrashDumpFolder);
                        }

                        // Check for cleanup
                        Directory.GetFiles(pathToCrashDumpFolder)
                        .OrderByDescending(File.GetLastWriteTime) // Sort by age --> old one last
                        .Skip(maxNumOfCrashDumps)                 // Skip max num crash dumps
                        .ToList()
                        .ForEach(File.Delete);                    // Remove the rest

                        var excludeExceptions = new[]
                        {
                            "E0434F4D.COM", // .NET native exception
                            "E06D7363.msc",
                            "E06D7363.PAVEEFileLoadException@@",
                            "E0434F4D.System.IO.FileNotFoundException" // .NET managed exception
                        };

                        var excludeExcpetionsCmd = string.Join(" ", excludeExceptions.Select(elem => "-fx " + elem));

                        var fullCmdArgs = "-accepteula -mm -e 1 -n 10 " + excludeExcpetionsCmd +
                                          " -g -w Spartan.exe \"" + pathToCrashDumpFolder + "\"";

                        // MsgBox.ShowMessage(fullCmd);
                        var startInfo = new ProcessStartInfo(procdumpFileName, fullCmdArgs)
                        {
                            WorkingDirectory       = path,
                            CreateNoWindow         = true,
                            UseShellExecute        = false,
                            RedirectStandardError  = true,
                            RedirectStandardOutput = true
                        };

                        Process.Start(startInfo);
                    }
                }
                catch (Exception exception)
                {
                    MsgBox.ShowMessage(
                        $"Warning: {exception.Message}",
                        @"Celeste Fan Project",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                var arg = Program.UserConfig?.MpSettings == null || Program.UserConfig.MpSettings.IsOnline
                    ? $"--email \"{Program.UserConfig.LoginInfo.Email}\"  --password \"{Program.UserConfig.LoginInfo.Password}\" --ignore_rest LauncherLang={lang} LauncherLocale=1033"
                    : $"--email \"{Program.UserConfig.LoginInfo.Email}\"  --password \"{Program.UserConfig.LoginInfo.Password}\" --online-ip \"{Program.UserConfig.MpSettings.PublicIp}\" --ignore_rest LauncherLang={lang} LauncherLocale=1033";

                Process.Start(new ProcessStartInfo(spartanPath, arg)
                {
                    WorkingDirectory = path
                });

                WindowState = FormWindowState.Minimized;
            }
            catch (Exception exception)
            {
                MsgBox.ShowMessage(
                    $"Error: {exception.Message}",
                    @"Celeste Fan Project",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            btn_Play.Enabled = true;
        }