Code:
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Screen
SetTitleMatchMode, 3
SetKeyDelay, 0, 2
Numpad9::
WinGet, Handle, ID, A
WinGet, pidn, PID, A
Break := 0
InputBox, HealAt, Enter Percent, Percent To Heal At?
SetFormat, float, 1
BaseHealth := GetHealth(Handle, pidn)
Heal := (Health * HealAt) / 100
Loop {
GetHealth(Handle, pidn)
If (Health < Heal)
{
ControlSend, , {q}, ahk_pid %pidn%
Sleep, 500
}
If (Break = 1)
{
break
}
else
{
Sleep, 30
}
}
Return
!NumPad7::
ExitApp
!NumPad9::
Break := 1
return
GetHealth(Handle, pid)
{
Global Health
Base := getProcessBaseAddress(Handle)
pointerBase := base + 0x00916028
z1 := ReadMemory(pointerBase, pid)
z2 := ReadMemory(z1 + 0x98, pid)
z3 := ReadMemory(z2 + 0x28, pid)
z4 := ReadMemory(z3 + 0x10, pid)
z5 := z4 + 0xcc
Health := ReadMemory(z5, pid)
}
getProcessBaseAddress(Handle)
{
return DllCall( A_PtrSize = 4
? "GetWindowLong"
: "GetWindowLongPtr"
, "Ptr", Handle
, "Int", -6
, "Int64") ; Use Int64 to prevent negative overflow when AHK is 32 bit and target process is 64bit
; If DLL call fails, returned value will = 0
}
ReadMemory(MADDRESS, pid)
{
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
}