Exemplo n.º 1
0
        void launchGameFromItem(WorkerArgs args, LaunchItem launchItem, Dictionary <string, DateTime> accountLaunchTimes)
        {
            Logger.WriteDebug("launchGameFromItem on thread {0}: Account={1}, Server={2}, Char={3}",
                              Thread.CurrentThread.ManagedThreadId,
                              launchItem.AccountName, launchItem.ServerName, launchItem.CharacterSelected);
            LaunchManager mgr = new LaunchManager(args.ClientExeLocation, launchItem, accountLaunchTimes);

            mgr.ReportStatusEvent += (status, item) => FireReportLaunchItemStatusEvent(status, item);
            LaunchManager.LaunchManagerResult launchResult;
            GameSession session = null;

            try
            {
                session = _gameSessionMap.StartLaunchingSession(launchItem.ServerName, launchItem.AccountName);
                FireReportAccountStatusEvent(ServerAccountStatusEnum.Starting, launchItem);
                launchResult = mgr.LaunchGameHandlingDelaysAndTitles(_worker);
            }
            finally
            {
                _gameSessionMap.EndLaunchingSession(launchItem.ServerName, launchItem.AccountName);
            }

            if (launchResult.Success)
            {
                ++_serverIndex;
                // Let's just wait for game monitor to check if the character list changed
                // b/c the AccountManager is subscribed for that event
                //CallUiNotifyAvailableCharactersChanged(); // Pick up any characters - experimental 2017-04-10
                // CallUiLoadUserAccounts(); // Pick up any characters - before 2017-04-10
                _gameSessionMap.StartSessionWatcher(session);
                session.WindowHwnd = launchResult.Hwnd;
                // session.ProcessId is already populated
                FireReportLaunchItemStatusEvent(GameStatusNotice.CreateSuccess("Launched"), launchItem);
            }
        }
Exemplo n.º 2
0
 private void FireReportLaunchItemStatusEvent(GameStatusNotice statusNotice, LaunchItem launchItem)
 {
     if (ReportLaunchItemStatusEvent == null)
     {
         return;
     }
     ReportLaunchItemStatusEvent(statusNotice, launchItem, _serverIndex, _serverTotal);
 }
Exemplo n.º 3
0
 private void ReportStatus(GameStatusNotice statusNotice, LaunchItem launchItem)
 {
     if (ReportStatusEvent == null)
     {
         return;
     }
     ReportStatusEvent(statusNotice, launchItem);
 }
Exemplo n.º 4
0
 private void LauncherReportingLaunchItemStatusEvent(GameStatusNotice statusNotice, LaunchItem launchItem, int serverIndex, int serverTotal)
 {
     if (statusNotice.IsWrongServer)
     {
         // TODO - 2020-08-12, Need to test this
         MessageBox.Show(statusNotice.StatusText, "Wrong Server");
     }
 }
Exemplo n.º 5
0
        private void ReportGameStatusWaiting(string status)
        {
            if (ReportGameStatusEvent == null)
            {
                return;
            }
            var statusNotice = GameStatusNotice.CreateWaiting(status);

            ReportGameStatusEvent(statusNotice);
        }
Exemplo n.º 6
0
        public LaunchManagerResult LaunchGameHandlingDelaysAndTitles(BackgroundWorker worker)
        {
            var result = new LaunchManagerResult();

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

            GameLaunchResult gameLaunchResult = null;

            ReportStatus(GameStatusNotice.CreateWaiting("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)
            {
                var statusNotice = GameStatusNotice.CreateFailure("Exception launching game launcher: " + exc.Message);
                ReportStatus(statusNotice, _launchItem);
                return(result);
            }
            if (gameLaunchResult != null && gameLaunchResult.Success)
            {
                result.Success   = true;
                result.ProcessId = gameLaunchResult.ProcessId;
            }
            return(result);
        }