Exemple #1
0
        private async Task <IMapSearchResult> FindBeatmaps(IMapSearchArgs mapSearchArgs, CancellationToken token)
        {
            if (mapSearchArgs.MapId == 0 && string.IsNullOrEmpty(mapSearchArgs.MapHash) && string.IsNullOrEmpty(mapSearchArgs.Raw))
            {
                //TODO: TEST
                return(null);
            }

            if (mapSearchArgs.EventType == OsuEventType.MapChange || _workerState.LastMapSearchResult == null || !_workerState.LastMapSearchResult.BeatmapsFound.Any())
            {
                _logger.SetContextData("SearchingForBeatmaps", "1");
                _workerState.LastMapSearchResult = await _mainMapDataGetter.FindMapData(mapSearchArgs, token);

                _logger.SetContextData("SearchingForBeatmaps", "0");
                return(_workerState.LastMapSearchResult);
            }

            var searchResult = new MapSearchResult(mapSearchArgs)
            {
                Mods = _workerState.LastMapSearchResult.Mods
            };

            searchResult.BeatmapsFound.AddRange(_workerState.LastMapSearchResult.BeatmapsFound);
            return(searchResult);
        }
Exemple #2
0
        public IMapSearchResult FindBeatmap(IMapSearchArgs searchArgs, CancellationToken cancellationToken)
        {
            if (!Started)
            {
                return(null);
            }

            if (searchArgs == null)
            {
                throw new ArgumentException(nameof(searchArgs));
            }

            var result = new MapSearchResult(searchArgs);

            if (!Started || !_settings.Get <bool>(_names.EnableMemoryScanner))
            {
                return(result);
            }

            var mods = ReadMods(searchArgs);

            result.Mods = GetModsEx(mods);

            Logger?.Log($">Got mods from memory: {result.Mods.ShownMods}({mods})", LogLevel.Debug);

            Mods eMods = result.Mods?.Mods ?? Mods.Omod;

            if (Helpers.IsInvalidCombination(eMods))
            {
                Logger?.Log("Sanity check tiggered - invalidating last result", LogLevel.Debug);
                result.Mods = null;
            }

            return(result);
        }
Exemple #3
0
        private void NewOsuEvent(object sender, IMapSearchArgs mapSearchArgs)
        {
            if (mapSearchArgs == null || workerCancellationTokenSource.IsCancellationRequested)
            {
                return;
            }

            _workerState.IsMemoryPoolingEnabled = _settings.Get <bool>(_names.EnableMemoryPooling);
            var eventData = new
            {
                eventType  = mapSearchArgs.EventType,
                mapId      = mapSearchArgs.MapId.ToString(),
                raw        = mapSearchArgs.Raw,
                hash       = mapSearchArgs.MapHash,
                playMode   = mapSearchArgs.PlayMode?.ToString() ?? "null",
                sourceName = mapSearchArgs.SourceName
            }.ToString();

            _logger.Log($"Received event: {eventData}", LogLevel.Debug);
            if (mapSearchArgs.SourceName.Contains("OsuMemory"))
            {
                _cancellationTokenSource.TryCancel();
                TasksMemory.Clear();
                _logger.SetContextData("OsuMemory_event", eventData);

                TasksMemory.Push(mapSearchArgs);
                return;
            }

            TasksMsn.Clear();
            TasksMsn.Push(mapSearchArgs);
        }
Exemple #4
0
        public IMapSearchResult FindBeatmap(IMapSearchArgs searchArgs, CancellationToken cancellationToken)
        {
            var      result  = new MapSearchResult(searchArgs);
            IBeatmap beatmap = null;

            if (!string.IsNullOrEmpty(searchArgs.MapHash))
            {
                beatmap = _databaseController.GetBeatmap(searchArgs.MapHash);
            }

            if (!IsValidBeatmap(beatmap) && searchArgs.MapId > 0)
            {
                beatmap = _databaseController.GetBeatmap(searchArgs.MapId);
            }

            if (!IsValidBeatmap(beatmap))
            {
                if (!(string.IsNullOrEmpty(searchArgs.Artist) && string.IsNullOrEmpty(searchArgs.Title)) || !string.IsNullOrEmpty(searchArgs.Raw))
                {
                    beatmap = _databaseController.GetBeatmap(searchArgs.Artist, searchArgs.Title, searchArgs.Diff, searchArgs.Raw);
                }
            }

            if (IsValidBeatmap(beatmap))
            {
                result.BeatmapsFound.Add(beatmap);
            }
            return(result);
        }
Exemple #5
0
        private async Task HandleMapSearchArgs(IMapSearchArgs mapSearchArgs)
        {
            if (mapSearchArgs == null)
            {
                return;
            }


            _cancellationTokenSource.Dispose();
            _cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken = _cancellationTokenSource.Token;
            var mapSearchResult   = await FindBeatmaps(mapSearchArgs, cancellationToken);

            if (_settings.Get <bool>(ConserveMemory))
            {
                GC.Collect();
            }

            if (mapSearchResult == null)
            {
                return;
            }

            if (!mapSearchResult.BeatmapsFound.Any() && mapSearchArgs.SourceName.Contains("OsuMemory"))
            {
                _workerState.MemorySearchFailed = true;
                return;
            }

            mapSearchResult.MapSource = mapSearchArgs.SourceName;
            await HandleMapSearchResult(mapSearchResult, cancellationToken);
        }
        public async Task <IMapSearchResult> FindMapData(IMapSearchArgs searchArgs, CancellationToken cancellationToken)
        {
            IMapSearchResult mapSearchResult = null;
            IModsEx          foundMods       = null;

            for (int i = 0; i < _mapDataFinders.Count; i++)
            {
                if ((_mapDataFinders[i].SearchModes & searchArgs.Status) == 0)
                {
                    continue;
                }
                try
                {
                    mapSearchResult = await _mapDataFinders[i].FindBeatmap(searchArgs, cancellationToken);
                }
                catch (OperationCanceledException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    _logger.Log(e, LogLevel.Error);
                    mapSearchResult = null;
                }

                if (mapSearchResult != null && mapSearchResult.BeatmapsFound.Any())
                {
                    if (mapSearchResult.Mods == null && foundMods != null)
                    {
                        mapSearchResult.Mods = foundMods;
                    }
                    _logger.Log($">Found data using \"{_mapDataFinders[i].SearcherName}\" ID: {mapSearchResult.BeatmapsFound[0]?.MapId}", LogLevel.Debug);
                    break;
                }
                if (mapSearchResult?.Mods != null)
                {
                    foundMods = mapSearchResult.Mods;
                }
            }

            if (mapSearchResult == null || !mapSearchResult.BeatmapsFound.Any())
            {
                _logger.Log("Couldn't find map data for specified map search args", LogLevel.Warning);
            }

            return(mapSearchResult ?? new MapSearchResult(searchArgs));
        }
        public async Task <IMapSearchResult> FindBeatmap(IMapSearchArgs args, CancellationToken cancellationToken)
        {
            if (args == null || string.IsNullOrEmpty(args.OsuFilePath))
            {
                return(null);
            }

            if (!File.Exists(args.OsuFilePath))
            {
                _logger.Log($"Osu file supplied in search args was not found on disk! ({args.OsuFilePath})", LogLevel.Error);
                return(null);
            }

            (Beatmap beatmap, CancelableAsyncLazy <IPpCalculator> ppTask)result;
            try
            {
                result = await LazerMapLoader.LoadLazerBeatmapWithPerformanceCalculator(args.OsuFilePath, args.PlayMode,
                                                                                        _modParser.GetModsFromEnum((int)args.Mods), _logger, cancellationToken);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception ex)
            {
                ex.Data["PreventedCrash"] = 1;
                ex.Data["location"]       = args.OsuFilePath;
                _logger.Log(ex, LogLevel.Critical);
                return(null);
            }

            if (result.beatmap == null)
            {
                var ex = new BeatmapLoadFailedException();
                ex.Data["location"] = args.OsuFilePath;
                _logger.Log(ex, LogLevel.Critical);
                _logger.Log($"Failed to load beatmap located at {args.OsuFilePath}", LogLevel.Warning);
                return(null);
            }

            return(new MapSearchResult(args)
            {
                BeatmapsFound = { result.beatmap },
                SharedObjects = { result.ppTask }
            });
        }
