title: C# - Read Write Process Memory , Pointers and Offsets Gamer Server Management Tool
body: <p>I am coding a <strong>server manager</strong> for a game and got stuck in pointers and offsets in C#. Old server manager is written in vb6 and for some reason does not work on my windows so i decided to code some basic functions of it in C#.</p>
  
  <p>I have pointer and offsets values of everything that is necessary for now i am writing only to get all player names.</p>
  
  <p>Player pointer  = <strong>96C290</strong>    Player name Offset = <strong>+20</strong></p>
  
  <p>Offset of <strong>+668</strong> give me the next player pointer, and adding <strong>+20</strong> to next player should give me next <strong>player name</strong> and so on.</p>
  
  <p>Reading First Player Name</p>
  
  <pre><code>  public static IntPtr BASE_ADDR = new IntPtr(0x96C290);
    public static IntPtr OFFSET_NAME = new IntPtr(0x20);
    const int PROCESS_WM_READ = 0x0010;
  
    public static void Read()
    {
  
          Process process = Process.GetProcessesByName("gameprocessname")[0];
          IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);   
  
          //defining data structures
          int bytesRead = 0;
          byte[] buffer = new byte[4];
  
          //Reading Base Address pointer value
          ReadProcessMemory((int)processHandle,(int)BASE_ADDR, buffer, 4, ref bytesRead);
          IntPtr myBaseAddress = new IntPtr(BitConverter.ToInt32(buffer, 0));
  
          //Adding offset of 20 to original base pointer address
          IntPtr namePointer = BASE_ADDR;
          namePointer = IntPtr.Add(namePointer,(int)OFFSET_NAME);
  
  
          //Getting memory address of name pointer
          ReadProcessMemory((int)processHandle, (int)namePointer,buffer, 4, ref bytesRead);
          IntPtr playerNameAddress = new IntPtr(BitConverter.ToInt32(buffer, 0));
  
  
          //reading name from name address . ASCII and Unicode
          byte[] playerNameBuffer = new byte[256];
           ReadProcessMemory((int)processHandle, (int)playerNameAddress, buffer, 256, ref bytesRead);
          string name = Encoding.Default.GetString(playerNameBuffer);
          MessageBox.Show(name);
  
  
          }
  </code></pre>
  
  <p>I am not getting player name . The scripts written in <strong>VB6</strong> are operational.
  I am Using <strong>Win8.1 64bit</strong> and the game is very old 32 bit application.</p>
  
  <p>What could be the problem ? i used <strong>cheat engine</strong> to view values manually but it also shows me nothing. Pointer and Offset values are correct.</p>
  
  <p>I have used different offsets values but got none of them return the right values.</p>
  
  <p>The questions is **If i am doing something wrong on coding end ? or it is the OS 64bit issue. **</p>