Advertisement
Guest User

PoE In Game Distance Source

a guest
Feb 12th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance force
  2.  
  3. #Include AutoHotkeyMemoryLib.ahk
  4.  
  5. SetBatchLines, -1
  6. DetectHiddenWindows, On
  7.  
  8. cliname=Path of Exile
  9.  
  10. cliexe=PathOfExile.exe
  11.  
  12. autoPotionsWatchdogPeriod:=10
  13.  
  14. baseMgrPtr:= 0
  15.  
  16. trayNotifications:= True
  17.  
  18. basePtrAoBArray:=[0x53,0x55,0x56,0x57,0x33,0xFF,0x3B,0xC7]
  19. basePtrAobOffset:=-0x0A
  20.  
  21. WindowBasicsCache:=[] ; keyed by "%hwnd%%CurrPid%", entries are objects with properties processHandle, moduleBase, moduleSize, baseFramePtr
  22.  
  23.  
  24. Loop
  25. {
  26.    Main()
  27. }
  28.  
  29. GetWindowBasics(hwnd, byref mB="", byref pH="", byref mS="")
  30. {
  31.    
  32.    global WindowBasicsCache
  33.    global cliexe
  34.    
  35.    WinGet, CurrPid, PID, ahk_id %hwnd%
  36.    
  37.    k="%hwnd%%CurrPid%"
  38.    
  39.    mB:=WindowBasicsCache[k].mBase
  40.    mS:=WindowBasicsCache[k].mSize
  41.    
  42.    if mB=
  43.    {
  44.       WindowBasicsCache[k]:=Object()
  45.       GetModuleInfo(cliexe, CurrPid, mB, mS)
  46.       if (mB="" || mS="")
  47.       {
  48.          MsgBox, Failed to obtain moduleBase or moduleSize for PID %CurrPid%, script will now terminate
  49.          ExitApp
  50.       }      
  51.       WindowBasicsCache[k].mBase:=mB
  52.       WindowBasicsCache[k].mSize:=mS
  53.    }
  54.  
  55.    pH:=WindowBasicsCache[k].ProcessHandle
  56.    if pH=
  57.    {
  58.       pH:=GetProcessHandle(CurrPid)
  59.       if (pH="" || pH=-1)
  60.       {
  61.          MsgBox, Invalid process handle obtained for PID %CurrPid%, script will now terminate
  62.          ExitApp
  63.       }      
  64.       WindowBasicsCache[k].ProcessHandle:=pH
  65.    }
  66. }
  67.  
  68. ScanBaseMgrPtr(mBase,pH,moduleSize)
  69. {
  70.    global basePtrAoBArray
  71.    global basePtrAobOffset
  72.    global baseMgrPtr
  73.  
  74.    CoordMode, Tooltip, Screen
  75.    ToolTip, PoE In Game Distance by Gurud, 0, 0
  76.  
  77.    aobResult:=AobScan(pH,mBase,moduleSize,basePtrAoBArray)
  78.  
  79.    if aobResult
  80.    {
  81.       SetFormat, IntegerFast, hex
  82.       baseMgrPtr:=ReadMemUInt(pH,mBase+aobResult+basePtrAobOffset)-mBase
  83.       if (trayNotifications)
  84.       TrayTip, New Base Pointer Found, baseMgrPtr = %baseMgrPtr%
  85.       GuiControl, , basePtrText, %baseMgrPtr%
  86.       SetFormat, IntegerFast, dec
  87.       CoordMode, Tooltip, Relative
  88.    }
  89.    else
  90.    {
  91.       MsgBox, baseMgrPtr not found with AoBScan, script will now terminate
  92.       ExitApp
  93.    }  
  94. }
  95.  
  96. GetFrameBase(hwnd)
  97. {
  98.    global baseMgrPtr
  99.    global WindowBasicsCache
  100.  
  101.    WinGet, CurrPid, PID, ahk_id %hwnd%
  102.    k="%hwnd%%CurrPid%"
  103.  
  104.    fB:=WindowBasicsCache[k].fBase
  105.  
  106.    if fB=
  107.    {
  108.       GetWindowBasics(hwnd, mBase, pH, mSize)
  109.  
  110.       if baseMgrPtr= 0
  111.       {
  112.          ScanBaseMgrPtr(mBase, pH, mSize)
  113.       }
  114.  
  115.       fB:=GetMultilevelPointer(pH,[mBase+baseMgrPtr,4,0x7C,0x94])
  116.       WindowBasicsCache[k].fBase:=fB
  117.    }
  118.    return fB
  119. }
  120.  
  121. ReadPlayerStats(hwnd, byRef PlayerStats)
  122. {
  123.    GetWindowBasics(hwnd, mBase, pH)
  124.    fBase:=GetFrameBase(hwnd)
  125.    PlayerBase:=GetMultilevelPointer(pH,[fBase+0xBC,0x59C])
  126.    PlayerBase2:=ReadMemUInt(pH,PlayerBase+0x24)
  127.    PlayerStats.PosX:=ReadMemFloat(pH,PlayerBase2+0x2c)
  128.    PlayerStats.PosY:=ReadMemFloat(pH,PlayerBase2+0x30)
  129. }
  130.  
  131. IsInGame(hwnd)
  132. {
  133.    if (hwnd=0 || hwnd="")
  134.       return false
  135.    GetWindowBasics(hwnd,mBase,pH)
  136.    if (mBase="" || mBase=0 || pH="" || pH=-1)
  137.       return false
  138.    fBase:=GetFrameBase(hwnd)
  139.    if (fBase="" || fBase=0)
  140.       return false
  141.    localConnection:=ReadMemUInt(pH,fBase+0xc0)
  142.    if (localConnection=0 || localConnection="")
  143.       return false
  144.    else
  145.       return true
  146. }
  147.  
  148. MousePos(hwnd,ByRef x, ByRef y)
  149. {
  150.    GetWindowBasics(hwnd,mBase,pH)
  151.    if (mBase!=0 && pH && pH!=-1)
  152.    {
  153.       FrameBase:=GetFrameBase(hwnd)
  154.       x:=ReadMemFloat(pH,FrameBase+0x16a4)
  155.       y:=ReadMemFloat(pH,FrameBase+0x16a8)
  156.       return true
  157.    }  
  158. }
  159.  
  160.  
  161. Main()
  162. {
  163.    global autoPotionsWatchdogPeriod
  164.    global lagCompensation
  165.    global WindowQueuedFlaskEffects
  166.    global cliname
  167.    global cliexe
  168.    global trayNotifications
  169.  
  170.    WinGet, WinID, List, %cliname%
  171.    
  172.    Loop, %WinID%
  173.    {
  174.      
  175.       WinGet, ProcModuleName, ProcessName,  % "ahk_id" WinID%A_Index%
  176.  
  177.       If(ProcModuleName!=cliexe) ; got a window with title "Path of Exile" but exe is not Client.exe, perhaps we have browser window open with PoE site, ignore it
  178.       {
  179.          ToolTip,, 0, 0
  180.          continue
  181.       }
  182.  
  183.       if (WinID%A_Index%=WinActive("A"))
  184.       ThisID:=WinActive("A")
  185.      
  186.       WinGet, CurrPID, PID,  % "ahk_id" WinID%A_Index%
  187.       hwnd:=WinID%A_Index%
  188.  
  189.       if (!IsInGame(WinID%A_Index%)) ;not ingame
  190.       {
  191.          IfWinActive Path of Exile ahk_class Direct3DWindowClass
  192.          {
  193.             ToolTip, Waiting For Log In, 0, 0
  194.          }
  195.          Else
  196.          {
  197.             ToolTip,, 0, 0
  198.          }
  199.  
  200.       }
  201.       Else
  202.       {      
  203.          IfWinActive Path of Exile ahk_class Direct3DWindowClass
  204.          {
  205.             CoordMode, Mouse, Relative
  206.             MouseGetPos, mx, my
  207.  
  208.             PlayerStats:={}
  209.             ReadPlayerStats(WinID%A_Index%, PlayerStats)
  210.             MousePos(hwnd,MouseX, MouseY)
  211.  
  212.             If (MouseX >= PlayerStats.PosX)
  213.             X_Dist:= (MouseX - PlayerStats.PosX)
  214.  
  215.             Else If (MouseX < PlayerStats.PosX)
  216.             X_Dist:= (PlayerStats.PosX - MouseX)
  217.            
  218.             If (MouseY >= PlayerStats.PosY)
  219.             Y_Dist:= (MouseY - PlayerStats.PosY)
  220.  
  221.             Else If MouseY < PlayerStats.PosY
  222.             Y_Dist:= (PlayerStats.PosY - MouseY)
  223.  
  224.             Distance:= Round(Sqrt((X_Dist*X_Dist)+(Y_Dist*Y_Dist)),1)
  225.  
  226.             ToolTip, % Distance, mx + 10 , my
  227.            
  228.          }
  229.          Else
  230.          {
  231.             ToolTip,, 0, 0
  232.          }
  233.       }
  234.    }
  235.    Sleep, %autoPotionsWatchdogPeriod%  
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement