Exemplo n.º 1
0
        public Component(LiveSplitState state)
        {
            model = new TimerModel() { CurrentState = state };
            model.CurrentState.OnStart += State_OnStart;

            eventList = settings.GetEventList();
            settings.EventsChanged += settings_EventsChanged;
        }
 public ShitSplitter(LiveSplitState state, ManualGameTimeSettings settings)
 {
     InitializeComponent();
     Model = new TimerModel()
     {
         CurrentState = state
     };
     Settings = settings;
 }
        public DragonAgeInquisitionComponent(LiveSplitState state)
        {
            _timer = new TimerModel { CurrentState = state };

            _gameMemory = new GameMemory();
            _gameMemory.OnLoadStarted += gameMemory_OnLoadStarted;
            _gameMemory.OnLoadFinished += gameMemory_OnLoadFinished;
            _gameMemory.StartMonitoring();
        }
Exemplo n.º 4
0
        public AmnesiaComponent(LiveSplitState state)
        {
            _timer = new TimerModel() { CurrentState = state };
            _timer.OnStart += timer_OnStart;

            _updateTimer = new Timer() { Interval = 15, Enabled = true };
            _updateTimer.Tick += updateTimer_Tick;

            _gameMemory = new GameMemory();
            _gameMemory.OnLoadingChanged += gameMemory_OnLoadingChanged;
        }
Exemplo n.º 5
0
        public Component(LiveSplitState state)
        {
            Settings = new Settings();
            Model = new TimerModel();
            Connections = new List<Connection>();

            DeltaFormatter = new PreciseDeltaFormatter(TimeAccuracy.Hundredths);
            SplitTimeFormatter = new RegularTimeFormatter(TimeAccuracy.Hundredths);

            ContextMenuControls = new Dictionary<String, Action>();
            ContextMenuControls.Add("Start Server", Start);

            State = state;
            Model.CurrentState = State;
            State.OnStart += State_OnStart;
        }
Exemplo n.º 6
0
 public ShareRunDialog(LiveSplitState state, ISettings settings, Func<Image> screenShotFunction)
 {
     State = state;
     if (State.CurrentPhase != TimerPhase.Ended)
         Run = state.Run;
     else
     {
         var model = new TimerModel();
         model.CurrentState = State;
         model.SetRunAsPB();
         model.UpdateAttemptHistory();
         Run = State.Run;
     }
     ScreenShotFunction = screenShotFunction;
     Settings = settings;
     InitializeComponent();
 }
        public RedFactionComponent(LiveSplitState state, bool isLayoutComponent)
        {
            _state = state;
            this.IsLayoutComponent = isLayoutComponent;

            this.Settings = new RedFactionSettings();

           _timer = new TimerModel { CurrentState = state };
           _timer.CurrentState.OnPause += timer_OnStart;

            _gameMemory = new GameMemory(this.Settings);
            _gameMemory.OnFirstLevelLoading += gameMemory_OnFirstLevelLoading;
            _gameMemory.OnPlayerGainedControl += gameMemory_OnPlayerGainedControl;
            _gameMemory.OnLoadStarted += gameMemory_OnLoadStarted;
            _gameMemory.OnLoadFinished += gameMemory_OnLoadFinished;
            _gameMemory.OnSplitCompleted += gameMemory_OnSplitCompleted;
            state.OnStart += State_OnStart;
            _gameMemory.StartMonitoring();
        }
Exemplo n.º 8
0
        public MOHAComponent(LiveSplitState state)
        {
#if DEBUG
            Debug.Listeners.Clear();
            Debug.Listeners.Add(TimedTraceListener.Instance);
#endif

            _timer = new TimerModel { CurrentState = state };
            _timer.CurrentState.OnStart += timer_OnStart;

            _updateTimer = new Timer() { Interval = 15, Enabled = true };
            _updateTimer.Tick += updateTimer_Tick;

            _gameMemory = new GameMemory();
            _gameMemory.OnFirstLevelLoaded += gameMemory_OnFirstLevelLoading;
            _gameMemory.OnFadeIn += gameMemory_OnFadeIn;
            _gameMemory.OnLoadStarted += gameMemory_OnLoadStarted;
            _gameMemory.OnLoadFinished += gameMemory_OnLoadFinished;
            _gameMemory.OnLastTrigger += gameMemory_OnLastTrigger;
			_gameMemory.OnLevelChanged += gameMemory_OnLevelCompleted;
			_gameMemory.OnActualLevelStart += gameMemory_OnActualLevelStart;
        }
