Its not my first time using ReadProcessMemory functions to read 4byte value in a game client at certain memory address, but i always have difficulties copy and paste this and that... declaring the functions
so today, i made up my mind and wrap it up together into a library function
Here:
Code:
ReadMemory(MADDRESS,PROGRAM)
{
winget, pid, PID, %PROGRAM%
VarSetCapacity(MVALUE,4,0)
ProcessHandle := DllCall("OpenProcess", "Int", 24, "Char", 0, "UInt", pid, "UInt")
DllCall("ReadProcessMemory","UInt",ProcessHandle,"UInt",MADDRESS,"Str",MVALUE,"UInt",4,"UInt *",0)
Loop 4
result += *(&MVALUE + A_Index-1) << 8*(A_Index-1)
return, result
}
(put this in "C:\Program Files\AutoHotkey\lib" folder with "ReadMemory.ahk" as name)
example usage:
Code:
Run calc.exe
winwait, Calc
StartTime := A_TickCount
loop 1000
value:=ReadMemory(0x41000C,"Calc")
ElapsedTime := A_TickCount - StartTime
msgbox, Memory address 0x41000C = %value%`nTake %ElapsedTime% ms to loop 1000 times
this function will refresh PID and process every time
but as shown in the results, ~5000 times per second isnt bad at all, because usually we only need like 1-2 times per second in reading a game client value
welcome for any suggestions
i really appreciated if i can improve this, as i use memory address often