private OsuStatus GetCurrentOsuStatus() { try { if (m_osu_process == null) { return(OsuStatus.NoFoundProcess); } if (m_osu_process.HasExited == true) { return(OsuStatus.NoFoundProcess); } if (m_status_finder == null) { m_status_finder = InitFinder <OsuStatusFinder>( LANG_INIT_STATUS_FINDER_SUCCESS, LANG_INIT_STATUS_FINDER_FAILED ); return(OsuStatus.Unkonwn); } } catch (Win32Exception e) { Logger.Error($":{e.Message}"); } OsuInternalStatus mode = m_status_finder.GetCurrentOsuModes(); #if DEBUG if (mode != m_last_test) { Logger.Info($"Internal Status:{mode}"); } m_last_test = mode; #endif switch (mode) { case OsuInternalStatus.Edit: return(OsuStatus.Editing); case OsuInternalStatus.Play: return(OsuStatus.Playing); case OsuInternalStatus.RankingTagCoop: case OsuInternalStatus.RankingTeam: case OsuInternalStatus.RankingVs: case OsuInternalStatus.Rank: return(OsuStatus.Rank); case OsuInternalStatus.BeatmapImport: case OsuInternalStatus.Menu: case OsuInternalStatus.OnlineSelection: return(OsuStatus.Idle); case OsuInternalStatus.MatchSetup: return(OsuStatus.MatchSetup); case OsuInternalStatus.Lobby: return(OsuStatus.Lobby); case OsuInternalStatus.SelectEdit: case OsuInternalStatus.SelectMulti: case OsuInternalStatus.SelectPlay: return(OsuStatus.SelectSong); default: return(OsuStatus.Unkonwn); } }
private void ListenLoopUpdate() { OsuStatus status = GetCurrentOsuStatus(); if (status == OsuStatus.NoFoundProcess) { m_osu_process = null; m_play_finder = null; m_status_finder = null; m_beatmap_finder = null; m_mode_finder = null; m_hit_event_finder = null; FindOsuProcess(); } //Waiting for osu to start if (status != OsuStatus.NoFoundProcess && status != OsuStatus.Unkonwn) { //Wait for player to playing if (status == OsuStatus.Playing) { if (m_play_finder == null) { m_play_finder = InitFinder <OsuPlayFinder>(LANG_INIT_PLAY_FINDER_SUCCESS, LANG_INIT_PLAY_FINDER_FAILED); } if (Setting.GameMode == "Auto" && m_mode_finder == null) { m_mode_finder = InitFinder <OsuPlayModeFinder>(LANG_INIT_MODE_FINDER_SUCCESS, LANG_INIT_MODE_FINDER_FAILED); } if (m_hit_event_finder == null) { m_hit_event_finder = InitFinder <OsuHitEventFinder>(LANG_INIT_HIT_EVENT_SUCCESS, LANG_INIT_HIT_EVENT_FAIL); } } if (m_beatmap_finder == null) { m_beatmap_finder = InitFinder <OsuBeatmapFinder>(LANG_INIT_BEATMAP_FINDER_SUCCESS, LANG_INIT_BEATMAP_FINDER_FAILED); } if (m_mode_finder != null) { OsuPlayMode mode = OsuPlayMode.Osu; if (OnPlayModeChanged != null) { mode = m_mode_finder.GetMode(); } if (m_last_mode != mode) { OnPlayModeChanged?.Invoke(m_last_mode, mode); } m_last_mode = mode; } else { if (Setting.GameMode != "Auto") { if (s_game_mode_map.TryGetValue(Setting.GameMode, out var mode)) { if (m_last_mode != mode) { OnPlayModeChanged?.Invoke(m_last_mode, mode); } } m_last_mode = mode; } } if (OnHitEventsChanged != null && m_hit_event_finder != null) { // Hit events should work with playing time if (OnPlayingTimeChanged == null) { OnPlayingTimeChanged += (t) => { } } ; bool hasChanged; m_hit_event_finder.GetHitEvents(status, m_playing_time, out m_play_type, out m_hit_events, out hasChanged); if (hasChanged) { OnHitEventsChanged?.Invoke(m_play_type, m_hit_events); } } if (m_play_finder != null) { Beatmap beatmap = Beatmap.Empty; ModsInfo mods = ModsInfo.Empty; ErrorStatisticsResult error_statistics = ErrorStatisticsResult.Empty; int cb = 0; int pt = 0; int n300 = 0; int n100 = 0; int n50 = 0; int ngeki = 0; int nkatu = 0; int nmiss = 0; int score = 0; double hp = 0.0; double acc = 0.0; string playername = Setting.Username; try { if (OnPlayingTimeChanged != null) { pt = m_play_finder.GetPlayingTime(); } if (OnBeatmapChanged != null) { beatmap = m_beatmap_finder.GetCurrentBeatmap(m_osu_id); } if (Setting.EnableModsChangedAtListening && status != OsuStatus.Playing) { if (OnModsChanged != null) { mods = m_play_finder.GetCurrentModsAtListening(); } } if (beatmap != Beatmap.Empty && beatmap != m_last_beatmap) { OnBeatmapChanged?.Invoke(beatmap); } if (status == OsuStatus.Playing) { if (OnErrorStatisticsChanged != null) { error_statistics = m_play_finder.GetUnstableRate(); } if (OnModsChanged != null) { mods = m_play_finder.GetCurrentMods(); } if (OnComboChanged != null) { cb = m_play_finder.GetCurrentCombo(); } if (OnCount300Changed != null) { n300 = m_play_finder.Get300Count(); } if (OnCount100Changed != null) { n100 = m_play_finder.Get100Count(); } if (OnCount50Changed != null) { n50 = m_play_finder.Get50Count(); } if (OnCountGekiChanged != null) { ngeki = m_play_finder.GetGekiCount(); } if (OnCountKatuChanged != null) { nkatu = m_play_finder.GetKatuCount(); } if (OnCountMissChanged != null) { nmiss = m_play_finder.GetMissCount(); } if (OnAccuracyChanged != null) { acc = m_play_finder.GetCurrentAccuracy(); } if (OnHealthPointChanged != null) { hp = m_play_finder.GetCurrentHP(); } if (OnScoreChanged != null) { score = m_play_finder.GetCurrentScore(); } if (OnPlayerChanged != null) { playername = m_play_finder.GetCurrentPlayerName(); } } if (status != m_last_osu_status) { OnStatusChanged?.Invoke(m_last_osu_status, status); } if (mods != ModsInfo.Empty && !ModsInfo.VaildMods(mods)) { mods = m_last_mods; } if (mods != m_last_mods) { OnModsChanged?.Invoke(mods); } if (hp != m_last_hp) { OnHealthPointChanged?.Invoke(hp); } if (acc != m_last_acc) { OnAccuracyChanged?.Invoke(acc); } if (!error_statistics.Equals(m_last_error_statistics)) { OnErrorStatisticsChanged?.Invoke(error_statistics); } if (playername != m_last_playername) { OnPlayerChanged(playername); } if (score != m_last_score) { OnScoreChanged?.Invoke(score); } if (n300 != m_last_300) { OnCount300Changed?.Invoke(n300); } if (n100 != m_last_100) { OnCount100Changed?.Invoke(n100); } if (n50 != m_last_50) { OnCount50Changed?.Invoke(n50); } if (ngeki != m_last_geki) { OnCountGekiChanged?.Invoke(ngeki); } if (nkatu != m_last_katu) { OnCountKatuChanged?.Invoke(nkatu); } if (nmiss != m_last_miss) { OnCountMissChanged?.Invoke(nmiss); } if (cb != m_last_combo) { OnComboChanged?.Invoke(cb); } if (pt != m_playing_time) { OnPlayingTimeChanged?.Invoke(pt); } } catch (Exception e) { Logger.Error(e.ToString()); } m_last_beatmap = beatmap; m_last_mods = mods; m_last_hp = hp; m_last_acc = acc; m_last_error_statistics = error_statistics; m_last_combo = cb; m_playing_time = pt; m_last_300 = n300; m_last_100 = n100; m_last_50 = n50; m_last_geki = ngeki; m_last_katu = nkatu; m_last_miss = nmiss; m_last_score = score; m_last_osu_status = status; m_last_playername = playername; } } }