In response to your PM, for some reason with your 'special' version of warcraft the 'winget, pid,PID, ahk_exe war3.exe' command (which is used internally in the class) fails, but 'winget, pid,PID, Warcraft III' works fine.
You need to either use the wintitle 'Warcraft III' or use the 'ahk_pid xxxx'.
You must also run the script as admin AND enable setSeDebugPrivilege().
The code below works with your warcraft version.
Code: Select all
#SingleInstance Force
#Include <classMemory>
if !A_IsAdmin
{
Run *RunAs "%A_ScriptFullPath%"
exitapp
}
if (_ClassMemory.__Class != "_ClassMemory")
{
msgbox class memory not correctly installed.
ExitApp
}
_ClassMemory.setSeDebugPrivilege() ; Required
; get the pid using an alternate method.
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where Name='war3.exe'")
{
pid := process.ProcessId
}
TargetProcess := new _ClassMemory("ahk_pid " pid,, hProcessCopy)
;TargetProcess := new _ClassMemory("Warcraft III",, hProcessCopy) ; This also works fine.
if !isObject(TargetProcess)
{
if (hProcessCopy = 0)
msgbox The program isn't running (not found) or you passed an incorrect program identifier parameter.
else if (hProcessCopy = "")
msgbox OpenProcess failed. If the target process has admin rights, then the script also needs to be ran as admin. _ClassMemory.setSeDebugPrivilege() may also be required. Consult A_LastError for more information.
ExitApp
}
myAOBstringpattern := "test2"
Loop
{
myAOBscan := TargetProcess.stringToPattern(myAOBstringpattern, "UTF-8")
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 at %myAOBaddresshex%
}
else ;AOB not found, continue scanning
{
Sleep, 500
}
}
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
}
Edit:
I had another play around with this tonight and realised something pretty obvious...
providing you call _ClassMemory.setSeDebugPrivilege(), using AHK_exe war3.exe works fine.
e.g.
Code: Select all
#SingleInstance Force
#Include <classMemory>
if !A_IsAdmin
{
Run *RunAs "%A_ScriptFullPath%"
exitapp
}
if (_ClassMemory.__Class != "_ClassMemory")
{
msgbox class memory not correctly installed.
ExitApp
}
_ClassMemory.setSeDebugPrivilege() ; Required - must be first thing called
TargetProcess := new _ClassMemory("ahk_exe war3.exe",, hProcessCopy)
if !isObject(TargetProcess)
{
if (hProcessCopy = 0)
msgbox The program isn't running (not found) or you passed an incorrect program identifier parameter.
else if (hProcessCopy = "")
msgbox OpenProcess failed. If the target process has admin rights, then the script also needs to be ran as admin. _ClassMemory.setSeDebugPrivilege() may also be required. Consult A_LastError for more information.
ExitApp
}
myAOBstringpattern := "test2"
Loop
{
myAOBscan := TargetProcess.stringToPattern(myAOBstringpattern, "UTF-8")
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 at %myAOBaddresshex%
}
else ;AOB not found, continue scanning
{
Sleep, 500
}
}
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
}