Exemplo n.º 1
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();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public async Task DoSplit()
        {
            if (_settings.Config.igt != null && _settings.Config.igt.active == "1" && _usb2snes.Connected())
            {
                uint[] allAddresses = new uint[] { _settings.Config.igt.framesAddressInt, _settings.Config.igt.secondsAddressInt,
                                                   _settings.Config.igt.minutesAddressInt, _settings.Config.igt.hoursAddressInt };
                IEnumerable <uint> validAddresses = allAddresses.Where(address => address > 0);
                uint startingAddress = validAddresses.Min();
                uint igtDataSize     = (validAddresses.Max() + 2) - startingAddress;
                if (0 == igtDataSize || igtDataSize > 512)
                {
                    Debug.WriteLine("DoSplit: IGT configuration invalid, skipping it");
                }
                else
                {
                    byte[] data;
                    try
                    {
                        data = await _usb2snes.GetAddress((0xF50000 + startingAddress), igtDataSize);
                    }
                    catch
                    {
                        Debug.WriteLine("DoSplit: Exception getting address");
                        _model.Split();
                        return;
                    }

                    if (data.Count() == 0)
                    {
                        Debug.WriteLine("DoSplit: Get address failed to return result");
                    }
                    else
                    {
                        Func <uint, int> readIgt = (address) =>
                                                   (0 == address) ? 0 : (data[address - startingAddress] + (data[(address + 1) - startingAddress] << 8));
                        int ms  = (readIgt(_settings.Config.igt.framesAddressInt) * 1000) / 60;
                        int sec = readIgt(_settings.Config.igt.secondsAddressInt);
                        int min = readIgt(_settings.Config.igt.minutesAddressInt);
                        int hr  = readIgt(_settings.Config.igt.hoursAddressInt);
                        var gt  = new TimeSpan(0, hr, min, sec, ms);
                        _state.SetGameTime(gt);
                    }
                }
            }
            _model.Split();
        }
 public void DoSplit()
 {
     if (_game.name == "Super Metroid" && _usb2snes.Connected())
     {
         var data = new byte[512];
         data = _usb2snes.GetAddress((uint)(0xF509DA), (uint)512);
         int ms  = (data[0] + (data[1] << 8)) * (1000 / 60);
         int sec = data[2] + (data[3] << 8);
         int min = data[4] + (data[5] << 8);
         int hr  = data[6] + (data[7] << 8);
         var gt  = new TimeSpan(0, hr, min, sec, ms);
         _state.SetGameTime(gt);
         _model.Split();
     }
     else
     {
         _model.Split();
     }
 }
Exemplo n.º 4
0
 public void DoSplit()
 {
     if (_game.name == "Super Metroid" && core.Connected())
     {
         var data = new byte[512];
         core.SendCommand(core.usbint_server_opcode_e.USBINT_SERVER_OPCODE_GET, core.usbint_server_space_e.USBINT_SERVER_SPACE_SNES, core.usbint_server_flags_e.USBINT_SERVER_FLAGS_NONE, (uint)(0xF509DA), (uint)512);
         core.GetData(data, 0, 512);
         int ms  = (data[0] + (data[1] << 8)) * (1000 / 60);
         int sec = data[2] + (data[3] << 8);
         int min = data[4] + (data[5] << 8);
         int hr  = data[6] + (data[7] << 8);
         var gt  = new TimeSpan(0, hr, min, sec, ms);
         _state.SetGameTime(gt);
         _model.Split();
     }
     else
     {
         _model.Split();
     }
 }
Exemplo n.º 5
0
        public async Task DoSplit()
        {
            if (_settings.Config.igt != null && _settings.Config.igt.active == "1" && _usb2snes.Connected())
            {
                var addressSizePairs = new List <Tuple <uint, uint> >();
                addressSizePairs.Add(new Tuple <uint, uint>(_settings.Config.igt.framesAddressInt, 2));
                addressSizePairs.Add(new Tuple <uint, uint>(_settings.Config.igt.secondsAddressInt, 2));
                addressSizePairs.Add(new Tuple <uint, uint>(_settings.Config.igt.minutesAddressInt, 2));
                addressSizePairs.Add(new Tuple <uint, uint>(_settings.Config.igt.hoursAddressInt, 2));
                List <byte[]> data = null;
                try
                {
                    data = await _usb2snes.GetAddress(addressSizePairs);
                }
                catch
                {
                    Debug.WriteLine("DoSplit: Exception getting address");
                    _model.Split();
                    return;
                }

                if ((null == data) || (data.Count != addressSizePairs.Count))
                {
                    Debug.WriteLine("DoSplit: Get address failed to return result");
                }
                else
                {
                    int frames = (int)data[0][0] + ((int)data[0][1] << 8);
                    int ms     = (frames * 1000) / 60;
                    int sec    = (int)data[1][0] + ((int)data[1][1] << 8);
                    int min    = (int)data[2][0] + ((int)data[2][1] << 8);
                    int hr     = (int)data[3][0] + ((int)data[3][1] << 8);
                    var gt     = new TimeSpan(0, hr, min, sec, ms);
                    _state.SetGameTime(gt);
                }
            }
            _model.Split();
        }
Exemplo n.º 6
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;
            }
        }