예제 #1
0
        private bool CheckAndSetGamePath()
        {
            if (Directory.Exists(XIVGame.GamePath))
            {
                if (!File.Exists(Path.Combine(XIVGame.GamePath, "boot/ffxivboot.exe")))
                {
                    MessageBox.Show($"GamePath is a valid directory, but not the correct one. Going to reset this. {XIVGame.GamePath}", "Error", MessageBoxButton.OK);
                    XIVGame.GamePath = string.Empty;
                }
            }

            AppConfig config = new AppConfig();

            // check directory
            var appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + "ChipLauncher";

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

            // check file
            var configFile = appDataDir + Path.DirectorySeparatorChar + "settings.json";

            if (!File.Exists(configFile))
            {
                config.GamePath = XIVGame.GetFFXIVInstallPath();
                if (config.GamePath.Equals("UNKNOWN"))
                {
                    MessageBox.Show($"Unable to auto-detect install path for FFXIV. Please navigate to your ffxivboot.exe.", "Error", MessageBoxButton.OK);
                    config.GamePath = AskUserToManuallySetGamePath();
                }

                string js = JsonSerializer.Serialize(config);
                File.WriteAllText(configFile, js);
            }

            // check final game path
            string jsonStr = File.ReadAllText(configFile).Replace('\\', '/');

            config = JsonSerializer.Deserialize <AppConfig>(jsonStr);
            if (!Directory.Exists(config.GamePath))
            {
                MessageBox.Show($"Unable to detect install path for FFXIV. Please add correct path to FFXIV in settings.json at {configFile}", "Error", MessageBoxButton.OK);
                File.Delete(configFile);
                return(false);
            }

            XIVGame.GamePath = config.GamePath;
            return(true);
        }
