❓ ReadMemory [help]

Posts 1–5 of 5 · Page 1 of 1
❓ ReadMemory [help]
i've searched online how i can readMemory with ahk, i had to put this in my library so i can use this function in the future.
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)
DllCall("ReadProcessMemory", "UInt", ProcessHandle, "Ptr", MADDRESS, "Ptr", &MVALUE, "Uint",4)
Loop 4
result += *(&MVALUE + A_Index-1) << 8*(A_Index-1)

return, result
}
now i've wrote the following code but it always gives me maxhp 0 curHP 0.
the win activate for trove.exe is to see if i can activate the window (it doesnt work) :/
Code:
^s::
WinActivate trove.exe
maxHP := ReadMemory(2164BEA0, "Trove")
currHP := ReadMemory(2164BE9C, "Trove")
MsgBox maxhp %maxHP% currHP %currHP%
esc::exitapp
r::Reload
okay let's do it steb-by-step

Fist of all you should know that addesses are changing evey time you start the .exe you are reading memory of

This takes as argument a window (title, or eventually other stuff, confert aahk doc) :
Code:
WinActivate [, WinTitle, WinText, ExcludeTitle, ExcludeText]
It will work with this :
Code:
WinActivate Trove
or you can use something else if you want to use the process name :
Code:
WinActivate, ahk_exe Trove.exe
the Pid is correctly acquired through your function and the rest is the same as I am using so it should work

NOTE again that you have to find a new address EVERY NEW START of Trove.
Also NOTE that you have to use the DECIMAl values of the address, not the hex one :
Code:
maxHP := ReadMemory(560250528, "Trove")
currHP := ReadMemory(560250524, "Trove")
Should work better !

Also add a
Code:
return
At the end of your hotkeys labels, it will prevent the whole script from executing himself (and closing or doing random stuff)


That's what it lookes like fo me (tested, woking, just eplace addess with you own values) (not sue if you can change Ahk's own int epesentation to use hex by default):
Code:
^s::
	WinActivate, ahk_exe Trove.exe
	maxHP := ReadMemory(560250528, "Trove")
	currHP := ReadMemory(560250524, "Trove")
	MsgBox maxhp %maxHP% currHP %currHP%
	return

esc::
	ExitApp

R::
	Reload

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, "Ptr", MADDRESS, "Ptr", &MVALUE, "Uint",4)
	Loop 4
		result += *(&MVALUE + A_Index-1) << 8*(A_Index-1)
	return, result
}
- - - Updated - - -

Also I have removed the line with ';' before : it is a comment and is not usen when the script is executed
the code looks like this now, i still have some troubles (probably stupid ones). for some reason it gives 0/0 in the second msgbox, i think it is because it doesnt want or cant read the variable. any suggestions?
Code:
^g::
	WinActivate, ahk_exe Trove.exe
	global mHPdec:= BToD("1E7D6760",16) 
	global cHPdec := BToD("1E7D675C",16)
	msgbox %mHPdec% %cHPdec% ;gives correct numbers

	maxHP := ReadMemory(%mHPdec% , "Trove") ; it doesnt read the variable
	currHP := ReadMemory(%cHPdec% , "Trove")
	MsgBox maxhp %maxHP% currHP %currHP% ; gives maxhp 0 currhp 0
	return

esc::
	ExitApp

R::
	Reload

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, "Ptr", MADDRESS, "Ptr", &MVALUE, "Uint",4)
	Loop 4
		result += *(&MVALUE + A_Index-1) << 8*(A_Index-1)
	return, result
}
BToD(n, Base) { ;base 16=decimal
	static U := A_IsUnicode ? "wcstoui64_l" : "strtoui64"
	return, DllCall("msvcrt\_" U, "Str",n, "Uint",0, "Int",Base, "CDECL Int64")
}
btw i used to have scite4 editor but i removed it by accident and the download page seems down, does anyone has it?
Have you tried with my code and by replacing the addresses ?
And btw, when sending a func some vars as arg, just don't use the %, your script should work like this :
Code:
^g::
	WinActivate, ahk_exe Trove.exe
	mHPdec := BToD("1BDE048C",16) 
	cHPdec := BToD("1BDE0490",16)
	msgbox %mHPdec% %cHPdec%

	maxHP := ReadMemory(mHPdec , "Trove")
	currHP := ReadMemory(cHPdec , "Trove")
	MsgBox maxhp %maxHP% currHP %currHP%
	return

esc::
	ExitApp

R::
	Reload

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, "Ptr", MADDRESS, "Ptr", &MVALUE, "Uint",4)
	Loop 4
		result += *(&MVALUE + A_Index-1) << 8*(A_Index-1)
	return, result
}
BToD(n, Base)
{
	static U := A_IsUnicode ? "wcstoui64_l" : "strtoui64"
	return, DllCall("msvcrt\_" U, "Str",n, "Uint",0, "Int",Base, "CDECL Int64")
}
Again, remove the ';' lines in the funcs you are using
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Talk with us