Code:
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
CoordMode, ToolTip, Screen
SetTitleMatchMode, 3
SetKeyDelay, 0, 2
Numpad9::
FileDelete, %A_ScriptDir%\tmp\break.txt
FileAppend, 0, %A_ScriptDir%\tmp\break.txt
GetWindowsHandle()
return
!Numpad9::
FileDelete, %A_ScriptDir%\tmp\break.txt
FileAppend, 1, %A_ScriptDir%\tmp\break.txt
return
Numpad7::
ExitApp
GetWindowsHandle()
{
Global
AccNum := 0
WinGet, id, list, Trove
Loop, %id%
{
AccNum := AccNum + 1
ids := id%A_Index%
SetWindowHandle(AccNum, ids)
}
}
SetWindowHandle(AccNumF, this_id)
{
Global
If (AccNumF = 1)
{
1Handle = %this_id%
WinGet, pid1, PID, ahk_id %1Handle%
pid1 := pid1
Lure1 := GetLureAmmount(1Handle, pid1)
FileDelete, %A_ScriptDir%\tmp\lure1.txt
FileAppend, %Lure1%, %A_ScriptDir%\tmp\lure1.txt
FileDelete, %A_ScriptDir%\tmp\pid1.txt
FileAppend, %pid1%, %A_ScriptDir%\tmp\pid1.txt
FileDelete, %A_ScriptDir%\tmp\handle1.txt
FileAppend, %1Handle%, %A_ScriptDir%\tmp\handle1.txt
Run, %A_ScriptDir%\Thread1.exe
}
else If (AccNumF = 2)
{
2Handle = %this_id%
WinGet, pid2, PID, ahk_id %2Handle%
pid2 := pid2
Lure2 := GetLureAmmount(2Handle, pid2)
FileDelete, %A_ScriptDir%\tmp\lure2.txt
FileAppend, %Lure2%, %A_ScriptDir%\tmp\lure2.txt
FileDelete, %A_ScriptDir%\tmp\pid2.txt
FileAppend, %pid2%, %A_ScriptDir%\tmp\pid2.txt
FileDelete, %A_ScriptDir%\tmp\handle2.txt
FileAppend, %2Handle%, %A_ScriptDir%\tmp\handle2.txt
Run, %A_ScriptDir%\Thread2.exe
}
else If (AccNumF = 3)
{
3Handle = %this_id%
WinGet, pid3, PID, ahk_id %3Handle%
pid3 := pid3
Lure3 := GetLureAmmount(3Handle, pid3)
FileDelete, %A_ScriptDir%\tmp\lure3.txt
FileAppend, %Lure3%, %A_ScriptDir%\tmp\lure3.txt
FileDelete, %A_ScriptDir%\tmp\pid3.txt
FileAppend, %pid3%, %A_ScriptDir%\tmp\pid3.txt
FileDelete, %A_ScriptDir%\tmp\handle3.txt
FileAppend, %3Handle%, %A_ScriptDir%\tmp\handle3.txt
Run, %A_ScriptDir%\Thread3.exe
}
else If (AccNumF = 4)
{
4Handle = %this_id%
WinGet, pid4, PID, ahk_id %4Handle%
pid4 := pid4
Lure4 := GetLureAmmount(4Handle, pid4)
FileDelete, %A_ScriptDir%\tmp\lure4.txt
FileAppend, %Lure4%, %A_ScriptDir%\tmp\lure4.txt
FileDelete, %A_ScriptDir%\tmp\pid4.txt
FileAppend, %pid4%, %A_ScriptDir%\tmp\pid4.txt
FileDelete, %A_ScriptDir%\tmp\handle4.txt
FileAppend, %4Handle%, %A_ScriptDir%\tmp\handle4.txt
Run, %A_ScriptDir%\Thread4.exe
}
else If (AccNumF = 5)
{
5Handle = %this_id%
WinGet, pid5, PID, ahk_id %5Handle%
pid5 := pid5
Lure5 := GetLureAmmount(5Handle, pid5)
FileDelete, %A_ScriptDir%\tmp\lure5.txt
FileAppend, %Lure5%, %A_ScriptDir%\tmp\lure5.txt
FileDelete, %A_ScriptDir%\tmp\pid5.txt
FileAppend, %pid5%, %A_ScriptDir%\tmp\pid5.txt
FileDelete, %A_ScriptDir%\tmp\handle5.txt
FileAppend, %5Handle%, %A_ScriptDir%\tmp\handle5.txt
Run, %A_ScriptDir%\Thread5.exe
}
else If (AccNumF = 6)
{
6Handle = %this_id%
WinGet, pid6, PID, ahk_id %6Handle%
pid6 := pid6
Lure6 := GetLureAmmount(6Handle, pid6)
FileDelete, %A_ScriptDir%\tmp\lure6.txt
FileAppend, %Lure6%, %A_ScriptDir%\tmp\lure6.txt
FileDelete, %A_ScriptDir%\tmp\pid6.txt
FileAppend, %pid6%, %A_ScriptDir%\tmp\pid6.txt
FileDelete, %A_ScriptDir%\tmp\handle6.txt
FileAppend, %6Handle%, %A_ScriptDir%\tmp\handle6.txt
Run, %A_ScriptDir%\Thread6.exe
}
else If (AccNumF = 7)
{
7Handle = %this_id%
WinGet, pid7, PID, ahk_id %7Handle%
pid7 := pid7
Lure7 := GetLureAmmount(7Handle, pid7)
FileDelete, %A_ScriptDir%\tmp\lure7.txt
FileAppend, %Lure7%, %A_ScriptDir%\tmp\lure7.txt
FileDelete, %A_ScriptDir%\tmp\pid7.txt
FileAppend, %pid7%, %A_ScriptDir%\tmp\pid7.txt
FileDelete, %A_ScriptDir%\tmp\handle7.txt
FileAppend, %7Handle%, %A_ScriptDir%\tmp\handle7.txt
Run, %A_ScriptDir%\Thread7.exe
}
else If (AccNumF = 8)
{
8Handle = %this_id%
WinGet, pid8, PID, ahk_id %8Handle%
pid8 := pid8
Lure8 := GetLureAmmount(8Handle, pid8)
FileDelete, %A_ScriptDir%\tmp\lure8.txt
FileAppend, %Lure8%, %A_ScriptDir%\tmp\lure8.txt
FileDelete, %A_ScriptDir%\tmp\pid8.txt
FileAppend, %pid8%, %A_ScriptDir%\tmp\pid8.txt
FileDelete, %A_ScriptDir%\tmp\handle8.txt
FileAppend, %8Handle%, %A_ScriptDir%\tmp\handle8.txt
Run, %A_ScriptDir%\Thread8.exe
}
}
GetLureAmmount(HandleL, pidL)
{
base := getProcessBaseAddress(HandleL)
pointerBase := base + 0x008E8E18
y1 := ReadMemory(pointerBase, pidL)
y2 := ReadMemory(y1 + 0x9c, pidL)
y3 := ReadMemory(y2 + 0x78, pidL)
y4 := ReadMemory(y3 + 0x0, pidL)
y5 := y4 + 0x58
Return Lure := ReadMemory(y5, pidL)
}
getProcessBaseAddress(HandleUse)
{
return DllCall( A_PtrSize = 4
? "GetWindowLong"
: "GetWindowLongPtr"
, "Ptr", HandleUse
, "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, PIDUse)
{
VarSetCapacity(MVALUE,4,0)
ProcessHandle := DllCall("OpenProcess", "Int", 24, "Char", 0, "UInt", PIDUse, "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
}