Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Array.au3>
- #include <GUIConstantsEx.au3>
- #include <WindowsConstants.au3>
- #include <ColorConstants.au3>
- #include <GDIPlus.au3>
- #include <StaticConstants.au3>
- #include <WindowsConstants.au3>
- #include <WinAPIProc.au3>
- #include <ScreenCapture.au3>
- #include <Misc.au3>
- #include <TrayConstants.au3>
- #include <ColorConstants.au3>
- #include <GDIPlus.au3>
- HotKeySet("^{SPACE}", "Terminate")
- Global $hBitmap
- Global $hHBitmap
- Global $BSpos[2]
- Global $user32 = DllOpen("user32.dll")
- Global $HWnD = WinGetHandle(WinGetTitle("BlueStacks App Player"))
- Global $Top[2] = [430, 20]
- Global $Bottom[2] = [430, 600]
- Global $Left[2] = [60, 310]
- Global $Right[2] = [780, 310]
- 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
- Global $a = Floor(($Top[0] + $Bottom[0] + $Left[0] + $Right[0]) / 4)
- Global $b = Floor(($Top[1] + $Bottom[1] + $Left[1] + $Right[1]) / 4)
- Global $sResults = ""
- _GDIPlus_Startup()
- getBSPos()
- WinActivate($HWnD)
- Global $sStart, $sStop
- ;TH9: 0x404450, 9, 1, 0x494C58, 11, -2, 0x414753
- ;TH8: 0x9F6B40, -2, 8, 0x976641, -2, 30, 0xF8FCFF
- ;TH10: 0xFF7D00, 3, 10, 0x752C14, -7, 11, 0x807868
- ;Wall 7: 0x473354, -8, -7, 0x482657, 5, 2, 7E6294
- ;Wall 8: 0x4B4F57, 3, 3, 0x2F3236, -7, -4, 0x2C2D2E
- ;Wall 8: 0x202124, 3, 2, 4A4A4D, -1, -3, 0x796C5C
- #Region ##### MAIN CODE #####
- _CaptureRegion()
- If WeakBase(9) Then
- TrayTip("","TH8 Found (" & $sStop & " seconds)","",0)
- $sResults &= "TH8 Found (" & $sStop & " seconds)" & @CRLF
- Else
- $sStop = Round(TimerDiff($sStart) / 1000, 2)
- $sResults &= "TH8 Not Found (" & $sStop & " seconds)" & @CRLF
- EndIf
- If WeakBase(10) Then
- TrayTip("","TH9 Found (" & $sStop & " seconds)","",0)
- $sResults &= "TH9 Found (" & $sStop & " seconds)" & @CRLF
- Else
- $sStop = Round(TimerDiff($sStart) / 1000, 2)
- $sResults &= "TH9 Not Found (" & $sStop & " seconds)" & @CRLF
- EndIf
- If WeakBase(11) Then
- TrayTip("","TH10 Found (" & $sStop & " seconds)","",0)
- $sResults &= "TH10 Found (" & $sStop & " seconds)" & @CRLF
- Else
- $sStop = Round(TimerDiff($sStart) / 1000, 2)
- $sResults &= "TH10 Not Found (" & $sStop & " seconds)" & @CRLF
- EndIf
- If BaseCheck("Wall 7") Then
- TrayTip("","Wall 7 Found (" & $sStop & " seconds)","",0)
- $sResults &= "Wall 7 Found (" & $sStop & " seconds)" & @CRLF
- Else
- $sStop = Round(TimerDiff($sStart) / 1000, 2)
- $sResults &= "Wall 7 Not Found (" & $sStop & " seconds)" & @CRLF
- EndIf
- If BaseCheck("Wall 8") Then
- TrayTip("","Wall 8 Found (" & $sStop & " seconds)","",0)
- $sResults &= "Wall 8 Found (" & $sStop & " seconds)" & @CRLF
- Else
- $sStop = Round(TimerDiff($sStart) / 1000, 2)
- $sResults &= "Wall 8 Not Found (" & $sStop & " seconds)" & @CRLF
- EndIf
- MsgBox(0,"",$sResults)
- #EndRegion ##### MAIN CODE #####
- #Region ##### WEAK BASE SEARCH #####
- Func WeakBase($TH)
- Switch $TH
- Case 9
- If BaseCheck("TownHall 8") Then Return True
- Case 10
- If BaseCheck("TownHall 9") Then Return True
- Case 11
- If BaseCheck("TownHall 10") Then Return True
- EndSwitch
- Return False
- EndFunc ;==>WeakBase
- Func BaseCheck($item)
- Switch $item
- Case "TownHall 9"
- If BaseSearch(0x404450, 9, 1, 0x494C58, 11, -2, 0x414753) Then Return True
- Case "TownHall 8"
- If BaseSearch(0x9F6B40, -2, 8, 0x976641, -2, 30, 0xF8FCFF) Then Return True
- Case "TownHall 10"
- If BaseSearch(0xA52015, 8, 7, 0xEC5114, 5, 11, 0x7F3928) Then Return True
- Case "Wall 7"
- If BaseSearch(0x331450, 4, 4, 0x3D2949, 3, 1, 0x473357) Then Return True
- Case "Wall 8"
- If BaseSearch(0x202124, 3, 2, 0x4A4A4D, -1, -3, 0x796C5C) Then Return True
- EndSwitch
- Return False
- EndFunc ;==>BaseCheck
- Func BaseSearch($pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3)
- $sStart = TimerInit()
- If _MultiPixelSearch($a + 5, $b + 5, 10, 15, $pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, -10, -10, False) Then Return True;top left
- If _MultiPixelSearch($a - 5, $b - 5, 835, 625, $pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, 10, 10, False) Then Return True ;bottom right
- If _MultiPixelSearch($a + 5, $b - 5, 10, 625, $pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, -10, 10, False) Then Return True ;bottom left
- If _MultiPixelSearch($a - 5, $b + 5, 835, 15, $pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, 10, -10, False) Then Return True ;top right
- Return False
- EndFunc ;==>BaseSearch
- Func _MultiPixelSearch($x1, $y1, $x2, $y2, $1c, $2x, $2y, $2c, $3x, $3y, $3c, $sStepx, $sStepy, $sSingle = False)
- For $m = $x1 To $x2 + $sStepx Step $sStepx
- For $n = $y1 To $y2 + $sStepy Step $sStepy
- ;MouseMove($BSpos[0] + $m, $BSpos[1] + $n,1)
- If OutofBound($m, $n) Then ExitLoop
- If _ColorCheckVariation(_PixelGetColor_GetPixel($m, $n), Hex($1c, 6), 10) Then
- For $o = $m - $sStepx + 1 To $m + $sStepx - 1 Step $sStepx / Abs($sStepx)
- For $p = $n - $sStepy + 1 To $n + $sStepy - 1 Step $sStepy / Abs($sStepy)
- If _ColorCheckVariation(_PixelGetColor_GetPixel($o, $p), Hex($1c, 6), 2) Then
- If CheckColorVariPos($o + $2x, $p + $2y, $2c, 3, 5) Then
- If CheckColorVariPos($o + $3x, $p + $3y, $3c, 3, 5) Then
- $sStop = Round(TimerDiff($sStart) / 1000, 2)
- WinActivate($HWnD)
- MouseMove($BSpos[0] + $o, $BSpos[1] + $p)
- Return True
- EndIf
- EndIf
- EndIf
- Next
- Next
- EndIf
- Next
- Next
- Return False
- EndFunc ;==>_MultiPixelSearch
- Func OutofBound($x, $y)
- $chkArea = TriArea($x, $y, $Top, $Left) + TriArea($x, $y, $Top, $Right) + TriArea($x, $y, $Right, $Bottom) + TriArea($x, $y, $Left, $Bottom)
- If $chkArea - $Area > 20 Then
- Return True
- Else
- Return False
- EndIf
- EndFunc ;==>OutofBound
- Func TriArea($dx, $dy, $e, $f)
- $tArea = Abs(($dx * ($e[1] - $f[1]) + $e[0] * ($f[1] - $dy) + $f[0] * ($dy - $e[1])) / 2)
- Return $tArea
- EndFunc ;==>TriArea
- Func CheckColorVariPos($x, $y, $c, $vp = 0, $vc = 10)
- For $a = $x - $vp To $x + $vp
- For $b = $y - $vp To $y + $vp
- If _ColorCheckVariation(_PixelGetColor_GetPixel($a, $b), Hex($c, 6), $vc) Then
- Return True
- EndIf
- Next
- Next
- Return False
- EndFunc ;==>CheckColorVariPos
- #EndRegion ##### WEAK BASE SEARCH #####
- Func _CaptureRegion($iLeft = 0, $iTop = 0, $iRight = 860, $iBottom = 720, $ReturnBMP = False)
- _GDIPlus_BitmapDispose($hBitmap)
- _WinAPI_DeleteObject($hHBitmap)
- Local $iW = Number($iRight) - Number($iLeft), $iH = Number($iBottom) - Number($iTop)
- Local $hDC_Capture = _WinAPI_GetWindowDC(ControlGetHandle("BlueStacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]"))
- Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
- $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $iW, $iH)
- Local $hObjectOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
- DllCall($user32, "int", "PrintWindow", "hwnd", $HWnD, "handle", $hMemDC, "int", 0)
- _WinAPI_SelectObject($hMemDC, $hHBitmap)
- _WinAPI_BitBlt($hMemDC, 0, 0, $iW, $iH, $hDC_Capture, $iLeft, $iTop, 0x00CC0020)
- $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
- _WinAPI_DeleteDC($hMemDC)
- _WinAPI_SelectObject($hMemDC, $hObjectOld)
- _WinAPI_ReleaseDC($HWnD, $hDC_Capture)
- EndFunc ;==>_CaptureRegion
- Func _PixelGetColor_GetPixel($iX, $iY)
- Local $aPixelColor = _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
- Return Hex($aPixelColor, 6)
- EndFunc ;==>_PixelGetColor_GetPixel
- Func _PixelSearch($iLeft, $iTop, $iRight, $iBottom, $iColor, $ColorVariation)
- _CaptureRegion($iLeft, $iTop, $iRight, $iBottom)
- For $x = $iRight - $iLeft To 0 Step -1
- For $y = $iBottom - $iTop To 0 Step -1
- Local $nColor1 = $iColor
- Local $nColor2 = _PixelGetColor_GetPixel($x, $y)
- If _ColorCheckVariation($nColor1, $nColor2, $ColorVariation) Then
- Local $Pos[2] = [$iLeft + $x, $iTop + $y]
- Return $Pos
- EndIf
- Next
- Next
- Return 0
- EndFunc ;==>_PixelSearch
- Func _ColorCheckVariation($nColor1, $nColor2, $sVari = 5)
- Local $Red1, $Red2, $Blue1, $Blue2, $Green1, $Green2
- $Red1 = Dec(StringMid(String($nColor1), 1, 2))
- $Blue1 = Dec(StringMid(String($nColor1), 3, 2))
- $Green1 = Dec(StringMid(String($nColor1), 5, 2))
- $Red2 = Dec(StringMid(String($nColor2), 1, 2))
- $Blue2 = Dec(StringMid(String($nColor2), 3, 2))
- $Green2 = Dec(StringMid(String($nColor2), 5, 2))
- If Abs($Blue1 - $Blue2) > $sVari Then Return False
- If Abs($Green1 - $Green2) > $sVari Then Return False
- If Abs($Red1 - $Red2) > $sVari Then Return False
- Return True
- EndFunc ;==>_ColorCheckVariation
- Func getBSPos()
- $aPos = ControlGetPos("BlueStacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]")
- $tPoint = DllStructCreate("int X;int Y")
- DllStructSetData($tPoint, "X", $aPos[0])
- DllStructSetData($tPoint, "Y", $aPos[1])
- _WinAPI_ClientToScreen(WinGetHandle(WinGetTitle("BlueStacks App Player")), $tPoint)
- $BSpos[0] = DllStructGetData($tPoint, "X")
- $BSpos[1] = DllStructGetData($tPoint, "Y")
- $CtrlHandle = ControlGetHandle("BlueStacks App Player", "", "BlueStacksApp1")
- EndFunc ;==>getBSPos
- Func Terminate()
- Exit
- EndFunc ;==>EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement