title: How to use ReadProcessMemory
body: <p>So I have been trying to read variables with ReadProcessMemory and finding the adresses in cheat engine worked perfectly, but as soon as I got to programming I encountered some problems.
  I searched for the ammo and health addresses in cheat engine and the health was a one level pointer and the ammo was a three level pointer. 
  I tried reading the health, but everytime I read it, it returns 0.</p>
  
  <pre><code>namespace AssaultCubeTrainer
  
  {
  
  public partial class MainWindow : Window
  {
  
      [DllImport("kernel32.dll", SetLastError = true)]
      public static extern bool ReadProcessMemory(IntPtr pHandle, IntPtr Address, byte[] Buffer, int Size, IntPtr NumberofBytesRead);
  
      public static Process myProc;
  
      public static Player p1;
  
      public MainWindow()
      {
          InitializeComponent();
  
          p1  = new Player();
  
          MessageBox.Show("Please press the attach button as soon as the game has started", " Information",MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
  
  
  
      }
  
      private void AttachProcButton_Click(object sender, RoutedEventArgs e)
      {
  
          try
          {
              myProc = Process.GetProcessesByName("ac_client")[0];
  
  
              if (myProc.Handle != null)
              {
                  MessageBox.Show("Process successfully attached", "Success", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
              }
          }
  
          catch
          {
              MessageBox.Show("The process was not found","Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
          }
  
      }
  
      private void ButtonTest_Click(object sender, RoutedEventArgs e)
      {
  
              lbHealthInfo.Content = p1.GetHealthInfo();
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>namespace AssaultCubeTrainer
  {
      public class Player
  {
  
      private byte[] buffer;
  
      public bool ReadSuccess;
  
      public int HealthAddress;
      public int HealthOffset;
  
      public int AmmoAddress;
      public int AmmoOffset;
  
      public int Health;
      public int Ammo;
  
      public IntPtr bytesRead;
  
      public Player()
      {
          HealthAddress = 0x00509B74;
          HealthOffset = 0xF8;
  
          AmmoAddress = 0x00509B74;
          AmmoOffset = 0x374;
  
          Health = HealthAddress + HealthOffset;
          Ammo = AmmoAddress + AmmoOffset;
  
      }
  
  
  //Here I have the problem when reading variable
  public int GetHealthInfo()
          {
              **buffer = new byte[4];
              ReadSuccess = MainWindow.ReadProcessMemory(MainWindow.myProc.Handle, (IntPtr)Health, buffer, buffer.Length, bytesRead);
              return BitConverter.ToInt32(buffer, 0);**
  
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Heres the links to the addresses in cheat engine 
  Couldnt upload them here :P</p>
  
  <p><a href="http://prntscr.com/gp1ko0" rel="nofollow noreferrer">http://prntscr.com/gp1ko0</a></p>
  
  <p><a href="http://prntscr.com/gp1ksu" rel="nofollow noreferrer">http://prntscr.com/gp1ksu</a></p>
  
  <p>How do I use pointers and offsets from cheat engine properly in my code and how do I implement multi-level pointers into my code?
  Please excuse my shitty english.</p>