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 $gi_ChildProcParent = 0
- Global $gs_ChildProcReciverFunction = ""
- Global $gv_ChildProcReviverParameter = 0
- Global $_ChildProc_pid[1], $_ChildProc_num_children = 0
- Global $hBitmap
- Global $hHBitmap
- Global $BSpos[2]
- Global $a = 860 / 2, $b = 720 / 2
- Global $iMatch = False
- Global $user32 = DllOpen("user32.dll")
- Global $HWnD = WinGetHandle(WinGetTitle("BlueStacks App Player"))
- Global $xSearch[6] = [430, 430, 430, 150, 500, 750]
- Global $ySearch[6] = [450, 250, 50, 310, 310, 310]
- _GDIPlus_Startup()
- getBSPos()
- Global $sStart = TimerInit()
- _MultiPixelSearch($a, $b, 0x9F6B40, -2, 8, 0x976641, -2, 30, 0xF8FCFF)
- If Not $iMatch Then
- ParallelSearch(6)
- EndIf
- #Region ##### PARALLEL SEARCH #####
- Func ParallelSearch($nNum)
- __ChildProcStartup()
- _ChildProc_WriteToEnvVar("n", $nNum)
- For $i = 0 To $nNum - 1
- _ChildProc_WriteToEnvVar("x" & $i, $xSearch[$i])
- _ChildProc_WriteToEnvVar("y" & $i, $ySearch[$i])
- _ChildProc_Start("ProcessSearch", $i, 0)
- Next
- While _ChildProc_GetChildCount() > 0
- Sleep(250)
- WEnd
- EndFunc ;==>ParallelSearch
- Func ProcessSearch($order)
- $count = _ChildProc_ReadFromEnvVar("n")
- $xX = _ChildProc_ReadFromEnvVar("x" & $order)
- $yY = _ChildProc_ReadFromEnvVar("y" & $order)
- _CaptureRegion()
- _MultiPixelSearch($xX, $yY, 0x9F6B40, -2, 8, 0x976641, -2, 30, 0xF8FCFF)
- If $iMatch Then
- $sStop = Round(TimerDiff($sStart) / 1000, 2)
- MsgBox(0, "", "Found in process [" & $order + 1 & "] of [" & $count & "] . Time: " & $sStop & " seconds.")
- EndIf
- EndFunc ;==>ProcessSearch
- #EndRegion ##### PARALLEL SEARCH #####
- #Region ##### PIXEL PROCESSING #####
- Func _MultiPixelSearch($x, $y, $1c, $2x, $2y, $2c, $3x, $3y, $3c, $sStep = 10, $sSingle = False)
- While 1
- If $y < 180 Or $y > 620 Or $x < 30 Or $x > 800 Then
- ;SetLog("Out of bound (" & $x & ", " & $y & "). Time: " & Round(TimerDiff($cStart) / 1000, 2) & " seconds.")
- $iMatch = False
- ExitLoop
- EndIf
- If _ColorCheckVariation(_PixelGetColor_GetPixel($x, $y), Hex($1c, 6), 18) Then
- For $m = $x - $sStep + 1 To $x + $sStep - 1
- For $n = $y - $sStep + 1 To $y + $sStep - 1
- If _ColorCheckVariation(_PixelGetColor_GetPixel($m, $n), Hex($1c, 6), 5) Then
- If _ColorCheckVariation(_PixelGetColor_GetPixel($m + $2x, $n + $2y), Hex($2c, 6), 5) Then
- If CheckColorVariPos($m + $3x, $n + $3y, $3c, 3, 5) Then
- WinActivate($HWnD)
- MouseMove($BSpos[0] + $m, $BSpos[1] + $n)
- $iMatch = True
- ExitLoop (3)
- EndIf
- EndIf
- EndIf
- Next
- Next
- EndIf
- If Not $sSingle Then
- If $x = $a And $y <= $b Then $x += $sStep
- If $x >= $a And $y < $b Then
- _MultiPixelSearch($x + $sStep, $y + $sStep, $1c, $2x, $2y, $2c, $3x, $3y, $3c)
- ElseIf $x > $a And $y >= $b Then
- _MultiPixelSearch($x - $sStep, $y + $sStep, $1c, $2x, $2y, $2c, $3x, $3y, $3c)
- ElseIf $x <= $a And $y > $b Then
- _MultiPixelSearch($x - $sStep, $y - $sStep, $1c, $2x, $2y, $2c, $3x, $3y, $3c)
- ElseIf $x < $a And $y <= $b Then
- _MultiPixelSearch($x + $sStep, $y - $sStep, $1c, $2x, $2y, $2c, $3x, $3y, $3c)
- EndIf
- EndIf
- ExitLoop
- WEnd
- EndFunc ;==>_MultiPixelSearch
- 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 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 ##### PIXEL PROCESSING #####
- #Region ##### CHILD PROCESS #####
- Func _ChildProc_Start($sFunction = Default, $vParameter = Default, $max_children = 0)
- Local $iPid
- If IsKeyword($sFunction) Or $sFunction = "" Then $sFunction = "__ChildProcDummy"
- EnvSet("ChildProc", "0x" & Hex(StringToBinary($sFunction)))
- EnvSet("ChildProcParent", @AutoItPID)
- If Not IsKeyword($vParameter) Then
- EnvSet("ChildProcParameterPresent", "True")
- EnvSet("ChildProcParameter", StringToBinary($vParameter))
- Else
- EnvSet("ChildProcParameterPresent", "False")
- EndIf
- If $max_children > 0 And $_ChildProc_num_children >= $max_children Then
- While _ChildProc_GetChildCount() >= $max_children
- Sleep(250)
- WEnd
- EndIf
- If @Compiled Then
- $iPid = Run(FileGetShortName(@AutoItExe), @WorkingDir, @SW_HIDE, 1 + 2 + 4)
- Else
- $iPid = Run(FileGetShortName(@AutoItExe) & ' "' & @ScriptFullPath & '"', @WorkingDir, @SW_HIDE, 1 + 2 + 4)
- EndIf
- If @error Then SetError(1)
- If $_ChildProc_pid[0] = "" Then
- $_ChildProc_pid[0] = $iPid
- Else
- _ArrayAdd($_ChildProc_pid, $iPid)
- EndIf
- $_ChildProc_num_children = $_ChildProc_num_children + 1
- Return $iPid
- EndFunc ;==>_ChildProc_Start
- Func _ChildProc_WriteToEnvVar($sName, $vValue = Default)
- Local $vTmp
- $sName = "_CP_" & $sName
- If $vValue = "" Or $vValue = Default Then
- EnvSet($sName)
- Return True
- EndIf
- EnvSet($sName, $vValue)
- Return True
- EndFunc ;==>_ChildProc_WriteToEnvVar
- Func _ChildProc_ReadFromEnvVar($sName, $fOption = 1)
- $sName = "_CP_" & $sName
- If $fOption = "" Or $fOption = Default Then $fOption = False
- $value = EnvGet($sName)
- If $fOption Then
- EnvSet($sName)
- EndIf
- Return $value
- EndFunc ;==>_ChildProc_ReadFromEnvVar
- Func _ChildProc_GetChildCount()
- $num_children = 0
- For $pid_num = 0 To (UBound($_ChildProc_pid) - 1)
- If ProcessExists($_ChildProc_pid[$pid_num]) = True Then $num_children = $num_children + 1
- Next
- Return $num_children
- EndFunc ;==>_ChildProc_GetChildCount
- Func __ChildProcDummy($vPar = Default)
- If Not IsKeyword($vPar) Then _ChildProcReciver($vPar)
- While ProcessExists($gi_ChildProcParent)
- Sleep(500)
- WEnd
- EndFunc ;==>__ChildProcDummy
- Func __ChildProcStartup()
- Local $sCmd = EnvGet("ChildProc")
- If StringLeft($sCmd, 2) = "0x" Then
- $sCmd = BinaryToString($sCmd)
- $gi_ChildProcParent = Number(EnvGet("ChildProcParent"))
- If StringInStr($sCmd, "(") And StringInStr($sCmd, ")") Then
- Execute($sCmd)
- If @error And Not @Compiled Then MsgBox(16, "ChildProc Error", "Unable to Execute: " & $sCmd)
- Exit
- EndIf
- If EnvGet("ChildProcParameterPresent") = "True" Then
- Call($sCmd, BinaryToString(EnvGet("ChildProcParameter")))
- If @error And Not @Compiled Then MsgBox(16, "ChildProc Error", "Unable to Call: " & $sCmd & @LF & "Parameter: " & BinaryToString(EnvGet("ChildProcParameter")))
- Else
- Call($sCmd)
- If @error And Not @Compiled Then MsgBox(16, "ChildProc Error", "Unable to Call: " & $sCmd)
- EndIf
- Exit
- EndIf
- EndFunc ;==>__ChildProcStartup
- #EndRegion ##### CHILD PROCESS #####
- #Region ##### ADDITIONAL #####
- 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 ;==>Terminate
- #EndRegion ##### ADDITIONAL #####
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement