title: Reading Program Memory In AHK
body: <p>So I am working on a program to read values from a game (Mitos.is: The Game).
  It is similiar to <a href="https://en.wikipedia.org/wiki/Agar.io" rel="nofollow noreferrer">Agar.io</a></p>
  
  <p>You have a size (mass), and I want to get the mass amount, it is a program, not an online game like Agar.io.</p>
  
  <p>I have found this Auto Hotkey script:</p>
  
  <pre><code>#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  ; #Warn  ; Enable warnings to assist with detecting common errors.
  SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  
  
  ReadMemory(MADDRESS=0,PROGRAM="",BYTES=4)
  {
     Static OLDPROC, ProcessHandle
     VarSetCapacity(MVALUE, BYTES,0)
     If PROGRAM != %OLDPROC%
     {
        WinGet, pid, pid, % OLDPROC := PROGRAM
        ProcessHandle := ( ProcessHandle ? 0*(closed:=DllCall("CloseHandle"
        ,"UInt",ProcessHandle)) : 0 )+(pid ? DllCall("OpenProcess"
        ,"Int",16,"Int",0,"UInt",pid) : 0)
     }
     If (ProcessHandle) &amp;&amp; DllCall("ReadProcessMemory","UInt",ProcessHandle,"UInt",MADDRESS,"Str",MVALUE,"UInt",BYTES,"UInt *",0)
     {    Loop % BYTES
              Result += *(&amp;MVALUE + A_Index-1) &lt;&lt; 8*(A_Index-1)
          Return Result
      }
     return !ProcessHandle ? "Handle Closed:" closed : "Fail"
  }
  
  
  mass := ReadMemory(Address here, "Mitos.is: The Game")
  
  MsgBox, %mass%
  </code></pre>
  
  <p>It works seamlessly but there is one slight problem, in Cheat Engine I took the liberty of finding the base address as shown below:
  <a href="https://i.stack.imgur.com/FfCgM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FfCgM.png" alt="Cheat Engine Base Address"></a></p>
  
  <p>So I took the address circled here:<a href="https://i.stack.imgur.com/WK01l.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WK01l.gif" alt="Red Circle"></a></p>
  
  <p>And inserted that into the program where it says "Address Here", correct me if this is not the right address, but when I restart the game and run my script it says "Fail", but in Cheat Engine the address is still valid. Help?</p>