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()) { Started?.Invoke(null, new GameStartedArgs(properties, mode)); if (mode == GameMode.Race) { properties.SetAdditional(new RaceCommandExecutor(properties)); properties.SetAdditional(new DBoxIntegration()); 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; } if (mode == GameMode.Replay) { await PrepareReplay(properties, ui, cancellationToken); } ui.OnProgress("Loading data for Custom Shaders Patch…"); var trackId = string.IsNullOrWhiteSpace(properties.BasicProperties?.TrackConfigurationId) ? properties.BasicProperties?.TrackId : properties.BasicProperties?.TrackId + @"/" + properties.BasicProperties?.TrackConfigurationId; await PatchTracksDataUpdater.Instance.TriggerAutoLoadAsync(trackId); await PatchTracksVaoDataUpdater.Instance.TriggerAutoLoadAsync(trackId); await PatchBackgroundDataUpdater.Instance.TriggerAutoLoadAsync(trackId); await PatchCarsDataUpdater.Instance.TriggerAutoLoadAsync(properties.BasicProperties?.CarId); result = await Game.StartAsync(CreateStarter(properties), properties, new ProgressHandler(ui), cancellationToken); } Logging.Write($"Result: {result?.GetDescription() ?? @"<NULL>"}"); if (ui.CancellationToken.IsCancellationRequested) { ui.OnError(new UserCancelledException()); return(null); } var whatsGoingOn = mode != GameMode.Race || result == null?AcLogHelper.TryToDetermineWhatsGoingOn() : null; if (whatsGoingOn != null) { properties.SetAdditional(whatsGoingOn); } if (mode == GameMode.Race) { 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.IsCancelled()) { // 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; } } }
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; } } }
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 { FileUtils.TryToDelete(AcPaths.GetLogFilename()); Game.Result result; using (ReplaysExtensionSetter.OnlyNewIfEnabled()) using (ScreenshotsConverter.OnlyNewIfEnabled()) { Started?.Invoke(null, new GameStartedArgs(properties, mode)); if (mode == GameMode.Race) { properties.SetAdditional(new RaceCommandExecutor(properties)); properties.SetAdditional(new DBoxIntegration()); 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; } if (mode == GameMode.Replay) { await PrepareReplay(properties, ui, cancellationToken); } if (SettingsHolder.Drive.LoadPatchDataAutomatically && PatchHelper.IsActive()) { var trackId = string.IsNullOrWhiteSpace(properties.BasicProperties?.TrackConfigurationId) ? properties.BasicProperties?.TrackId : properties.BasicProperties?.TrackId + @"/" + properties.BasicProperties?.TrackConfigurationId; using (var cancellation = new CancellationTokenSource()) { ui.OnProgress("Loading data for Custom Shaders Patch…", AsyncProgressEntry.Indetermitate, () => { cancellation.Cancel(); }); var carName = properties.BasicProperties?.CarId == null ? null : CarsManager.Instance.GetById(properties.BasicProperties?.CarId); var trackName = trackId == null ? null : TracksManager.Instance.GetById(trackId)?.Name ?? trackId; await PatchTracksDataUpdater.Instance.TriggerAutoLoadAsync(trackId, PatchSubProgress($"Config for track {trackName}"), cancellation.Token); await PatchTracksVaoDataUpdater.Instance.TriggerAutoLoadAsync(trackId, PatchSubProgress($"Ambient occlusion patch for track {trackName}"), cancellation.Token); await PatchBackgroundDataUpdater.Instance.TriggerAutoLoadAsync(trackId, PatchSubProgress($"Backgrounds for track {trackName}"), cancellation.Token); await PatchCarsDataUpdater.Instance.TriggerAutoLoadAsync(properties.BasicProperties?.CarId, PatchSubProgress($"Config for car {carName}"), cancellation.Token); await PatchCarsVaoDataUpdater.Instance.TriggerAutoLoadAsync(properties.BasicProperties?.CarId, PatchSubProgress($"Ambient occlusion patch for car {carName}"), cancellation.Token); ui.OnProgress("Final preparations…"); IProgress <AsyncProgressEntry> PatchSubProgress(string target) { return(new Progress <AsyncProgressEntry>(p => ui.OnProgress("Loading data for Custom Shaders Patch…", new AsyncProgressEntry($"{target}\n{p.Message ?? @"…"}", p.IsReady || p.Progress == null ? 0d : p.Progress), () => cancellation.Cancel()))); } } } result = await Game.StartAsync(CreateStarter(properties), properties, new ProgressHandler(ui), cancellationToken); } Logging.Write($"Result: {result?.GetDescription() ?? @"<NULL>"}"); if (ui.CancellationToken.IsCancellationRequested) { ui.OnError(new UserCancelledException()); return(null); } var whatsGoingOn = mode != GameMode.Race || result == null?AcLogHelper.TryToDetermineWhatsGoingOn() : null; if (whatsGoingOn != null) { properties.SetAdditional(whatsGoingOn); } if (mode == GameMode.Race) { 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.IsCancelled()) { // 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; } } }
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; } } }