Advertisement
GkevinOD

GetGold Function 2.0

Dec 21st, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 13.62 KB | None | 0 0
  1. #include <Color.au3>
  2. #include <Math.au3>
  3. #include <ScreenCapture.au3>
  4.  
  5. $HWnD = WinGetHandle (WinGetTitle ("BlueStacks App Player"))
  6. $BlueStacks_XY = WinGetPos($HWnD, "")
  7.  
  8. $x_default = $BlueStacks_XY [0] + 53
  9. $y_default = $BlueStacks_XY [1] + 94
  10.  
  11. MsgBox(0, "Gold Count", "Gold: " & getGold($x_default, $y_default))
  12.  
  13. ;==============================================================================================================
  14. ;===Main Function==============================================================================================
  15. ;--------------------------------------------------------------------------------------------------------------
  16. ;Checks if the color components exceed $sVari and returns true if they are below $sVari.
  17. ;--------------------------------------------------------------------------------------------------------------
  18.  
  19. Func getGold($x_start, $y_start)
  20.     Global $hDll = DllOpen("gdi32.dll")
  21.     Global $vDC = _PixelGetColor_CreateDC($hDll)
  22.     _PixelGetColor_CaptureRegion($vDC, 0, 0, $x_start + 90, $y_start + 20)
  23.     ;-----------------------------------------------------------------------------
  24.     Local $x = $x_start, $y = $y_start
  25.     Local $Gold
  26.    
  27.     $Gold &= getGoldDigit($x, $y)
  28.     $Gold &= getGoldDigit($x, $y)
  29.     $Gold &= getGoldDigit($x, $y)
  30.     $x += 6                         ;Space between the set of numbers : "123 321"
  31.     $Gold &= getGoldDigit($x, $y)
  32.     $Gold &= getGoldDigit($x, $y)
  33.     $Gold &= getGoldDigit($x, $y)
  34.    
  35.     If $Gold = "" Then ;When the pixels are 1 off the y-axis
  36.         $x -= 6
  37.         $y += 1
  38.         $Gold &= getGoldDigit($x, $y)
  39.         $Gold &= getGoldDigit($x, $y)
  40.         $Gold &= getGoldDigit($x, $y)
  41.         $x += 6
  42.         $Gold &= getGoldDigit($x, $y)
  43.         $Gold &= getGoldDigit($x, $y)
  44.         $Gold &= getGoldDigit($x, $y)
  45.     EndIf
  46.  
  47.     Return $Gold
  48. EndFunc
  49.  
  50. ;==============================================================================================================
  51. ;==============================================================================================================
  52. ;===Color Variation============================================================================================
  53. ;--------------------------------------------------------------------------------------------------------------
  54. ;Checks if the color components exceed $sVari and returns true if they are below $sVari.
  55. ;--------------------------------------------------------------------------------------------------------------
  56.  
  57. Func _ColorCheckVariation($nColor1, $nColor2, $sVari=5)
  58.     $Red1 = Dec(StringMid(String($nColor1), 1, 2))
  59.     $Blue1 = Dec(StringMid(String($nColor1), 3, 2))
  60.     $Green1 = Dec(StringMid(String($nColor1), 5, 2))
  61.    
  62.     $Red2 = Dec(StringMid(String($nColor2), 1, 2))
  63.     $Blue2 = Dec(StringMid(String($nColor2), 3, 2))
  64.     $Green2 = Dec(StringMid(String($nColor2), 5, 2))
  65.  
  66.     If abs($Blue1 - $Blue2) > $sVari Then Return False
  67.     If abs($Green1 - $Green2) > $sVari Then Return False
  68.     If abs($Red1 - $Red2) > $sVari Then Return False
  69.     Return True
  70. EndFunc
  71.  
  72. ;==============================================================================================================
  73. ;===Check Pixels============================================================================================
  74. ;--------------------------------------------------------------------------------------------------------------
  75. ;Using _ColorCheckVariation, checks compares multiple pixels and returns true if they all pass _ColorCheckVariation.
  76. ;--------------------------------------------------------------------------------------------------------------
  77.  
  78. Func boolPixelSearch($pixel1, $pixel2, $pixel3)
  79.     Local $Color1 = _PixelGetColor_GetPixel($vDC, $pixel1[0], $pixel1[1])
  80.     Local $Color2 = _PixelGetColor_GetPixel($vDC, $pixel2[0], $pixel2[1])
  81.     Local $Color3 = _PixelGetColor_GetPixel($vDC, $pixel3[0], $pixel3[1])
  82.     If _ColorCheckVariation($Color1, $pixel1[2], 15) And _ColorCheckVariation($Color2, $pixel2[2], 15) And _ColorCheckVariation($Color3, $pixel3[2], 15) Then Return True
  83.    
  84.     Return False
  85. EndFunc
  86.  
  87. ;==============================================================================================================
  88. ;===Get Digit Gold=============================================================================================
  89. ;--------------------------------------------------------------------------------------------------------------
  90. ;Finds pixel color pattern of specific X and Y values, returns digit if pixel color pattern found.
  91. ;--------------------------------------------------------------------------------------------------------------
  92.  
  93. Func getGoldDigit(ByRef $x, $y)
  94.     Local $width = 0
  95.    
  96.     ;Search for digit 0
  97.     $width = 13
  98.     Local $c1 = Hex(0x989579, 6),   $c2 = Hex(0x39382E, 6), $c3 = Hex(0x272720, 6)
  99.     Local $pixel1[3] = [$x+6, $y+4, $c1], $pixel2[3] = [$x+7, $y+7, $c2], $pixel3[3] = [$x+10, $y+13, $c3]
  100.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  101.       $x += $width ;Adds to x coordinate to get the next digit
  102.       Return 0
  103.     Else
  104.       $x -= 1 ;Solves the problem when the spaces between the middle goes from 6 to 5 pixels
  105.       Local $pixel1[3] = [$x+6, $y+4, $c1], $pixel2[3] = [$x+7, $y+7, $c2], $pixel3[3] = [$x+10, $y+13, $c3]
  106.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  107.          $x += $width ;Changes x coordinate for the next digit.
  108.          Return 0
  109.       Else
  110.          $x += 2 ;Solves the problem when there is 1 pixel space between a set of numbers
  111.          Local $pixel1[3] = [$x+6, $y+4, $c1], $pixel2[3] = [$x+7, $y+7, $c2], $pixel3[3] = [$x+10, $y+13, $c3]
  112.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  113.             $x += $width
  114.             Return 0
  115.          Else
  116.             $x -= 1
  117.          EndIf
  118.       EndIf
  119.     EndIf
  120.  
  121.     ;Search for digit 1
  122.     $width = 6
  123.     Local $c1 = Hex(0x979478, 6),   $c2 = Hex(0x313127, 6), $c3 = Hex(0xD7D4AC, 6)
  124.     Local $pixel1[3] = [$x+1, $y+1, $c1], $pixel2[3] = [$x+1, $y+12, $c2], $pixel3[3] = [$x+4, $y+12, $c3]
  125.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  126.       $x += $width
  127.       Return 1
  128.     Else
  129.       $x -= 1
  130.       Local $pixel1[3] = [$x+1, $y+1, $c1], $pixel2[3] = [$x+1, $y+12, $c2], $pixel3[3] = [$x+4, $y+12, $c3]
  131.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  132.          $x += $width
  133.          Return 1
  134.       Else
  135.          $x += 2
  136.          Local $pixel1[3] = [$x+1, $y+1, $c1], $pixel2[3] = [$x+1, $y+12, $c2], $pixel3[3] = [$x+4, $y+12, $c3]
  137.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  138.             $x += $width
  139.             Return 1
  140.          Else
  141.             $x -= 1
  142.          EndIf
  143.       EndIf
  144.     EndIf
  145.  
  146.     ;Search for digit 2
  147.     $width = 10
  148.     Local $c1 = Hex(0xA09E80, 6),   $c2 = Hex(0xD8D4AC, 6), $c3 = Hex(0x979579, 6)
  149.     Local $pixel1[3] = [$x+1, $y+7, $c1], $pixel2[3] = [$x+3, $y+6, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  150.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  151.       $x += $width
  152.       Return 2
  153.     Else
  154.       $x -= 1
  155.       Local $pixel1[3] = [$x+1, $y+7, $c1], $pixel2[3] = [$x+3, $y+6, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  156.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  157.          $x += $width
  158.          Return 2
  159.       Else
  160.          $x += 2
  161.          Local $pixel1[3] = [$x+1, $y+7, $c1], $pixel2[3] = [$x+3, $y+6, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  162.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  163.             $x += $width
  164.             Return 2
  165.          Else
  166.             $x -= 1
  167.          EndIf
  168.       EndIf
  169.     EndIf
  170.  
  171.     ;Search for digit 3
  172.     $width = 10
  173.     Local $c1 = Hex(0x7F7D65, 6),   $c2 = Hex(0x070706, 6), $c3 = Hex(0x37362C, 6)
  174.     Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+4, $y+8, $c2], $pixel3[3] = [$x+5, $y+13, $c3]
  175.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  176.       $x += $width
  177.       Return 3
  178.     Else
  179.       $x -= 1
  180.       Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+4, $y+8, $c2], $pixel3[3] = [$x+5, $y+13, $c3]
  181.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  182.          $x += $width
  183.          Return 3
  184.       Else
  185.          $x += 2
  186.          Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+4, $y+8, $c2], $pixel3[3] = [$x+5, $y+13, $c3]
  187.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  188.             $x += $width
  189.             Return 3
  190.          Else
  191.                $x -= 1
  192.          EndIf
  193.       EndIf
  194.     EndIf
  195.  
  196.     ;Search for digit 4
  197.     $width = 12
  198.     Local $c1 = Hex(0x282720, 6),   $c2 = Hex(0x080806, 6), $c3 = Hex(0x403F33, 6)
  199.     Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+3, $y+1, $c2], $pixel3[3] = [$x+1, $y+5, $c3]
  200.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  201.       $x += $width
  202.       Return 4
  203.     Else
  204.       $x -= 1
  205.       Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+3, $y+1, $c2], $pixel3[3] = [$x+1, $y+5, $c3]
  206.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  207.          $x += $width
  208.          Return 4
  209.       Else
  210.          $x += 2
  211.          Local $pixel1[3] = [$x+2, $y+3, $c1], $pixel2[3] = [$x+3, $y+1, $c2], $pixel3[3] = [$x+1, $y+5, $c3]
  212.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  213.             $x += $width
  214.             Return 4
  215.          Else
  216.             $x -= 1
  217.          EndIf
  218.       EndIf
  219.     EndIf
  220.  
  221.     ;Search for digit 5
  222.     $width = 10
  223.     Local $c1 = Hex(0x060604, 6),   $c2 = Hex(0x040403, 6), $c3 = Hex(0xB7B492, 6)
  224.     Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+4, $y+9, $c2], $pixel3[3] = [$x+6, $y+12, $c3]
  225.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  226.       $x += $width
  227.       Return 5
  228.     Else
  229.       $x -= 1
  230.       Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+4, $y+9, $c2], $pixel3[3] = [$x+6, $y+12, $c3]
  231.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  232.          $x += $width
  233.          Return 5
  234.       Else
  235.          $x += 2
  236.          Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+4, $y+9, $c2], $pixel3[3] = [$x+6, $y+12, $c3]
  237.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  238.             $x += $width
  239.             Return 5
  240.          Else
  241.             $x -= 1
  242.          EndIf
  243.       EndIf
  244.     EndIf
  245.  
  246.     ;Search for digit 6
  247.     $width = 11
  248.     Local $c1 = Hex(0x070605, 6),   $c2 = Hex(0x040403, 6), $c3 = Hex(0x181713, 6)
  249.     Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+5, $c3]
  250.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  251.       $x += $width
  252.       Return 6
  253.     Else
  254.       $x -= 1
  255.       Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+5, $c3]
  256.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  257.          $x += $width
  258.          Return 6
  259.       Else
  260.          $x += 2
  261.          Local $pixel1[3] = [$x+5, $y+4, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+5, $c3]
  262.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  263.             $x += $width
  264.             Return 6
  265.          Else
  266.             $x -= 1
  267.          EndIf
  268.       EndIf
  269.     EndIf
  270.  
  271.     ;Search for digit 7
  272.     $width = 10
  273.     Local $c1 = Hex(0x5E5C4B, 6),   $c2 = Hex(0x87856C, 6), $c3 = Hex(0x5D5C4B, 6)
  274.     Local $pixel1[3] = [$x+5, $y+11, $c1], $pixel2[3] = [$x+4, $y+3, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  275.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  276.       $x += $width
  277.       Return 7
  278.     Else
  279.       $x -= 1
  280.       Local $pixel1[3] = [$x+5, $y+11, $c1], $pixel2[3] = [$x+4, $y+3, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  281.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  282.          $x += $width
  283.          Return 7
  284.       Else
  285.          $x += 2
  286.          Local $pixel1[3] = [$x+5, $y+11, $c1], $pixel2[3] = [$x+4, $y+3, $c2], $pixel3[3] = [$x+7, $y+7, $c3]
  287.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  288.             $x += $width
  289.             Return 7
  290.          Else
  291.             $x -= 1
  292.          EndIf
  293.       EndIf
  294.     EndIf
  295.  
  296.     ;Search for digit 8
  297.     $width = 11
  298.     Local $c1 = Hex(0x27261F, 6),   $c2 = Hex(0x302F26, 6), $c3 = Hex(0x26261F, 6)
  299.     Local $pixel1[3] = [$x+5, $y+3, $c1], $pixel2[3] = [$x+5, $y+10, $c2], $pixel3[3] = [$x+1, $y+6, $c3]
  300.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  301.       $x += $width
  302.       Return 8
  303.     Else
  304.       $x -= 1
  305.       Local $pixel1[3] = [$x+5, $y+3, $c1], $pixel2[3] = [$x+5, $y+10, $c2], $pixel3[3] = [$x+1, $y+6, $c3]
  306.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  307.          $x += $width
  308.          Return 8
  309.       Else
  310.          $x += 2
  311.          Local $pixel1[3] = [$x+5, $y+3, $c1], $pixel2[3] = [$x+5, $y+10, $c2], $pixel3[3] = [$x+1, $y+6, $c3]
  312.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  313.             $x += $width
  314.             Return 8
  315.          Else
  316.             $x -= 1
  317.          EndIf
  318.       EndIf
  319.     EndIf
  320.  
  321.     ;Search for digit 9
  322.     $width = 11
  323.     Local $c1 = Hex(0x302F26, 6),   $c2 = Hex(0x050504, 6), $c3 = Hex(0x272720, 6)
  324.     Local $pixel1[3] = [$x+5, $y+5, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+12, $c3]
  325.     If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  326.       $x += $width
  327.       Return 9
  328.     Else
  329.       $x -= 1
  330.       Local $pixel1[3] = [$x+5, $y+5, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+12, $c3]
  331.       If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  332.          $x += $width
  333.          Return 9
  334.       Else
  335.          $x += 2
  336.          Local $pixel1[3] = [$x+5, $y+5, $c1], $pixel2[3] = [$x+5, $y+9, $c2], $pixel3[3] = [$x+8, $y+12, $c3]
  337.          If boolPixelSearch($pixel1, $pixel2, $pixel3) Then
  338.             $x += $width
  339.             Return 9
  340.          Else
  341.             $x -= 1
  342.          EndIf
  343.       EndIf
  344.     EndIf
  345.     Return ""
  346. EndFunc
  347.  
  348. ;==============================================================================================================
  349. ;===Other Functions============================================================================================
  350. ;==============================================================================================================
  351.  
  352. Func _PixelGetColor_CreateDC($hDll = "gdi32.dll")
  353.     $iPixelGetColor_MemoryContext = DllCall($hDll, "int", "CreateCompatibleDC", "int", 0)
  354.     If @error Then Return SetError(@error,0,0)
  355.     Return $iPixelGetColor_MemoryContext[0]
  356. EndFunc
  357.  
  358. Func _PixelGetColor_CaptureRegion($iPixelGetColor_MemoryContext, $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = False, $hDll = "gdi32.dll")
  359.     $HBITMAP = _ScreenCapture_Capture("", $iLeft, $iTop, $iRight, $iBottom, $fCursor)
  360.     DllCall($hDll, "hwnd", "SelectObject", "int", $iPixelGetColor_MemoryContext, "hwnd", $HBITMAP)
  361.     Return $HBITMAP
  362. EndFunc
  363.  
  364. Func _PixelGetColor_GetPixel($iPixelGetColor_MemoryContext,$iX,$iY, $hDll = "gdi32.dll")
  365.     $iColor = DllCall($hDll,"int","GetPixel","int",$iPixelGetColor_MemoryContext,"int",$iX,"int",$iY)
  366.     If $iColor[0] = -1 then Return SetError(1,0,-1)
  367.     $sColor = Hex($iColor[0],6)
  368.     Return StringRight($sColor,2) & StringMid($sColor,3,2) & StringLeft($sColor,2)
  369. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement