Advertisement
Guest User

PoE PM Logger.ahk

a guest
Feb 20th, 2014
143
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. baseMgrPtr:= 0
  13.  
  14. LastChatLogged:=
  15.  
  16. basePtrAoBArray:=[0x53,0x55,0x56,0x57,0x33,0xFF,0x3B,0xC7]
  17. basePtrAobOffset:=-0x0A
  18.  
  19. WindowBasicsCache:=[] ; keyed by "%hwnd%%CurrPid%", entries are objects with properties processHandle, moduleBase, moduleSize, baseFramePtr
  20.  
  21.  
  22. Loop
  23. {
  24.    Main()
  25. }
  26.  
  27. GetWindowBasics(hwnd, byref mB="", byref pH="", byref mS="")
  28. {
  29.    
  30.    global WindowBasicsCache
  31.    global cliexe
  32.    
  33.    WinGet, CurrPid, PID, ahk_id %hwnd%
  34.    
  35.    k="%hwnd%%CurrPid%"
  36.    
  37.    mB:=WindowBasicsCache[k].mBase
  38.    mS:=WindowBasicsCache[k].mSize
  39.    
  40.    if mB=
  41.    {
  42.       WindowBasicsCache[k]:=Object()
  43.       GetModuleInfo(cliexe, CurrPid, mB, mS)
  44.       if (mB="" || mS="")
  45.       {
  46.          MsgBox, Failed to obtain moduleBase or moduleSize for PID %CurrPid%, script will now terminate
  47.          ExitApp
  48.       }      
  49.       WindowBasicsCache[k].mBase:=mB
  50.       WindowBasicsCache[k].mSize:=mS
  51.    }
  52.  
  53.    pH:=WindowBasicsCache[k].ProcessHandle
  54.    if pH=
  55.    {
  56.       pH:=GetProcessHandle(CurrPid)
  57.       if (pH="" || pH=-1)
  58.       {
  59.          MsgBox, Invalid process handle obtained for PID %CurrPid%, script will now terminate
  60.          ExitApp
  61.       }      
  62.       WindowBasicsCache[k].ProcessHandle:=pH
  63.    }
  64. }
  65.  
  66. ScanBaseMgrPtr(mBase,pH,moduleSize)
  67. {
  68.    global basePtrAoBArray
  69.    global basePtrAobOffset
  70.    global baseMgrPtr
  71.  
  72.    CoordMode, Tooltip, Screen
  73.    ToolTip, PoE PM Logger by Gurud, 0, 0
  74.  
  75.    aobResult:=AobScan(pH,mBase,moduleSize,basePtrAoBArray)
  76.  
  77.    if aobResult
  78.    {
  79.       SetFormat, IntegerFast, hex
  80.       baseMgrPtr:=ReadMemUInt(pH,mBase+aobResult+basePtrAobOffset)-mBase
  81.       SetFormat, IntegerFast, dec
  82.       CoordMode, Tooltip, Relative
  83.       ToolTip,, 0, 0
  84.    }
  85.    else
  86.    {
  87.       MsgBox, baseMgrPtr not found with AoBScan, script will now terminate
  88.       ExitApp
  89.    }  
  90. }
  91.  
  92. GetFrameBase(hwnd)
  93. {
  94.    global baseMgrPtr
  95.    global WindowBasicsCache
  96.  
  97.    WinGet, CurrPid, PID, ahk_id %hwnd%
  98.    k="%hwnd%%CurrPid%"
  99.  
  100.    fB:=WindowBasicsCache[k].fBase
  101.  
  102.    if fB=
  103.    {
  104.       GetWindowBasics(hwnd, mBase, pH, mSize)
  105.  
  106.       if baseMgrPtr= 0
  107.       {
  108.          ScanBaseMgrPtr(mBase, pH, mSize)
  109.       }
  110.  
  111.       fB:=GetMultilevelPointer(pH,[mBase+baseMgrPtr,4,0x7C,0x94])
  112.       WindowBasicsCache[k].fBase:=fB
  113.    }
  114.    return fB
  115. }
  116.  
  117. GetChatBase(hwnd)
  118. {
  119.    global baseMgrPtr
  120.    global WindowBasicsCache
  121.  
  122.    WinGet, CurrPid, PID, ahk_id %hwnd%
  123.    k="%hwnd%%CurrPid%"
  124.  
  125.    uB:=WindowBasicsCache[k].uBase
  126.  
  127.    if uB=
  128.    {
  129.       GetWindowBasics(hwnd, mBase, pH, mSize)
  130.  
  131.       if baseMgrPtr= 0
  132.       {
  133.          ScanBaseMgrPtr(mBase, pH, mSize)
  134.       }
  135.  
  136.       uB:=ReadMemUInt(ph,mBase+baseMgrPtr)
  137.       WindowBasicsCache[k].uBase:=uB
  138.    }
  139.    return uB
  140. }
  141.  
  142. ReadPlayerStats(hwnd, byRef PlayerStats)
  143. {
  144.    GetWindowBasics(hwnd, mBase, pH)
  145.    fBase:=GetFrameBase(hwnd)
  146.    ChatBase:=GetChatBase(hwnd)
  147.    LastChatStr:=ReadMemStr(ph,ChatBase+0xD508,255,"UTF-8")
  148.    PlayerBase:=GetMultilevelPointer(pH,[fBase+0xBC,0x59C])
  149.    PlayerMain:=ReadMemUInt(pH,PlayerBase+4)
  150.    If (ReadMemUInt(pH, ReadMemUInt(pH,PlayerMain+0x14)+0x24)<8) ;names shorter than 7 chars are stored immediately in component
  151.    {
  152.       PlayerStats.Name:=ReadMemStr(pH, ReadMemUint(pH,PlayerMain+0x14)+0x10,100,"UTF-16") ;immediate name in component
  153.    }
  154.    Else
  155.    {
  156.       PlayerStats.Name:=ReadMemStr(pH, GetMultilevelPointer(pH,[PlayerMain+0x14,0x10]),100,"UTF-16") ; otherwise pointer to name is stored
  157.    }
  158.    Loop, Parse, LastChatStr, `n, `r
  159.    {
  160.       If A_Index = 1
  161.       {
  162.          IfInString, A_LoopField, @
  163.          {
  164.             PlayerStats.LastChatStr:=A_LoopField
  165.             PlayerStats.ChatDate:=SubStr(A_LoopField, 1, 10)
  166.             PlayerStats.ChatTime:=SubStr(A_LoopField, 12, 8)
  167.             StringGetPos, PositionName, A_LoopField,@
  168.             PositionNameEnd:= InStr(A_LoopField, ":" , CaseSensitive = false, StartingPos = PositionName)
  169.             PlayerStats.ChatMsg:=SubStr(A_LoopField, PositionName, 255)
  170.             PlayerStats.ChatName:=SubStr(A_LoopField, (PositionName+2), (PositionNameEnd-(PositionName+2)))
  171.          }
  172.       }
  173.       Break
  174.    }
  175. }
  176.  
  177. IsInGame(hwnd)
  178. {
  179.    if (hwnd=0 || hwnd="")
  180.       return false
  181.    GetWindowBasics(hwnd,mBase,pH)
  182.    if (mBase="" || mBase=0 || pH="" || pH=-1)
  183.       return false
  184.    fBase:=GetFrameBase(hwnd)
  185.    if (fBase="" || fBase=0)
  186.       return false
  187.    localConnection:=ReadMemUInt(pH,fBase+0xc0)
  188.    if (localConnection=0 || localConnection="")
  189.       return false
  190.    else
  191.       return true
  192. }
  193.  
  194. Main()
  195. {
  196.    global cliname
  197.    global cliexe
  198.  
  199.    WinGet, WinID, List, %cliname%
  200.    
  201.    Loop, %WinID%
  202.    {
  203.      
  204.       WinGet, ProcModuleName, ProcessName,  % "ahk_id" WinID%A_Index%
  205.  
  206.       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
  207.       {
  208.          ToolTip,, 0, 0
  209.          continue
  210.       }
  211.  
  212.       if (WinID%A_Index%=WinActive("A"))
  213.       ThisID:=WinActive("A")
  214.      
  215.       WinGet, CurrPID, PID,  % "ahk_id" WinID%A_Index%
  216.       hwnd:=WinID%A_Index%
  217.  
  218.       if (!IsInGame(WinID%A_Index%)) ;if not in game
  219.       {
  220.          Sleep, 100
  221.       }
  222.       Else
  223.       {      
  224.          PlayerStats:={}
  225.          ReadPlayerStats(WinID%A_Index%, PlayerStats)
  226.          If (PlayerStats.LastChatStr!=LastChatLogged)
  227.          {
  228.             LastChatLogged:=PlayerStats.LastChatStr
  229.  
  230.             ;-----AFTER NEW PM SCRIPT WILL EXUCUTE LINES BELOW ONCE------;
  231.  
  232.             ;PlayerStats.ChatMsg contains "@PlayerName: MSG"
  233.             ;PlayeStats.ChatName constains "PlayerName"
  234.             ;PlayerStats.ChatDate contains "YEAR/MONTH/DAY"
  235.             ;PlayerStats.ChatTime contains "HOUR:MIN:SEC"
  236.             ;PlayerStats.Name contains "YourPlayerName"
  237.             ;Linked Items will appear as "_"
  238.  
  239.             IniWrite, % " " PlayerStats.ChatMsg, PMLog.ini,% PlayerStats.ChatDate, % PlayerStats.ChatTime "  "
  240.  
  241.             ;-----AFTER NEW PM SCRIPT WILL EXUCUTE LINES ABOVE ONCE------;
  242.  
  243.          }
  244.       }
  245.       Sleep, 10
  246.    }
  247.    Sleep, 10
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement