private void LaunchUpdater()
        {
            var ticks = (uint)Environment.TickCount;
            var key   = ticks & 0xFFFF_0000;

            var argumentBuilder = new ArgumentBuilder()
                                  .Append("T", ticks.ToString())
                                  .Append("BootVersion", XivGame.GetLocalBootVer())
                                  .Append("CallerWindow", _windowHwnd.ToString())
                                  .Append("GameVersion", XivGame.GetLocalGameVer())
                                  .Append("IsSteam", "0")
                                  .Append("NextExe", Path.Combine(Settings.GamePath.FullName, "game", "ffxiv.exe"))
                                  .Append("ShowMode", "2")
                                  .Append("UserPath", _userPath);

            Debug.WriteLine($"Launching ffxivupdater with key {key}: {argumentBuilder.Build()}");

            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName  = Path.Combine(_userPath, "downloads", "ffxivupdater.exe"),
                    Arguments = argumentBuilder.BuildEncrypted(key)
                }
            };

            process.Start();
        }
Example #2
0
        public static bool CanRunDalamud(DirectoryInfo gamePath)
        {
            using (var client = new WebClient())
            {
                var versionInfoJson   = client.DownloadString(Remote + "version");
                var remoteVersionInfo = JsonConvert.DeserializeObject <HooksVersionInfo>(versionInfoJson);


                if (XivGame.GetLocalGameVer(gamePath) != remoteVersionInfo.SupportedGameVer)
                {
                    return(false);
                }
            }

            return(true);
        }
        public MainWindow(ILauncherSettingsV3 setting, string accountName)
        {
            _setting = setting;
            _game    = new XivGame(setting);

            InitializeComponent();

#if !XL_NOAUTOUPDATE
            Title += " v" + Util.GetAssemblyVersion();
#else
            Title += " " + Util.GetGitHash();
#endif

            if (!string.IsNullOrEmpty(accountName))
            {
                Properties.Settings.Default.CurrentAccount = accountName;
            }

#if XL_NOAUTOUPDATE
            Title += " - UNSUPPORTED VERSION - NO UPDATES - COULD DO BAD THINGS";
#endif

            InitializeWindow();
        }
Example #4
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.");
                    var startLauncher = MessageBox.Show(
                        "Square Enix seems to be running maintenance work right now. The game shouldn't be launched. Do you want to start the official launcher to check for patches?", "XIVLauncherLite", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;

                    if (startLauncher)
                    {
                        _setting.StartOfficialLauncher(SteamCheckBox.IsChecked == true);
                    }

                    _isLoggingIn = false;

                    return;
                }
#endif

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

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

                    // If this is an autologin, we don't want to stick around after a failed login
                    if (AutoLoginCheckBox.IsChecked == true)
                    {
                        Close();
                        Environment.Exit(0);
                    }

                    return;
                }

                if (loginResult.State != XivGame.LoginState.Ok)
                {
                    var msgBoxResult = MessageBox.Show(
                        "Your game is out of date. Please start the official launcher and update it before trying to log in. Do you want to start the official launcher?",
                        "Out of date", MessageBoxButton.YesNo, MessageBoxImage.Error);

                    if (msgBoxResult == MessageBoxResult.Yes)
                    {
                        _setting.StartOfficialLauncher(SteamCheckBox.IsChecked == true);
                    }

                    return;
                }

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

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



                this.Close();

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

                    Log.Information("Game has exited.");
                    Environment.Exit(0);
                });
                watchThread.Start();
            }
            catch (Exception ex)
            {
                new ErrorWindow(ex, "Please also check your login information or try again.", "Login").ShowDialog();
                _isLoggingIn = false;
            }
        }
Example #5
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.");
                    var startLauncher = MessageBox.Show(
                        "Square Enix seems to be running maintenance work right now. The game shouldn't be launched. Do you want to start the official launcher to check for patches?", "XIVLauncher", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;

                    if (startLauncher)
                    {
                        Util.StartOfficialLauncher(App.Settings.GamePath, SteamCheckBox.IsChecked == true);
                    }

                    _isLoggingIn = false;

                    return;
                }
