Exemplo n.º 1
0
        private async void StartGame(string otp)
        {
            Log.Information("StartGame() called");
            try
            {
                var gateStatus = false;
                try
                {
                    gateStatus = await Task.Run(() => _game.GetGateStatus());
                }
                catch
                {
                    // ignored
                }

                #if !DEBUG
                if (!gateStatus)
                {
                    Log.Information("GateStatus is false.");
                    MessageBox.Show(
                        "Square Enix seems to be running maintenance work right now or the login server is unreachable. The game shouldn't be launched.",
                        "Error", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                    _isLoggingIn = false;

                    return;
                }
                #endif

                var gameProcess = _game.Login(LoginUsername.Text, LoginPassword.Password, otp,
                                              Settings.SteamIntegrationEnabled, Settings.AdditionalLaunchArgs, Settings.UniqueIdCacheEnabled);

                if (gameProcess == null)
                {
                    Log.Error("GameProcess was null...");
                    _isLoggingIn = false;
                    return;
                }

                var addonMgr = new AddonManager();

                try
                {
                    await Task.Run(() => addonMgr.RunAddons(gameProcess, Settings.GetAddonList().Where(x => x.IsEnabled).ToList()));
                }
                catch (Exception ex)
                {
                    new ErrorWindow(ex,
                                    "This could be caused by your antivirus, please check its logs and add any needed exclusions.",
                                    "Addons").ShowDialog();
                    _isLoggingIn = false;

                    addonMgr.StopAddons();
                }

                try
                {
                    if (Settings.IsInGameAddonEnabled())
                    {
                        await Task.Run(() =>
                        {
                            var hooks = new HooksAddon(); hooks.Setup(gameProcess); hooks.Run();
                        });
                    }
                }
                catch (Exception ex)
                {
                    new ErrorWindow(ex,
                                    "This could be caused by your antivirus, please check its logs and add any needed exclusions.",
                                    "Hooks").ShowDialog();
                    _isLoggingIn = false;

                    addonMgr.StopAddons();
                }

                this.Close();

                var watchThread = new Thread(() =>
                {
                    while (!gameProcess.HasExited)
                    {
                        gameProcess.Refresh();
                        Thread.Sleep(1);
                    }

                    Log.Information("Game has exited.");
                    addonMgr.StopAddons();
                    Environment.Exit(0);
                });
                watchThread.Start();
            }
            catch (Exception ex)
            {
                new ErrorWindow(ex, "Please also check your login information or try again.", "Login").ShowDialog();
                _isLoggingIn = false;
            }
        }
        private async void StartGame(string otp)
        {
            Log.Information("StartGame() called");
            try
            {
                var gateStatus = false;
                try
                {
                    gateStatus = await Task.Run(() => _game.GetGateStatus());
                }
                catch
                {
                    // ignored
                }

                #if !DEBUG
                if (!gateStatus)
                {
                    Log.Information("GateStatus is false.");
                    MessageBox.Show(
                        "Square Enix seems to be running maintenance work right now or the login server is unreachable. The game shouldn't be launched.",
                        "Error", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                    _isLoggingIn = false;

                    return;
                }
                #endif

                var loginResult = _game.Login(LoginUsername.Text, LoginPassword.Password, otp, SteamCheckBox.IsChecked == true, Settings.UniqueIdCacheEnabled);

                if (loginResult == null)
                {
                    Log.Information("LoginResult was null...");
                    _isLoggingIn = false;
                    return;
                }

                if (loginResult.State == XivGame.LoginState.NeedsPatch)
                {
                    /*
                     * var patcher = new Game.Patch.PatchInstaller(_game, "ffxiv");
                     * //var window = new IntegrityCheckProgressWindow();
                     * var progress = new Progress<PatchDownloadProgress>();
                     * progress.ProgressChanged += (sender, checkProgress) => Log.Verbose("PROGRESS");
                     *
                     * Task.Run(async () => await patcher.DownloadPatchesAsync(loginResult.PendingPatches, loginResult.OauthLogin.SessionId, progress)).ContinueWith(task =>
                     * {
                     *  //window.Dispatcher.Invoke(() => window.Close());
                     *  MessageBox.Show("Download OK");
                     * });
                     */
                    return;
                }

                var gameProcess = XivGame.LaunchGame(loginResult.UniqueId, loginResult.OauthLogin.Region,
                                                     loginResult.OauthLogin.MaxExpansion, Settings.SteamIntegrationEnabled,
                                                     SteamCheckBox.IsChecked == true, Settings.AdditionalLaunchArgs);

                if (gameProcess == null)
                {
                    Log.Information("GameProcess was null...");
                    _isLoggingIn = false;
                    return;
                }

                var addonMgr = new AddonManager();

                try
                {
                    var addons = Settings.GetAddonList().Where(x => x.IsEnabled).ToList();

                    addons.Add(new AddonEntry {
                        Addon = new CharacterBackupAddon()
                    });

                    if (Settings.CharacterSyncEnabled)
                    {
                        addons.Add(new AddonEntry {
                            Addon = new CharacterSyncAddon()
                        });
                    }

                    await Task.Run(() => addonMgr.RunAddons(gameProcess, addons));
                }
                catch (Exception ex)
                {
                    new ErrorWindow(ex,
                                    "This could be caused by your antivirus, please check its logs and add any needed exclusions.",
                                    "Addons").ShowDialog();
                    _isLoggingIn = false;

                    addonMgr.StopAddons();
                }

                try
                {
                    if (Settings.IsInGameAddonEnabled())
                    {
                        var hooks = new HooksAddon();
                        hooks.Setup(gameProcess);
                        hooks.Run();
                    }
                }
                catch (Exception ex)
                {
                    new ErrorWindow(ex,
                                    "This could be caused by your antivirus, please check its logs and add any needed exclusions.",
                                    "Hooks").ShowDialog();
                    _isLoggingIn = false;

                    addonMgr.StopAddons();
                }

                this.Close();

                var watchThread = new Thread(() =>
                {
                    while (!gameProcess.HasExited)
                    {
                        gameProcess.Refresh();
                        Thread.Sleep(1);
                    }

                    Log.Information("Game has exited.");
                    addonMgr.StopAddons();
                    Environment.Exit(0);
                });
                watchThread.Start();
            }
            catch (Exception ex)
            {
                new ErrorWindow(ex, "Please also check your login information or try again.", "Login").ShowDialog();
                _isLoggingIn = false;
            }
        }