Exemplo n.º 1
0
        void MemoryReadThread()
        {
            Debug.WriteLine("[NoLoads] MemoryReadThread");
            _settings_SplitsChanged(null, null);

            while (!_cancelSource.IsCancellationRequested)
            {
                try
                {
                    Debug.WriteLine("[NoLoads] Waiting for thief.exe or thief2.exe...");

                    Process game;
                    while ((game = GetGameProcess()) == null)
                    {
                        if (_cancelSource.IsCancellationRequested)
                        {
                            return;
                        }
                    }

                    Debug.WriteLine("[NoLoads] Got games process!");

                    uint frameCounter = 0;

                    while (!game.HasExited)
                    {
                        isLoading = _isLoadingPtr.ReadBool();
                        if (_levelCompleteCounter != null)
                        {
                            LevelCompletedCounter = _levelCompleteCounter.ReadInteger();
                        }
                        string tempRead = _levelName.ReadString(StringReadLenght, SuisReader.StringType.UTF8).ToString();
                        if (tempRead != "")
                        {
                            CurrentMap = tempRead.ToLower();
                        }
                        if (CurrentMap.EndsWith(".mis"))
                        {
                            CurrentMap = CurrentMap.Substring(0, CurrentMap.Length - 4);
                        }

                        if (isLoading != prevIsLoading)
                        {
                            if (isLoading)
                            {
                                Debug.WriteLine(String.Format("[NoLoads] Load Start - {0}", frameCounter));

                                loadingStarted = true;

                                // pause game timer
                                _uiThread.Post(d =>
                                {
                                    if (this.OnLoadStarted != null)
                                    {
                                        this.OnLoadStarted(this, EventArgs.Empty);
                                    }
                                }, null);
                            }
                            else
                            {
                                Debug.WriteLine(String.Format("[NoLoads] Load End - {0}", frameCounter));

                                if (loadingStarted)
                                {
                                    loadingStarted = false;


                                    // unpause game timer
                                    _uiThread.Post(d =>
                                    {
                                        if (this.OnLoadFinished != null)
                                        {
                                            this.OnLoadFinished(this, EventArgs.Empty);
                                        }
                                    }, null);
                                }

                                if (Splits != null && Splits.Length > 0 && CurrentMap == Splits[0].MapName)
                                {
                                    // StartTimer
                                    _uiThread.Post(d =>
                                    {
                                        if (this.OnPlayerGainedControl != null)
                                        {
                                            this.OnFirstLevelLoading(this, EventArgs.Empty);
                                            this.OnPlayerGainedControl(this, EventArgs.Empty);
                                        }
                                    }, null);
                                }
                            }
                        }

                        if (CurrentMap != prevMap && CurrentMap != "" || prevLevelCompletedCounter != LevelCompletedCounter)
                        {
                            for (int i = 1; i < Splits.Length; i++)
                            {
                                if (Splits[i].Checked && Splits[i].MapName == CurrentMap && Splits[i - 1].MapName == prevMap)
                                {
                                    Split(i, frameCounter);
                                    break;
                                }
                            }
                            Debug.WriteLine("[NOLOADS] Map changed from \"" + prevMap + "\" to \"" + CurrentMap + "\"");

                            if (SplitOnLastSplit)
                            {
                                if (Splits.Last().MapName == CurrentMap && LevelCompletedCounter > prevLevelCompletedCounter)
                                {
                                    Split(SplitStates.Length - 1, frameCounter);
                                }
                            }
                        }

                        prevMap                   = CurrentMap;
                        prevIsLoading             = isLoading;
                        prevLevelCompletedCounter = LevelCompletedCounter;
                        frameCounter++;

                        Thread.Sleep(15);

                        if (_cancelSource.IsCancellationRequested)
                        {
                            return;
                        }
                    }

                    // pause game timer on exit or crash
                    _uiThread.Post(d =>
                    {
                        if (this.OnLoadStarted != null)
                        {
                            this.OnLoadStarted(this, EventArgs.Empty);
                        }
                    }, null);
                    isLoading = true;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    Thread.Sleep(1000);
                }
            }
        }