#endif

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

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

                    // If this is an autologin, we don't want to stick around after a failed login
                    if (AutoLoginCheckBox.IsChecked == true)
                    {
                        Close();
                        Environment.Exit(0);
                    }

                    return;
                }

                if (loginResult.State != XivGame.LoginState.Ok)
                {
                    var msgBoxResult = MessageBox.Show(
                        "Your game is out of date. Please start the official launcher and update it before trying to log in. Do you want to start the official launcher?",
                        "Out of date", MessageBoxButton.YesNo, MessageBoxImage.Error);

                    if (msgBoxResult == MessageBoxResult.Yes)
                    {
                        Util.StartOfficialLauncher(App.Settings.GamePath, SteamCheckBox.IsChecked == true);
                    }

                    /*
                     * 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, App.Settings.SteamIntegrationEnabled,
                                                     SteamCheckBox.IsChecked == true, App.Settings.AdditionalLaunchArgs, App.Settings.GamePath, App.Settings.IsDx11, App.Settings.Language.GetValueOrDefault(ClientLanguage.English), App.Settings.EncryptArguments.GetValueOrDefault(false));

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

                this.Hide();

                var addonMgr = new AddonManager();

                try
                {
                    var addons = App.Settings.AddonList.Where(x => x.IsEnabled).Select(x => x.Addon).Cast <IAddon>().ToList();

                    if (App.Settings.InGameAddonEnabled && App.Settings.IsDx11)
                    {
                        addons.Add(new DalamudLauncher());
                    }

                    await Task.Run(() => addonMgr.RunAddons(gameProcess, App.Settings, 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();
                }

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

                    Log.Information("Game has exited.");
                    addonMgr.StopAddons();
                    Environment.Exit(0);
                });
                watchThread.Start();

                this.Close();
            }
            catch (Exception ex)
            {
                new ErrorWindow(ex, "Please also check your login information or try again.", "Login").ShowDialog();
                _isLoggingIn = false;
            }
        }
Example #6
0
        private void Run(DirectoryInfo gamePath, ClientLanguage language, Process gameProcess)
        {
            var addonDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                              "XIVLauncher", "addon", "Hooks");
            var addonExe = Path.Combine(addonDirectory, "Dalamud.Injector.exe");

            var ingamePluginPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                                "XIVLauncher", "installedPlugins");
            var defaultPluginPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                                 "XIVLauncher", "devPlugins");

            Directory.CreateDirectory(ingamePluginPath);
            Directory.CreateDirectory(defaultPluginPath);

            using (var client = new WebClient())
            {
                // GitHub requires TLS 1.2, we need to hardcode this for Windows 7
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                var versionInfoJson = client.DownloadString(Remote + "version");

                var remoteVersionInfo = JsonConvert.DeserializeObject <HooksVersionInfo>(versionInfoJson);


                if (!Mutex.TryOpenExisting(DALAMUD_MUTEX_NAME, out _))
                {
                    _openMutex = new Mutex(true, DALAMUD_MUTEX_NAME);

                    if (!File.Exists(addonExe))
                    {
                        Serilog.Log.Information("[HOOKS] Not found, redownloading");
                        Download(addonDirectory);
                    }
                    else
                    {
                        var versionInfo = FileVersionInfo.GetVersionInfo(addonExe);
                        var version     = versionInfo.ProductVersion;

                        Serilog.Log.Information("Hooks update check: local {0} remote {1}", version,
                                                remoteVersionInfo.AssemblyVersion);

                        if (!remoteVersionInfo.AssemblyVersion.StartsWith(version))
                        {
                            Download(addonDirectory);
                        }
                    }
                }

                if (XivGame.GetLocalGameVer(gamePath) != remoteVersionInfo.SupportedGameVer)
                {
                    return;
                }

                if (!File.Exists(Path.Combine(addonDirectory, "EasyHook.dll")) ||
                    !File.Exists(Path.Combine(addonDirectory, "Dalamud.dll")))
                {
                    MessageBox.Show(
                        "Could not launch the in-game addon successfully. This might be caused by your antivirus.\n To prevent this, please add an exception for the folder \"%AppData%\\XIVLauncher\\addons\".",
                        "XIVLauncher Error", MessageBoxButton.OK, MessageBoxImage.Error);

                    Directory.Delete(addonDirectory, true);
                    return;
                }

                var configPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                              "XIVLauncher", "dalamudConfig.json");

                var startInfo = new DalamudStartInfo
                {
                    Language               = language,
                    PluginDirectory        = ingamePluginPath,
                    DefaultPluginDirectory = defaultPluginPath,
                    ConfigurationPath      = configPath,
                    GameVersion            = remoteVersionInfo.SupportedGameVer
                };

                var parameters = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(startInfo)));

                var process = new Process
                {
                    StartInfo =
                    {
                        FileName  = addonExe,                                     WindowStyle      = ProcessWindowStyle.Hidden, CreateNoWindow = true,
                        Arguments = gameProcess.Id.ToString() + " " + parameters, WorkingDirectory = addonDirectory
                    }
                };

                process.Start();

                Serilog.Log.Information("Started dalamud!");

                // Reset security protocol after updating
                ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault;
            }
        }
        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 DalamudLauncher(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;
            }
        }
Example #8
0
        public void Run()
        {
            // Launcher Hooks don't work on DX9 and probably never will
            if (!Settings.IsDX11())
            {
                return;
            }

            var addonDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "XIVLauncher", "addon", "Hooks");
            var addonExe       = Path.Combine(addonDirectory, "Dalamud.Injector.exe");

            var ingamePluginPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                                "XIVLauncher", "plugins");
            var defaultPluginPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                                 "XIVLauncher", "defaultplugins");

            Directory.CreateDirectory(ingamePluginPath);

            using (var client = new WebClient())
            {
                var versionInfoJson   = client.DownloadString(REMOTE + "version");
                var remoteVersionInfo = JsonConvert.DeserializeObject <HooksVersionInfo>(versionInfoJson);

                if (!File.Exists(addonExe))
                {
                    Download(addonDirectory, defaultPluginPath);
                }
                else
                {
                    var versionInfo = FileVersionInfo.GetVersionInfo(addonExe);
                    var version     = versionInfo.ProductVersion;

                    Serilog.Log.Information("Hooks update check: local {0} remote {1}", version, remoteVersionInfo.AssemblyVersion);

                    if (!remoteVersionInfo.AssemblyVersion.StartsWith(version))
                    {
                        Download(addonDirectory, defaultPluginPath);
                    }
                }

                if (XivGame.GetLocalGameVer() != remoteVersionInfo.SupportedGameVer)
                {
                    return;
                }

                if (!File.Exists(Path.Combine(addonDirectory, "EasyHook.dll")))
                {
                    MessageBox.Show(
                        "Could not launch the in-game addon successfully. This might be caused by your antivirus.\n To prevent this, please add an exception for the folder \"%AppData%\\XIVLauncher\\addons\".",
                        "XIVLauncher Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                var dalamudConfig = new DalamudStartInfo
                {
                    Language               = Settings.GetLanguage(),
                    DiscordFeatureConfig   = Settings.DiscordFeatureConfig,
                    PluginDirectory        = ingamePluginPath,
                    DefaultPluginDirectory = defaultPluginPath,
                    OptOutMbCollection     = Settings.OptOutMbUpload
                };

                var parameters = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dalamudConfig)));

                var process = new Process
                {
                    StartInfo = { FileName = addonExe, WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, Arguments = _gameProcess.Id.ToString() + " " + parameters, WorkingDirectory = addonDirectory }
                };

                process.Start();

                Serilog.Log.Information("Started dalamud!");
            }
        }
Example #9
0
        public void Run()
        {
            // Launcher Hooks don't work on DX9 and probably never will
            if (!Settings.IsDX11())
            {
                return;
            }

            var addonDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "XIVLauncher", "addon", "Hooks");
            var addonExe       = Path.Combine(addonDirectory, "Dalamud.Injector.exe");

            var ingamePluginPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                                "XIVLauncher", "plugins");
            var defaultPluginPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                                 "XIVLauncher", "defaultplugins");

            Directory.CreateDirectory(ingamePluginPath);

            using (var client = new WebClient())
            {
                var versionInfoJson   = client.DownloadString(REMOTE + "version");
                var remoteVersionInfo = JsonConvert.DeserializeObject <HooksVersionInfo>(versionInfoJson);

                if (!File.Exists(addonExe))
                {
                    Download(addonDirectory, defaultPluginPath);
                }
                else
                {
                    var versionInfo = FileVersionInfo.GetVersionInfo(addonExe);
                    var version     = versionInfo.ProductVersion;

                    Serilog.Log.Information("Hooks update check: local {0} remote {1}", version, remoteVersionInfo.AssemblyVersion);

                    if (!remoteVersionInfo.AssemblyVersion.StartsWith(version))
                    {
                        Download(addonDirectory, defaultPluginPath);
                    }
                }

                if (XivGame.GetLocalGameVer() != remoteVersionInfo.SupportedGameVer)
                {
                    return;
                }

                var dalamudConfig = new DalamudStartInfo
                {
                    Language               = Settings.GetLanguage(),
                    DiscordFeatureConfig   = Settings.DiscordFeatureConfig,
                    PluginDirectory        = ingamePluginPath,
                    DefaultPluginDirectory = defaultPluginPath
                };

                var parameters = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dalamudConfig)));

                var process = new Process
                {
                    StartInfo = { FileName = addonExe, WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, Arguments = _gameProcess.Id.ToString() + " " + parameters, WorkingDirectory = addonDirectory }
                };

                process.Start();

                Serilog.Log.Information("Started dalamud!");
            }
        }
 public PatchInstaller(XivGame game, string repository)
 {
     _game = game;
 }