IEnumerator DoLevelLoadOperation(bool manuallyEnterLevel) { OnLoadStarted.Invoke(); if (manuallyEnterLevel) { levelLoadOperation.allowSceneActivation = false; } while ( (!manuallyEnterLevel && !levelLoadOperation.isDone) || (manuallyEnterLevel && Mathf.Approximately(levelLoadOperation.progress, 0.9f)) ) { yield return(null); } if (!manuallyEnterLevel) { levelLoadOperation = null; } OnLoadFinished.Invoke(); }
void MemoryReadThread() { Process game = null; while (!_cancelSource.IsCancellationRequested) { try { Trace.WriteLine("[NoLoads] Waiting for a game process..."); while ((game = GetGameProcess()) == null) { Thread.Sleep(250); if (_cancelSource.IsCancellationRequested) { return; } } Trace.WriteLine($"[NoLoads] Attached to {game.ProcessName}.exe ({Game.GetType().Name})"); _uiThread.Post(d => OnLoadEnded?.Invoke(this, EventArgs.Empty), null); //unpause at launch uint frameCounter = 0; bool isLoading; bool prevIsLoading = false; var map = string.Empty; var prevMap = string.Empty; DoTimerAction(Game.OnAttach(game)); while (!game.HasExited) { _watchers.UpdateAll(game); DoTimerAction(Game.OnUpdate(game, _watchers)); var gameSupportIsLoading = Game.IsLoading(_watchers); if (!gameSupportIsLoading.HasValue) { isLoading = _status.Current != (int)Status.None; } else { isLoading = gameSupportIsLoading.Value; } Debug.WriteLineIf(_status.Changed, string.Format("[NoLoads] Status changed from {1} to {2} - {0}", frameCounter, (Status)_status.Old, (Status)_status.Current)); if (_map.Changed) { if (string.IsNullOrEmpty(Game.MapExtension) || string.IsNullOrEmpty(Path.GetExtension(_map.Current)) || string.Equals(Path.GetExtension(_map.Current), Game.MapExtension, StringComparison.OrdinalIgnoreCase)) { prevMap = map; map = Path.GetFileNameWithoutExtension(_map.Current); _uiThread.Post(d => OnMapChange?.Invoke(this, prevMap, map), null); Debug.WriteLine(string.Format("[NoLoads] Map is changing from \"{0}\" to \"{1}\" - {2}", prevMap, map, frameCounter)); } } if (_status.Changed && _status.Current == (int)Status.LoadingMap) { DoTimerAction(Game.OnMapLoad(_watchers)); } if (isLoading != prevIsLoading) { if (isLoading) { _uiThread.Post(d => OnLoadStarted?.Invoke(this, EventArgs.Empty), null); Trace.WriteLine(string.Format("[NoLoads] Load start - {0}", frameCounter)); } else { _uiThread.Post(d => OnLoadEnded?.Invoke(this, EventArgs.Empty), null); Trace.WriteLine(string.Format("[NoLoads] Load end - {0}", frameCounter)); } } prevIsLoading = isLoading; frameCounter++; Thread.Sleep(SLEEP_TIME); if (_cancelSource.IsCancellationRequested) { break; } } DoTimerAction(Game.OnDetach(game)); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); Thread.Sleep(1000); } } Unpatch(game); }