Exemple #8
0
        public IMapSearchResult FindMapData(IMapSearchArgs searchArgs)
        {
            IMapSearchResult mapSearchResult = null;
            IModsEx          foundMods       = null;

            for (int i = 0; i < _mapDataFinders.Count; i++)
            {
                if ((_mapDataFinders[i].SearchModes & searchArgs.Status) == 0)
                {
                    continue;
                }
                try
                {
                    mapSearchResult = _mapDataFinders[i].FindBeatmap(searchArgs);
                }
                catch (Exception e)
                {
                    _logger.Log(e, LogLevel.Error);
                    mapSearchResult = null;
                }

                if (mapSearchResult != null && mapSearchResult.BeatmapsFound.Any())
                {
                    if (mapSearchResult.Mods == null && foundMods != null)
                    {
                        mapSearchResult.Mods = foundMods;
                    }
                    _logger.Log(string.Format(">Found data using \"{0}\" ID: {1}", _mapDataFinders[i].SearcherName, mapSearchResult.BeatmapsFound[0]?.MapId), LogLevel.Debug);
                    break;
                }
                if (mapSearchResult?.Mods != null)
                {
                    foundMods = mapSearchResult.Mods;
                }
            }

            return(mapSearchResult ?? new MapSearchResult(searchArgs));
        }
        private int ReadMods(IMapSearchArgs searchArgs, int retryCount = 0)
        {
            if (searchArgs is MemoryMapSearchArgs memorySearchArgs)
            {
                return(memorySearchArgs.Mods);
            }

            int mods;

            if (searchArgs.Status == OsuStatus.Playing || searchArgs.Status == OsuStatus.Watching)
            {
                Thread.Sleep(250);

                mods = MemoryReader.TryReadProperty(MemoryReader.OsuMemoryAddresses.Player, nameof(Player.Mods), out var rawMods)
                    ? ((OsuMemoryDataProvider.OsuMemoryModels.Abstract.Mods)rawMods)?.Value ?? -1
                    : -1;
            }
            else
            {
                mods = MemoryReader.TryReadProperty(MemoryReader.OsuMemoryAddresses.GeneralData, nameof(GeneralData.Mods), out var rawMods)
                    ? (int)rawMods
                    : -1;
            }

            if ((mods < 0 || Helpers.IsInvalidCombination((Mods)mods)))
            {
                if (retryCount < 5)
                {
                    Logger.Log($"Mods read attempt failed - retrying (attempt {retryCount}); Status: {searchArgs.Status}; read: {(Mods)mods}({mods})", LogLevel.Debug);
                    return(ReadMods(searchArgs, ++retryCount));
                }

                Logger.Log($"Mods read attempt failed after {retryCount} retries; Status: {searchArgs.Status}", LogLevel.Debug);
                mods = 0;
            }

            return(mods);
        }
        private async Task HandleMapSearchArgs(IMapSearchArgs mapSearchArgs)
        {
            if (mapSearchArgs == null)
            {
                return;
            }

            _cancellationTokenSource = new CancellationTokenSource();
            var mapSearchResult = await FindBeatmaps(mapSearchArgs);

            if (mapSearchResult == null)
            {
                return;
            }

            if (!mapSearchResult.BeatmapsFound.Any() && mapSearchArgs.SourceName.Contains("OsuMemory"))
            {
                _workerState.MemorySearchFailed = true;
                return;
            }

            mapSearchResult.MapSource = mapSearchArgs.SourceName;
            await HandleMapSearchResult(mapSearchResult);
        }
 public MapSearchResult(IMapSearchArgs searchArgs)
 {
     SearchArgs = searchArgs;
 }
Exemple #12
0
 public IMapSearchResult FindBeatmap(IMapSearchArgs searchArgs)
 {
     lastMapSearchArgs = searchArgs;
     return(null);
 }
Exemple #13
0
        public IMapSearchResult FindBeatmap(IMapSearchArgs searchArgs, CancellationToken cancellationToken)
        {
            MapSearchResult mapSearchResult = new MapSearchResult(searchArgs);

            return(mapSearchResult);
        }
Exemple #14
0
 public Task <IMapSearchResult> FindBeatmap(IMapSearchArgs searchArgs, CancellationToken cancellationToken)
 => Task.FromResult <IMapSearchResult>(new MapSearchResult(searchArgs));
Exemple #15
0
 public IMapSearchResult FindBeatmap(IMapSearchArgs searchArgs, CancellationToken cancellationToken)
 {
     lastMapSearchArgs = searchArgs;
     return(null);
 }
Exemple #16
0
        public IMapSearchResult FindBeatmap(IMapSearchArgs searchArgs)
        {
            MapSearchResult mapSearchResult = new MapSearchResult(searchArgs);

            return(mapSearchResult);
        }