private void LoadStatusSymbols()
 {
     _SessionStatusNone     = ConfigSettings.GetConfigString("SessionStatusNone", "🎻");
     _SessionStatusStarting = ConfigSettings.GetConfigString("SessionStatusStarting", "=");
     _SessionStatusRunning  = ConfigSettings.GetConfigString("SessionStatusRunning", "✔");
     _SessionStatusWarning  = ConfigSettings.GetConfigString("SessionStatusWarning", "☔");
 }
Example #2
0
        private static Regex GetGameWindowCaptionRegex()
        {
            string gameCaptionPattern = ConfigSettings.GetConfigString("GameCaptionPattern", null);

            if (gameCaptionPattern != null)
            {
                var regex = new System.Text.RegularExpressions.Regex(gameCaptionPattern);
                return(regex);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        private void LookForGameWindow(GameSession session)
        {
            var    finder = new ThwargUtils.WindowFinder();
            IntPtr hwnd   = finder.FindWindowByCaptionAndProcessId(regex: null, newWindow: false, processId: session.ProcessId);

            if (hwnd != (IntPtr)0)
            {
                // Only save hwnd if window has been renamed, meaning launch completed
                string gameCaptionPattern = ConfigSettings.GetConfigString("GameCaptionPattern", null);
                string caption            = ThwargUtils.WindowFinder.GetWindowTextString(hwnd);
                if (caption != gameCaptionPattern)
                {
                    session.WindowHwnd = hwnd;
                }
            }
        }
 private string GetNewGameTitle(LaunchItem launchItem)
 {
     if (launchItem.CharacterSelected == "None")
     {
         string pattern = ConfigSettings.GetConfigString("NewGameTitleNoChar", "");
         pattern = pattern.Replace("%ACCOUNT%", launchItem.AccountName);
         pattern = pattern.Replace("%SERVER%", launchItem.ServerName);
         return(pattern);
     }
     else
     {
         string pattern = ConfigSettings.GetConfigString("NewGameTitle", "");
         pattern = pattern.Replace("%ACCOUNT%", launchItem.AccountName);
         pattern = pattern.Replace("%SERVER%", launchItem.ServerName);
         pattern = pattern.Replace("%CHARACTER%", launchItem.CharacterSelected);
         return(pattern);
     }
 }
Example #5
0
        private string GetNewGameTitle(LaunchItem launchItem)
        {
            string pattern = ConfigSettings.GetConfigString("NewGameTitle", "");

            if (launchItem.CharacterSelected == "None")
            {
                pattern = ConfigSettings.GetConfigString("NewGameTitleNoChar", "");
            }
            string alias = launchItem.Alias;

            if (string.IsNullOrEmpty(alias))
            {
                alias = launchItem.AccountName;
            }                                                                    // fall back to account if no alias
            pattern = pattern.Replace("%ALIAS%", alias);
            pattern = pattern.Replace("%ACCOUNT%", launchItem.AccountName);
            pattern = pattern.Replace("%SERVER%", launchItem.ServerName);
            if (launchItem.CharacterSelected != "None")
            {
                pattern = pattern.Replace("%CHARACTER%", launchItem.CharacterSelected);
            }
            return(pattern);
        }
        public LaunchManagerResult LaunchGameHandlingDelaysAndTitles(BackgroundWorker worker)
        {
            var result = new LaunchManagerResult();

            if (worker.CancellationPending)
            {
                return(result);
            }
            DateTime lastLaunchUtc = (_accountLaunchTimes.ContainsKey(_launchItem.AccountName)
                                       ? _accountLaunchTimes[_launchItem.AccountName]
                                       : DateTime.MinValue);
            // Add a 5 second delay before launching the same account. EMU servers won't have cross-server timouts like Live servers did.
            TimeSpan         delay            = new TimeSpan(0, 0, 5) - (DateTime.UtcNow - lastLaunchUtc);
            GameLaunchResult gameLaunchResult = null;

            while (delay.TotalMilliseconds > 0)
            {
                if (worker.CancellationPending)
                {
                    return(result);
                }
                string context = string.Format("Waiting {0} sec", (int)delay.TotalSeconds + 1);
                ReportStatus(context, _launchItem);

                System.Threading.Thread.Sleep(1000);
                delay = new TimeSpan(0, 0, 5) - (DateTime.UtcNow - lastLaunchUtc);
            }

            ReportStatus("Launching", _launchItem);
            _accountLaunchTimes[_launchItem.AccountName] = DateTime.UtcNow;

            var launcher = new GameLauncher();

            launcher.ReportGameStatusEvent += (o) => { ReportStatus(o, _launchItem); };
            launcher.StopLaunchEvent       += (o, eventArgs) => { return(worker.CancellationPending); };
            try
            {
                var finder = new ThwargUtils.WindowFinder();
                finder.RecordExistingWindows();
                string launcherPath = GetLaunchItemLauncherLocation(_launchItem);
                OverridePreferenceFile(_launchItem.CustomPreferencePath);
                gameLaunchResult = launcher.LaunchGameClient(
                    launcherPath,
                    _launchItem.ServerName,
                    accountName: _launchItem.AccountName,
                    password: _launchItem.Password,
                    ipAddress: _launchItem.IpAndPort,
                    gameApiUrl: _launchItem.GameApiUrl,
                    loginServerUrl: _launchItem.LoginServerUrl,
                    discordurl: _launchItem.DiscordUrl,
                    emu: _launchItem.EMU,
                    desiredCharacter: _launchItem.CharacterSelected,
                    rodatSetting: _launchItem.RodatSetting,
                    secureSetting: _launchItem.SecureSetting,
                    simpleLaunch: _launchItem.IsSimpleLaunch
                    );
                if (!gameLaunchResult.Success)
                {
                    return(result);
                }
                string gameCaptionPattern = ConfigSettings.GetConfigString("GameCaptionPattern", null);
                if (gameCaptionPattern != null)
                {
                    var    regex = new System.Text.RegularExpressions.Regex(gameCaptionPattern);
                    IntPtr hwnd  = finder.FindNewWindow(regex);
                    if (hwnd != IntPtr.Zero)
                    {
                        string newGameTitle = GetNewGameTitle(_launchItem);
                        if (!string.IsNullOrEmpty(newGameTitle))
                        {
                            finder.SetWindowTitle(hwnd, newGameTitle);
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                ReportStatus("Exception launching game launcher: " + exc.Message, _launchItem);
                return(result);
            }
            if (gameLaunchResult != null && gameLaunchResult.Success)
            {
                result.Success   = true;
                result.ProcessId = gameLaunchResult.ProcessId;
            }
            return(result);
        }