示例#1
0
        private static IAcsStarter CreateStarter(Game.StartProperties properties)
        {
            var starter = AcsStarterFactory.Create();

            if (SettingsHolder.Drive.PatchAcToDisableShadows && AcShadowsPatcher.IsSupposedToWork())
            {
                properties.SetAdditional(new AcShadowsPatcher(starter));
            }

            return(starter);
        }
示例#2
0
        private static async Task <Game.Result> StartAsync_NoUi(Game.StartProperties properties, GameMode mode)
        {
            using (ReplaysExtensionSetter.OnlyNewIfEnabled())
                using (ScreenshotsConverter.OnlyNewIfEnabled()) {
                    if (mode == GameMode.Race)
                    {
                        properties.SetAdditional(new RaceCommandExecutor(properties));
                    }
                    else if (mode == GameMode.Replay)
                    {
                        properties.SetAdditional(new ReplayCommandExecutor(properties));
                    }

                    return(await Game.StartAsync(AcsStarterFactory.Create(), properties, null, CancellationToken.None));
                }
        }
示例#3
0
        private static async Task <Game.Result> StartAsync(Game.StartProperties properties, bool raceMode)
        {
            AcSettingsHolder.Graphics.FixShadowMapBias();

            if (SettingsHolder.Drive.CopyFilterToSystemForOculus && AcSettingsHolder.Video.CameraMode.Id == "OCULUS")
            {
                properties.SetAdditional(new CopyFilterToSystemForOculusHelper());
            }

            if (SettingsHolder.Common.FixResolutionAutomatically)
            {
                AcSettingsHolder.Video.EnsureResolutionIsCorrect();
            }

            if (SettingsHolder.Drive.WeatherSpecificClouds)
            {
                properties.SetAdditional(new WeatherSpecificCloudsHelper());
            }

            if (SettingsHolder.Drive.WeatherSpecificTyreSmoke)
            {
                properties.SetAdditional(new WeatherSpecificTyreSmokeHelper());
            }

            if (SettingsHolder.Live.RsrEnabled && SettingsHolder.Live.RsrDisableAppAutomatically)
            {
                PrepareRaceModeRsr(properties);
            }

            if (SettingsHolder.Drive.SidekickIntegration && properties.BasicProperties?.CarId != null)
            {
                SidekickHelper.UpdateSidekickDatabase(properties.BasicProperties.CarId);
            }

            properties.SetAdditional(new WeatherSpecificVideoSettingsHelper());
            properties.SetAdditional(new ModeSpecificPresetsHelper());
            properties.SetAdditional(new CarSpecificControlsPresetHelper());

            if (raceMode)
            {
                if (properties.AssistsProperties == null)
                {
                    properties.AssistsProperties = _defaultAssistsFactory?.Create();
                }

                PrepareRaceModeImmediateStart(properties);
                PrepareRaceDriverName(properties);

                Logging.Write("Assists: " + properties.AssistsProperties?.GetDescription());
            }

            if (_uiFactory == null)
            {
                using (ReplaysExtensionSetter.OnlyNewIfEnabled())
                    using (ScreenshotsConverter.OnlyNewIfEnabled()) {
                        if (raceMode)
                        {
                            properties.SetAdditional(new RaceCommandExecutor(properties));
                        }
                        else
                        {
                            properties.SetAdditional(new ReplayCommandExecutor(properties));
                        }

                        return(await Game.StartAsync(AcsStarterFactory.Create(), properties, null, CancellationToken.None));
                    }
            }

            using (var ui = _uiFactory.Create()) {
                Logging.Write($"Starting game: {properties.GetDescription()}");
                ui.Show(properties);

                CancellationTokenSource linked = null;
                IsInGame = true;

                try {
                    Game.Result result;
                    using (ReplaysExtensionSetter.OnlyNewIfEnabled())
                        using (ScreenshotsConverter.OnlyNewIfEnabled()) {
                            if (raceMode)
                            {
                                properties.SetAdditional(new RaceCommandExecutor(properties));
                                Started?.Invoke(null, new GameStartedArgs(properties));

                                if (SettingsHolder.Drive.ContinueOnEscape)
                                {
                                    properties.SetAdditional(new ContinueRaceHelper());
                                }
                            }
                            else
                            {
                                properties.SetAdditional(new ReplayCommandExecutor(properties));
                            }

                            var cancellationToken = ui.CancellationToken;

                            if (SettingsHolder.Drive.ImmediateCancel)
                            {
                                var cancelHelper = new ImmediateCancelHelper();
                                linked            = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, cancelHelper.GetCancellationToken());
                                cancellationToken = linked.Token;

                                properties.SetAdditional(cancelHelper);
                                properties.SetKeyboardListener = true;
                            }

                            result = await Game.StartAsync(AcsStarterFactory.Create(), properties, new ProgressHandler(ui), cancellationToken);
                        }

                    Logging.Write($"Result: {result?.GetDescription() ?? @"<NULL>"}");
                    if (ui.CancellationToken.IsCancellationRequested)
                    {
                        ui.OnError(new UserCancelledException());
                        return(null);
                    }

                    if (raceMode)
                    {
                        if (result == null)
                        {
                            var whatsGoingOn = AcLogHelper.TryToDetermineWhatsGoingOn();
                            if (whatsGoingOn != null)
                            {
                                properties.SetAdditional(whatsGoingOn);
                            }
                        }

                        var param = new GameEndedArgs(properties, result);
                        Ended?.Invoke(null, param);
                        /* TODO: should set result to null if param.Cancel is true? */

                        var replayHelper = new ReplayHelper(properties, result);
                        (result == null || param.Cancel ? Cancelled : Finished)?.Invoke(null, new GameFinishedArgs(properties, result));

                        ui.OnResult(result, replayHelper);
                    }
                    else
                    {
                        ui.OnResult(null, null);
                    }

                    return(result);
                } catch (TaskCanceledException) {
                    // ui.OnError(new UserCancelledException());
                    ui.OnResult(null, null);
                    return(null);
                } catch (Exception e) {
                    Logging.Warning(e);
                    ui.OnError(e);
                    return(null);
                } finally {
                    linked?.Dispose();
                    IsInGame = false;
                }
            }
        }
