public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode) { var comparison = Settings.Comparison; if (!state.Run.Comparisons.Contains(comparison)) { // #1682: Currently, support "Best Segments" comparison only ("Current Comparison" not supported) InternalComponent.InformationName = "Split #" + Settings.VisualCompareSplitNumber + " comparison not available"; InternalComponent.TimeValue = null; } else { if (Settings.VisualCompareSplitNumber > state.Run.Count) { InternalComponent.InformationName = "Split #" + Settings.VisualCompareSplitNumber + " not available"; InternalComponent.TimeValue = null; } else // get information for Settings.VisualCompareSplitNumber { ISegment visualCompareSplitNumberSegment = state.Run[Settings.VisualCompareSplitNumber - 1]; if (state.CurrentSplitIndex > Settings.VisualCompareSplitNumber - 1) { InternalComponent.InformationName = "Time (" + visualCompareSplitNumberSegment.Name + ")"; InternalComponent.TimeValue = visualCompareSplitNumberSegment.SplitTime[state.CurrentTimingMethod].GetValueOrDefault(); } else { InternalComponent.InformationName = "Best Possible Time (" + visualCompareSplitNumberSegment.Name + ")"; if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused) { TimeSpan?delta = LiveSplitStateHelper.GetLastDelta(state, state.CurrentSplitIndex, comparison, state.CurrentTimingMethod) ?? TimeSpan.Zero; var liveDelta = state.CurrentTime[state.CurrentTimingMethod] - state.CurrentSplit.Comparisons[comparison][state.CurrentTimingMethod]; if (liveDelta > delta) { delta = liveDelta; } InternalComponent.TimeValue = delta + visualCompareSplitNumberSegment.Comparisons[comparison][state.CurrentTimingMethod]; } else { TimeSpan?timeValue = visualCompareSplitNumberSegment.Comparisons[comparison][state.CurrentTimingMethod]; InternalComponent.TimeValue = timeValue; } } } } InternalComponent.Update(invalidator, state, width, height, mode); }
public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode) { var comparison = Settings.Comparison == "Current Comparison" ? state.CurrentComparison : Settings.Comparison; if (!state.Run.Comparisons.Contains(comparison)) { comparison = state.CurrentComparison; } var comparisonName = comparison.StartsWith("[Race] ") ? comparison.Substring(7) : comparison; if (InternalComponent.InformationName != comparisonName) { InternalComponent.AlternateNameText.Clear(); InternalComponent.AlternateNameText.Add(CompositeComparisons.GetShortComparisonName(comparison)); } InternalComponent.LongestString = comparisonName; InternalComponent.InformationName = comparisonName; var useLiveDelta = false; if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused) { TimeSpan?delta = LiveSplitStateHelper.GetLastDelta(state, state.CurrentSplitIndex, comparison, state.CurrentTimingMethod); var liveDelta = state.CurrentTime[state.CurrentTimingMethod] - state.CurrentSplit.Comparisons[comparison][state.CurrentTimingMethod]; if (liveDelta > delta || (delta == null && liveDelta > TimeSpan.Zero)) { delta = liveDelta; useLiveDelta = true; } InternalComponent.TimeValue = delta; } else if (state.CurrentPhase == TimerPhase.Ended) { InternalComponent.TimeValue = state.Run.Last().SplitTime[state.CurrentTimingMethod] - state.Run.Last().Comparisons[comparison][state.CurrentTimingMethod]; } else { InternalComponent.TimeValue = null; } var color = LiveSplitStateHelper.GetSplitColor(state, InternalComponent.TimeValue, state.CurrentSplitIndex - (useLiveDelta ? 0 : 1), true, false, comparison, state.CurrentTimingMethod); if (color == null) { color = Settings.OverrideTextColor ? Settings.TextColor : state.LayoutSettings.TextColor; } InternalComponent.ValueLabel.ForeColor = color.Value; InternalComponent.Update(invalidator, state, width, height, mode); }
private SplitState GetSplitState( LiveSplitState state, TimeSpan?timeDifference, int splitNumber, string comparison, TimingMethod method) { SplitState splitState = SplitState.Unknown; if (splitNumber < 0) { return(splitState); } if (timeDifference != null) { if (timeDifference < TimeSpan.Zero) { splitState = SplitState.AheadGaining; var lastDelta = LiveSplitStateHelper.GetLastDelta(state, splitNumber - 1, comparison, method); if (splitNumber > 0 && lastDelta != null && timeDifference > lastDelta) { splitState = SplitState.AheadLosing; } } else { splitState = SplitState.BehindLosing; var lastDelta = LiveSplitStateHelper.GetLastDelta(state, splitNumber - 1, comparison, method); if (splitNumber > 0 && lastDelta != null && timeDifference < lastDelta) { splitState = SplitState.BehindGaining; } } } if (LiveSplitStateHelper.CheckBestSegment(state, splitNumber, method)) { splitState = SplitState.BestSegment; } return(splitState); }
public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode) { var comparison = Settings.Comparison == "Current Comparison" ? state.CurrentComparison : Settings.Comparison; if (!state.Run.Comparisons.Contains(comparison)) { comparison = state.CurrentComparison; } InternalComponent.InformationName = InternalComponent.LongestString = GetDisplayedName(comparison); if (InternalComponent.InformationName != PreviousInformationName) { SetAlternateText(comparison); PreviousInformationName = InternalComponent.InformationName; } if (InternalComponent.InformationName.StartsWith("Current Pace") && state.CurrentPhase == TimerPhase.NotRunning) { InternalComponent.TimeValue = null; } else if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused) { TimeSpan?delta = LiveSplitStateHelper.GetLastDelta(state, state.CurrentSplitIndex, comparison, state.CurrentTimingMethod) ?? TimeSpan.Zero; var liveDelta = state.CurrentTime[state.CurrentTimingMethod] - state.CurrentSplit.Comparisons[comparison][state.CurrentTimingMethod]; if (liveDelta > delta) { delta = liveDelta; } InternalComponent.TimeValue = delta + state.Run.Last().Comparisons[comparison][state.CurrentTimingMethod]; } else if (state.CurrentPhase == TimerPhase.Ended) { InternalComponent.TimeValue = state.Run.Last().SplitTime[state.CurrentTimingMethod]; } else { InternalComponent.TimeValue = state.Run.Last().Comparisons[comparison][state.CurrentTimingMethod]; } InternalComponent.Update(invalidator, state, width, height, mode); }
private TimeSpan?PredictTime(LiveSplitState state, string comparison) { if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused) { TimeSpan?delta = LiveSplitStateHelper.GetLastDelta(state, state.CurrentSplitIndex, comparison, State.CurrentTimingMethod) ?? TimeSpan.Zero; var liveDelta = state.CurrentTime[State.CurrentTimingMethod] - state.CurrentSplit.Comparisons[comparison][State.CurrentTimingMethod]; if (liveDelta > delta) { delta = liveDelta; } return(delta + state.Run.Last().Comparisons[comparison][State.CurrentTimingMethod]); } else if (state.CurrentPhase == TimerPhase.Ended) { return(state.Run.Last().SplitTime[State.CurrentTimingMethod]); } else { return(state.Run.Last().Comparisons[comparison][State.CurrentTimingMethod]); } }
private void ProcessMessage(String message, Connection clientConnection) { try { if (message == "startorsplit") { if (State.CurrentPhase == TimerPhase.Running) { Model.Split(); } else { Model.Start(); } } else if (message == "split") { Model.Split(); } else if (message == "unsplit") { Model.UndoSplit(); } else if (message == "skipsplit") { Model.SkipSplit(); } else if (message == "pause" && State.CurrentPhase != TimerPhase.Paused) { Model.Pause(); } else if (message == "resume" && State.CurrentPhase == TimerPhase.Paused) { Model.Pause(); } else if (message == "reset") { Model.Reset(); } else if (message == "starttimer") { Model.Start(); } else if (message.StartsWith("setgametime ")) { var value = message.Split(' ')[1]; var time = parseTime(value); State.SetGameTime(time); } else if (message.StartsWith("setloadingtimes ")) { var value = message.Split(' ')[1]; var time = parseTime(value); State.LoadingTimes = time ?? TimeSpan.Zero; } else if (message == "pausegametime") { State.IsGameTimePaused = true; } else if (message == "unpausegametime") { AlwaysPauseGameTime = false; State.IsGameTimePaused = false; } else if (message == "alwayspausegametime") { AlwaysPauseGameTime = true; State.IsGameTimePaused = true; } else if (message == "getdelta" || message.StartsWith("getdelta ")) { var comparison = State.CurrentComparison; if (message.Contains(" ")) { comparison = message.Split(new char[] { ' ' }, 2)[1]; } var delta = LiveSplitStateHelper.GetLastDelta(State, State.CurrentSplitIndex, comparison, State.CurrentTimingMethod); var response = DeltaFormatter.Format(delta); clientConnection.SendMessage(response); } else if (message == "getsplitindex") { var splitindex = State.CurrentSplitIndex; var response = splitindex.ToString(); clientConnection.SendMessage(response); } else if (message == "getcurrentsplitname") { var splitindex = State.CurrentSplitIndex; var currentsplitname = State.CurrentSplit.Name; var response = currentsplitname; clientConnection.SendMessage(response); } else if (message == "getprevioussplitname") { var previoussplitindex = State.CurrentSplitIndex - 1; var previoussplitname = State.Run[previoussplitindex].Name; var response = previoussplitname; clientConnection.SendMessage(response); } else if (message == "getlastsplittime" && State.CurrentSplitIndex > 0) { var splittime = State.Run[State.CurrentSplitIndex - 1].SplitTime[State.CurrentTimingMethod]; var response = SplitTimeFormatter.Format(splittime); clientConnection.SendMessage(response); } else if (message == "getcomparisonsplittime") { var splittime = State.CurrentSplit.Comparisons[State.CurrentComparison][State.CurrentTimingMethod]; var response = SplitTimeFormatter.Format(splittime); clientConnection.SendMessage(response); } else if (message == "getcurrentrealtime") { var time = State.CurrentTime.RealTime; var response = SplitTimeFormatter.Format(time); clientConnection.SendMessage(response); } else if (message == "getcurrentgametime") { var timingMethod = TimingMethod.GameTime; if (!State.IsGameTimeInitialized) { timingMethod = TimingMethod.RealTime; } var time = State.CurrentTime[timingMethod]; var response = SplitTimeFormatter.Format(time); clientConnection.SendMessage(response); } else if (message == "getcurrenttime") { var timingMethod = State.CurrentTimingMethod; if (timingMethod == TimingMethod.GameTime && !State.IsGameTimeInitialized) { timingMethod = TimingMethod.RealTime; } var time = State.CurrentTime[timingMethod]; var response = SplitTimeFormatter.Format(time); clientConnection.SendMessage(response); } else if (message == "getfinaltime" || message.StartsWith("getfinaltime ")) { var comparison = State.CurrentComparison; if (message.Contains(" ")) { comparison = message.Split(new char[] { ' ' }, 2)[1]; } var time = (State.CurrentPhase == TimerPhase.Ended) ? State.CurrentTime[State.CurrentTimingMethod] : State.Run.Last().Comparisons[comparison][State.CurrentTimingMethod]; var response = SplitTimeFormatter.Format(time); clientConnection.SendMessage(response); } else if (message.StartsWith("getpredictedtime ")) { var comparison = message.Split(new char[] { ' ' }, 2)[1]; var prediction = PredictTime(State, comparison); var response = SplitTimeFormatter.Format(prediction); clientConnection.SendMessage(response); } else if (message == "getbestpossibletime") { var comparison = LiveSplit.Model.Comparisons.BestSegmentsComparisonGenerator.ComparisonName; var prediction = PredictTime(State, comparison); var response = SplitTimeFormatter.Format(prediction); clientConnection.SendMessage(response); } else if (message == "getcurrenttimerphase") { var response = State.CurrentPhase.ToString(); clientConnection.SendMessage(response); } else if (message.StartsWith("setcomparison ")) { var comparison = message.Split(new char[] { ' ' }, 2)[1]; State.CurrentComparison = comparison; } else if (message == "switchto realtime") { State.CurrentTimingMethod = TimingMethod.RealTime; } else if (message == "switchto gametime") { State.CurrentTimingMethod = TimingMethod.GameTime; } else if (message.StartsWith("setsplitname ")) { int index = Convert.ToInt32(message.Split(new char[] { ' ' }, 3)[1]); string title = message.Split(new char[] { ' ' }, 3)[2]; State.Run[index].Name = title; State.Run.HasChanged = true; } else if (message.StartsWith("setcurrentsplitname ")) { string title = message.Split(new char[] { ' ' }, 2)[1]; State.Run[State.CurrentSplitIndex].Name = title; State.Run.HasChanged = true; } } catch (Exception ex) { Log.Error(ex); } }
void connection_MessageReceived(object sender, MessageEventArgs e) { if (State == null) { return; } try { var message = e.Message; if (message == "split") { Model.Split(); } else if (message == "unsplit") { Model.UndoSplit(); } else if (message == "skipsplit") { Model.SkipSplit(); } else if (message == "pause" && State.CurrentPhase != TimerPhase.Paused) { Model.Pause(); } else if (message == "resume" && State.CurrentPhase == TimerPhase.Paused) { Model.Pause(); } else if (message == "reset") { Model.Reset(); } else if (message == "starttimer") { Model.Start(); } else if (message.StartsWith("setgametime ")) { var value = message.Split(' ')[1]; var time = parseTime(value); State.SetGameTime(time); } else if (message.StartsWith("setloadingtimes ")) { var value = message.Split(' ')[1]; var time = parseTime(value); State.LoadingTimes = time ?? TimeSpan.Zero; } else if (message == "pausegametime") { State.IsGameTimePaused = true; } else if (message == "unpausegametime") { State.IsGameTimePaused = false; } else if (message == "getdelta") { var delta = LiveSplitStateHelper.GetLastDelta(State, State.CurrentSplitIndex, State.CurrentComparison, State.CurrentTimingMethod); var response = DeltaFormatter.Format(delta); e.Connection.SendMessage(response); } else if (message == "getlastsplittime" && State.CurrentSplitIndex > 0) { var splittime = State.Run[State.CurrentSplitIndex - 1].SplitTime[State.CurrentTimingMethod]; var response = SplitTimeFormatter.Format(splittime); e.Connection.SendMessage(response); } else if (message == "getcomparisonsplittime") { var splittime = State.CurrentSplit.Comparisons[State.CurrentComparison][State.CurrentTimingMethod]; var response = SplitTimeFormatter.Format(splittime); e.Connection.SendMessage(response); } else if (message == "getcurrenttime") { var time = State.CurrentTime[State.CurrentTimingMethod]; var response = SplitTimeFormatter.Format(time); e.Connection.SendMessage(response); } else if (message == "getfinaltime" || message.StartsWith("getfinaltime ")) { var comparison = State.CurrentComparison; if (message.Contains(" ")) { comparison = message.Split(new char[] { ' ' }, 2)[1]; } var time = (State.CurrentPhase == TimerPhase.Ended) ? State.CurrentTime[State.CurrentTimingMethod] : State.Run.Last().Comparisons[comparison][State.CurrentTimingMethod]; var response = SplitTimeFormatter.Format(time); e.Connection.SendMessage(response); } else if (message.StartsWith("getpredictedtime ")) { var comparison = message.Split(new char[] { ' ' }, 2)[1]; var prediction = PredictTime(State, comparison); var response = SplitTimeFormatter.Format(prediction); e.Connection.SendMessage(response); } else if (message == "getbestpossibletime") { var comparison = LiveSplit.Model.Comparisons.BestSegmentsComparisonGenerator.ComparisonName; var prediction = PredictTime(State, comparison); var response = SplitTimeFormatter.Format(prediction); e.Connection.SendMessage(response); } else if (message.StartsWith("setcomparison ")) { var comparison = message.Split(new char[] { ' ' }, 2)[1]; State.CurrentComparison = comparison; } else if (message == "switchto realtime") { State.CurrentTimingMethod = TimingMethod.RealTime; } else if (message == "switchto gametime") { State.CurrentTimingMethod = TimingMethod.GameTime; } } catch (Exception ex) { Log.Error(ex); } }
public void UpdatePresence(LiveSplitState state) { DeltaFormatter.Accuracy = Settings.Accuracy; DeltaFormatter.DropDecimals = Settings.DropDecimals; string GlobalComparison = Settings.Comparison; if (GlobalComparison == "Current Comparison") { GlobalComparison = state.CurrentComparison; } TimerPhase RunState = state.CurrentPhase; string CategoryName = state.Run.CategoryName; string DetailedCategoryName = state.Run.GetExtendedCategoryName(); string GameName = state.Run.GameName; string ShortGameName = state.Run.GameName.GetAbbreviations().Last(); TimeSpan?delta = TimeSpan.Zero; if (RunState == TimerPhase.NotRunning && Settings.NRClearActivity) { activityManager.ClearActivity((res) => { if (res != Result.Ok) { throw new ResultException(res); } }); return; } string RunningImage = "gray_square"; string SplitName = ""; if (RunState == TimerPhase.Running || RunState == TimerPhase.Paused) { SplitName = state.CurrentSplit.Name; // Want to do more with this, maybe more advanced formatting. For now, simple removal. if (Settings.SubSplitCount && SplitName.Length > 0) { int bracket1 = SplitName.IndexOf("{"); int bracket2 = SplitName.IndexOf("}"); if (SplitName.Substring(0, 1) == "-") { SplitName = SplitName.Substring(1); } if ((bracket1 != -1 && bracket2 != -1) && SplitName.Length > bracket2) { SplitName = SplitName.Substring(bracket2 + 1); } } } if (RunState != TimerPhase.NotRunning) { var timestring = ""; if (state.CurrentSplitIndex > 0) { GetDelta(GlobalComparison); } if (RunState != TimerPhase.Paused && timestring.Length > 0) { RunningImage = timestring.Substring(0, 1) == "+" ? "red_square" : "green_square"; } } long StartTime = 0; if (Settings.DisplayElapsedTimeType == ElapsedTimeType.DisplayAttemptDuration || Settings.DisplayElapsedTimeType == ElapsedTimeType.DisplayADwOffset) { DateTime sTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); StartTime = (long)(state.AttemptStarted - sTime).TotalSeconds; if (Settings.DisplayElapsedTimeType == ElapsedTimeType.DisplayADwOffset) { StartTime -= (long)state.Run.Offset.TotalSeconds; } } else if (Settings.DisplayElapsedTimeType == ElapsedTimeType.DisplayGameTime) { StartTime = DateTime.UtcNow.Ticks - (long)state.CurrentTime[state.CurrentTimingMethod].Value.TotalSeconds; } var activity = new Activity { Details = CheckText("Details"), State = CheckText("State"), Assets = { LargeImage = "livesplit_icon", LargeText = CheckText("largeImage") } }; if (Settings.Comparison != NoneComparisonGenerator.ComparisonName) { activity.Assets.SmallText = CheckText("smallImage"); activity.Assets.SmallImage = RunningImage; } if (RunState == TimerPhase.Running && (int)Settings.DisplayElapsedTimeType >= 1) { activity.Timestamps.Start = StartTime; } activityManager.UpdateActivity(activity, (res) => { if (res != Result.Ok) { throw new ResultException(res); } }); string CheckText(string item) { string text = GetText(item); if (text == "%inherit") { text = GetText(item, true); if (text.Contains("%delta") || text.Contains("%split")) { if (RunState == TimerPhase.NotRunning) { return("Not Running"); } else if (RunState == TimerPhase.Ended) { return("Ended. Final Time: " + TimeFormatter.Format(state.CurrentTime[state.CurrentTimingMethod])); } else if (RunState == TimerPhase.Paused) { return("Paused"); } else { text = FindDelta(text); text = text.Replace("%split", SplitName); } } } else { text = FindDelta(text); text = text.Replace("%split", SplitName); } text = text.Replace("%game_short", ShortGameName); text = text.Replace("%game", GameName); text = text.Replace("%category_detailed", DetailedCategoryName); text = text.Replace("%category", CategoryName); text = text.Replace("%attempts", state.Run.AttemptCount.ToString()); text = text.Replace("%comparison", GlobalComparison); text = text.Replace("%time", TimeFormatter.Format(state.CurrentTime[state.CurrentTimingMethod])); return(text); } string GetText(string item, bool GetRunning = false) { if (RunState == TimerPhase.Running || GetRunning) { if (item == "Details") { return(Settings.Details); } else if (item == "State") { return(Settings.State); } else if (item == "largeImage") { return(Settings.largeImageKey); } else { return(Settings.smallImageKey); } } else if (RunState == TimerPhase.NotRunning) { if (item == "Details") { return(Settings.NRDetails); } else if (item == "State") { return(Settings.NRState); } else if (item == "largeImage") { return(Settings.NRlargeImageKey); } else { return(Settings.NRsmallImageKey); } } else if (RunState == TimerPhase.Ended) { if (item == "Details") { return(Settings.EDetails); } else if (item == "State") { return(Settings.EState); } else if (item == "largeImage") { return(Settings.ElargeImageKey); } else { return(Settings.EsmallImageKey); } } else { if (item == "Details") { return(Settings.PDetails); } else if (item == "State") { return(Settings.PState); } else if (item == "largeImage") { return(Settings.PlargeImageKey); } else { return(Settings.PsmallImageKey); } } } string GetDelta(string Comparison) { int SplitIndex = (RunState == TimerPhase.Ended ? state.CurrentSplitIndex - 1 : state.CurrentSplitIndex); delta = LiveSplitStateHelper.GetLastDelta(state, SplitIndex, Comparison, state.CurrentTimingMethod); return(DeltaFormatter.Format(delta)); } string FindDelta(string SearchText) { if (SearchText.IndexOf("%delta_") != -1) { SearchText = SearchText.Replace("%delta_cur", GetDelta(state.CurrentComparison)); foreach (KeyValuePair <string, string> deltaCheck in ComparisonDict) { SearchText = SearchText.Replace(deltaCheck.Key, GetDelta(deltaCheck.Value)); } } SearchText = SearchText.Replace("%delta", GetDelta(GlobalComparison)); return(SearchText); } }
private void ProcessMessage(String message, string[] arguments, Connection clientConnection) { try { if (message == "registerEvent") { if (arguments.Length == 0) { } foreach (string ev in arguments) { dynamic handler; switch (ev) { case "pause": handler = new EventHandler((object o, EventArgs e) => { clientConnection.SendMessage(ev); }); State.OnPause += handler; clientConnection.addDisconnectHandler(() => State.OnPause -= handler); break; case "reset": handler = new EventHandlerT <TimerPhase>((object o, TimerPhase e) => { clientConnection.SendMessage(ev, e.ToString()); }); State.OnReset += handler; clientConnection.addDisconnectHandler(() => State.OnReset -= handler); break; case "resume": handler = new EventHandler((object o, EventArgs e) => { clientConnection.SendMessage(ev); }); State.OnResume += handler; clientConnection.addDisconnectHandler(() => State.OnResume -= handler); break; case "skipSplit": handler = new EventHandler((object o, EventArgs e) => { clientConnection.SendMessage(ev); }); State.OnSkipSplit += handler; clientConnection.addDisconnectHandler(() => State.OnSkipSplit -= handler); break; case "split": handler = new EventHandler((object o, EventArgs e) => { clientConnection.SendMessage(ev); }); State.OnSplit += handler; clientConnection.addDisconnectHandler(() => State.OnSplit -= handler); break; case "start": handler = new EventHandler((object o, EventArgs e) => { clientConnection.SendMessage(ev); }); State.OnStart += handler; clientConnection.addDisconnectHandler(() => State.OnStart -= handler); break; case "switchComparison": handler = new EventHandler((object o, EventArgs e) => { clientConnection.SendMessage(ev, State.CurrentComparison); }); State.OnSwitchComparisonNext += handler; State.OnSwitchComparisonPrevious += handler; clientConnection.addDisconnectHandler(() => { State.OnSwitchComparisonNext -= handler; State.OnSwitchComparisonPrevious -= handler; }); break; case "undoAllPauses": handler = new EventHandler((object o, EventArgs e) => { clientConnection.SendMessage(ev); }); State.OnUndoAllPauses += handler; clientConnection.addDisconnectHandler(() => State.OnUndoAllPauses -= handler); break; case "undoSplit": handler = new EventHandler((object o, EventArgs e) => { clientConnection.SendMessage(ev); }); State.OnUndoSplit += handler; clientConnection.addDisconnectHandler(() => State.OnUndoSplit -= handler); break; } } } if (message == "startorsplit") { if (State.CurrentPhase == TimerPhase.Running) { Model.Split(); } else { Model.Start(); } } else if (message == "split") { Model.Split(); } else if (message == "unsplit") { Model.UndoSplit(); } else if (message == "skipsplit") { Model.SkipSplit(); } else if (message == "pause" && State.CurrentPhase != TimerPhase.Paused) { Model.Pause(); } else if (message == "resume" && State.CurrentPhase == TimerPhase.Paused) { Model.Pause(); } else if (message == "reset") { Model.Reset(); } else if (message == "starttimer") { Model.Start(); } else if (message.StartsWith("setgametime ")) { var value = message.Split(' ')[1]; var time = parseTime(value); State.SetGameTime(time); } else if (message.StartsWith("setloadingtimes ")) { var value = message.Split(' ')[1]; var time = parseTime(value); State.LoadingTimes = time ?? TimeSpan.Zero; } else if (message == "pausegametime") { State.IsGameTimePaused = true; } else if (message == "unpausegametime") { AlwaysPauseGameTime = false; State.IsGameTimePaused = false; } else if (message == "alwayspausegametime") { AlwaysPauseGameTime = true; State.IsGameTimePaused = true; } else if (message == "getdelta" || message.StartsWith("getdelta ")) { var comparison = State.CurrentComparison; if (message.Contains(" ")) { comparison = message.Split(new char[] { ' ' }, 2)[1]; } var delta = LiveSplitStateHelper.GetLastDelta(State, State.CurrentSplitIndex, comparison, State.CurrentTimingMethod); clientConnection.SendMessage(message.Trim(), delta.HasValue ? delta.Value.TotalMilliseconds : 0); } else if (message == "getsplits") { clientConnection.SendMessage(message, State.Run.Select((segment) => { dynamic result = new System.Dynamic.ExpandoObject(); result.icon = segment.Icon; result.name = segment.Name; var comparison = segment.Comparisons[State.CurrentComparison][State.CurrentTimingMethod]; if (comparison.HasValue) { result.comparison = comparison.Value.TotalMilliseconds; } var splitTime = segment.SplitTime[State.CurrentTimingMethod]; if (splitTime.HasValue) { result.splitTime = splitTime.Value.TotalMilliseconds; } var personalBestSplitTime = segment.PersonalBestSplitTime[State.CurrentTimingMethod]; if (personalBestSplitTime.HasValue) { result.personalBestSplitTime = personalBestSplitTime.Value.TotalMilliseconds; } var bestSegmentTime = segment.BestSegmentTime[State.CurrentTimingMethod]; if (bestSegmentTime.HasValue) { result.bestSegmentTime = bestSegmentTime.Value.TotalMilliseconds; } return(result); })); } else if (message == "getsplitindex") { clientConnection.SendMessage(message, State.CurrentSplitIndex); } else if (message == "getcurrentsplitname") { var splitindex = State.CurrentSplitIndex; var currentsplitname = State.CurrentSplit.Name; var response = currentsplitname; clientConnection.SendMessage(message, response); } else if (message == "getprevioussplitname") { var previoussplitindex = State.CurrentSplitIndex - 1; var previoussplitname = State.Run[previoussplitindex].Name; var response = previoussplitname; clientConnection.SendMessage(message, response); } else if (message == "getlastsplittime" && State.CurrentSplitIndex > 0) { var splittime = State.Run[State.CurrentSplitIndex - 1].SplitTime[State.CurrentTimingMethod]; clientConnection.SendMessage(message, splittime.HasValue ? splittime.Value.TotalMilliseconds : 0); } else if (message == "getcomparisonsplittime") { try { TimeSpan?splittime; if (State.CurrentSplit == null) { splittime = State.Run[0].Comparisons[State.CurrentComparison][State.CurrentTimingMethod]; } else { splittime = State.CurrentSplit.Comparisons[State.CurrentComparison][State.CurrentTimingMethod]; } var response = 0.0; if (splittime.HasValue) { response = splittime.Value.TotalMilliseconds; } clientConnection.SendMessage(message, response); } catch (Exception e) { clientConnection.SendError(message, e); } } else if (message == "getcurrenttime") { var timingMethod = State.CurrentTimingMethod; if (timingMethod == TimingMethod.GameTime && !State.IsGameTimeInitialized) { timingMethod = TimingMethod.RealTime; } var time = State.CurrentTime[timingMethod]; clientConnection.SendMessage(message, time.HasValue ? time.Value.TotalMilliseconds : 0); } else if (message == "getfinaltime" || message.StartsWith("getfinaltime ")) { var comparison = State.CurrentComparison; if (message.Contains(" ")) { comparison = message.Split(new char[] { ' ' }, 2)[1]; } var time = (State.CurrentPhase == TimerPhase.Ended) ? State.CurrentTime[State.CurrentTimingMethod] : State.Run.Last().Comparisons[comparison][State.CurrentTimingMethod]; clientConnection.SendMessage(message.Trim(), time.HasValue ? time.Value.TotalMilliseconds : 0); } else if (message.StartsWith("getpredictedtime ")) { var comparison = message.Split(new char[] { ' ' }, 2)[1]; var prediction = PredictTime(State, comparison); clientConnection.SendMessage(message, prediction.HasValue ? prediction.Value.TotalMilliseconds : 0); } else if (message == "getbestpossibletime") { var comparison = LiveSplit.Model.Comparisons.BestSegmentsComparisonGenerator.ComparisonName; var prediction = PredictTime(State, comparison); clientConnection.SendMessage(message, prediction.HasValue ? prediction.Value.TotalMilliseconds : 0); } else if (message == "getcurrenttimerphase") { var response = State.CurrentPhase.ToString(); clientConnection.SendMessage(message, response); } else if (message == "getcomparison") { clientConnection.SendMessage(message, State.CurrentComparison); } else if (message.StartsWith("setcomparison ")) { var comparison = message.Split(new char[] { ' ' }, 2)[1]; State.CurrentComparison = comparison; } else if (message == "switchto realtime") { State.CurrentTimingMethod = TimingMethod.RealTime; } else if (message == "switchto gametime") { State.CurrentTimingMethod = TimingMethod.GameTime; } else if (message.StartsWith("setsplitname ")) { int index = Convert.ToInt32(message.Split(new char[] { ' ' }, 3)[1]); string title = message.Split(new char[] { ' ' }, 3)[2]; State.Run[index].Name = title; State.Run.HasChanged = true; } else if (message.StartsWith("setcurrentsplitname ")) { string title = message.Split(new char[] { ' ' }, 2)[1]; State.Run[State.CurrentSplitIndex].Name = title; State.Run.HasChanged = true; } else if (message == "getGame") { dynamic response = new System.Dynamic.ExpandoObject(); response.gameName = State.Run.GameName; response.gameIcon = State.Run.GameIcon; response.categoryName = State.Run.CategoryName; response.attempts = State.Run.AttemptCount; response.completedAttempts = State.Run.AttemptHistory.Where(x => x.Time.RealTime != null).Count(); clientConnection.SendMessage(message, response); } } catch (Exception ex) { Log.Error(ex); } }