Exemplo n.º 9
0
        public SourceSplitComponent(LiveSplitState state, bool isLayoutComponent)
        {
            // make Debug.WriteLine prepend update count and tick count
            while (Debug.Listeners.Count > 0)
                Debug.Listeners.RemoveAt(0);
            Debug.Listeners.Add(TimedTraceListener.Instance);
            while (Trace.Listeners.Count > 0)
                Trace.Listeners.RemoveAt(0);
            Trace.Listeners.Add(TimedTraceListener.Instance); // is it okay to use the same instance?
            //Debug.AutoFlush = Trace.AutoFlush = true;

            _state = state;
            this.IsLayoutComponent = isLayoutComponent;

            this.Settings = new SourceSplitSettings();
            this.InternalComponent = new InfoTimeComponent("Game Time", null, new RegularTimeFormatter(TimeAccuracy.Hundredths));

            this.ContextMenuControls = new Dictionary<String, Action>();
            this.ContextMenuControls.Add("SourceSplit: Map Times", () => MapTimesForm.Instance.Show());

            _cache = new GraphicsCache();

            _timer = new TimerModel { CurrentState = state };
            state.OnSplit += state_OnSplit;
            state.OnReset += state_OnReset;
            state.OnStart += state_OnStart;

            _mapsVisited = new List<string>();

            _gameMemory = new GameMemory(this.Settings);
            _gameMemory.OnSessionTimeUpdate += gameMemory_OnSessionTimeUpdate;
            _gameMemory.OnPlayerGainedControl += gameMemory_OnPlayerGainedControl;
            _gameMemory.OnPlayerLostControl += gameMemory_OnPlayerLostControl;
            _gameMemory.OnMapChanged += gameMemory_OnMapChanged;
            _gameMemory.OnSessionStarted += gameMemory_OnSessionStarted;
            _gameMemory.OnSessionEnded += gameMemory_OnSessionEnded;
            _gameMemory.OnNewGameStarted += gameMemory_OnNewGameStarted;
            _gameMemory.StartReading();
        }
 // Update the script
 public void Update(LiveSplitState state)
 {
     if (_game == null)
     {
         if (_timer == null)
             _timer = new TimerModel() { CurrentState = state };
         TryConnect(state);
     }
     else if (_game.HasExited)
     {
         DoExit(state);
     }
     else
     {
         if (!_init_completed)
             DoInit(state);
         else
             DoUpdate(state);
     }
 }
Exemplo n.º 11
0
        private void SaveSplits(bool promptPBMessage)
        {
            var savePath = CurrentState.Run.FilePath;

            if (savePath == null)
            {
                SaveSplitsAs(promptPBMessage);
                return;
            }

            CurrentState.Run.FixSplits();

            var stateCopy = CurrentState.Clone() as LiveSplitState;
            var modelCopy = new TimerModel();
            modelCopy.CurrentState = stateCopy;
            var result = DialogResult.No;

            if (promptPBMessage && ((CurrentState.CurrentPhase == TimerPhase.Ended
                && CurrentState.Run.Last().PersonalBestSplitTime[CurrentState.CurrentTimingMethod] != null
                && CurrentState.Run.Last().SplitTime[CurrentState.CurrentTimingMethod] >= CurrentState.Run.Last().PersonalBestSplitTime[CurrentState.CurrentTimingMethod])
                || CurrentState.CurrentPhase == TimerPhase.Running
                || CurrentState.CurrentPhase == TimerPhase.Paused))
            {
                DontRedraw = true;
                result = MessageBox.Show(this, "This run did not beat your current splits. Would you like to save this run as a Personal Best?", "Save as Personal Best?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                DontRedraw = false;
                if (result == DialogResult.Yes)
                {
                    Model.Reset();
                    modelCopy.SetRunAsPB();
                    modelCopy.UpdateAttemptHistory();
                    modelCopy.UpdateBestSegments();
                    modelCopy.UpdateSegmentHistory();
                    SetRun(stateCopy.Run);
                }
                else if (result == DialogResult.Cancel)
                    return;
            }

            if (result == DialogResult.Yes)
                modelCopy.Reset(false);
            else
                modelCopy.Reset();

            try
            {
                if (!File.Exists(savePath))
                    File.Create(savePath).Close();

                using (var memoryStream = new MemoryStream())
                {
                    RunSaver.Save(stateCopy.Run, memoryStream);

                    using (var stream = File.Open(savePath, FileMode.Create, FileAccess.Write))
                    {
                        var buffer = memoryStream.GetBuffer();
                        stream.Write(buffer, 0, (int)memoryStream.Length);
                    }

                    CurrentState.Run.HasChanged = false;
                }

                AddSplitsFileToLRU(savePath, stateCopy.Run, CurrentState.CurrentTimingMethod);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Splits could not be saved!", "Save Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Log.Error(ex);
            }
        }
Exemplo n.º 12
0
        private void Init(String splitsPath = null, String layoutPath = null)
        {
            GlobalCache = new GraphicsCache();
            Invalidator = new Invalidator(this);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);

            ComponentManager.BasePath = BasePath;

            SpeedRunsLiveAPI.Instance.RacesRefreshed += SRL_RacesRefreshed;
            SpeedRunsLiveAPI.Instance.RefreshRacesListAsync();

            CurrentState = new LiveSplitState(null, null, null);

            ComparisonGeneratorsFactory = new StandardComparisonGeneratorsFactory();

            TimerOnlyLayout = new TimerOnlyLayoutFactory().Create(CurrentState);
            TimerOnlyRun = new StandardRunFactory().Create(ComparisonGeneratorsFactory);
            InTimerOnlyMode = false;

            Model = new TimerModel();
            //LiveSplit.Web.Share.Twitch.Instance.AutoUpdateModel = Model;

            RunFactory = new StandardFormatsRunFactory();
            RunSaver = new XMLRunSaver();
            LayoutSaver = new XMLLayoutSaver();
            SettingsSaver = new XMLSettingsSaver();
            LoadSettings();

            UpdateRecentSplits();
            UpdateRecentLayouts();

            IRun run = null;
            if (!String.IsNullOrEmpty(splitsPath))
            {
                run = LoadRunFromFile(splitsPath, true);
            }
            else
            {
                try
                {
                    run = LoadRunFromFile(Settings.RecentSplits.Last(), true);
                }
                catch (Exception e)
                {
                    Log.Error(e);

                    run = TimerOnlyRun;
                }
            }

            if (!String.IsNullOrEmpty(layoutPath))
            {
                Layout = LoadLayoutFromFile(layoutPath);
            }
            else
            {
                try
                {
                    Layout = LoadLayoutFromFile(Settings.RecentLayouts.Last());
                }
                catch (Exception e)
                {
                    Log.Error(e);

                    if (run == TimerOnlyRun)
                    {
                        Layout = TimerOnlyLayout;
                        InTimerOnlyMode = true;
                    }
                    else
                        Layout = new StandardLayoutFactory().Create(CurrentState);
                }
            }

            CurrentState.Run = run;
            CurrentState.LayoutSettings = Layout.Settings;
            CurrentState.Settings = Settings;

            RegenerateComparisons();
            SwitchComparison(Settings.LastComparison);
            Model.CurrentState = CurrentState;

            CurrentState.OnReset += CurrentState_OnReset;
            CurrentState.OnStart += CurrentState_OnStart;
            CurrentState.OnSplit += CurrentState_OnSplit;
            CurrentState.OnSkipSplit += CurrentState_OnSkipSplit;
            CurrentState.OnUndoSplit += CurrentState_OnUndoSplit;
            CurrentState.OnPause += CurrentState_OnPause;
            CurrentState.OnResume += CurrentState_OnResume;
            CurrentState.OnSwitchComparisonPrevious += CurrentState_OnSwitchComparisonPrevious;
            CurrentState.OnSwitchComparisonNext += CurrentState_OnSwitchComparisonNext;

            ComponentRenderer = new ComponentRenderer();

            this.StartPosition = FormStartPosition.Manual;

            SetLayout(Layout);

            OldSize = -20;

            RefreshTimer = new System.Timers.Timer(25f);
            RefreshTimer.Elapsed += timer_Elapsed;
            RefreshTimer.Enabled = true;
            RefreshCounter = 0;
            RefreshesRemaining = 0;

            Hook = new CompositeHook();
            Hook.KeyOrButtonPressed += hook_KeyOrButtonPressed;
            Settings.RegisterHotkeys(Hook);

            RegisterTaskbarButtons();

            this.SizeChanged += TimerForm_SizeChanged;

            lock (BackBufferLock)
            {
                BackBuffer = new Bitmap(this.Width, this.Height);
            }

            this.TopMost = Layout.Settings.AlwaysOnTop;
        }
Exemplo n.º 13
0
        private void SaveSplits(bool promptPBMessage)
        {
            var savePath = CurrentState.Run.FilePath;

            if (savePath == null)
            {
                SaveSplitsAs(promptPBMessage);
                return;
            }

            var stateCopy = CurrentState.Clone() as LiveSplitState;
            var modelCopy = new TimerModel();
            modelCopy.CurrentState = stateCopy;
            var result = System.Windows.Forms.DialogResult.No;

            if (promptPBMessage && ((CurrentState.CurrentPhase == TimerPhase.Ended 
                && CurrentState.Run.Last().PersonalBestSplitTime != null 
                && CurrentState.Run.Last().RTASplitTime >= CurrentState.Run.Last().PersonalBestSplitTime)
                || CurrentState.CurrentPhase == TimerPhase.Running
                || CurrentState.CurrentPhase == TimerPhase.Paused))
            {
                DontRedraw = true;
                result = MessageBox.Show(this, "This run did not beat your current splits. Would you like to save this run as a Personal Best?", "Save as Personal Best?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                DontRedraw = false;
                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    Model.Reset();
                    modelCopy.SetRunAsPB();
                    modelCopy.UpdateRunHistory();
                    modelCopy.UpdateBestSegments();
                    modelCopy.UpdateSegmentHistory();
                    SetRun(stateCopy.Run);
                }
                else if (result == System.Windows.Forms.DialogResult.Cancel)
                    return;
            }

            if (result == System.Windows.Forms.DialogResult.Yes)
                modelCopy.ResetWithoutUpdating();
            else
                modelCopy.Reset();

            if (!System.IO.File.Exists(savePath))
                System.IO.File.Create(savePath).Close();
            using (var stream = System.IO.File.Open(savePath, System.IO.FileMode.OpenOrCreate | System.IO.FileMode.Truncate, System.IO.FileAccess.Write))
            {
                RunSaver.Save(stateCopy.Run, stream);
                CurrentState.Run.HasChanged = false;
            }
            Settings.AddToRecentSplits(savePath);
            UpdateRecentSplits();
        }
        public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode) {
            if (Model == null) {
                Model = new TimerModel() { CurrentState = state };
                state.OnReset += OnReset;
                state.OnPause += OnPause;
                state.OnResume += OnResume;
                state.OnStart += OnStart;
                state.OnSplit += OnSplit;
                state.OnUndoSplit += OnUndoSplit;
                state.OnSkipSplit += OnSkipSplit;
            }

            oriState.Loop();
            oriState.oriTriggers.timerRunning = (Model.CurrentState.CurrentPhase == TimerPhase.Running);

            if (Settings.showMapDisplay) {
                textInfo.InformationName = "Total Map: " + oriState.sMapCompletion.ToString("0.00") + "%";
                textInfo.InformationValue = oriState.sCurrentArea.ToString();
                textInfo.LongestString = "Valley Of The Wind - 100.00%";
                textInfo.Update(invalidator, state, width, height, mode);
                if (invalidator != null) {
                    invalidator.Invalidate(0, 0, width, height);
                }
            }
        }
        public void Update(LiveSplitState lsState)
        {
            if (Game != null && !Game.HasExited)
            {
                OldState = State.RefreshValues(Game);

                if (lsState.CurrentPhase == TimerPhase.Running || lsState.CurrentPhase == TimerPhase.Paused)
                {
                    var isPaused = IsLoading.Run(lsState, OldState, State);
                    if (isPaused != null)
                        lsState.IsGameTimePaused = isPaused;

                    var gameTime = GameTime.Run(lsState, OldState, State);
                    if (gameTime != null)
                        lsState.SetGameTime(gameTime);

                    if (Reset.Run(lsState, OldState, State) ?? false)
                    {
                        Model.Reset();
                    }
                    else if (Split.Run(lsState, OldState, State) ?? false)
                    {
                        Model.Split();
                    }
                }

                if (lsState.CurrentPhase == TimerPhase.NotRunning)
                {
                    if (Start.Run(lsState, OldState, State) ?? false)
                    {
                        Model.Start();
                    }
                }
            }
            else
            {
                if (Model == null)
                {
                    Model = new TimerModel() { CurrentState = lsState };
                }
                TryConnect();
            }
        }
Exemplo n.º 16
0
		public TimerPause(LiveSplitState state)
		{
            Settings = new TimerPauseSettings();
            PauseTime = TimeStamp.Now;
			var timerModel = new TimerModel();
            timerModel.CurrentState = state;
            Model = timerModel;
            state.OnPause += state_OnPause;
            CurrentState = state;
		}
		public void Update(IInvalidator invalidator, LiveSplitState lvstate, float width, float height, LayoutMode mode) {
			if (Model == null) {
				Model = new TimerModel() { CurrentState = lvstate };
				Model.InitializeGameTime();
				Model.CurrentState.IsGameTimePaused = true;
				lvstate.OnReset += OnReset;
				lvstate.OnPause += OnPause;
				lvstate.OnResume += OnResume;
				lvstate.OnStart += OnStart;
				lvstate.OnSplit += OnSplit;
				lvstate.OnUndoSplit += OnUndoSplit;
				lvstate.OnSkipSplit += OnSkipSplit;
			}

			GetValues();
		}
Exemplo n.º 18
0
        public void Update(IInvalidator invalidator, LiveSplitState lvstate, float width, float height, LayoutMode mode) {
            if (Model == null) {
                Model = new TimerModel() { CurrentState = lvstate };
                lvstate.OnReset += OnReset;
                lvstate.OnPause += OnPause;
                lvstate.OnResume += OnResume;
                lvstate.OnStart += OnStart;
                lvstate.OnSplit += OnSplit;
                lvstate.OnUndoSplit += OnUndoSplit;
                lvstate.OnSkipSplit += OnSkipSplit;
            }

            GetValues(invalidator, lvstate, width, height, mode);
        }
        public void RunUpdate(LiveSplitState lsState)
        {
            if (Game != null && !Game.HasExited)
            {
                OldState = State.RefreshValues(Game);

                string ver = Version;
                runMethod(Update, lsState, ref ver);

                if (lsState.CurrentPhase == TimerPhase.Running || lsState.CurrentPhase == TimerPhase.Paused)
                {
                    if (UsesGameTime && !lsState.IsGameTimeInitialized)
                        Model.InitializeGameTime();

                    var isPaused = runMethod(IsLoading, lsState, ref ver);
                    if (isPaused != null)
                        lsState.IsGameTimePaused = isPaused;

                    var gameTime = runMethod(GameTime, lsState, ref ver);
                    if (gameTime != null)
                        lsState.SetGameTime(gameTime);

                    if (runMethod(Reset, lsState, ref ver) ?? false)
                    {
                        Model.Reset();
                    }
                    else if (runMethod(Split, lsState, ref ver) ?? false)
                    {
                        Model.Split();
                    }
                }

                if (lsState.CurrentPhase == TimerPhase.NotRunning)
                {
                    if (runMethod(Start, lsState, ref ver) ?? false)
                    {
                        Model.Start();
                    }
                }
            }
            else
            {
                if (Model == null)
                {
                    Model = new TimerModel() { CurrentState = lsState };
                }
                TryConnect(lsState);
            }
        }
Exemplo n.º 20
0
 protected AutoSplitComponent(IAutoSplitter autoSplitter, LiveSplitState state)
 {
     Model = new TimerModel() { CurrentState = state };
     AutoSplitter = autoSplitter;
 }