Func CheckSmashedTownhall()
Local $SmashedThx, $SmashedTHy
If _Sleep(100) Then Return
_CaptureRegion()
$IsTHSmashed = _ImageSearch($SmashedTH, 1, $SmashedTHx, $SmashedTHy, 20) ; Getting smashed TH Location
If $DebugTH = True Then
SetLog("Check1 Smashed TH returned: " & $IsTHSmashed & ", " & $SmashedTHx & ", " & $SmashedTHy, $COLOR_BLUE)
EndIf
If $IsTHSmashed = 1 Then
Return 1
EndIf
If $IsTHSmashed = 0 Then Return "-"
EndFunc
#include <Misc.au3>
#include <WinAPI.au3>
Global $BSpos[2] ; Inside BlueStacks positions relative to the screen
$Title = "BlueStacks App Player for Windows (beta-1)" ; Window name
$Full = WinGetTitle ($Title) ; Get The Full Title..
$HWnD = WinGetHandle ($Full) ; Get The Handle
WinActivate ($HWnD)
Func getBSPos()
$aPos = ControlGetPos($Title, "", "[CLASS:BlueStacksApp; INSTANCE:1]")
$tPoint = DllStructCreate("int X;int Y")
DllStructSetData($tPoint, "X", $aPos[0])
DllStructSetData($tPoint, "Y", $aPos[1])
_WinAPI_ClientToScreen(WinGetHandle(WinGetTitle($Title)), $tPoint)
$BSpos[0] = DllStructGetData($tPoint, "X")
$BSpos[1] = DllStructGetData($tPoint, "Y")
EndFunc ;==>getBSPos
HotKeySet ("{F7}", "FindPos")
HotKeySet ("{F8}", "Terminate")
While 1
Sleep (100)
WEnd
Func FindPos()
getBSPos()
Local $Pos[2]
Local $iColour = 0
While 1
If _IsPressed("01") Then
$Pos[0] = MouseGetPos()[0] - $BSpos[0]
$Pos[1] = MouseGetPos()[1] - $BSpos[1]
$iColour = Hex (PixelGetColor($Pos[0],$Pos[1]),6)
ClipPut($Pos[0] & "," & $Pos[1] & "," & $iColour)
Return $Pos
EndIf
WEnd
EndFunc ;==>FindPos
Func Terminate()
Exit
EndFunc ;==>Terminate
Func _CaptureRegion($iLeft = 0, $iTop = 0, $iRight = 860, $iBottom = 720, $ReturnBMP = False)
If CheckSmashedTownhall() = 1 Then ; check to see if TH is smashed.
SetLog("TH Attack successful!", $COLOR_BLUE)
ExitLoop 2
EndIf
getBSPos()
$hHBitmap = _ScreenCapture_Capture("", $iLeft + $BSpos[0], $iTop + $BSpos[1], $iRight + $BSpos[0], $iBottom + $BSpos[1])
Global $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
(02-24-2015, 07:17 PM)knowjack Wrote: Thanks Snarg! Appreciate your continued effort to help.
I'm using the function posted above just like checkTownHall.au3, except instead of searching for 5 different images, using only 1? All I do is look for successful return value and the x,y positions in the function call, like this:
Code:If CheckSmashedTownhall() = 1 Then ; check to see if TH is smashed.
SetLog("TH Attack successful!", $COLOR_BLUE)
ExitLoop 2
EndIf
The reason I used _CaptureRegion() like checkTownHall() function; is that it appears to get the BS offsets and loads $hHBitmap (showing only the non-background code)
Code:getBSPos()
$hHBitmap = _ScreenCapture_Capture("", $iLeft + $BSpos[0], $iTop + $BSpos[1], $iRight + $BSpos[0], $iBottom + $BSpos[1])
Global $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
Unless I am reading image search wrong, _ImageSearch calls _ImageSearchArea, and it checks to see if $hHBitmap has an image loaded from _captureRegion(), then executes DLLCALL to search for the image passed to it??
I was really hoping to reuse the existing image capture/search functions as the initially seemed pretty straight forward. But after beating my head against the wall on this off/on for a couple days, I'm just getting more confused.