示例#4
0
        private static async Task <Game.Result> StartAsync_Ui(Game.StartProperties properties, GameMode mode)
        {
            using (var ui = _uiFactory.Create()) {
                Logging.Write($"Starting game: {properties.GetDescription()}");
                ui.Show(properties, mode);

                CancellationTokenSource linked = null;
                IsInGame = true;

                try {
                    Game.Result result;
                    using (ReplaysExtensionSetter.OnlyNewIfEnabled())
                        using (ScreenshotsConverter.OnlyNewIfEnabled()) {
                            if (mode == GameMode.Race)
                            {
                                properties.SetAdditional(new RaceCommandExecutor(properties));
                                Started?.Invoke(null, new GameStartedArgs(properties));

                                if (SettingsHolder.Drive.ContinueOnEscape)
                                {
                                    properties.SetAdditional(new ContinueRaceHelper());
                                }
                            }
                            else if (mode == GameMode.Replay)
                            {
                                properties.SetAdditional(new ReplayCommandExecutor(properties));
                            }

                            var cancellationToken = ui.CancellationToken;

                            if (SettingsHolder.Drive.ImmediateCancel)
                            {
                                var cancelHelper = new ImmediateCancelHelper();
                                linked            = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, cancelHelper.GetCancellationToken());
                                cancellationToken = linked.Token;

                                properties.SetAdditional(cancelHelper);
                                properties.SetKeyboardListener = true;
                            }

                            result = await Game.StartAsync(AcsStarterFactory.Create(), properties, new ProgressHandler(ui), cancellationToken);
                        }

                    Logging.Write($"Result: {result?.GetDescription() ?? @"<NULL>"}");
                    if (ui.CancellationToken.IsCancellationRequested)
                    {
                        ui.OnError(new UserCancelledException());
                        return(null);
                    }

                    if (mode == GameMode.Race)
                    {
                        if (result == null)
                        {
                            var whatsGoingOn = AcLogHelper.TryToDetermineWhatsGoingOn();
                            if (whatsGoingOn != null)
                            {
                                properties.SetAdditional(whatsGoingOn);
                            }
                        }

                        var param = new GameEndedArgs(properties, result);
                        Ended?.Invoke(null, param);
                        /* TODO: should set result to null if param.Cancel is true? */

                        var replayHelper = new ReplayHelper(properties, result);
                        (result == null || param.Cancel ? Cancelled : Finished)?.Invoke(null, new GameFinishedArgs(properties, result));

                        ui.OnResult(result, replayHelper);
                    }
                    else
                    {
                        ui.OnResult(null, null);
                    }

                    return(result);
                } catch (Exception e) when(e.IsCanceled())
                {
                    // ui.OnError(new UserCancelledException());
                    ui.OnResult(null, null);
                    return(null);
                } catch (Exception e) {
                    Logging.Warning(e);
                    ui.OnError(e);
                    return(null);
                } finally {
                    linked?.Dispose();
                    IsInGame = false;
                }
            }
        }