Advertisement
CocBotTBC

Weak Base Search

Jan 21st, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 19.69 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 $sMatch = False
  24.  
  25. Global $gi_ChildProcParent = 0
  26. Global $gs_ChildProcReciverFunction = ""
  27. Global $gv_ChildProcReviverParameter = 0
  28. Global $_ChildProc_pid[1], $_ChildProc_num_children = 0
  29.  
  30. Global $Top[2] = [430, 20]
  31. Global $Bottom[2] = [430, 600]
  32. Global $Left[2] = [60, 310]
  33. Global $Right[2] = [780, 310]
  34. 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
  35. Global $a = Floor(($Top[0] + $Bottom[0] + $Left[0] + $Right[0]) / 4)
  36. Global $b = Floor(($Top[1] + $Bottom[1] + $Left[1] + $Right[1]) / 4)
  37. Global $sChildResult, $sResults = ""
  38. _GDIPlus_Startup()
  39. getBSPos()
  40. WinActivate($HWnD)
  41. Global $sStart, $sStop
  42.  
  43. HotKeySet("+{SPACE}","Terminate")
  44. Func Terminate()
  45.     Exit
  46. EndFunc
  47. ;$Mouse = MsgBox(4,"Weak Base Search","Show mouse pointers?",$HWnD)
  48.  
  49. #Region ##### MAIN CODE #####
  50.  
  51. ;========== Use this if you want to use parallel search ==========
  52. _CaptureRegion()
  53. __ChildProcStartup()
  54. $sStart = TimerInit()
  55. _ChildProc_Start("SearchTH8")
  56. _ChildProc_Start("SearchTH9")
  57. _ChildProc_Start("SearchTH10")
  58. _ChildProc_Start("SearchWall7")
  59. _ChildProc_Start("SearchWall8")
  60.  
  61. While _ChildProc_GetChildCount() > 0
  62.         Sleep(50)
  63. WEnd
  64. $sStop = Round(TimerDiff($sStart)/1000, 2)
  65. $sChildResult = _ChildProc_ReadFromAllFiles()
  66. If $sChildResult = "" Then $sChildResult = "Not Found"
  67. MsgBox(0,"",$sChildResult & ". Time: " & $sStop & "s")
  68.  
  69. Func SearchTH8()
  70.     If BaseSearch(0x815933, 10, -7, -2, 0xAE7643, 1, 14, 0x886C58) Then _ChildProc_WriteToFile("", "TH8, ")
  71. EndFunc
  72. Func SearchTH9()
  73.     If BaseSearch(0x404450, 10, 9, 1, 0x494C58, 11, -2, 0x414753) Then _ChildProc_WriteToFile("", "TH9, ")
  74. EndFunc
  75. Func SearchTH10()
  76.     If BaseSearch(0x484646, 10, 8, -12, 0x705858, -5, -20, 0x382F2F) Then _ChildProc_WriteToFile("", "TH10, ")
  77. EndFunc
  78. Func SearchWall7()
  79.     If BaseSearch(0x331450, 5, 4, 4, 0x3D2949, 3, 1, 0x473357) Then _ChildProc_WriteToFile("", "Wall7, ")
  80. EndFunc
  81. Func SearchWall8()
  82.     If BaseSearch(0x605850, 5, 5, -5, 0x282828, -3, 4, 0x202428) Then _ChildProc_WriteToFile("", "Wall8")
  83. EndFunc
  84. ;========== Use this if you want to use parallel search ==========
  85.  
  86. ;========== Use this if you want to use normal (single-threaded) search ==========
  87. ;~ $sStart = TimerInit()
  88. ;~ _CaptureRegion()
  89. ;~ $sStart8 = TimerInit()
  90. ;~ If WeakBase(8) Then
  91. ;~  $sStop = Round(TimerDiff($sStart8) / 1000, 2)
  92. ;~  ;TrayTip("", "TH8 Found (" & $sStop & " seconds)", "", 0)
  93. ;~  $sResults &= "TH8 Found (" & $sStop & " seconds)" & @CRLF
  94. ;~ Else
  95. ;~  $sStop = Round(TimerDiff($sStart8) / 1000, 2)
  96. ;~  $sResults &= "TH8 Not Found (" & $sStop & " seconds)" & @CRLF
  97. ;~ EndIf
  98. ;~ $sStart9 = TimerInit()
  99. ;~ If WeakBase(9) Then
  100. ;~  $sStop = Round(TimerDiff($sStart9) / 1000, 2)
  101. ;~  ;TrayTip("","TH9 Found (" & $sStop & " seconds)","",0)
  102. ;~  $sResults &= "TH9 Found (" & $sStop & " seconds)" & @CRLF
  103. ;~ Else
  104. ;~  $sStop = Round(TimerDiff($sStart9) / 1000, 2)
  105. ;~  $sResults &= "TH9 Not Found (" & $sStop & " seconds)" & @CRLF
  106. ;~ EndIf
  107. ;~ $sStart10 = TimerInit()
  108. ;~ If WeakBase(10) Then
  109. ;~  $sStop = Round(TimerDiff($sStart10) / 1000, 2)
  110. ;~  ;TrayTip("","TH10 Found (" & $sStop & " seconds)","",0)
  111. ;~  $sResults &= "TH10 Found (" & $sStop & " seconds)" & @CRLF
  112. ;~ Else
  113. ;~  $sStop = Round(TimerDiff($sStart10) / 1000, 2)
  114. ;~  $sResults &= "TH10 Not Found (" & $sStop & " seconds)" & @CRLF
  115. ;~ EndIf
  116. ;~ $sStartw7 = TimerInit()
  117. ;~ If BaseCheck("Wall 7") Then
  118. ;~  $sStop = Round(TimerDiff($sStartw7) / 1000, 2)
  119. ;~  ;TrayTip("","Wall 7 Found (" & $sStop & " seconds)","",0)
  120. ;~  $sResults &= "Wall 7 Found (" & $sStop & " seconds)" & @CRLF
  121. ;~ Else
  122. ;~  $sStop = Round(TimerDiff($sStartw7) / 1000, 2)
  123. ;~  $sResults &= "Wall 7 Not Found (" & $sStop & " seconds)" & @CRLF
  124. ;~ EndIf
  125. ;~ $sStartw8 = TimerInit()
  126. ;~ If BaseCheck("Wall 8") Then
  127. ;~  $sStop = Round(TimerDiff($sStartw8) / 1000, 2)
  128. ;~  ;TrayTip("","Wall 8 Found (" & $sStop & " seconds)","",0)
  129. ;~  $sResults &= "Wall 8 Found (" & $sStop & " seconds)" & @CRLF
  130. ;~ Else
  131. ;~  $sStop = Round(TimerDiff($sStartw8) / 1000, 2)
  132. ;~  $sResults &= "Wall 8 Not Found (" & $sStop & " seconds)" & @CRLF
  133. ;~ EndIf
  134. ;~ $sStop = Round(TimerDiff($sStart) / 1000, 2)
  135. ;~ $sResults &= "Total time: " & $sStop & " seconds"
  136. ;~ MsgBox(0, "", $sResults)
  137. ;========== Use this if you want to use normal (single-threaded) search ==========
  138. #EndRegion ##### MAIN CODE #####
  139.  
  140. #Region ##### WEAK BASE SEARCH #####
  141. ;~ Func SnipeAlgorithm($pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx = 3, $Stepy = 3, $Width = 100)
  142. ;~  If LinearSearchAlgorithm(310, 240, 10, 15, $pixel1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, -$Stepx, -$Stepy, False) Then Return True;top left
  143. ;~ EndFunc   ;==>SnipeAlgorithm
  144.  
  145. Func WeakBase($TH)
  146.     Switch $TH
  147.         Case 8
  148.             If BaseCheck("TownHall 8") Then Return True
  149.         Case 9
  150.             If BaseCheck("TownHall 9") Then Return True
  151.         Case 10
  152.             If BaseCheck("TownHall 10") Then Return True
  153.     EndSwitch
  154.     Return False
  155. EndFunc   ;==>WeakBase
  156.  
  157. Func BaseCheck($item)
  158.     Switch $item
  159.         Case "TownHall 9"
  160.             If BaseSearch(0x404450, 9, 9, 1, 0x494C58, 11, -2, 0x414753) Then Return True
  161.         Case "TownHall 8"
  162.             If BaseSearch(0x815933, 6, -7, -2, 0xAE7643, 1, 14, 0x886C58) Then Return True
  163.         Case "TownHall 10"
  164.             ;If BaseSearch(0xA52015, 10, 8, 7, 0xEC5114, 5, 11, 0x7F3928) Then Return True
  165.             If BaseSearch(0x484646, 9, 8, -12, 0x705858, -5, -20, 0x382F2F) Then Return True
  166.         Case "Wall 7"
  167.             If BaseSearch(0x331450, 4, 4, 4, 0x3D2949, 3, 1, 0x473357) Then Return True
  168.         Case "Wall 8"
  169.             ;If BaseSearch(0x202124, 10, 3, 2, 0x4A4A4D, -1, -3, 0x796C5C) Then Return True
  170.             ;If BaseSearch(0x8A7D75, 10, -1, 3, 0x24282B, -4, 2, 0x121516) Then Return True
  171.             If BaseSearch(0x605850, 4, 5, -5, 0x282828, -3, 4, 0x202428) Then Return True
  172.     EndSwitch
  173.     Return False
  174. EndFunc   ;==>BaseCheck
  175.  
  176. Func BaseSearch($pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx = 15, $Stepy = 15)
  177.     If LinearSearchAlgorithm($pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx, $Stepy) Then Return True
  178.     ;If SpiralSearchAlgorithm($a, $b, $pixel1, $colorvariation1, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx) Then Return True
  179.     Return False
  180. EndFunc   ;==>BaseSearch
  181.  
  182. Func LinearSearchAlgorithm($pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx = 10, $Stepy = 10)
  183.     If LinearSearchSingle($a + 5, $b + 5, 10, 15, $pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, -$Stepx, -$Stepy) Then Return True;top left
  184.     If LinearSearchSingle($a - 5, $b - 5, 835, 625, $pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx, $Stepy) Then Return True ;bottom right
  185.     If LinearSearchSingle($a + 5, $b - 5, 10, 625, $pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, -$Stepx, $Stepy) Then Return True ;bottom left
  186.     If LinearSearchSingle($a - 5, $b + 5, 835, 15, $pixel1, $colorvariation1, $x2offset, $y2offset, $pixel2, $x3offset, $y3offset, $pixel3, $Stepx, -$Stepy) Then Return True ;top right
  187.     Return False
  188. EndFunc
  189.  
  190. Func SpiralSearchAlgorithm($x, $y, $1c, $1v, $2x, $2y, $2c, $3x, $3y, $3c, $sStep = 20, $sSingle = False)
  191.     If SpiralSearchSingleV($x, $y, $1c, $1v, $2x, $2y, $2c, $3x, $3y, $3c, $sStep) Then Return True
  192.     If SpiralSearchSingleH($x, $y, $1c, $1v, $2x, $2y, $2c, $3x, $3y, $3c, $sStep) Then Return True
  193.     Return False
  194. EndFunc
  195.  
  196. Func LinearSearchSingle($x1, $y1, $x2, $y2, $1c, $1v, $2x, $2y, $2c, $3x, $3y, $3c, $sStepx, $sStepy, $sSingle = False)
  197.     For $m = $x1 To $x2 + $sStepx Step $sStepx
  198.         For $n = $y1 To $y2 + $sStepy Step $sStepy
  199.             ;If $Mouse = 6 Then MouseMove($BSpos[0] + $m, $BSpos[1] + $n,1)
  200.             If OutofBound($m, $n) Then ExitLoop
  201.             If _ColorCheckVariation(_PixelGetColor_GetPixel($m, $n), Hex($1c, 6), $1v) _
  202.             Or _ColorCheckVariation(_PixelGetColor_GetPixel($m, $n), Hex($2c, 6), $1v) _
  203.             Or _ColorCheckVariation(_PixelGetColor_GetPixel($m, $n), Hex($3c, 6), $1v) Then
  204.                 For $o = $m - $sStepx + 1 To $m + $sStepx - 1 Step $sStepx/Abs($sStepx)
  205.                     For $p = $n - $sStepy + 1 To $n + $sStepy - 1 Step $sStepy/Abs($sStepy)
  206.                         ;If $Mouse = 6 Then MouseMove($BSpos[0] + $o, $BSpos[1] + $p,0.9)
  207.                         If _ColorCheckVariation(_PixelGetColor_GetPixel($o, $p), Hex($1c, 6), 2) Then
  208.                             If CheckColorVariPos($o + $2x, $p + $2y, $2c, 1, 3) Then
  209.                                 If CheckColorVariPos($o + $3x, $p + $3y, $3c, 1, 3) Then
  210.                                     ;MouseMove($BSpos[0] + $o, $BSpos[1] + $p)
  211.                                     ;ControlClick("BlueStacks App Player", "", "", "left", "1", $o, $p)
  212.                                     ;Sleep(500)
  213.                                     Return True
  214.                                 EndIf
  215.                             EndIf
  216.                         EndIf
  217.                     Next
  218.                 Next
  219.             EndIf
  220.         Next
  221.     Next
  222.     Return False
  223. EndFunc   ;==>LinearSearchAlgorithm
  224.  
  225. Func SpiralSearchSingleV($x, $y, $1c, $1v, $2x, $2y, $2c, $3x, $3y, $3c, $sStep, $sSingle = False) ; first pixel (x,y), second pixel (x offset, y offset, color), third pixel (x offset, y offset, color)
  226.     While 1
  227.         ;If $Mouse = 6 Then MouseMove($BSpos[0] + $x, $BSpos[1] + $y,1)
  228.         If _ColorCheckVariation(_PixelGetColor_GetPixel($x, $y), Hex($1c, 6), $1v) _
  229.         Or _ColorCheckVariation(_PixelGetColor_GetPixel($x, $y), Hex($2c, 6), $1v) _
  230.         Or _ColorCheckVariation(_PixelGetColor_GetPixel($x, $y), Hex($3c, 6), $1v) Then
  231.             For $m = $x - $sStep-3 To $x + $sStep+3
  232.                 For $n = $y - $sStep-3 To $y + $sStep+3
  233.                     ;If $Mouse = 6 Then MouseMove($BSpos[0] + $m, $BSpos[1] + $n,0.9)
  234.                     If _ColorCheckVariation(_PixelGetColor_GetPixel($m, $n), Hex($1c, 6), 1) Then
  235.                         If CheckColorVariPos($m + $2x, $n + $2y, $2c, 2, 3) Then
  236.                             If CheckColorVariPos($m + $3x, $n + $3y, $3c, 2, 3) Then Return True
  237.                         EndIf
  238.                     EndIf
  239.                 Next
  240.             Next
  241.         EndIf
  242.         If OutofBound($x, $y) Then ExitLoop
  243.         If Not $sSingle Then ;algorithm for spriral out search (fast but still not covering all pixels on screen, need work)
  244.             If $x = $a And $y <= $b Then $x += $sStep
  245.             If $x >= $a And $y < $b Then
  246.                 $x += $sStep-3
  247.                 $y += $sStep+3
  248.             ElseIf $x > $a And $y >= $b Then
  249.                 $x -= $sStep-3
  250.                 $y += $sStep+3
  251.             ElseIf $x <= $a And $y > $b Then
  252.                 $x -= $sStep-3
  253.                 $y -= $sStep+3
  254.             ElseIf $x < $a And $y <= $b Then
  255.                 $x += $sStep-3
  256.                 $y -= $sStep+3
  257.             EndIf
  258.         EndIf
  259.     WEnd
  260.     Return False
  261. EndFunc   ;==>SpiralSearchAlgorithm
  262.  
  263. Func SpiralSearchSingleH($x, $y, $1c, $1v, $2x, $2y, $2c, $3x, $3y, $3c, $sStep, $sSingle = False) ; first pixel (x,y), second pixel (x offset, y offset, color), third pixel (x offset, y offset, color)
  264.     While 1
  265.         ;MouseMove($BSpos[0] + $x, $BSpos[1] + $y,1)
  266.         If _ColorCheckVariation(_PixelGetColor_GetPixel($x, $y), Hex($1c, 6), $1v) _
  267.         Or _ColorCheckVariation(_PixelGetColor_GetPixel($x, $y), Hex($2c, 6), $1v) _
  268.         Or _ColorCheckVariation(_PixelGetColor_GetPixel($x, $y), Hex($3c, 6), $1v) Then
  269.             For $m = $x - $sStep-3 To $x + $sStep+3
  270.                 For $n = $y - $sStep-3 To $y + $sStep+3
  271.                     ;MouseMove($BSpos[0] + $m, $BSpos[1] + $n,0.9)
  272.                     If _ColorCheckVariation(_PixelGetColor_GetPixel($m, $n), Hex($1c, 6), 1) Then
  273.                         If CheckColorVariPos($m + $2x, $n + $2y, $2c, 3, 5) Then
  274.                             If CheckColorVariPos($m + $3x, $n + $3y, $3c, 3, 5) Then Return True
  275.                         EndIf
  276.                     EndIf
  277.                 Next
  278.             Next
  279.         EndIf
  280.         If OutofBound($x, $y) Then ExitLoop
  281.         If Not $sSingle Then ;algorithm for spriral out search (fast but still not covering all pixels on screen, need work)
  282.             If $x = $a And $y <= $b Then $x += $sStep
  283.             If $x >= $a And $y < $b Then
  284.                 $x += $sStep+3
  285.                 $y += $sStep-3
  286.             ElseIf $x > $a And $y >= $b Then
  287.                 $x -= $sStep+3
  288.                 $y += $sStep-3
  289.             ElseIf $x <= $a And $y > $b Then
  290.                 $x -= $sStep+3
  291.                 $y -= $sStep-3
  292.             ElseIf $x < $a And $y <= $b Then
  293.                 $x += $sStep+3
  294.                 $y -= $sStep-3
  295.             EndIf
  296.         EndIf
  297.     WEnd
  298.     Return False
  299. EndFunc   ;==>SpiralSearchAlgorithm
  300.  
  301. Func OutofBound($x, $y)
  302.     $chkArea = TriArea($x, $y, $Top, $Left) + TriArea($x, $y, $Top, $Right) + TriArea($x, $y, $Right, $Bottom) + TriArea($x, $y, $Left, $Bottom)
  303.     If $chkArea - $Area > 100 Then
  304.         Return True
  305.     Else
  306.         Return False
  307.     EndIf
  308. EndFunc   ;==>OutofBound
  309.  
  310. Func TriArea($dx, $dy, $e, $f)
  311.     $tArea = Abs(($dx * ($e[1] - $f[1]) + $e[0] * ($f[1] - $dy) + $f[0] * ($dy - $e[1])) / 2)
  312.     Return $tArea
  313. EndFunc   ;==>TriArea
  314.  
  315. Func CheckColorVariPos($x, $y, $c, $vp = 0, $vc = 10)
  316.     For $a = $x - $vp To $x + $vp
  317.         For $b = $y - $vp To $y + $vp
  318.             If _ColorCheckVariation(_PixelGetColor_GetPixel($a, $b), Hex($c, 6), $vc) Then
  319.                 Return True
  320.             EndIf
  321.         Next
  322.     Next
  323.     Return False
  324. EndFunc   ;==>CheckColorVariPos
  325. #EndRegion ##### WEAK BASE SEARCH #####
  326.  
  327. Func _CaptureRegion($iLeft = 0, $iTop = 0, $iRight = 860, $iBottom = 720, $ReturnBMP = False)
  328.     _GDIPlus_BitmapDispose($hBitmap)
  329.     _WinAPI_DeleteObject($hHBitmap)
  330.     Local $iW = Number($iRight) - Number($iLeft), $iH = Number($iBottom) - Number($iTop)
  331.     Local $hDC_Capture = _WinAPI_GetWindowDC(ControlGetHandle("BlueStacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]"))
  332.     Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
  333.     $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $iW, $iH)
  334.     Local $hObjectOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
  335.     DllCall($user32, "int", "PrintWindow", "hwnd", $HWnD, "handle", $hMemDC, "int", 0)
  336.     _WinAPI_SelectObject($hMemDC, $hHBitmap)
  337.     _WinAPI_BitBlt($hMemDC, 0, 0, $iW, $iH, $hDC_Capture, $iLeft, $iTop, 0x00CC0020)
  338.     $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
  339.     _WinAPI_DeleteDC($hMemDC)
  340.     _WinAPI_SelectObject($hMemDC, $hObjectOld)
  341.     _WinAPI_ReleaseDC($HWnD, $hDC_Capture)
  342. EndFunc   ;==>_CaptureRegion
  343.  
  344. Func _PixelGetColor_GetPixel($iX, $iY)
  345.     Local $aPixelColor = _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
  346.     Return Hex($aPixelColor, 6)
  347. EndFunc   ;==>_PixelGetColor_GetPixel
  348. Func _PixelSearch($iLeft, $iTop, $iRight, $iBottom, $iColor, $ColorVariation)
  349.     _CaptureRegion($iLeft, $iTop, $iRight, $iBottom)
  350.     For $x = $iRight - $iLeft To 0 Step -1
  351.         For $y = $iBottom - $iTop To 0 Step -1
  352.             Local $nColor1 = $iColor
  353.             Local $nColor2 = _PixelGetColor_GetPixel($x, $y)
  354.             If _ColorCheckVariation($nColor1, $nColor2, $ColorVariation) Then
  355.                 Local $Pos[2] = [$iLeft + $x, $iTop + $y]
  356.                 Return $Pos
  357.             EndIf
  358.         Next
  359.     Next
  360.     Return 0
  361. EndFunc   ;==>_PixelSearch
  362.  
  363. Func _ColorCheckVariation($nColor1, $nColor2, $sVari = 5)
  364.     Local $Red1, $Red2, $Blue1, $Blue2, $Green1, $Green2
  365.     $Red1 = Dec(StringMid(String($nColor1), 1, 2))
  366.     $Blue1 = Dec(StringMid(String($nColor1), 3, 2))
  367.     $Green1 = Dec(StringMid(String($nColor1), 5, 2))
  368.     $Red2 = Dec(StringMid(String($nColor2), 1, 2))
  369.     $Blue2 = Dec(StringMid(String($nColor2), 3, 2))
  370.     $Green2 = Dec(StringMid(String($nColor2), 5, 2))
  371.     If Abs($Blue1 - $Blue2) > $sVari Then Return False
  372.     If Abs($Green1 - $Green2) > $sVari Then Return False
  373.     If Abs($Red1 - $Red2) > $sVari Then Return False
  374.     Return True
  375. EndFunc   ;==>_ColorCheckVariation
  376.  
  377. Func getBSPos()
  378.     $aPos = ControlGetPos("BlueStacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]")
  379.     $tPoint = DllStructCreate("int X;int Y")
  380.     DllStructSetData($tPoint, "X", $aPos[0])
  381.     DllStructSetData($tPoint, "Y", $aPos[1])
  382.     _WinAPI_ClientToScreen(WinGetHandle(WinGetTitle("BlueStacks App Player")), $tPoint)
  383.     $BSpos[0] = DllStructGetData($tPoint, "X")
  384.     $BSpos[1] = DllStructGetData($tPoint, "Y")
  385.     $CtrlHandle = ControlGetHandle("BlueStacks App Player", "", "BlueStacksApp1")
  386. EndFunc   ;==>getBSPos
  387.  
  388. #Region ##### CHILD PROCESS #####
  389. Func _ChildProc_Start($sFunction = Default, $vParameter = Default, $max_children = 0)
  390.     Local $iPid
  391.     If IsKeyword($sFunction) Or $sFunction = "" Then $sFunction = "__ChildProcDummy"
  392.     EnvSet("ChildProc", "0x" & Hex(StringToBinary($sFunction)))
  393.     EnvSet("ChildProcParent", @AutoItPID)
  394.     If Not IsKeyword($vParameter) Then
  395.         EnvSet("ChildProcParameterPresent", "True")
  396.         EnvSet("ChildProcParameter", StringToBinary($vParameter))
  397.     Else
  398.         EnvSet("ChildProcParameterPresent", "False")
  399.     EndIf
  400.     If $max_children > 0 And $_ChildProc_num_children >= $max_children Then
  401.         While _ChildProc_GetChildCount() >= $max_children
  402.             Sleep(250)
  403.         WEnd
  404.     EndIf
  405.     If @Compiled Then
  406.         $iPid = Run(FileGetShortName(@AutoItExe), @WorkingDir, @SW_HIDE, 1 + 2 + 4)
  407.     Else
  408.         $iPid = Run(FileGetShortName(@AutoItExe) & ' "' & @ScriptFullPath & '"', @WorkingDir, @SW_HIDE, 1 + 2 + 4)
  409.     EndIf
  410.     If @error Then SetError(1)
  411.     If $_ChildProc_pid[0] = "" Then
  412.         $_ChildProc_pid[0] = $iPid
  413.     Else
  414.         _ArrayAdd($_ChildProc_pid, $iPid)
  415.     EndIf
  416.     $_ChildProc_num_children = $_ChildProc_num_children + 1
  417.     Return $iPid
  418. EndFunc   ;==>_ChildProc_Start
  419. Func _ChildProc_WriteToFile($name, $text = Default, $pid = @AutoItPID)
  420.     $file_fullpath = @TempDir & "\_ChildProc_" & $pid & "_" & $name & ".txt"
  421.     If $text = "" Or $text = Default Then
  422.         FileDelete($file_fullpath)
  423.         Return True
  424.     EndIf
  425.     FileDelete($file_fullpath)
  426.     FileWrite($file_fullpath, $text)
  427.     Return True
  428. EndFunc   ;==>_ChildProc_WriteToFile
  429. Func _ChildProc_WriteToEnvVar($sName, $vValue = Default)
  430.     Local $vTmp
  431.     $sName = "_CP_" & $sName
  432.     If $vValue = "" Or $vValue = Default Then
  433.         EnvSet($sName)
  434.         Return True
  435.     EndIf
  436.     EnvSet($sName, $vValue)
  437.     Return True
  438. EndFunc   ;==>_ChildProc_WriteToEnvVar
  439. Func _ChildProc_ReadFromEnvVar($sName, $fOption = 1)
  440.     $sName = "_CP_" & $sName
  441.     If $fOption = "" Or $fOption = Default Then $fOption = False
  442.     $value = EnvGet($sName)
  443.     If $fOption Then
  444.         EnvSet($sName)
  445.     EndIf
  446.     Return $value
  447. EndFunc   ;==>_ChildProc_ReadFromEnvVar
  448. Func _ChildProc_ReadFromFile($pid, $name, $fOption = 1)
  449.     $file_fullpath = @TempDir & "\_ChildProc_" & $pid & "_" & $name & ".txt"
  450.     If $fOption = "" Or $fOption = Default Then $fOption = False
  451.     $text = FileRead($file_fullpath)
  452.     If $fOption Then
  453.         FileDelete($file_fullpath)
  454.     EndIf
  455.     Return $text
  456. EndFunc   ;==>_ChildProc_ReadFromFile
  457. Func _ChildProc_ReadFromAllFiles()
  458.     $text = ""
  459.     For $pid In $_ChildProc_pid
  460.         $text = $text & _ChildProc_ReadFromFile($pid, "")
  461.     Next
  462.     Return $text
  463. EndFunc   ;==>_ChildProc_ReadFromAllFiles
  464. Func _ChildProc_GetChildCount()
  465.     $num_children = 0
  466.     For $pid_num = 0 To (UBound($_ChildProc_pid) - 1)
  467.         If ProcessExists($_ChildProc_pid[$pid_num]) = True Then $num_children = $num_children + 1
  468.     Next
  469.     Return $num_children
  470. EndFunc   ;==>_ChildProc_GetChildCount
  471. Func __ChildProcDummy($vPar = Default)
  472.     If Not IsKeyword($vPar) Then _ChildProcReciver($vPar)
  473.     While ProcessExists($gi_ChildProcParent)
  474.         Sleep(500)
  475.     WEnd
  476. EndFunc   ;==>__ChildProcDummy
  477. Func __ChildProcStartup()
  478.     Local $sCmd = EnvGet("ChildProc")
  479.     If StringLeft($sCmd, 2) = "0x" Then
  480.         $sCmd = BinaryToString($sCmd)
  481.         $gi_ChildProcParent = Number(EnvGet("ChildProcParent"))
  482.         If StringInStr($sCmd, "(") And StringInStr($sCmd, ")") Then
  483.             Execute($sCmd)
  484.             If @error And Not @Compiled Then MsgBox(16, "ChildProc Error", "Unable to Execute: " & $sCmd)
  485.             Exit
  486.         EndIf
  487.         If EnvGet("ChildProcParameterPresent") = "True" Then
  488.             Call($sCmd, BinaryToString(EnvGet("ChildProcParameter")))
  489.             If @error And Not @Compiled Then MsgBox(16, "ChildProc Error", "Unable to Call: " & $sCmd & @LF & "Parameter: " & BinaryToString(EnvGet("ChildProcParameter")))
  490.         Else
  491.             Call($sCmd)
  492.             If @error And Not @Compiled Then MsgBox(16, "ChildProc Error", "Unable to Call: " & $sCmd)
  493.         EndIf
  494.         Exit
  495.     EndIf
  496. EndFunc   ;==>__ChildProcStartup
  497. #EndRegion ##### CHILD PROCESS #####
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement