Code:
#Persistent
Pids := Object()
global _Pointer=0x00AD2A6C
global _wOffset="0x8+0xb4+0x28+0x22c"
global _lOffset="0x8+0xb4+0x28+0x6e8"
global _cOffset="0x8+0xb4+0x28+0x488"
global iniFile := A_ScriptDir . "/config.ini"
if (FileExist(iniFile)){
IniRead, _Pointer, %iniFile%, Global, _Pointer
IniRead, _wOffset, %iniFile%, Global, _wOffset
IniRead, _lOffset, %iniFile%, Global, _lOffset
IniRead, _cOffset, %iniFile%, Global, _cOffset
}
SaveIni()
SetTimer, Scan, 1
SetTimer, Relaunch, 1
return
Scan:
WinGet, l, list, Trove
Loop %l%
{
d := l%a_index%
WinGet, pid, PID, ahk_id %d%
WinGet, Handle, ID, ahk_pid %pid%
Base := getProcessBaseAddress(Handle)
wAddress := GetAddress(pid, Base, _Pointer, _wOffset)
wValue := ReadMemory(wAddress, pid)
lAddress := GetAddress(pid, Base, _Pointer, _lOffset)
lValue := ReadMemory(lAddress, pid)
cAddress := GetAddress(pid, Base, _Pointer, _cOffset)
cValue := ReadMemory(cAddress, pid)
if (cValue=1||lValue=1||wValue=1){
Sleep, 100
ControlSend, , {f down}, ahk_pid %pid%
Sleep, 90
ControlSend, , {f up}, ahk_pid %pid%
Pids.Insert(pid)
}
}
SetTimer, Scan, 2000
return
Relaunch:
sPids := Pids
Pids := Object()
Sleep, 2000
for i, p in sPids{
Sleep, 100
ControlSend, , {f down}, ahk_pid %p%
Sleep, 90
ControlSend, , {f up}, ahk_pid %p%
Sleep, 90
}
SetTimer, Relaunch, 1
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
getProcessBaseAddress(Handle){
Return DllCall( A_PtrSize = 4
? "GetWindowLong"
: "GetWindowLongPtr"
, "Ptr", Handle
, "Int", -6
, "Int64")
}
GetAddress(PID, Base, Address, Offset){
pointerBase := base + Address
y := ReadMemory(pointerBase,PID)
OffsetSplit := StrSplit(Offset, "+")
OffsetCount := OffsetSplit.MaxIndex()
Loop, %OffsetCount%{
if (a_index = OffsetCount) {
Address := (y + OffsetSplit[a_index])
}Else
if(a_index = 1) {
y := ReadMemory(y + OffsetSplit[a_index],PID)
}Else{
y := ReadMemory(y + OffsetSplit[a_index],PID)
}
}
Return Address
}
ReadMemory(MADDRESS, pid){
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
}
SaveIni(){
IniWrite, %X%, %iniFile%, Global, X
IniWrite, %Y%, %iniFile%, Global, Y
IniWrite, %_Pointer%, %iniFile%, Global, _Pointer
IniWrite, %_wOffset%, %iniFile%, Global, _wOffset
IniWrite, %_lOffset%, %iniFile%, Global, _lOffset
IniWrite, %_cOffset%, %iniFile%, Global, _cOffset
}