public void GotMemory(int mapId, OsuStatus status, string mapString) { if (!this.IsHandleCreated) { return; } lock (_lockingObject) { this.BeginInvoke((MethodInvoker) delegate { label_memoryStatus.Text = $"{status}, id:{mapId}, valid mapset:{CurrentMap.BelongsToSet(mapId)}"; }); if (CurrentMap.BelongsToSet(mapId) && status == OsuStatus.Playing) { this.BeginInvoke((MethodInvoker) delegate { SetCalibrationText("Searching. It can take up to 20 seconds."); this.button_Next.Enabled = false; }); var everythingIsOk = Helpers.ExecWithTimeout(token => { Thread.Sleep(2000); if (token.IsCancellationRequested) { return(false); } int mods = memoryReader.GetMods(); if (mods == ExpectedMods) { return(true); } return(false); }, 20000); _settings.Add(_names.EnableMemoryScanner.Name, everythingIsOk); _settings.Add(_names.EnableMemoryPooling.Name, everythingIsOk); Passed = everythingIsOk; this.BeginInvoke((MethodInvoker) delegate { var resultText = everythingIsOk ? "Found right offset, Continue :)" : "Something went wrong. Try again(start map again) or continue with DISABLED memory"; SetCalibrationText(resultText); this.button_Next.Enabled = true; }); } } }
public void Tick(IOsuMemoryReader reader, bool sendEvents) { _currentStatus = reader.GetCurrentStatus(out _); if (_lastStatusLog != _currentStatus) { _lastStatusLog = _currentStatus; //Console.WriteLine("status: {0} {1}", _currentStatus, _currentStatus == OsuMemoryStatus.Unknown ? num.ToString() : ""); } if (_currentStatus != OsuMemoryStatus.NotRunning) { _currentMapId = reader.GetMapId(); _currentMapString = reader.GetSongString(); OsuStatus status = _currentStatus.Convert(); var gameMode = reader.ReadSongSelectGameMode(); var mapHash = reader.GetMapMd5Safe(); var mapSelectionMods = reader.GetMods(); var mapHashDiffers = mapHash != null && _lastMapHash != null && _lastMapHash != mapHash; if (sendEvents && (_lastMapId != _currentMapId || _lastStatus != _currentStatus || _currentMapString != _lastMapString || gameMode != _lastGameMode || mapSelectionMods != _lastMapSelectionMods || mapHashDiffers) ) { _lastMapId = _currentMapId; _lastStatus = _currentStatus; _lastMapString = _currentMapString; _lastGameMode = gameMode; _lastMapSelectionMods = mapSelectionMods; _lastMapHash = mapHash; NewOsuEvent?.Invoke(this, new MapSearchArgs("OsuMemory") { MapId = _currentMapId, Status = status, Raw = _currentMapString, MapHash = mapHash, PlayMode = (PlayMode)gameMode, }); } _memoryDataProcessor.Tick(status, reader); } }
private void OnShown(object sender, EventArgs eventArgs) { if (!string.IsNullOrEmpty(_osuWindowTitleHint)) { Text += $": {_osuWindowTitleHint}"; } _ = Task.Run(async() => { try { var playContainer = new PlayContainerEx(); var playReseted = false; while (true) { if (cts.IsCancellationRequested) { return; } var patternsToRead = GetPatternsToRead(); var stopwatch = Stopwatch.StartNew(); #region OsuBase var mapId = -1; var songString = string.Empty; var mapMd5 = string.Empty; var mapFolderName = string.Empty; var osuFileName = string.Empty; var retrys = -1; var gameMode = -1; var mapData = string.Empty; var status = OsuMemoryStatus.Unknown; var statusNum = -1; var playTime = -1; if (patternsToRead.OsuBase) { mapId = _reader.GetMapId(); songString = _reader.GetSongString(); mapMd5 = _reader.GetMapMd5(); mapFolderName = _reader.GetMapFolderName(); osuFileName = _reader.GetOsuFileName(); retrys = _reader.GetRetrys(); gameMode = _reader.ReadSongSelectGameMode(); mapData = $"HP:{_reader.GetMapHp()} OD:{_reader.GetMapOd()}, CS:{_reader.GetMapCs()}, AR:{_reader.GetMapAr()}, setId:{_reader.GetMapSetId()}"; status = _reader.GetCurrentStatus(out statusNum); playTime = _reader.ReadPlayTime(); } #endregion #region Mods var mods = -1; if (patternsToRead.Mods) { mods = _reader.GetMods(); } #endregion #region CurrentSkinData var skinFolderName = string.Empty; if (patternsToRead.CurrentSkinData) { skinFolderName = _reader.GetSkinFolderName(); } #endregion #region PlayContainer double hp = 0; var playerName = string.Empty; var hitErrorCount = -1; var playingMods = -1; double displayedPlayerHp = 0; if (status == OsuMemoryStatus.Playing && patternsToRead.PlayContainer) { playReseted = false; _reader.GetPlayData(playContainer); hp = _reader.ReadPlayerHp(); playerName = _reader.PlayerName(); hitErrorCount = _reader.HitErrors()?.Count ?? -2; playingMods = _reader.GetPlayingMods(); displayedPlayerHp = _reader.ReadDisplayedPlayerHp(); } else if (!playReseted) { playReseted = true; playContainer.Reset(); } #endregion #region TourneyBase // TourneyBase var tourneyIpcState = TourneyIpcState.Unknown; var tourneyIpcStateNumber = -1; var tourneyLeftStars = -1; var tourneyRightStars = -1; var tourneyBO = -1; var tourneyStarsVisible = false; var tourneyScoreVisible = false; if (status == OsuMemoryStatus.Tourney && patternsToRead.TourneyBase) { tourneyIpcState = _reader.GetTourneyIpcState(out tourneyIpcStateNumber); tourneyLeftStars = _reader.ReadTourneyLeftStars(); tourneyRightStars = _reader.ReadTourneyRightStars(); tourneyBO = _reader.ReadTourneyBO(); tourneyStarsVisible = _reader.ReadTourneyStarsVisible(); tourneyScoreVisible = _reader.ReadTourneyScoreVisible(); } #endregion stopwatch.Stop(); var readTimeMs = stopwatch.ElapsedTicks / (double)TimeSpan.TicksPerMillisecond; double readTimeMsMin; double readTimeMsMax; lock (_minMaxLock) { if (readTimeMs < _memoryReadTimeMin) { _memoryReadTimeMin = readTimeMs; } if (readTimeMs > _memoryReadTimeMax) { _memoryReadTimeMax = readTimeMs; } // copy value since we're inside lock readTimeMsMin = _memoryReadTimeMin; readTimeMsMax = _memoryReadTimeMax; } Invoke((MethodInvoker)(() => { textBox_readTime.Text = $" ReadTimeMS: {readTimeMs}{Environment.NewLine}" + $" Min ReadTimeMS: {readTimeMsMin}{Environment.NewLine}" + $"Max ReadTimeMS: {readTimeMsMax}{Environment.NewLine}"; textBox_mapId.Text = mapId.ToString(); textBox_strings.Text = $"songString: \"{songString}\" {Environment.NewLine}" + $"md5: \"{mapMd5}\" {Environment.NewLine}" + $"mapFolder: \"{mapFolderName}\" {Environment.NewLine}" + $"fileName: \"{osuFileName}\" {Environment.NewLine}" + $"Retrys:{retrys} {Environment.NewLine}" + $"mods:{(Mods)mods}({mods}) {Environment.NewLine}" + $"SkinName: \"{skinFolderName}\""; textBox_time.Text = playTime.ToString(); textBox_mapData.Text = mapData; textBox_Status.Text = status + " " + statusNum + " " + gameMode; textBox_CurrentPlayData.Text = playContainer + Environment.NewLine + $"hp________: {hp:00.##} {Environment.NewLine}" + $"displayedHp: {displayedPlayerHp:00.##} {Environment.NewLine}" + $"playingMods:{(Mods)playingMods} ({playingMods}) " + $"PlayerName: {playerName}{Environment.NewLine}" + $"HitErrorCount: {hitErrorCount} "; if (status == OsuMemoryStatus.Tourney) { textBox_TourneyStuff.Text = $"IPC-State: {tourneyIpcState} ({tourneyIpcStateNumber}) | BO {tourneyBO}{Environment.NewLine}" + $"Stars: {tourneyLeftStars} | {tourneyRightStars}{Environment.NewLine}" + $"Warmup/Stars State: {(tourneyStarsVisible ? "stars visible, warmup disabled" : "stars hidden, warmup enabled")}{Environment.NewLine}" + $"Score/Chat state: {(tourneyScoreVisible ? "chat hidden, score visible or no lobby joined" : "chat visible, score hidden")}{Environment.NewLine}"; } else { textBox_TourneyStuff.Text = "no data since not in tourney mode"; } })); await Task.Delay(_readDelay); } } catch (ThreadAbortException) { } }); }
public void Tick(IOsuMemoryReader reader, bool sendEvents) { _currentStatus = reader.GetCurrentStatus(out _); if (_lastStatusLog != _currentStatus) { _lastStatusLog = _currentStatus; //Console.WriteLine("status: {0} {1}", _currentStatus, _currentStatus == OsuMemoryStatus.Unknown ? num.ToString() : ""); } if (_currentStatus != OsuMemoryStatus.NotRunning) { _currentMapId = reader.GetMapId(); var isReplay = reader.IsReplay(); OsuStatus status = _currentStatus.Convert(); status = status == OsuStatus.Playing && isReplay ? OsuStatus.Watching : status; var gameMode = reader.ReadSongSelectGameMode(); var mapHash = reader.GetMapMd5Safe(); var mapSelectionMods = reader.GetMods(); var playingMods = status == OsuStatus.Playing || status == OsuStatus.Watching ? reader.GetPlayingMods() : -1; var retries = reader.GetRetrys(); var currentTime = reader.ReadPlayTime(); var mapHashDiffers = mapHash != null && _lastMapHash != null && _lastMapHash != mapHash; var mapIdDiffers = _lastMapId != _currentMapId; var memoryStatusDiffers = _lastStatus != _currentStatus; var gameModeDiffers = gameMode != _lastGameMode; var mapSelectionModsDiffer = mapSelectionMods != _lastMapSelectionMods; var playingModsDiffer = (status == OsuStatus.Watching || status == OsuStatus.Playing) && playingMods != _lastPlayingMods; OsuEventType?osuEventType = null; //"good enough" replay retry detection. if (isReplay && _currentStatus == OsuMemoryStatus.Playing && _lastTime > currentTime && DateTime.UtcNow > _nextReplayRetryAllowedAt) { osuEventType = OsuEventType.PlayChange; _nextReplayRetryAllowedAt = DateTime.UtcNow.AddMilliseconds(500); } _lastTime = currentTime; var playInitialized = (status != OsuStatus.Watching && status != OsuStatus.Playing) || playingMods != -1; if (sendEvents && playInitialized && ( osuEventType.HasValue || mapIdDiffers || memoryStatusDiffers || mapHashDiffers || gameModeDiffers || mapSelectionModsDiffer || retries != _lastRetries ) ) { if (!osuEventType.HasValue || playingModsDiffer) { osuEventType = mapIdDiffers || mapHashDiffers || gameModeDiffers || mapSelectionModsDiffer || playingModsDiffer ? OsuEventType.MapChange //different mapId/hash/mode/mods(changed stats) = different map : memoryStatusDiffers ? OsuEventType.SceneChange //memory scene(status) change = Scene change : _currentStatus == OsuMemoryStatus.Playing ? OsuEventType.PlayChange // map retry : OsuEventType.MapChange; //bail } _lastMapId = _currentMapId; _lastStatus = _currentStatus; _lastRetries = retries; _lastGameMode = gameMode; _lastMapSelectionMods = mapSelectionMods; _lastMapHash = mapHash; _lastPlayingMods = playingMods; NewOsuEvent?.Invoke(this, new MapSearchArgs("OsuMemory", osuEventType.Value) { MapId = _currentMapId, Status = status, Raw = reader.GetSongString(), MapHash = mapHash, PlayMode = (PlayMode)gameMode, }); } _memoryDataProcessor.Tick(status, reader); } }