Kalamity / classMemory

An AHK memory reading/writing class with pattern scans.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unable to loop AOB scans

WAZAAAAA0 opened this issue · comments

I can't seem to be able to loop stringToPattern() searches while the targeted program does not exist yet. I can do that easily with read() so that my memory tool will pick up the right memory addresses as soon as the targeted program is detected. This way I'm not forcing the user to run the target program BEFORE the memory tool, thus making it easier to use.

Here's an example. If I first launch Notepad, type Thisisatest and launch the script, the AOB is correctly found:

#Include classMemory.ahk
#SingleInstance Force
TargetProcess := new _ClassMemory("ahk_exe notepad.exe", "", hProcessCopy)
myAOBstringpattern := "Thisisatest"
ConvertBase(InputBase, OutputBase, number)
{
	static u := A_IsUnicode ? "_wcstoui64" : "_strtoui64"
	static v := A_IsUnicode ? "_i64tow"    : "_i64toa"
	VarSetCapacity(s, 65, 0)
	value := DllCall("msvcrt.dll\" u, "Str", number, "UInt", 0, "UInt", InputBase, "CDECL Int64")
	DllCall("msvcrt.dll\" v, "Int64", value, "Str", s, "UInt", OutputBase, "CDECL")
	return s
}

Loop
{
	myAOBscan := TargetProcess.stringToPattern(myAOBstringpattern, "UTF-16")
	myAOBaddressdec := TargetProcess.processPatternScan(,, myAOBscan*)
	if (myAOBaddressdec > 0) ;AOB found, stop scanning and convert it from decimal to hexadecimal
	{
		myAOBaddresshex := "0x" ConvertBase(10, 16, myAOBaddressdec)
		MsgBox, found AOB at: %myAOBaddresshex%
		ExitApp
	}
	else ;AOB not found, continue scanning
	{
		Sleep,500
	}
}

Launching Notepad, launching the script and finally typing Thisisatest also works.
But if I first launch the script, then Notepad and type Thisisatest, the AOB will never be found even though the search is looped. Is there any workaround for this? I want to make my scripts as easy as possible for users.

Also, just an unrelated suggestion, I think classMemory should convert the found AOB address from decimal to hexadecimal AUTOMATICALLY. I mean the rest of the stuff I worked with in classMemory outputted addresses in hex, so why does this one in particular have to be dec?