Пример #1
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;
                }
            }
        }
Пример #2
0
        public LaunchManagerResult LaunchGameHandlingDelaysAndTitles(BackgroundWorker worker)
        {
            var result = new LaunchManagerResult();

            if (worker.CancellationPending)
            {
                return(result);
            }

            GameLaunchResult gameLaunchResult = null;

            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();
                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);
                }
                var regex = GetGameWindowCaptionRegex();
                if (regex != null)
                {
                    IntPtr hwnd = finder.FindWindowByCaptionAndProcessId(regex, newWindow: true, processId: gameLaunchResult.ProcessId);
                    if (hwnd != IntPtr.Zero)
                    {
                        result.Hwnd = hwnd;
                        string newGameTitle = GetNewGameTitle(_launchItem);
                        if (!string.IsNullOrEmpty(newGameTitle))
                        {
                            Logger.WriteDebug("Found hwnd: " + newGameTitle);
                            finder.SetWindowTitle(hwnd, newGameTitle);
                        }
                    }
                    else
                    {
                        Logger.WriteDebug("Unable to find hwnd");
                    }
                }
            }
            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);
        }