Ejemplo n.º 1
0
        private void UpdateAutosplitter()
        {
            var previousLatestSavePath = latestSavePath;

            latestSavePath = FindLatestSavePath();
            if (latestSavePath != previousLatestSavePath)
            {
                if (timer.CurrentState.CurrentPhase == TimerPhase.Running)
                {
                    ResetWools();
                    timer.Reset(true);
                }
                watcher?.Dispose();
                watcher = new FileSystemWatcher
                {
                    Path = latestSavePath, NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                                          | NotifyFilters.FileName |
                                                          NotifyFilters.DirectoryName |
                                                          NotifyFilters.Size |
                                                          NotifyFilters.Attributes,
                    Filter = "*.*"
                };
                watcher.Renamed            += NewLevelDat;
                watcher.Created            += SessionLock;
                watcher.Changed            += SessionLock;
                watcher.EnableRaisingEvents = true;

                CheckExistingSessionLock();
            }

            if (timer.CurrentState.CurrentPhase == TimerPhase.NotRunning)
            {
                ResetWools();
            }
        }
        private void _state_OnStart(object sender, EventArgs e)
        {
            if (!_usb2snes.Connected())
            {
                if (!this.connect())
                {
                    _model.Reset();
                    return;
                }
            }

            if (_game == null)
            {
                if (!this.readConfig())
                {
                    _model.Reset();
                    return;
                }
            }

            _error = false;

            _splits = _game.categories.Where(c => c.name.ToLower() == _state.Run.CategoryName.ToLower()).First()?.splits;
            if (_splits == null)
            {
                MessageBox.Show("There are no splits for the current category in the split config file, check that the run category is correctly set and exists in the config file.");
            }
        }
Ejemplo n.º 3
0
        void gameMemory_OnPlayerGainedControl(object sender, PlayerControlChangedEventArgs e)
        {
            if (!this.Settings.AutoStartEndResetEnabled)
            {
                return;
            }

            _timer.Reset(); // make sure to reset for games that start from a quicksave (Aperture Tag)
            _timer.Start();
            _sessionTicksOffset += e.TicksOffset;
        }
Ejemplo n.º 4
0
        public override void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
        {
            if (!gameMemory.ProcessHook())
            {
                return;
            }

            if (logic.ShouldStart())
            {
                logic.ResetLogic();
                if (liveSplitState.CurrentPhase == TimerPhase.Running)
                {
                    timerModel.Reset();
                }
                timerModel.Start();
            }

            if (liveSplitState.CurrentPhase == TimerPhase.Running)
            {
                if (logic.ShouldSplit(liveSplitState.CurrentSplitIndex, liveSplitState.Run.Count))
                {
                    timerModel.Split();
                }
            }
        }
Ejemplo n.º 5
0
        private void handleStandingOnArea(Checkpoint checkpoint, int checkpointIndex, LiveSplitState state,
                                          bool playingTransition, int mapId)
        {
            switch (checkpoint.CheckpointType)
            {
            case CheckpointType.StartingArea:
                if (_wasPlayingTransition && !playingTransition)
                {
                    Log.Info(
                        $"Resetting timer because {checkpoint.Name} is a starting area and a transition was playing.");
                    _timer.Reset();
                }

                break;

            case CheckpointType.Checkpoint:
                Log.Info($"Splitting because player is on {checkpoint.Name}");
                _lastCheckpoint[mapId] = checkpointIndex;
                _timer.Split();
                break;

            case CheckpointType.Boss:
                if (playingTransition)
                {
                    Log.Info($"Splitting because player is on boss {checkpoint.Name} and a transition happened");
                    var currentSplit = state.CurrentSplit;
                    _timer.Split();
                    currentSplit.SplitTime =
                        new Time(currentSplit.SplitTime.RealTime?.Subtract(
                                     TimeSpan.FromMilliseconds(checkpoint.TimeSubtract)));
                }

                break;
            }
        }
Ejemplo n.º 6
0
 void gameMemory_OnReset(object sender, EventArgs e)
 {
     if (Settings.AutoReset)
     {
         _timer.Reset();
     }
 }
Ejemplo n.º 7
0
 void gameMemory_OnFirstLevelLoading(object sender, EventArgs e)
 {
     if (this.Settings.AutoReset)
     {
         _timer.Reset();
     }
 }
Ejemplo n.º 8
0
 //Reset timer on music selection screen
 void gameMemory_OnMusicSelect(object sender, EventArgs e)
 {
     if (this.Settings.AutoReset)
     {
         _timer.Reset();
     }
 }
Ejemplo n.º 9
0
        public override void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
        {
            state.IsGameTimePaused = true;

            bool start = false;

            lock (eventsLock)
            {
                foreach (var ev in events)
                {
                    if (ev is GameEndEvent)
                    {
                        if (state.CurrentPhase == TimerPhase.Running && settings.ShouldSplitOnGameEnd())
                        {
                            state.SetGameTime(ev.Time);
                            model.Split();
                        }
                    }
                    else if (ev is MapChangeEvent)
                    {
                        var e = (MapChangeEvent)ev;
                        if (visitedMaps.Add(e.Map) && settings.ShouldSplitOn(e.Map))
                        {
                            state.SetGameTime(e.Time);
                            model.Split();
                        }
                    }
                    else if (ev is TimerResetEvent)
                    {
                        if (settings.IsAutoResetEnabled())
                        {
                            state.SetGameTime(ev.Time);
                            model.Reset();
                        }
                    }
                    else if (ev is TimerStartEvent)
                    {
                        if (settings.IsAutoStartEnabled())
                        {
                            state.SetGameTime(ev.Time);
                            start = true;
                        }
                    }
                }
                events.Clear();
            }
            if (start)
            {
                model.Start();
            }

            TimeSpan curTime;

            lock (currentTimeLock)
            {
                curTime = currentTime;
            }
            state.SetGameTime(curTime);
        }
Ejemplo n.º 10
0
 void gameMemory_OnFirstLevelLoading(object sender, EventArgs e)
 {
     if ((_state.CurrentPhase == TimerPhase.Running || _state.CurrentPhase == TimerPhase.Ended) && this.Settings.AutoReset)
     {
         Trace.WriteLine(String.Format("[NoLoads] Reset - {0}", _gameMemory.frameCounter));
         _timer.Reset();
     }
 }
Ejemplo n.º 11
0
        // This is executed repeatedly as long as the game is connected and initialized.
        private void DoUpdate(LiveSplitState state)
        {
            OldState = State.RefreshValues(_game);

            if (!(RunMethod(_methods.update, state) ?? true))
            {
                // If Update explicitly returns false, don't run anything else
                return;
            }

            // Call the start segment if the splits are not running, but ensure that the segment is called at least once.
            if (state.CurrentPhase == TimerPhase.NotRunning || !startMethodCalledFromUpdate)
            {
                if (RunMethod(_methods.start, state) ?? false)
                {
                    if (_settings.GetBasicSettingValue("start") && state.CurrentPhase == TimerPhase.NotRunning)
                    {
                        _timer.Start();
                    }
                }
                startMethodCalledFromUpdate = true;
            }

            if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused)
            {
                if (_uses_game_time && !state.IsGameTimeInitialized)
                {
                    _timer.InitializeGameTime();
                }

                var is_paused = RunMethod(_methods.isLoading, state);
                if (is_paused != null)
                {
                    state.IsGameTimePaused = is_paused;
                }

                var game_time = RunMethod(_methods.gameTime, state);
                if (game_time != null)
                {
                    state.SetGameTime(game_time);
                }

                if (RunMethod(_methods.reset, state) ?? false)
                {
                    if (_settings.GetBasicSettingValue("reset"))
                    {
                        _timer.Reset();
                    }
                }
                else if (RunMethod(_methods.split, state) ?? false)
                {
                    if (_settings.GetBasicSettingValue("split"))
                    {
                        _timer.Split();
                    }
                }
            }
        }
        private void UpdateAutosplitter()
        {
            var previousLatestSavePath = latestSavePath;

            latestSavePath = FindLatestSavePath();
            var levelDat = new NbtFile(Path.Combine(latestSavePath, "level.dat"));

            if (levelDat.RootTag.First()["DataVersion"].IntValue < 1122)
            {
                timer.Reset();

                Properties.Settings.Default.AutosplitterEnabled = false;
                Properties.Settings.Default.Save();

                MessageBox.Show("Autosplitting is not supported for versions under 1.12 and has been disabled",
                                ComponentName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var previousWorldTime = worldTime;

            worldTime = levelDat.RootTag.First()["Time"].LongValue;

            // We don't have a previous time to compare with yet, skip
            if (previousWorldTime == -1)
            {
                return;
            }

            if (timer.CurrentState.CurrentPhase != TimerPhase.NotRunning && worldTime == 0)
            {
                timer.Reset();
            }

            if (timer.CurrentState.CurrentPhase == TimerPhase.NotRunning && worldTime > 0 && previousWorldTime != worldTime && latestSavePath == previousLatestSavePath)
            {
                timer.Start();
            }

            if (timer.CurrentState.CurrentPhase == TimerPhase.Running && previousWorldTime != worldTime && latestSavePath == previousLatestSavePath &&
                levelDat.RootTag.First()["Player"]["seenCredits"].ByteValue == 1)
            {
                timer.Split();
            }
        }
Ejemplo n.º 13
0
        // This is executed repeatedly as long as the game is connected and initialized.
        private void DoUpdate(LiveSplit.UI.Components.LiveSplitState state)
        {
            OldState = State.RefreshValues(_game);

            if (!(RunMethod(_methods.update, state) ?? true))
            {
                // If Update explicitly returns false, don't run anything else
                return;
            }

            if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused)
            {
                if (_uses_game_time && !state.IsGameTimeInitialized)
                {
                    _timer.InitializeGameTime();
                }

                var is_paused = RunMethod(_methods.isLoading, state);
                if (is_paused != null)
                {
                    state.IsGameTimePaused = is_paused;
                }

                var game_time = RunMethod(_methods.gameTime, state);
                if (game_time != null)
                {
                    state.SetGameTime(game_time);
                }

                if (RunMethod(_methods.reset, state) ?? false)
                {
                    if (_settings.GetBasicSettingValue("reset"))
                    {
                        _timer.Reset();
                    }
                }
                else if (RunMethod(_methods.split, state) ?? false)
                {
                    if (_settings.GetBasicSettingValue("split"))
                    {
                        _timer.Split();
                    }
                }
            }

            if (state.CurrentPhase == TimerPhase.NotRunning)
            {
                if (RunMethod(_methods.start, state) ?? false)
                {
                    if (_settings.GetBasicSettingValue("start"))
                    {
                        _timer.Start();
                    }
                }
            }
        }
Ejemplo n.º 14
0
 public void On_Start()
 {
     if (_state.CurrentPhase != TimerPhase.NotRunning && _settings.AutoReset)
     {
         _timer.Reset();
     }
     if (_state.CurrentPhase == TimerPhase.NotRunning && _settings.AutoStart)
     {
         _timer.Start();
     }
     _state.IsGameTimePaused = true;
     _starting = true;
 }
Ejemplo n.º 15
0
        void gameMemory_OnPlayerGainedControl(object sender, PlayerControlChangedEventArgs e)
        {
            if (Settings.ResetMapTransitions.Value)
            {
                _splitOperations.Clear();
                _splitCount = 0;
            }

            if (!this.Settings.AutoStartEnabled.Value)
            {
                return;
            }

            if (_timer.CurrentState.CurrentPhase == TimerPhase.Running)
            {
                if (Settings.SplitInstead.Value)
                {
                    gameMemory_ManualSplit(sender, e);
                    return;
                }
                else if (!Settings.AutoResetEnabled.Value)
                {
                    return;
                }
            }

            _timer.Reset(); // make sure to reset for games that start from a quicksave (Aperture Tag)
            _timer.Start();

            if (Settings.RTAStartOffset.Value)
            {
                _timer.CurrentState.AdjustedStartTime -= TimeSpan.FromSeconds(Math.Abs(e.TicksOffset) * _intervalPerTick);
            }

            _sessionTicksOffset += e.TicksOffset;
            _tickOffset          = e.TicksOffset;
        }
Ejemplo n.º 16
0
        void gameMemory_OnStartSaveLoad(object sender, EventArgs e)
        {
            Stopwatch s = Stopwatch.StartNew();

            if (this.Settings.AutoReset)
            {
                UpdateBearCartPB(true);
                _timer.Reset();
            }

            if (this.Settings.AutoStart)
            {
                StartTimer(s.Elapsed);
            }
        }
Ejemplo n.º 17
0
 private void _gameMemory_OnFirstLevelLoaded(object sender, EventArgs e)
 {
     if (_state.CurrentPhase == TimerPhase.NotRunning)
     {
         if (this.Settings.AutoReset)
         {
             Debug.WriteLine($"Restting");
             _timer.Reset();
         }
     }
     if (this.Settings.AutoStart)
     {
         Debug.WriteLine($"strating timer");
         _timer.Start();
     }
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Reset and start the timer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnNewGame(object sender, StateEventArgs e)
        {
            if (gameData.IsRandomized)
            {
                e.State.Run.Clear();

                // LiveSplit pretends its in Timer-only mode if there is only one segment (Triforce), which means new segments won't be added
                e.State.Run.AddSegment(START);

                e.State.Run.AddSegment(TRIFORCE, icon: icons[TRIFORCE]);
            }

            timer.Reset();
            timer.Start();

            e.State.IsGameTimePaused = true;
        }
        public void Update()
        {
            _oldMemoryState     = _currentMemoryState;
            _currentMemoryState = Memory.GetState();

            switch (_state.CurrentPhase)
            {
            case TimerPhase.NotRunning:
                if (ShouldStart())
                {
                    _startingMemoryState = _currentMemoryState;

                    // Temporarily adjust the start offset for real-time accuracy.
                    var userOffset = _state.Run.Offset;
                    _state.Run.Offset = DateTime.Now - _firstLoadStartTime + TimeSpan.FromSeconds(StartOffset[AutosplitterSettings.StartCondition]);
                    _model.Start();
                    _state.Run.Offset = userOffset;
                    _state.SetGameTime(TimeSpan.FromSeconds(StartOffset[AutosplitterSettings.StartCondition]));
                }
                break;

            case TimerPhase.Running:
                // Pause timer when loading
                _state.IsGameTimePaused = _currentMemoryState.IsLoading;

                if (DateTime.Now > _timeUntilNextSplit && ShouldSplit())
                {
                    _model.Split();
                }
                else if (ShouldReset())
                {
                    _model.Reset();
                }
                break;
            }
        }
Ejemplo n.º 20
0
 void do_reset(object sender, EventArgs e)
 {
     _tm.Reset();
 }
Ejemplo n.º 21
0
        public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
        {
            if (Game == null || Game.HasExited)
            {
                Game = null;
                var process = Process.GetProcessesByName("SuperMeatBoy").FirstOrDefault();
                if (process != null)
                {
                    Game = process;
                }
                OldTitleScreenShowing = false;
            }

            if (Model == null)
            {
                Model = new TimerModel()
                {
                    CurrentState = state
                };
                state.OnStart += state_OnStart;
            }

            if (Game != null)
            {
                float    time;
                TimeSpan levelTime = OldLevelTime ?? TimeSpan.Zero;

                bool isInALevel;
                IsInALevel.Deref <bool>(Game, out isInALevel);
                if (isInALevel)
                {
                    try
                    {
                        LevelTimer.Deref <float>(Game, out time);
                        levelTime = TimeSpan.FromSeconds(time);
                    }
                    catch { }
                }

                //AliveTimer.Deref<float>(Game, out time);
                //var aliveTime = TimeSpan.FromSeconds(time);

                //int deathCounter;
                //DeathCounter.Deref<int>(Game, out deathCounter);

                int levelID;
                LevelID.Deref <int>(Game, out levelID);

                int chapterID;
                ChapterID.Deref <int>(Game, out chapterID);

                int levelType;
                LevelType.Deref <int>(Game, out levelType);

                int chapterSelectID;
                ChapterSelectID.Deref <int>(Game, out chapterSelectID);

                bool creditsPlaying;
                CreditsPlaying.Deref <bool>(Game, out creditsPlaying);

                bool isAtLevelSelect;
                IsAtLevelSelect.Deref <bool>(Game, out isAtLevelSelect);

                bool isNotAtLevelEnd;
                IsNotAtLevelEnd.Deref <bool>(Game, out isNotAtLevelEnd);
                if (!WasAtLevelEnd && !isNotAtLevelEnd)
                {
                    WasAtLevelEnd     = true;
                    FinishedLevelTime = levelTime;
                }

                bool titleScreenShowing;
                bool couldFetch = TitleScreenShowing.Deref <bool>(Game, out titleScreenShowing);
                if (!couldFetch)
                {
                    titleScreenShowing = true;
                }

                //bool isTimeRunning = OldLevelTime != levelTime;

                if (OldLevelTime != null)// && OldLevelTime != null)
                {
                    if (state.CurrentPhase == TimerPhase.NotRunning && !titleScreenShowing && OldTitleScreenShowing)
                    {
                        Model.Start();
                    }
                    else if (state.CurrentPhase == TimerPhase.Running)
                    {
                        if (chapterID == 6 && levelID == 99)
                        {
                            if (creditsPlaying && !OldCreditsPlaying)
                            {
                                Model.Split(); //The End
                            }
                        }
                        else
                        {
                            if ((levelType != 0 && levelType != 10) || chapterID == 7)
                            {
                                if (((levelType <= 1) ? (levelID == 20) : true) &&
                                    !isInALevel &&
                                    (levelID == 20 && state.CurrentSplitIndex == state.Run.Count - 1
                                        ? WasInALevel //Split earlier for Cotton Alley if it's the last split
                                        : (!isAtLevelSelect && WasAtLevelSelect)))
                                {
                                    Model.Split(); //Dark World or Cotton Alley
                                }
                            }
                            else if (!creditsPlaying && OldCreditsPlaying)
                            {
                                Model.Split(); //Chapter Splits
                            }
                        }

                        if (titleScreenShowing && !creditsPlaying)
                        {
                            Model.Reset();
                        }
                    }
                    if (OldLevelTime > levelTime)
                    {
                        //OldDeathCounter = deathCounter;
                        GameTime     += (WasAtLevelEnd ? FinishedLevelTime : OldLevelTime ?? TimeSpan.Zero);
                        WasAtLevelEnd = false;
                    }
                }

#if GAME_TIME
                state.IsLoading = true;
                var currentGameTime = GameTime + (WasAtLevelEnd ? FinishedLevelTime : levelTime);
                state.SetGameTime(currentGameTime < TimeSpan.Zero ? TimeSpan.Zero : currentGameTime);
#endif

                //WasTimeRunning = isTimeRunning;
                //OldLevelTime = levelTime;
                OldLevelTime          = levelTime;
                OldLevelID            = levelID;
                OldChapterSelectID    = chapterSelectID;
                OldCreditsPlaying     = creditsPlaying;
                WasAtLevelSelect      = isAtLevelSelect;
                WasInALevel           = isInALevel;
                OldTitleScreenShowing = titleScreenShowing;
            }
        }
Ejemplo n.º 22
0
        public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
        {
            if (Game == null || Game.HasExited)
            {
                Game = null;
                var process = Process.GetProcessesByName("GrooveCity").FirstOrDefault();
                if (process != null)
                {
                    Game = process;
                }
            }

            if (!state.Run.CustomComparisons.Contains("Game Time"))
            {
                state.Run.CustomComparisons.Add("Game Time");
            }

            if (Model == null)
            {
                Model = new TimerModel()
                {
                    CurrentState = state
                };
                state.OnStart += state_OnStart;
            }

            if (Game != null)
            {
                float time;
                //LevelTimer.Deref<float>(Game, out time);
                //var levelTime = TimeSpan.FromSeconds(time);

                AliveTimer.Deref <float>(Game, out time);
                var aliveTime = TimeSpan.FromSeconds(time);

                //int deathCounter;
                //DeathCounter.Deref<int>(Game, out deathCounter);

                int levelID;
                LevelID.Deref <int>(Game, out levelID);

                //bool isTimeRunning = OldLevelTime != levelTime;

                if (OldAliveTime != null)// && OldLevelTime != null)
                {
                    if (levelID != OldLevelID &&
                        levelID >= 6 &&
                        levelID <= 22 &&
                        levelID != 7 &&
                        levelID != 8 &&
                        levelID != 18)
                    {
                        if (state.CurrentPhase == TimerPhase.NotRunning && levelID == 6)
                        {
                            Model.Start();
                        }
                        else if (state.CurrentPhase == TimerPhase.Running)
                        {
                            Model.Split();
                        }
                    }
                    if (levelID == 4 && state.CurrentPhase == TimerPhase.Running)
                    {
                        Model.Reset();
                    }
                    if (OldAliveTime > aliveTime)
                    {
                        //OldDeathCounter = deathCounter;
                        GameTime += OldAliveTime ?? TimeSpan.Zero;
                    }
                }

                state.IsLoading       = true;
                state.CurrentGameTime = GameTime + aliveTime;

                //WasTimeRunning = isTimeRunning;
                //OldLevelTime = levelTime;
                OldAliveTime = aliveTime;
                OldLevelID   = levelID;
            }
        }
Ejemplo n.º 23
0
 void gameMemory_OnReset(object sender, EventArgs e)
 {
     _timer.Reset();
 }