<commit_before>using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using CollectionManager.DataTypes;
using OsuMemoryDataProvider;
using StreamCompanionTypes;
using StreamCompanionTypes.DataTypes;
using StreamCompanionTypes.Interfaces;
using Timer = System.Threading.Timer;

namespace OsuMemoryEventSource
{
    //TODO: OsuMemoryEventSource should get refactored into several interface-scoped classes
    public class OsuMemoryEventSource : OsuMemoryEventSourceBase,
        IMapDataFinder, ISettingsProvider, IFirstRunControlProvider
    {
        public string SettingGroup { get; } = "Map matching";

        protected override void OnSettingsSettingUpdated(object sender, SettingUpdated e)
        {
            if (e.Name == _names.EnableMemoryPooling.Name)
            {
                base.MemoryPoolingIsEnabled = _settings.Get<bool>(_names.EnableMemoryPooling);
            }
            base.OnSettingsSettingUpdated(sender, e);
        }

        public void Free()
        {
            userSettings?.Dispose();
        }

        private MemoryDataFinderSettings userSettings = null;
        public UserControl GetUiSettings()
        {
            if (userSettings == null || userSettings.IsDisposed)
            {
                userSettings = new MemoryDataFinderSettings(_settings);
            }

            return userSettings;
        }

        private bool TEMPfatalExceptionTiggered = false;
        public MapSearchResult FindBeatmap(MapSearchArgs searchArgs)
        {
            if (!Started)
                return null;

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

            if (!TEMPfatalExceptionTiggered)
            {
                if (_memoryReader == null)
                {
                    TEMPfatalExceptionTiggered = true;
                    throw new Exception("MemoryReader was not initalized");
                }
                if (_settings == null)
                {
                    TEMPfatalExceptionTiggered = true;
                    throw new Exception("Settings were not initalized");
                }
            }

            var result = new MapSearchResult(searchArgs);

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

            int mapId = _memoryReader.GetMapId();
            int mods = 0;

            if (searchArgs.Status == OsuStatus.Playing)
            {
                Thread.Sleep(250);
                mods = _memoryReader.GetMods();
                result.Mods = GetMods(mods);
            }

            Logger?.Log(">Got {0} & {1} from memory", LogLevel.Advanced, mapId.ToString(), mods.ToString());

            Mods eMods = result.Mods?.Mods ?? Mods.Omod;
            if (mapId > 2000000 || mapId < 0 || Helpers.IsInvalidCombination(eMods))
            {
                Logger?.Log("Sanity check tiggered - invalidating last result", LogLevel.Advanced);
                result.Mods = null;
                return result;
            }

            if (mapId == 0)
            {
                Logger?.Log("Map has no ID", LogLevel.Advanced);
                return result;<commit_msg>Fix: Increase MemoryEventSource mapId sanity-check<commit_after>using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using CollectionManager.DataTypes;
using OsuMemoryDataProvider;
using StreamCompanionTypes;
using StreamCompanionTypes.DataTypes;
using StreamCompanionTypes.Interfaces;
using Timer = System.Threading.Timer;

namespace OsuMemoryEventSource
{
    //TODO: OsuMemoryEventSource should get refactored into several interface-scoped classes
    public class OsuMemoryEventSource : OsuMemoryEventSourceBase,
        IMapDataFinder, ISettingsProvider, IFirstRunControlProvider
    {
        public string SettingGroup { get; } = "Map matching";

        protected override void OnSettingsSettingUpdated(object sender, SettingUpdated e)
        {
            if (e.Name == _names.EnableMemoryPooling.Name)
            {
                base.MemoryPoolingIsEnabled = _settings.Get<bool>(_names.EnableMemoryPooling);
            }
            base.OnSettingsSettingUpdated(sender, e);
        }

        public void Free()
        {
            userSettings?.Dispose();
        }

        private MemoryDataFinderSettings userSettings = null;
        public UserControl GetUiSettings()
        {
            if (userSettings == null || userSettings.IsDisposed)
            {
                userSettings = new MemoryDataFinderSettings(_settings);
            }

            return userSettings;
        }

        private bool TEMPfatalExceptionTiggered = false;
        public MapSearchResult FindBeatmap(MapSearchArgs searchArgs)
        {
            if (!Started)
                return null;

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

            if (!TEMPfatalExceptionTiggered)
            {
                if (_memoryReader == null)
                {
                    TEMPfatalExceptionTiggered = true;
                    throw new Exception("MemoryReader was not initalized");
                }
                if (_settings == null)
                {
                    TEMPfatalExceptionTiggered = true;
                    throw new Exception("Settings were not initalized");
                }
            }

            var result = new MapSearchResult(searchArgs);

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

            int mapId = _memoryReader.GetMapId();
            int mods = 0;

            if (searchArgs.Status == OsuStatus.Playing)
            {
                Thread.Sleep(250);
                mods = _memoryReader.GetMods();
                result.Mods = GetMods(mods);
            }

            Logger?.Log(">Got {0} & {1} from memory", LogLevel.Advanced, mapId.ToString(), mods.ToString());

            Mods eMods = result.Mods?.Mods ?? Mods.Omod;
            if (mapId > 200_000_000 || mapId < 0 || Helpers.IsInvalidCombination(eMods))
            {
                Logger?.Log("Sanity check tiggered - invalidating last result", LogLevel.Advanced);
                result.Mods = null;
                return result;
            }

            if (mapId == 0)
            {
                Logger?.Log("Map has no ID", LogLevel.Advanced);
                return result;
{'fraction_non_alphanumeric': 0.08181400337061437, 'fraction_numerical': 0.004902711812471273, 'mean_word_length': 1.8357949609035622, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1785812', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1592, 'n_words': 365}