private void SetNumPlayers() { ProcessMemoryReader pr = new ProcessMemoryReader(); pr.ReadProcess = GetBorderlandsProcess(); if (pr.ReadProcess == null) { return; } pr.OpenProcess(); if (NumPlayersIsGood()) { WriteValueToMemory(pr, (byte)this.slider.Value); } else { MessageBox.Show("Player value has changed. Please rescan."); this.slider.Value = 1; this.slider.Enabled = false; this.btnCancel.Enabled = false; this.btnScan.Enabled = true; this.progressBar1.Value = 0; } this.lblNumPlayers.Text = "# Players: " + this.slider.Value.ToString(); pr.CloseHandle(); }
private bool NumPlayersIsGood() { ProcessMemoryReader pr = new ProcessMemoryReader(); pr.ReadProcess = GetBorderlandsProcess(); if (pr.ReadProcess == null) { return(false); } pr.OpenProcess(); int bytesRead; byte[] valToTest = pr.ReadProcessMemory((IntPtr)this.valLocation.Value, (uint)this.CurrentGame.ValToFind.Length, out bytesRead); if (MemoryScanAsync.ArrayEqual(this.CurrentGame.ValToFindWildcard, valToTest)) { pr.CloseHandle(); return(true); } else { pr.CloseHandle(); return(false); } }
public void ScanMemoryNew(object memoryScanParameters) { ProcessMemoryReader pr = null; try { MemoryScanParameters parameters = (MemoryScanParameters)memoryScanParameters; Parameters = parameters; byte[] valToFind = parameters.ValToFind; int maxMemoryLocation = parameters.MaxLocation; int minMemoryLocation = parameters.MinLocation; uint startLocation = parameters.StartLocation; bm = new BoyerMoore(valToFind); pr = parameters.Reader; List <MEMORY_BASIC_INFORMATION> pages = ProcessMemoryMapper.GetMemoryMap(pr.ReadProcess); List <MemoryPage> memPages = ProcessMemoryMapper.CondensePages(pages, 4096 * 4); int r = memPages.Count / 2; for (int i = 0; i < memPages.Count; i++) { uint low = (uint)memPages[i].BaseAddress; uint high = low + memPages[i].RegionSize; if (startLocation >= low && startLocation < high) { r = i; } } int l = r - 1; int bytesRead = 0; int lastPercentage = 0; Decimal onePercentAmount = memPages.Count / 100.0M; pr.OpenProcess(); while (r < memPages.Count || l >= 0) { if (Cancel) { this.ScanCanceled(this, new ScanCanceledEventArgs()); Cancel = false; return; } if ((r - l) / (Decimal)memPages.Count > lastPercentage / 100M) { lastPercentage++; this.ScanProgressChanged(this, new ScanProgressChangedEventArgs(lastPercentage)); } if (r < memPages.Count) { MemoryPage mbi = memPages[r]; byte[] valToTest = pr.ReadProcessMemory(mbi.BaseAddress, mbi.RegionSize, out bytesRead); if (bytesRead == 0) { r++; continue; } int foundIndex = ArrayIndexOf(valToTest, valToFind); if (foundIndex >= 0) { this.ScanCompleted(this, new ScanCompletedEventArgs(new [] { (uint)mbi.BaseAddress + (uint)foundIndex })); return; } } if (l >= 0) { MemoryPage mbi = memPages[l]; byte[] valToTest = pr.ReadProcessMemory(mbi.BaseAddress, mbi.RegionSize, out bytesRead); if (bytesRead == 0) { l--; continue; } int foundIndex = ArrayIndexOf(valToTest, valToFind); if (foundIndex >= 0) { this.ScanCompleted(this, new ScanCompletedEventArgs(new[] { (uint)mbi.BaseAddress + (uint)foundIndex })); return; } } if (r < memPages.Count) { r++; } if (l >= 0) { l--; } } this.ScanCompleted(this, new ScanCompletedEventArgs(null)); } catch (Exception ex) { this.ScanCanceled(this, new ScanCanceledEventArgs() { Exception = ex }); } finally { pr.CloseHandle(); } }