예제 #2
0
        private void Login(CharacterData data)
        {
            if (!XIVGame.GetGateStatus())
            {
                MessageBox.Show("Square Enix seems to be running maintenance work right now. The game shouldn't be launched.", "Error", MessageBoxButton.OK);
                return;
            }

            string otp = string.Empty;

            if (data.useOtp)
            {
                OTPInputDialog inputDialog = new OTPInputDialog();
                inputDialog.ShowDialog();

                otp = inputDialog.UserInputOTPString;
                if (otp == string.Empty)
                {
                    return;
                }
            }

            try
            {
                var sid = XIVGame.GetRealSid(data.username, data.password, otp, data.isSteam);
                if (sid.Equals("BAD"))
                {
                    return;
                }

                var ffxivGame = XIVGame.LaunchGame(sid, 1, true, 0, data.isSteam);
                if (ffxivGame != null)
                {
                    EscalateProcess(ffxivGame, data.cpuIds, data.priority);
                }

                App.Current.Shutdown();
            }
            catch (Exception exc)
            {
                MessageBox.Show("Logging in failed, check your login information or try again.\n" + exc.Message, "Error", MessageBoxButton.OK);
            }
        }
        private async void LoginAsync()
        {
            Settings.Instance.Save();

#if !DEBUG
            if (!this.Config.ExistGame)
            {
                MessageBox.Show(
                    "FFXIV not found.\nPlease setup options. [Options] -> [Game Path]",
                    "Not Avalable",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);

                return;
            }

            var stat = await Task.Run(() => XIVGame.GetGateStatus());

            if (!stat)
            {
                MessageBox.Show(
                    "SQUARE ENIX seems to be running maintenance work right now.\nThe game shouldn't be launched.",
                    "Login failed",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);

                return;
            }
#endif

            try
            {
                var kicked = false;

                foreach (var tool in Models.Settings.Instance.ToolSettings)
                {
                    tool.IsRunning = false;
                }

                // ツールを起動する
                await Task.Run(() =>
                {
                    foreach (var tool in Models.Settings.Instance.ToolSettings
                             .Where(x =>
                                    x.IsEnabled &&
                                    !x.IsPostProcess)
                             .OrderBy(x => x.Priority))
                    {
                        if (tool.Run())
                        {
                            kicked = true;
                            Thread.Sleep(TimeSpan.FromSeconds(0.5));
                        }

                        tool.IsRunning = true;
                    }
                });

                if (kicked)
                {
                    await Task.Delay(TimeSpan.FromSeconds(Settings.Instance.DelayLaunchFFXIV));
                }

#if !DEBUG
                // FFXIVを起動する
                await Task.Run(() =>
                               XIVGame.LaunchGame(
                                   XIVGame.GetRealSid(
                                       this.Config.SavedID,
                                       this.Config.SavedPW,
                                       this.Config.OnetimePassword),
                                   (int)this.Config.Language,
                                   this.Config.IsDX11,
                                   this.Config.UseSteam,
                                   (int)this.Config.ExpansionLevel));
#else
                Debug.WriteLine("●FFXIV Started");
#endif
                var ffxivStartedTime = DateTime.Now;

                // ポストプロセスツールを起動する
                await Task.Run(() =>
                {
                    var posts =
                        from x in Models.Settings.Instance.ToolSettings
                        where
                        x.IsEnabled &&
                        x.IsPostProcess
                        orderby
                        x.Delay,
                    x.Priority
                    select
                    x;

                    var startTime = DateTime.Now;
                    while ((DateTime.Now - startTime).TotalMinutes <= 5.0)
                    {
                        foreach (var tool in posts)
                        {
                            if (DateTime.Now >= ffxivStartedTime.AddSeconds(tool.Delay))
                            {
                                tool.Run();
                                tool.IsRunning = true;
                            }
                        }

                        if (!posts.Any(x => !x.IsRunning))
                        {
                            break;
                        }

                        Thread.Sleep(TimeSpan.FromSeconds(0.05));
                    }
                });

                // 起動したら終わる
                await Task.Delay(TimeSpan.FromSeconds(0.5));

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "Logging in failed, check your login information or try again.\n\n" + ex,
                    "Login failed",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }
        }
        private async void MainView_Loaded(
            object sender,
            RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(this.Config.SavedID))
            {
                this.IDTextBox.Focusable = true;
                this.IDTextBox.Focus();
            }
            else
            {
                this.OTPTextBox.Focusable = true;
                this.OTPTextBox.Focus();
            }

            if (!this.IsActive)
            {
                this.Activate();
            }

            if (!this.Config.ExistGame)
            {
                MessageBox.Show(
                    @"You will now be asked to select the path your game is installed in." + Environment.NewLine +
                    @"It should contain the folders ""game"" and ""boot"".",
                    "Select Game Path",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);

                var fsd = new FolderSelectDialog();
                fsd.Title = "Choose your game path";

                if (fsd.ShowDialog(new WindowInteropHelper(this).Handle))
                {
                    this.Config.GamePath = fsd.FileName;
                }
            }

            if (this.Config.AutoLogin &&
                !SettingsHelper.IsAdministrator() &&
                this.CanExecute())
            {
                var stat = await Task.Run(() => XIVGame.GetGateStatus());

                if (!stat)
                {
                    MessageBox.Show(
                        "SQUARE ENIX seems to be running maintenance work right now.\nThe game shouldn't be launched.",
                        "Login failed",
                        MessageBoxButton.OK,
                        MessageBoxImage.Information);

                    this.Config.AutoLogin = false;
                    Settings.Instance.Save();

                    return;
                }

                try
                {
                    await Task.Run(() =>
                                   XIVGame.LaunchGame(
                                       XIVGame.GetRealSid(
                                           this.Config.SavedID,
                                           this.Config.SavedPW,
                                           this.Config.OnetimePassword),
                                       (int)this.Config.Language,
                                       this.Config.IsDX11,
                                       this.Config.UseSteam,
                                       (int)this.Config.ExpansionLevel));

                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        "Logging in failed, check your login information or try again.\n\n" + ex,
                        "Login failed",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
        }
예제 #5
0
        public void Run(Process gameProcess)
        {
            // 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
                {
                    LanguageId             = (int)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 }
                };

                Serilog.Log.Information("Starting dalamud with parameters: {0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);

                process.Start();
            }
        }