GkevinOD

GetResources Function 3.0

Dec 21st, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 20.45 KB | None | 0 0
  1.     ; GetResources Function which finds the pixel pattern of the resources and translates it into text.
  2.     ; Copyright (C) 2014 Kevin Quito
  3.  
  4.     ; This function is free function: you can redistribute it and/or modify
  5.     ; it under the terms of the GNU General Public License as published by
  6.     ; the Free Software Foundation, either version 3 of the License, or
  7.     ; (at your option) any later version.
  8.  
  9.     ; This function is distributed in the hope that it will be useful,
  10.     ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     ; GNU General Public License for more details.
  13.  
  14.     ; You should have received a copy of the GNU General Public License
  15.     ; along with this function.  If not, see <http://www.gnu.org/licenses/>.
  16.  
  17. #include <ScreenCapture.au3>
  18.  
  19. $HWnD = WinGetHandle (WinGetTitle ("BlueStacks App Player"))
  20. $BlueStacks_XY = WinGetPos($HWnD, "")
  21.  
  22. $x_default = $BlueStacks_XY [0] + 53
  23. $y_default = $BlueStacks_XY [1] + 94
  24.  
  25. $tStart = TimerInit()
  26. If getGold($x_default, $y_default) <> "" Then
  27.   $tStop = TimerDiff($tStart)
  28.   MsgBox(0, "Resource Count", "Gold: " & getGold($x_default, $y_default) & @CR & "Elixir: " & getElixir($x_default, $y_default + 29) & @CR & "Dark Elixir: " & getDarkElixir($x_default, $y_default + 57) & @CR & "Trophy: " & getTrophy($x_default, $y_default + 90) & @CR & "First Pixel: 53, 94" & @CR & "Time: " & Round($tStop,3) & " milliseconds")
  29. ElseIf getGold($x_default, $y_default+1) <> "" Then
  30.   $tStop = TimerDiff($tStart)
  31.   MsgBox(0, "Resource Count", "Gold: " & getGold($x_default, $y_default+1) & @CR & "Elixir: " & getElixir($x_default, $y_default + 30) & @CR & "Trophy: " & getTrophy($x_default, $y_default + 61) & @CR & "First Pixel: 53, 95" & @CR & "Time: " & Round($tStop,3) & " milliseconds")
  32. ElseIf getGold($x_default, $y_default-1) <> "" Then
  33.   $tStop = TimerDiff($tStart)
  34.   MsgBox(0, "Resource Count", "Gold: " & getGold($x_default, $y_default-1) & @CR & "Elixir: " & getElixir($x_default, $y_default + 28) & @CR & "Trophy: " & getTrophy($x_default, $y_default + 59) & @CR & "First Pixel: 53, 93" & @CR & "Time: " & Round($tStop,3) & " milliseconds")
  35. EndIf
  36.  
  37. ;==============================================================================================================
  38. ;===Main Function==============================================================================================
  39. ;--------------------------------------------------------------------------------------------------------------
  40. ;Checks if the color components exceed $sVari and returns true if they are below $sVari.
  41. ;--------------------------------------------------------------------------------------------------------------
  42.  
  43. Func getGold($x_start, $y_start)
  44.     Global $hDll = DllOpen("gdi32.dll")
  45.     Global $vDC = _PixelGetColor_CreateDC($hDll)
  46.     _PixelGetColor_CaptureRegion($vDC, 0, 0, $x_start + 90, $y_start + 20)
  47.     ;-----------------------------------------------------------------------------
  48.     Local $x = $x_start, $y = $y_start
  49.     Local $Gold
  50.  
  51.     $Gold &= getDigit($x, $y, "Gold")
  52.     $Gold &= getDigit($x, $y, "Gold")
  53.     $Gold &= getDigit($x, $y, "Gold")
  54.     $x += 6
  55.     $Gold &= getDigit($x, $y, "Gold")
  56.     $Gold &= getDigit($x, $y, "Gold")
  57.     $Gold &= getDigit($x, $y, "Gold")
  58.     Return $Gold
  59. EndFunc
  60.  
  61. Func getElixir($x_start, $y_start)
  62.     Global $hDll = DllOpen("gdi32.dll")
  63.     Global $vDC = _PixelGetColor_CreateDC($hDll)
  64.     _PixelGetColor_CaptureRegion($vDC, 0, 0, $x_start + 90, $y_start + 20)
  65.     ;-----------------------------------------------------------------------------
  66.     Local $x = $x_start, $y = $y_start
  67.     Local $Elixir
  68.  
  69.     $Elixir &= getDigit($x, $y, "Elixir")
  70.     $Elixir &= getDigit($x, $y, "Elixir")
  71.     $Elixir &= getDigit($x, $y, "Elixir")
  72.     $x += 6
  73.     $Elixir &= getDigit($x, $y, "Elixir")
  74.     $Elixir &= getDigit($x, $y, "Elixir")
  75.     $Elixir &= getDigit($x, $y, "Elixir")
  76.     Return $Elixir
  77. EndFunc
  78.  
  79. Func getDarkElixir($x_start, $y_start)
  80.     Global $hDll = DllOpen("gdi32.dll")
  81.     Global $vDC = _PixelGetColor_CreateDC($hDll)
  82.     _PixelGetColor_CaptureRegion($vDC, 0, 0, $x_start + 90, $y_start + 20)
  83.     ;-----------------------------------------------------------------------------
  84.     Local $x = $x_start, $y = $y_start
  85.     Local $DarkElixir
  86.  
  87.     $DarkElixir &= getDigit($x, $y, "DarkElixir")
  88.     $DarkElixir &= getDigit($x, $y, "DarkElixir")
  89.     $DarkElixir &= getDigit($x, $y, "DarkElixir")
  90.     $x += 6
  91.     $DarkElixir &= getDigit($x, $y, "DarkElixir")
  92.     $DarkElixir &= getDigit($x, $y, "DarkElixir")
  93.     $DarkElixir &= getDigit($x, $y, "DarkElixir")
  94.     Return $DarkElixir
  95. EndFunc
  96.  
  97. Func getTrophy($x_start, $y_start)
  98.     Global $hDll = DllOpen("gdi32.dll")
  99.     Global $vDC = _PixelGetColor_CreateDC($hDll)
  100.     _PixelGetColor_CaptureRegion($vDC, 0, 0, $x_start + 90, $y_start + 20)
  101.     ;-----------------------------------------------------------------------------
  102.     Local $x = $x_start, $y = $y_start
  103.     Local $Trophy
  104.  
  105.     $Trophy &= getDigit($x, $y, "Trophy")
  106.     $Trophy &= getDigit($x, $y, "Trophy")
  107.     Return $Trophy
  108. EndFunc
  109.  
  110. ;==============================================================================================================
  111. ;==============================================================================================================
  112. ;===Color Variation============================================================================================
  113. ;--------------------------------------------------------------------------------------------------------------
  114. ;Checks if the color components exceed $sVari and returns true if they are below $sVari.
  115. ;--------------------------------------------------------------------------------------------------------------
  116.  
  117. Func _ColorCheckVariation($nColor1, $nColor2, $sVari=5)
  118.     $Red1 = Dec(StringMid(String($nColor1), 1, 2))
  119.     $Blue1 = Dec(StringMid(String($nColor1), 3, 2))
  120.     $Green1 = Dec(StringMid(String($nColor1), 5, 2))
  121.  
  122.     $Red2 = Dec(StringMid(String($nColor2), 1, 2))
  123.     $Blue2 = Dec(StringMid(String($nColor2), 3, 2))
  124.     $Green2 = Dec(StringMid(String($nColor2), 5, 2))
  125.  
  126.     If abs($Blue1 - $Blue2) > $sVari Then Return False
  127.     If abs($Green1 - $Green2) > $sVari Then Return False
  128.     If abs($Red1 - $Red2) > $sVari Then Return False
  129.     Return True
  130. EndFunc
  131.  
  132. ;==============================================================================================================
  133. ;===Check Pixels============================================================================================
  134. ;--------------------------------------------------------------------------------------------------------------
  135. ;Using _ColorCheckVariation, checks compares multiple pixels and returns true if they all pass _ColorCheckVariation.
  136. ;--------------------------------------------------------------------------------------------------------------
  137.  
  138. Func boolPixelSearch($pixel1, $pixel2, $pixel3)
  139.     Local $Color1 = _PixelGetColor_GetPixel($vDC, $pixel1[0], $pixel1[1])
  140.     Local $Color2 = _PixelGetColor_GetPixel($vDC, $pixel2[0], $pixel2[1])
  141.     Local $Color3 = _PixelGetColor_GetPixel($vDC, $pixel3[0], $pixel3[1])
  142.     If _ColorCheckVariation($Color1, $pixel1[2], 10) And _ColorCheckVariation($Color2, $pixel2[2], 10) And _ColorCheckVariation($Color3, $pixel3[2], 10) Then Return True
  143.     Return False
  144. EndFunc
  145.  
  146. ;==============================================================================================================
  147. ;===Get Digit Gold=============================================================================================
  148. ;--------------------------------------------------------------------------------------------------------------
  149. ;Finds pixel color pattern of specific X and Y values, returns digit if pixel color pattern found.
  150. ;--------------------------------------------------------------------------------------------------------------
  151.  
  152. Func getDigit(ByRef $x, $y, $type)
  153.     Local $width = 0
  154.  
  155.     ;Search for digit 0
  156.     $width = 13
  157.     Select
  158.         Case $type = "Gold"
  159.             Local $c1 = Hex(0x989579, 6),   $c2 = Hex(0x39382E, 6), $c3 = Hex(0x272720, 6)
  160.         Case $type = "Elixir"
  161.             Local $c1 = Hex(0x978A96, 6),   $c2 = Hex(0x393439, 6), $c3 = Hex(0x272427, 6)
  162.         Case $type = "DarkElixir"
  163.             Local $c1 = Hex(0x909090, 6),   $c2 = Hex(0x363636, 6), $c3 = Hex(0x262626, 6)
  164.         Case $type = "Trophy"
  165.             Local $c1 = Hex(0x979797, 6),   $c2 = Hex(0x393939, 6), $c3 = Hex(0x272727, 6)
  166.     EndSelect
  167.     Local $pixel1[3] = [$x+6, $y+4, $c1], $pixel2[3] = [$x+7, $y+7, $c2], $pixel3[3] = [$x+10, $y+13, $c3]
  168.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  169.       $x += $width ;Adds to x coordinate to get the next digit
  170.       Return 0
  171.     Else
  172.       $x -= 1 ;Solves the problem when the spaces between the middle goes from 6 to 5 pixels
  173.       Local $pixel1[3] = [$x+6, $y+4, $c1], $pixel2[3] = [$x+7, $y+7, $c2], $pixel3[3] = [$x+10, $y+13, $c3]
  174.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  175.          $x += $width ;Changes x coordinate for the next digit.
  176.          Return 0
  177.       Else
  178.          $x += 2 ;Solves the problem when there is 1 pixel space between a set of numbers
  179.          Local $pixel1[3] = [$x+6, $y+4, $c1], $pixel2[3] = [$x+7, $y+7, $c2], $pixel3[3] = [$x+10, $y+13, $c3]
  180.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  181.             $x += $width
  182.             Return 0
  183.          Else
  184.             $x -= 1
  185.          EndIf
  186.       EndIf
  187.     EndIf
  188.  
  189.     ;Search for digit 1
  190.     $width = 6
  191.     Select
  192.         Case $type = "Gold"
  193.             Local $c1 = Hex(0x979478, 6),   $c2 = Hex(0x313127, 6), $c3 = Hex(0xD7D4AC, 6)
  194.         Case $type = "Elixir"
  195.             Local $c1 = Hex(0x968895, 6),   $c2 = Hex(0x312D31, 6), $c3 = Hex(0xD8C4D6, 6)
  196.         Case $type = "DarkElixir"
  197.             Local $c1 = Hex(0x8F8F8F, 6),   $c2 = Hex(0x2F2F2F, 6), $c3 = Hex(0xCDCDCD, 6)
  198.         Case $type = "Trophy"
  199.             Local $c1 = Hex(0x969696, 6),   $c2 = Hex(0x313131, 6), $c3 = Hex(0xD8D8D8, 6)
  200.     EndSelect
  201.     Local $pixel1[3] = [$x+1, $y+1, $c1], $pixel2[3] = [$x+1, $y+12, $c2], $pixel3[3] = [$x+4, $y+12, $c3]
  202.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  203.       $x += $width
  204.       Return 1
  205.     Else
  206.       $x -= 1
  207.       Local $pixel1[3] = [$x+1, $y+1, $c1], $pixel2[3] = [$x+1, $y+12, $c2], $pixel3[3] = [$x+4, $y+12, $c3]
  208.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  209.          $x += $width
  210.          Return 1
  211.       Else
  212.          $x += 2
  213.          Local $pixel1[3] = [$x+1, $y+1, $c1], $pixel2[3] = [$x+1, $y+12, $c2], $pixel3[3] = [$x+4, $y+12, $c3]
  214.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  215.             $x += $width
  216.             Return 1
  217.          Else
  218.             $x -= 1
  219.          EndIf
  220.       EndIf
  221.     EndIf
  222.  
  223.     ;Search for digit 2
  224.     $width = 10
  225.     Select
  226.         Case $type = "Gold"
  227.             Local $c1 = Hex(0xA09E80, 6),   $c2 = Hex(0xD8D4AC, 6), $c3 = Hex(0x979579, 6)
  228.         Case $type = "Elixir"
  229.             Local $c1 = Hex(0xA0919F, 6),   $c2 = Hex(0xD8C4D6, 6), $c3 = Hex(0x978A96, 6)
  230.         Case $type = "DarkElixir"
  231.             Local $c1 = Hex(0x989898, 6),   $c2 = Hex(0xCDCDCD, 6), $c3 = Hex(0x909090, 6)
  232.         Case $type = "Trophy"
  233.             Local $c1 = Hex(0xA0A0A0, 6),   $c2 = Hex(0xD8D8D8, 6), $c3 = Hex(0x979797, 6)
  234.     EndSelect
  235.     Local $pixel1[3] = [$x+1, $y+7, $c1], $pixel2[3] = [$x+3, $y+6, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  236.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  237.       $x += $width
  238.       Return 2
  239.     Else
  240.       $x -= 1
  241.       Local $pixel1[3] = [$x+1, $y+7, $c1], $pixel2[3] = [$x+3, $y+6, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  242.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  243.          $x += $width
  244.          Return 2
  245.       Else
  246.          $x += 2
  247.          Local $pixel1[3] = [$x+1, $y+7, $c1], $pixel2[3] = [$x+3, $y+6, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  248.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  249.             $x += $width
  250.             Return 2
  251.          Else
  252.             $x -= 1
  253.          EndIf
  254.       EndIf
  255.     EndIf
  256.  
  257.     ;Search for digit 3
  258.     $width = 10
  259.     Select
  260.         Case $type = "Gold"
  261.             Local $c1 = Hex(0x7F7D65, 6),   $c2 = Hex(0x070706, 6), $c3 = Hex(0x37362C, 6)
  262.         Case $type = "Elixir"
  263.             Local $c1 = Hex(0x7F737E, 6),   $c2 = Hex(0x070607, 6), $c3 = Hex(0x373236, 6)
  264.         Case $type = "DarkElixir"
  265.             Local $c1 = Hex(0x797979, 6),   $c2 = Hex(0x070707, 6), $c3 = Hex(0x343434, 6)
  266.         Case $type = "Trophy"
  267.             Local $c1 = Hex(0x7F7F7F, 6),   $c2 = Hex(0x070707, 6), $c3 = Hex(0x373737, 6)
  268.     EndSelect
  269.     Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+4, $y+8, $c2], $pixel3[3] = [$x+5, $y+13, $c3]
  270.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  271.       $x += $width
  272.       Return 3
  273.     Else
  274.       $x -= 1
  275.       Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+4, $y+8, $c2], $pixel3[3] = [$x+5, $y+13, $c3]
  276.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  277.          $x += $width
  278.          Return 3
  279.       Else
  280.          $x += 2
  281.          Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+4, $y+8, $c2], $pixel3[3] = [$x+5, $y+13, $c3]
  282.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  283.             $x += $width
  284.             Return 3
  285.          Else
  286.                $x -= 1
  287.          EndIf
  288.       EndIf
  289.     EndIf
  290.  
  291.     ;Search for digit 4
  292.     $width = 12
  293.     Select
  294.         Case $type = "Gold"
  295.             Local $c1 = Hex(0x282720, 6),   $c2 = Hex(0x080806, 6), $c3 = Hex(0x403F33, 6)
  296.         Case $type = "Elixir"
  297.             Local $c1 = Hex(0x282428, 6),   $c2 = Hex(0x080708, 6), $c3 = Hex(0x403A40, 6)
  298.         Case $type = "DarkElixir"
  299.             Local $c1 = Hex(0x262626, 6),   $c2 = Hex(0x070707, 6), $c3 = Hex(0x3D3D3D, 6)
  300.         Case $type = "Trophy"
  301.             Local $c1 = Hex(0x282828, 6),   $c2 = Hex(0x080808, 6), $c3 = Hex(0x404040, 6)
  302.     EndSelect
  303.     Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+3, $y+1, $c2], $pixel3[3] = [$x+1, $y+5, $c3]
  304.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  305.       $x += $width
  306.       Return 4
  307.     Else
  308.       $x -= 1
  309.       Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+3, $y+1, $c2], $pixel3[3] = [$x+1, $y+5, $c3]
  310.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  311.          $x += $width
  312.          Return 4
  313.       Else
  314.          $x += 2
  315.          Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+3, $y+1, $c2], $pixel3[3] = [$x+1, $y+5, $c3]
  316.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  317.             $x += $width
  318.             Return 4
  319.          Else
  320.             $x -= 1
  321.          EndIf
  322.       EndIf
  323.     EndIf
  324.  
  325.     ;Search for digit 5
  326.     $width = 10
  327.     Select
  328.         Case $type = "Gold"
  329.             Local $c1 = Hex(0x060604, 6),   $c2 = Hex(0x040403, 6), $c3 = Hex(0xB7B492, 6)
  330.         Case $type = "Elixir"
  331.             Local $c1 = Hex(0x060606, 6),   $c2 = Hex(0x040404, 6), $c3 = Hex(0xB7A7B6, 6)
  332.         Case $type = "DarkElixir"
  333.             Local $c1 = Hex(0x060606, 6),   $c2 = Hex(0x040404, 6), $c3 = Hex(0xAFAFAF, 6)
  334.         Case $type = "Trophy"
  335.             Local $c1 = Hex(0x060606, 6),   $c2 = Hex(0x040404, 6), $c3 = Hex(0xB7B7B7, 6)
  336.     EndSelect
  337.     Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+4, $y+9, $c2], $pixel3[3] = [$x+6, $y+12, $c3]
  338.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  339.       $x += $width
  340.       Return 5
  341.     Else
  342.       $x -= 1
  343.       Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+4, $y+9, $c2], $pixel3[3] = [$x+6, $y+12, $c3]
  344.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  345.          $x += $width
  346.          Return 5
  347.       Else
  348.          $x += 2
  349.          Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+4, $y+9, $c2], $pixel3[3] = [$x+6, $y+12, $c3]
  350.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  351.             $x += $width
  352.             Return 5
  353.          Else
  354.             $x -= 1
  355.          EndIf
  356.       EndIf
  357.     EndIf
  358.  
  359.     ;Search for digit 6
  360.     $width = 11
  361.     Select
  362.         Case $type = "Gold"
  363.             Local $c1 = Hex(0x070605, 6),   $c2 = Hex(0x040403, 6), $c3 = Hex(0x181713, 6)
  364.         Case $type = "Elixir"
  365.             Local $c1 = Hex(0x070707, 6),   $c2 = Hex(0x040404, 6), $c3 = Hex(0x181618, 6)
  366.         Case $type = "DarkElixir"
  367.             Local $c1 = Hex(0x060606, 6),   $c2 = Hex(0x030303, 6), $c3 = Hex(0x161616, 6)
  368.         Case $type = "Trophy"
  369.             Local $c1 = Hex(0x070707, 6),   $c2 = Hex(0x040404, 6), $c3 = Hex(0x181818, 6)
  370.     EndSelect
  371.     Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+5, $c3]
  372.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  373.       $x += $width
  374.       Return 6
  375.     Else
  376.       $x -= 1
  377.       Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+5, $c3]
  378.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  379.          $x += $width
  380.          Return 6
  381.       Else
  382.          $x += 2
  383.          Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+5, $c3]
  384.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  385.             $x += $width
  386.             Return 6
  387.          Else
  388.             $x -= 1
  389.          EndIf
  390.       EndIf
  391.     EndIf
  392.  
  393.     ;Search for digit 7
  394.     $width = 10
  395.     Select
  396.         Case $type = "Gold"
  397.             Local $c1 = Hex(0x5E5C4B, 6),   $c2 = Hex(0x87856C, 6), $c3 = Hex(0x5D5C4B, 6)
  398.         Case $type = "Elixir"
  399.             Local $c1 = Hex(0x5F565E, 6),   $c2 = Hex(0x877B86, 6), $c3 = Hex(0x5F565E, 6)
  400.         Case $type = "DarkElixir"
  401.             Local $c1 = Hex(0x5A5A5A, 6),   $c2 = Hex(0x818181, 6), $c3 = Hex(0x5A5A5A, 6)
  402.         Case $type = "Trophy"
  403.             Local $c1 = Hex(0x5F5F5F, 6),   $c2 = Hex(0x878787, 6), $c3 = Hex(0x5F5F5F, 6)
  404.     EndSelect
  405.     Local $pixel1[3] = [$x+5, $y+11, $c1], $pixel2[3] = [$x+4, $y+3, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  406.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  407.       $x += $width
  408.       Return 7
  409.     Else
  410.       $x -= 1
  411.       Local $pixel1[3] = [$x+5, $y+11, $c1], $pixel2[3] = [$x+4, $y+3, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  412.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  413.          $x += $width
  414.          Return 7
  415.       Else
  416.          $x += 2
  417.          Local $pixel1[3] = [$x+5, $y+11, $c1], $pixel2[3] = [$x+4, $y+3, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  418.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  419.             $x += $width
  420.             Return 7
  421.          Else
  422.             $x -= 1
  423.          EndIf
  424.       EndIf
  425.     EndIf
  426.  
  427.     ;Search for digit 8
  428.     $width = 11
  429.     Select
  430.         Case $type = "Gold"
  431.             Local $c1 = Hex(0x27261F, 6),   $c2 = Hex(0x302F26, 6), $c3 = Hex(0x26261F, 6)
  432.         Case $type = "Elixir"
  433.             Local $c1 = Hex(0x272427, 6),   $c2 = Hex(0x302B2F, 6), $c3 = Hex(0x26261F, 6)
  434.         Case $type = "DarkElixir"
  435.             Local $c1 = Hex(0x252525, 6),   $c2 = Hex(0x2D2D2D, 6), $c3 = Hex(0x242424, 6)
  436.         Case $type = "Trophy"
  437.             Local $c1 = Hex(0x272727, 6),   $c2 = Hex(0x303030, 6), $c3 = Hex(0x262626, 6)
  438.     EndSelect
  439.     Local $pixel1[3] = [$x+5, $y+3, $c1], $pixel2[3] = [$x+5, $y+10, $c2], $pixel3[3] = [$x+1, $y+6, $c3]
  440.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  441.       $x += $width
  442.       Return 8
  443.     Else
  444.       $x -= 1
  445.       Local $pixel1[3] = [$x+5, $y+3, $c1], $pixel2[3] = [$x+5, $y+10, $c2], $pixel3[3] = [$x+1, $y+6, $c3]
  446.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  447.          $x += $width
  448.          Return 8
  449.       Else
  450.          $x += 2
  451.          Local $pixel1[3] = [$x+5, $y+3, $c1], $pixel2[3] = [$x+5, $y+10, $c2], $pixel3[3] = [$x+1, $y+6, $c3]
  452.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  453.             $x += $width
  454.             Return 8
  455.          Else
  456.             $x -= 1
  457.          EndIf
  458.       EndIf
  459.     EndIf
  460.  
  461.     ;Search for digit 9
  462.     $width = 11
  463.     Select
  464.         Case $type = "Gold"
  465.             Local $c1 = Hex(0x302F26, 6),   $c2 = Hex(0x050504, 6), $c3 = Hex(0x272720, 6)
  466.         Case $type = "Elixir"
  467.             Local $c1 = Hex(0x302C30, 6),   $c2 = Hex(0x050505, 6), $c3 = Hex(0x282427, 6)
  468.         Case $type = "DarkElixir"
  469.             Local $c1 = Hex(0x2E2E2E, 6),   $c2 = Hex(0x050505, 6), $c3 = Hex(0x262626, 6)
  470.         Case $type = "Trophy"
  471.             Local $c1 = Hex(0x303030, 6),   $c2 = Hex(0x050505, 6), $c3 = Hex(0x272727, 6)
  472.     EndSelect
  473.     Local $pixel1[3] = [$x+5, $y+5, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+12, $c3]
  474.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  475.       $x += $width
  476.       Return 9
  477.     Else
  478.       $x -= 1
  479.       Local $pixel1[3] = [$x+5, $y+5, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+12, $c3]
  480.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  481.          $x += $width
  482.          Return 9
  483.       Else
  484.          $x += 2
  485.          Local $pixel1[3] = [$x+5, $y+5, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+12, $c3]
  486.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  487.             $x += $width
  488.             Return 9
  489.          Else
  490.             $x -= 1
  491.          EndIf
  492.       EndIf
  493.     EndIf
  494.     Return ""
  495. EndFunc
  496.  
  497. ;==============================================================================================================
  498. ;===Other Functions============================================================================================
  499. ;==============================================================================================================
  500.  
  501. Func _PixelGetColor_CreateDC($hDll = "gdi32.dll")
  502.     $iPixelGetColor_MemoryContext = DllCall($hDll, "int", "CreateCompatibleDC", "int", 0)
  503.     If @error Then Return SetError(@error,0,0)
  504.     Return $iPixelGetColor_MemoryContext[0]
  505. EndFunc
  506.  
  507. Func _PixelGetColor_CaptureRegion($iPixelGetColor_MemoryContext, $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = False, $hDll = "gdi32.dll")
  508.     $HBITMAP = _ScreenCapture_Capture("", $iLeft, $iTop, $iRight, $iBottom, $fCursor)
  509.     DllCall($hDll, "hwnd", "SelectObject", "int", $iPixelGetColor_MemoryContext, "hwnd", $HBITMAP)
  510.     Return $HBITMAP
  511. EndFunc
  512.  
  513. Func _PixelGetColor_GetPixel($iPixelGetColor_MemoryContext,$iX,$iY, $hDll = "gdi32.dll")
  514.     $iColor = DllCall($hDll,"int","GetPixel","int",$iPixelGetColor_MemoryContext,"int",$iX,"int",$iY)
  515.     If $iColor[0] = -1 then Return SetError(1,0,-1)
  516.     $sColor = Hex($iColor[0],6)
  517.     Return StringRight($sColor,2) & StringMid($sColor,3,2) & StringLeft($sColor,2)
  518. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment