Advertisement
stybbe

Path of Exile wasd script

Nov 7th, 2012
3,722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 8.29 KB | None | 0 0
  1. ; #INDEX# ===================================================================================================
  2. ; Title .........: wasdPOE
  3. ; Version........: 1.0
  4. ; Language ......: English
  5. ; Description ...: Keyboard movement script for the game Path of Exile.
  6. ; Author(s) .....: Stybbe
  7. ; ===========================================================================================================
  8.  
  9. #include <WindowsConstants.au3>
  10. #include <GuiConstantsEx.au3>
  11. #include <Misc.au3>
  12. #include <GDIPlus.au3>
  13. #include <WinAPI.au3>
  14.  
  15. Opt("MouseClickDragDelay",1)
  16. Opt("SendKeyDelay",0)
  17. Opt("SendKeyDownDelay",0)
  18.  
  19. ;For list of keys see http://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm
  20.  
  21. $_up = "57"     ; W
  22. $_left = "41"   ; A
  23. $_down = "53"   ; S
  24. $_right = "44"  ; D
  25.  
  26. $_MouseOffset = 65 ; offset from player in pixels the mouse move when using wasd-Keys.
  27.                    ; go to GetKeyBoardInput() function to change it more specific.
  28.  
  29.  
  30. $_extra_mouseBtn = "06" ;pressing this will also press mouse1.
  31.                         ;Used due to $_UseShiftOnLeftAttack conflict in inventory.
  32.  
  33. $_move = "04"   ; middle mouse
  34. $_moveMouse = "middle" ; should be same as above but in textform lol
  35.  
  36. $_atk1 = "01"   ; mouse1
  37. $_atk2 = "02"   ; mouse2
  38. $_atk3 = "51"   ; Q
  39. $_atk4 = "20"   ; Space
  40. $_atk5 = "45"   ; E
  41. $_atk6 = "52"   ; R
  42. $_atk7 = "54"   ; T
  43.  
  44. HotKeySet("{F9}", "_Exit") ;The key that shut down this script
  45.                            ;Can also be closed by right clicking the Autoit icon in taskbar
  46.  
  47. $_GoBackToOldPosMouse = True    ;set to false if you dont want the mouse to move to the red mouse
  48. $_UseShiftOnLeftAttack = True   ;set to false if you dont want to auto use shift on mouse1.
  49.  
  50. $pngSrc = @ScriptDir & "\cursor.png"    ;By default the cursor image need to be in same map as the script
  51.  
  52.  
  53.  
  54. ;Only change stuff under here if you know what you doing
  55.  
  56. Enum $up, $upRight, $right, $downRight, $down, $downLeft, $left, $upLeft
  57. Local $prevMousePos
  58. Local $hasMovedMouse = true
  59. Local $hasMovedChar = false
  60. Local $releaseShift = false
  61.  
  62. Local $GameTitle = "Path of Exile"
  63. Local $ProgramTitle = "wasdPOEd"
  64.  
  65. Local $POEhandle = HWnd(WinGetHandle($GameTitle))
  66.  
  67. _GDIPlus_Startup()
  68.  
  69. $GUI = _GUICreate_Alpha($ProgramTitle, $pngSrc)
  70. $myGuiHandle = WinGetHandle($ProgramTitle)
  71. WinSetOnTop($myGuiHandle,"",1)
  72. _WinAPI_SetWindowLong($myGuiHandle, -20, BitOR(_WinAPI_GetWindowLong($myGuiHandle, -20), $WS_EX_TRANSPARENT))
  73.  
  74. $winSize = WinGetPos($ProgramTitle)
  75. $cursorXoffset = 0
  76. $cursorYoffset = 0
  77.  
  78. GUISetState()
  79.  
  80. $dll = DllOpen("user32.dll")
  81.  
  82. $moved = False
  83. $isActive = True
  84.  
  85. $goalX = 0
  86. $goalY = 0
  87. $fakeCursorX = 0
  88. $fakeCursorY = 0
  89. $prevDirection = 0
  90.  
  91. $mouseDown_extra = False
  92. $isChatOpen_extra = False
  93.  
  94. While 1
  95.     If GUIGetMsg() = -3 then _Exit()
  96.    
  97.     extraInputs()
  98.    
  99.     if WinActive($GameTitle) Then
  100.        
  101.         if Not $isActive Then
  102.             $isActive = True
  103.             GUICtrlSetState(-1, $GUI_SHOW)
  104.             WinSetOnTop($myGuiHandle,"",1)
  105.             GUISetState()
  106.         EndIf
  107.        
  108.         $mouse = MouseGetPos()
  109.        
  110.         ;move fake cursor
  111.         WinMove($myGuiHandle,"",$fakeCursorX - $cursorXoffset,$fakeCursorY - $cursorYoffset)
  112.        
  113.         $currentDirection = GetKeyBoardInput()
  114.        
  115.         if $currentDirection[0] <> -1 Then
  116.             $winPos = WinGetPos("[active]")
  117.            
  118.             $goalX = $winPos[2]/2 + $winPos[0] + $currentDirection[0]
  119.             $goalY = $winPos[3]/2 + $winPos[1] + $currentDirection[1]
  120.            
  121.             if $hasMovedMouse And $_GoBackToOldPosMouse Then
  122.                 $hasMovedMouse = false
  123.             ElseIf $currentDirection[0] == $prevDirection[0] And _
  124.                    $currentDirection[1] == $prevDirection[1] Then
  125.                 $fakeCursorX  += $mouse[0] - $goalX
  126.                 $fakeCursorY  += $mouse[1] - $goalY
  127.             EndIf
  128.            
  129.             MouseMove($goalX, $goalY,0)
  130.            
  131.             MouseDown($_moveMouse)
  132.            
  133.             $hasMovedChar = true
  134.         Else
  135.             if $hasMovedChar Then
  136.                 if _IsPressed($_move) Then
  137.                     MouseUp($_moveMouse)
  138.                    
  139.                     ;Fixes bug in PoE where if two mouse buttons are down at same time
  140.                     ;and you release one. PoE will not register the other one you still
  141.                     ;holding down.
  142.                     if _IsPressed($_atk1, $dll) Then
  143.                         MouseDown("left")
  144.                     endif
  145.                    
  146.                     if _IsPressed($_atk2, $dll) Then
  147.                         MouseDown("right")
  148.                     endif
  149.                 EndIf
  150.                
  151.                 $hasMovedChar = false
  152.             EndIf
  153.            
  154.             if Not $hasMovedMouse and $_GoBackToOldPosMouse Then
  155.                 MouseMove($fakeCursorX,$fakeCursorY,0)
  156.                 $hasMovedMouse = True
  157.             Else
  158.                 $fakeCursorX = $mouse[0]
  159.                 $fakeCursorY = $mouse[1]
  160.             EndIf
  161.         EndIf
  162.        
  163.         $prevDirection = $currentDirection
  164.     Else
  165.         if $isActive Then
  166.             $isActive = False
  167.             GUICtrlSetState(-1, $GUI_HIDE)
  168.         EndIf
  169.     EndIf
  170. WEnd
  171.  
  172. Func extraInputs()
  173.     ;Extra mouse button
  174.     if _IsPressed($_extra_mouseBtn, $dll) Then
  175.         MouseDown("left")
  176.         $mouseDown_extra = true
  177.     Elseif $mouseDown_extra Then
  178.         MouseUp("left")
  179.         $mouseDown_extra = False
  180.     EndIf
  181.    
  182.     ;Pause wasd-keys if typing in chat.
  183.     if WinActive($GameTitle) Then
  184.         if _IsPressed("0D", $dll) Then
  185.             $isChatOpen_extra = Not $isChatOpen_extra
  186.         EndIf
  187.     EndIf
  188. EndFunc
  189.  
  190. ;pos[0] = X-offset pixels from the middle position of the Path of Exile window
  191. ;pos[1] = Y-offset pixels from the middle position of the Path of Exile window
  192. ;Change the offset to whatever.
  193. Func GetKeyBoardInput()
  194.     Local $pos[2] = [-1,-1]
  195.    
  196.     if _IsPressed($_atk1,$dll) And Not $mouseDown_extra then
  197.         if $_UseShiftOnLeftAttack Then
  198.             if Not $releaseShift Then
  199.                 Send("{SHIFTDOWN}")
  200.                 $releaseShift = True
  201.             EndIf
  202.         EndIf
  203.        
  204.         return $pos
  205.     EndIf
  206.    
  207.     if  $isChatOpen_extra Or _
  208.         _IsPressed($_atk2,$dll) Or _
  209.         _IsPressed($_atk3,$dll) Or _
  210.         _IsPressed($_atk4,$dll) Or _
  211.         _IsPressed($_atk5,$dll) Or _
  212.         _IsPressed($_atk6,$dll) Or _
  213.         _IsPressed($_atk7,$dll) _
  214.     Then
  215.         ;break movement if any atk key is pressed.
  216.         return $pos
  217.     EndIf
  218.    
  219.    
  220.     if $_UseShiftOnLeftAttack Then
  221.         if $releaseShift Then
  222.             $releaseShift = False
  223.             Send("{SHIFTUP}")
  224.         EndIf
  225.     EndIf
  226.    
  227.     if _IsPressed($_up,$dll) And _IsPressed($_right,$dll) Then
  228.         $pos[0] = $_MouseOffset
  229.         $pos[1] = -$_MouseOffset
  230.         return $pos
  231.     EndIf
  232.     if _IsPressed($_up,$dll) And _IsPressed($_left,$dll) Then
  233.         $pos[0] = -$_MouseOffset
  234.         $pos[1] = -$_MouseOffset
  235.         return $pos
  236.     EndIf
  237.     if _IsPressed($_down,$dll) And _IsPressed($_left,$dll) Then
  238.         $pos[0] = -$_MouseOffset
  239.         $pos[1] = $_MouseOffset
  240.         return $pos
  241.     EndIf
  242.     if _IsPressed($_down,$dll) And _IsPressed($_right,$dll) Then
  243.         $pos[0] = $_MouseOffset
  244.         $pos[1] = $_MouseOffset
  245.         return $pos
  246.     EndIf
  247.     if _IsPressed($_left,$dll)Then
  248.         $pos[0] = -$_MouseOffset
  249.         $pos[1] = 0
  250.         return $pos
  251.     EndIf
  252.     if _IsPressed($_right,$dll)Then
  253.         $pos[0] = $_MouseOffset
  254.         $pos[1] = 0
  255.         return $pos
  256.     EndIf
  257.     if _IsPressed($_up,$dll)Then
  258.         $pos[0] = 0
  259.         $pos[1] = -$_MouseOffset
  260.         return $pos
  261.     EndIf
  262.     if _IsPressed($_down,$dll)Then
  263.         $pos[0] = 0
  264.         $pos[1] = $_MouseOffset
  265.         return $pos
  266.     EndIf
  267.    
  268.     return $pos
  269. EndFunc
  270.  
  271. ;the cursor is a .png GUI and it need this function to initialize
  272. Func _GUICreate_Alpha($sTitle, $sPath, $iX=-1, $iY=-1, $iOpacity=255)
  273.     Local $hGUI, $hImage, $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
  274.     $hImage = _GDIPlus_ImageLoadFromFile($sPath)
  275.     $width = _GDIPlus_ImageGetWidth($hImage)
  276.     $height = _GDIPlus_ImageGetHeight($hImage)
  277.     $hGUI = GUICreate($sTitle, $width, $height, $iX, $iY, $WS_POPUP, $WS_EX_LAYERED)
  278.  
  279.     $hScrDC = _WinAPI_GetDC(0)
  280.     $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
  281.     $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  282.     $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
  283.     $tSize = DllStructCreate($tagSIZE)
  284.     $pSize = DllStructGetPtr($tSize)
  285.     DllStructSetData($tSize, "X", $width)
  286.     DllStructSetData($tSize, "Y", $height)
  287.     $tSource = DllStructCreate($tagPOINT)
  288.     $pSource = DllStructGetPtr($tSource)
  289.     $tBlend = DllStructCreate($tagBLENDFUNCTION)
  290.     $pBlend = DllStructGetPtr($tBlend)
  291.     DllStructSetData($tBlend, "Alpha", $iOpacity)
  292.     DllStructSetData($tBlend, "Format", 1)
  293.     _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, 2)
  294.     _WinAPI_ReleaseDC(0, $hScrDC)
  295.     _WinAPI_SelectObject($hMemDC, $hOld)
  296.     _WinAPI_DeleteObject($hBitmap)
  297.     _WinAPI_DeleteObject($hImage)
  298.     _WinAPI_DeleteDC($hMemDC)
  299. EndFunc ;==>_GUICreate_Alpha
  300.  
  301. Func _Exit()
  302.     MouseUp($_moveMouse)
  303.     _GDIPlus_Shutdown()
  304.     GUIDelete($GUI)
  305.     DllClose($dll)
  306.     Exit
  307. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement