Advertisement
CocBotTBC

Weak Base Search

Jan 20th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 9.07 KB | None | 0 0
  1. #include <Array.au3>
  2. #include <GUIConstantsEx.au3>
  3. #include <WindowsConstants.au3>
  4. #include <ColorConstants.au3>
  5. #include <GDIPlus.au3>
  6. #include <StaticConstants.au3>
  7. #include <WindowsConstants.au3>
  8. #include <WinAPIProc.au3>
  9. #include <ScreenCapture.au3>
  10. #include <Misc.au3>
  11. #include <TrayConstants.au3>
  12. #include <ColorConstants.au3>
  13. #include <GDIPlus.au3>
  14.  
  15. HotKeySet("^{SPACE}", "Terminate")
  16.  
  17. Global $hBitmap
  18. Global $hHBitmap
  19. Global $BSpos[2]
  20. Global $user32 = DllOpen("user32.dll")
  21. Global $HWnD = WinGetHandle(WinGetTitle("BlueStacks App Player"))
  22.  
  23. Global $Top[2] = [430, 20]
  24. Global $Bottom[2] = [430, 600]
  25. Global $Left[2] = [60, 310]
  26. Global $Right[2] = [780, 310]
  27. Global $Area = (($Top[0] * $Right[1] - $Right[0] * $Top[1]) + ($Right[0] * $Bottom[1] - $Bottom[0] * $Right[1]) + ($Bottom[0] * $Left[1] - $Left[0] * $Bottom[1]) + ($Left[0] * $Top[1] - $Top[0] * $Left[1])) / 2
  28. Global $a = Floor(($Top[0] + $Bottom[0] + $Left[0] + $Right[0]) / 4)
  29. Global $b = Floor(($Top[1] + $Bottom[1] + $Left[1] + $Right[1]) / 4)
  30. Global $sResults = ""
  31. _GDIPlus_Startup()
  32. getBSPos()
  33. WinActivate($HWnD)
  34. Global $sStart, $sStop
  35.  
  36. ;TH9: 0x404450, 9, 1, 0x494C58, 11, -2, 0x414753
  37. ;TH8: 0x9F6B40, -2, 8, 0x976641, -2, 30, 0xF8FCFF
  38. ;TH10: 0xFF7D00, 3, 10, 0x752C14, -7, 11, 0x807868
  39. ;Wall 7: 0x473354, -8, -7, 0x482657, 5, 2, 7E6294
  40. ;Wall 8: 0x4B4F57, 3, 3, 0x2F3236, -7, -4, 0x2C2D2E
  41. ;Wall 8: 0x202124, 3, 2, 4A4A4D, -1, -3, 0x796C5C
  42.  
  43. #Region ##### MAIN CODE #####
  44.  
  45. _CaptureRegion()
  46.  
  47. If WeakBase(9) Then
  48.     TrayTip("","TH8 Found (" & $sStop & " seconds)","",0)
  49.     $sResults &= "TH8 Found (" & $sStop & " seconds)" & @CRLF
  50. Else
  51.     $sStop = Round(TimerDiff($sStart) / 1000, 2)
  52.     $sResults &= "TH8 Not Found (" & $sStop & " seconds)" & @CRLF
  53. EndIf
  54.  
  55. If WeakBase(10) Then
  56.     TrayTip("","TH9 Found (" & $sStop & " seconds)","",0)
  57.     $sResults &= "TH9 Found (" & $sStop & " seconds)" & @CRLF
  58. Else
  59.     $sStop = Round(TimerDiff($sStart) / 1000, 2)
  60.     $sResults &= "TH9 Not Found (" & $sStop & " seconds)" & @CRLF
  61. EndIf
  62.  
  63. If WeakBase(11) Then
  64.     TrayTip("","TH10 Found (" & $sStop & " seconds)","",0)
  65.     $sResults &= "TH10 Found (" & $sStop & " seconds)" & @CRLF
  66. Else
  67.     $sStop = Round(TimerDiff($sStart) / 1000, 2)
  68.     $sResults &= "TH10 Not Found (" & $sStop & " seconds)" & @CRLF
  69. EndIf
  70.  
  71. If BaseCheck("Wall 7") Then
  72.     TrayTip("","Wall 7 Found (" & $sStop & " seconds)","",0)
  73.     $sResults &= "Wall 7 Found (" & $sStop & " seconds)" & @CRLF
  74. Else
  75.     $sStop = Round(TimerDiff($sStart) / 1000, 2)
  76.     $sResults &= "Wall 7 Not Found (" & $sStop & " seconds)" & @CRLF
  77. EndIf
  78.  
  79. If BaseCheck("Wall 8") Then
  80.     TrayTip("","Wall 8 Found (" & $sStop & " seconds)","",0)
  81.     $sResults &= "Wall 8 Found (" & $sStop & " seconds)" & @CRLF
  82. Else
  83.     $sStop = Round(TimerDiff($sStart) / 1000, 2)
  84.     $sResults &= "Wall 8 Not Found (" & $sStop & " seconds)" & @CRLF
  85. EndIf
  86.  
  87. MsgBox(0,"",$sResults)
  88.  
  89. #EndRegion ##### MAIN CODE #####
  90.  
  91. #Region ##### WEAK BASE SEARCH #####
  92. Func WeakBase($TH)
  93.     Switch $TH
  94.         Case 9
  95.             If BaseCheck("TownHall 8") Then Return True
  96.         Case 10
  97.             If BaseCheck("TownHall 9") Then Return True
  98.         Case 11
  99.             If BaseCheck("TownHall 10") Then Return True
  100.     EndSwitch
  101.     Return False
  102. EndFunc   ;==>WeakBase
  103.  
  104. Func BaseCheck($item)
  105.     Switch $item
  106.         Case "TownHall 9"
  107.             If BaseSearch(0x404450, 9, 1, 0x494C58, 11, -2, 0x414753) Then Return True
  108.         Case "TownHall 8"
  109.             If BaseSearch(0x9F6B40, -2, 8, 0x976641, -2, 30, 0xF8FCFF) Then Return True
  110.         Case "TownHall 10"
  111.             If BaseSearch(0xA52015, 8, 7, 0xEC5114, 5, 11, 0x7F3928) Then Return True
  112.         Case "Wall 7"
  113.             If BaseSearch(0x331450, 4, 4, 0x3D2949, 3, 1, 0x473357) Then Return True
  114.         Case "Wall 8"
  115.             If BaseSearch(0x202124, 3, 2, 0x4A4A4D, -1, -3, 0x796C5C) Then Return True
  116.     EndSwitch
  117.     Return False
  118. EndFunc   ;==>BaseCheck
  119.  
  120. Func BaseSearch($pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3)
  121.     $sStart = TimerInit()
  122.     If _MultiPixelSearch($a + 5, $b + 5, 10, 15, $pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, -10, -10, False) Then Return True;top left
  123.     If _MultiPixelSearch($a - 5, $b - 5, 835, 625, $pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, 10, 10, False) Then Return True ;bottom right
  124.     If _MultiPixelSearch($a + 5, $b - 5, 10, 625, $pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, -10, 10, False) Then Return True ;bottom left
  125.     If _MultiPixelSearch($a - 5, $b + 5, 835, 15, $pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, 10, -10, False) Then Return True ;top right
  126.     Return False
  127. EndFunc   ;==>BaseSearch
  128.  
  129. Func _MultiPixelSearch($x1, $y1, $x2, $y2, $1c, $2x, $2y, $2c, $3x, $3y, $3c, $sStepx, $sStepy, $sSingle = False)
  130.     For $m = $x1 To $x2 + $sStepx Step $sStepx
  131.         For $n = $y1 To $y2 + $sStepy Step $sStepy
  132.             ;MouseMove($BSpos[0] + $m, $BSpos[1] + $n,1)
  133.             If OutofBound($m, $n) Then ExitLoop
  134.             If _ColorCheckVariation(_PixelGetColor_GetPixel($m, $n), Hex($1c, 6), 10) Then
  135.                 For $o = $m - $sStepx + 1 To $m + $sStepx - 1 Step $sStepx / Abs($sStepx)
  136.                     For $p = $n - $sStepy + 1 To $n + $sStepy - 1 Step $sStepy / Abs($sStepy)
  137.                         If _ColorCheckVariation(_PixelGetColor_GetPixel($o, $p), Hex($1c, 6), 2) Then
  138.                             If CheckColorVariPos($o + $2x, $p + $2y, $2c, 3, 5) Then
  139.                                 If CheckColorVariPos($o + $3x, $p + $3y, $3c, 3, 5) Then
  140.                                     $sStop = Round(TimerDiff($sStart) / 1000, 2)
  141.                                     WinActivate($HWnD)
  142.                                     MouseMove($BSpos[0] + $o, $BSpos[1] + $p)
  143.                                     Return True
  144.                                 EndIf
  145.                             EndIf
  146.                         EndIf
  147.                     Next
  148.                 Next
  149.             EndIf
  150.         Next
  151.     Next
  152.     Return False
  153. EndFunc   ;==>_MultiPixelSearch
  154.  
  155. Func OutofBound($x, $y)
  156.     $chkArea = TriArea($x, $y, $Top, $Left) + TriArea($x, $y, $Top, $Right) + TriArea($x, $y, $Right, $Bottom) + TriArea($x, $y, $Left, $Bottom)
  157.     If $chkArea - $Area > 20 Then
  158.         Return True
  159.     Else
  160.         Return False
  161.     EndIf
  162. EndFunc   ;==>OutofBound
  163.  
  164. Func TriArea($dx, $dy, $e, $f)
  165.     $tArea = Abs(($dx * ($e[1] - $f[1]) + $e[0] * ($f[1] - $dy) + $f[0] * ($dy - $e[1])) / 2)
  166.     Return $tArea
  167. EndFunc   ;==>TriArea
  168.  
  169. Func CheckColorVariPos($x, $y, $c, $vp = 0, $vc = 10)
  170.     For $a = $x - $vp To $x + $vp
  171.         For $b = $y - $vp To $y + $vp
  172.             If _ColorCheckVariation(_PixelGetColor_GetPixel($a, $b), Hex($c, 6), $vc) Then
  173.                 Return True
  174.             EndIf
  175.         Next
  176.     Next
  177.     Return False
  178. EndFunc   ;==>CheckColorVariPos
  179. #EndRegion ##### WEAK BASE SEARCH #####
  180.  
  181. Func _CaptureRegion($iLeft = 0, $iTop = 0, $iRight = 860, $iBottom = 720, $ReturnBMP = False)
  182.     _GDIPlus_BitmapDispose($hBitmap)
  183.     _WinAPI_DeleteObject($hHBitmap)
  184.     Local $iW = Number($iRight) - Number($iLeft), $iH = Number($iBottom) - Number($iTop)
  185.     Local $hDC_Capture = _WinAPI_GetWindowDC(ControlGetHandle("BlueStacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]"))
  186.     Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
  187.     $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $iW, $iH)
  188.     Local $hObjectOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
  189.     DllCall($user32, "int", "PrintWindow", "hwnd", $HWnD, "handle", $hMemDC, "int", 0)
  190.     _WinAPI_SelectObject($hMemDC, $hHBitmap)
  191.     _WinAPI_BitBlt($hMemDC, 0, 0, $iW, $iH, $hDC_Capture, $iLeft, $iTop, 0x00CC0020)
  192.     $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
  193.     _WinAPI_DeleteDC($hMemDC)
  194.     _WinAPI_SelectObject($hMemDC, $hObjectOld)
  195.     _WinAPI_ReleaseDC($HWnD, $hDC_Capture)
  196. EndFunc   ;==>_CaptureRegion
  197.  
  198. Func _PixelGetColor_GetPixel($iX, $iY)
  199.     Local $aPixelColor = _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
  200.     Return Hex($aPixelColor, 6)
  201. EndFunc   ;==>_PixelGetColor_GetPixel
  202. Func _PixelSearch($iLeft, $iTop, $iRight, $iBottom, $iColor, $ColorVariation)
  203.     _CaptureRegion($iLeft, $iTop, $iRight, $iBottom)
  204.     For $x = $iRight - $iLeft To 0 Step -1
  205.         For $y = $iBottom - $iTop To 0 Step -1
  206.             Local $nColor1 = $iColor
  207.             Local $nColor2 = _PixelGetColor_GetPixel($x, $y)
  208.             If _ColorCheckVariation($nColor1, $nColor2, $ColorVariation) Then
  209.                 Local $Pos[2] = [$iLeft + $x, $iTop + $y]
  210.                 Return $Pos
  211.             EndIf
  212.         Next
  213.     Next
  214.     Return 0
  215. EndFunc   ;==>_PixelSearch
  216.  
  217. Func _ColorCheckVariation($nColor1, $nColor2, $sVari = 5)
  218.     Local $Red1, $Red2, $Blue1, $Blue2, $Green1, $Green2
  219.     $Red1 = Dec(StringMid(String($nColor1), 1, 2))
  220.     $Blue1 = Dec(StringMid(String($nColor1), 3, 2))
  221.     $Green1 = Dec(StringMid(String($nColor1), 5, 2))
  222.     $Red2 = Dec(StringMid(String($nColor2), 1, 2))
  223.     $Blue2 = Dec(StringMid(String($nColor2), 3, 2))
  224.     $Green2 = Dec(StringMid(String($nColor2), 5, 2))
  225.     If Abs($Blue1 - $Blue2) > $sVari Then Return False
  226.     If Abs($Green1 - $Green2) > $sVari Then Return False
  227.     If Abs($Red1 - $Red2) > $sVari Then Return False
  228.     Return True
  229. EndFunc   ;==>_ColorCheckVariation
  230.  
  231. Func getBSPos()
  232.     $aPos = ControlGetPos("BlueStacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]")
  233.     $tPoint = DllStructCreate("int X;int Y")
  234.     DllStructSetData($tPoint, "X", $aPos[0])
  235.     DllStructSetData($tPoint, "Y", $aPos[1])
  236.     _WinAPI_ClientToScreen(WinGetHandle(WinGetTitle("BlueStacks App Player")), $tPoint)
  237.     $BSpos[0] = DllStructGetData($tPoint, "X")
  238.     $BSpos[1] = DllStructGetData($tPoint, "Y")
  239.     $CtrlHandle = ControlGetHandle("BlueStacks App Player", "", "BlueStacksApp1")
  240. EndFunc   ;==>getBSPos
  241.  
  242. Func Terminate()
  243.     Exit
  244. EndFunc   ;==>EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement