Example #1
0
 public Form1(string osuWindowTitleHint)
 {
     InitializeComponent();
     _sreader = StructuredOsuMemoryReader.Instance.GetInstanceForWindowTitleHint(osuWindowTitleHint);
     Shown   += OnShown;
     Closing += OnClosing;
 }
Example #2
0
 public Form1(string osuWindowTitleHint)
 {
     _osuWindowTitleHint = osuWindowTitleHint;
     InitializeComponent();
     _reader  = OsuMemoryReader.Instance.GetInstanceForWindowTitleHint(osuWindowTitleHint);
     _sreader = StructuredOsuMemoryReader.Instance.GetInstanceForWindowTitleHint(osuWindowTitleHint);
     Shown   += OnShown;
     Closing += OnClosing;
     numericUpDown_readDelay.ValueChanged += NumericUpDownReadDelayOnValueChanged;
 }
        public Form1(string osuWindowTitleHint)
        {
            _osuWindowTitleHint = osuWindowTitleHint;
            InitializeComponent();
#pragma warning disable CS0618 // Type or member is obsolete
            _reader = OsuMemoryReader.Instance.GetInstanceForWindowTitleHint(osuWindowTitleHint);
#pragma warning restore CS0618 // Type or member is obsolete
            _sreader = StructuredOsuMemoryReader.Instance.GetInstanceForWindowTitleHint(osuWindowTitleHint);
            Shown   += OnShown;
            Closing += OnClosing;
            numericUpDown_readDelay.ValueChanged += NumericUpDownReadDelayOnValueChanged;
        }
        public void Tick(OsuStatus status, OsuMemoryStatus rawStatus, StructuredOsuMemoryReader reader)
        {
            _notUpdatingTokens.WaitOne();
            _notUpdatingMemoryValues.Reset();
            lock (_lockingObject)
            {
                if (!ReferenceEquals(OsuMemoryData, reader.OsuMemoryAddresses))
                {
                    OsuMemoryData = reader.OsuMemoryAddresses;
                    _rawData.Play = OsuMemoryData.Player;
                }
                if ((OsuStatus)_liveTokens["status"].Token.Value != status)
                {
                    _liveTokens["status"].Token.Value = status;
                }

                _liveTokens["rawStatus"].Token.Value = rawStatus;

                if (status != OsuStatus.Playing && status != OsuStatus.Watching)
                {
                    var rawAudioTime = Retry.RetryMe(() =>
                                                     reader.ReadProperty(OsuMemoryData.GeneralData, nameof(GeneralData.AudioTime)), (val => val != null), 5);
                    if (int.TryParse(rawAudioTime?.ToString(), out var audioTime))
                    {
                        _rawData.PlayTime = audioTime;
                    }

                    reader.Read(OsuMemoryData.Skin);
                    UpdateLiveTokens(status);
                    _lastStatus = status;
                    _notUpdatingMemoryValues.Set();
                    return;
                }

                if (_lastStatus != OsuStatus.Playing && _lastStatus != OsuStatus.Watching)
                {
                    _newPlayStarted.Set();
                    Thread.Sleep(500);//Initial play delay
                }

                reader.Read(OsuMemoryData.Player);
                _rawData.PlayTime = OsuMemoryData.GeneralData.AudioTime;
                _liveTokens["time"].Update();

                _lastStatus = status;
            }

            _notUpdatingMemoryValues.Set();
        }
        public void Tick(OsuStatus status, OsuMemoryStatus rawStatus, StructuredOsuMemoryReader reader)
        {
            _notUpdatingTokens.WaitOne();
            _notUpdatingMemoryValues.Reset();
            lock (_lockingObject)
            {
                if (!ReferenceEquals(OsuMemoryData, reader.OsuMemoryAddresses))
                {
                    OsuMemoryData = reader.OsuMemoryAddresses;
                }
                if ((OsuStatus)_liveTokens["status"].Token.Value != status)
                {
                    _liveTokens["status"].Token.Value = status;
                }

                _liveTokens["rawStatus"].Token.Value = rawStatus;
                int playTime = OsuMemoryData.GeneralData.AudioTime;
                switch (status)
                {
                case OsuStatus.Playing:
                case OsuStatus.Watching:
                    if (_lastStatus != OsuStatus.Playing && _lastStatus != OsuStatus.Watching)
                    {
                        _newPlayStarted.Set();
                        Thread.Sleep(500);    //Initial play delay
                    }

                    reader.TryRead(OsuMemoryData.Player);
                    if (!ReferenceEquals(_rawData.Play, OsuMemoryData.Player))
                    {
                        _rawData.Play = OsuMemoryData.Player;
                    }

                    //TODO: support for live multiplayer leaderboard
                    if (!ReadLeaderboard)
                    {
                        //Read whole leaderboard once
                        if (reader.TryRead(OsuMemoryData.LeaderBoard))
                        {
                            ReadLeaderboard = true;
                            if (!ReferenceEquals(_rawData.LeaderBoard, OsuMemoryData.LeaderBoard))
                            {
                                _rawData.LeaderBoard = OsuMemoryData.LeaderBoard;
                            }
                        }
                    }
                    else
                    {
                        //Throttle whole leaderboard reads - Temporary solution until multiplayer detection is implemented, this should be only done in multiplayer
                        if (_nextLeaderBoardUpdate < DateTime.UtcNow)
                        {
                            reader.TryRead(OsuMemoryData.LeaderBoard);
                            _nextLeaderBoardUpdate = DateTime.UtcNow.AddMilliseconds(_settings.Get <int>(MultiplayerLeaderBoardUpdateRate));
                        }
                        else
                        {
                            //...then update main player data
                            if (OsuMemoryData.LeaderBoard.HasLeaderBoard)
                            {
                                reader.TryRead(OsuMemoryData.LeaderBoard.MainPlayer);
                            }
                        }
                    }

                    break;

                case OsuStatus.ResultsScreen:
                    ReadLeaderboard = false;
                    reader.TryRead(OsuMemoryData.ResultsScreen);
                    if (!ReferenceEquals(_rawData.Play, OsuMemoryData.ResultsScreen))
                    {
                        _rawData.Play = OsuMemoryData.ResultsScreen;
                    }

                    playTime = Convert.ToInt32(_rawData.PpCalculator?.BeatmapLength ?? 0);
                    break;

                default:
                    ReadLeaderboard      = false;
                    _rawData.LeaderBoard = new LeaderBoard();
                    reader.TryRead(OsuMemoryData.Skin);
                    _lastStatus = status;
                    break;
                }

                _rawData.PlayTime = playTime;
                _liveTokens["time"].Update();

                _lastStatus = status;
            }

            _notUpdatingMemoryValues.Set();
        }