The Bytecode Club - Reverse Engineering Forum
Image search help? - Printable Version

+- The Bytecode Club - Reverse Engineering Forum (https://the.bytecode.club)
+-- Forum: Lobby (https://the.bytecode.club/forumdisplay.php?fid=1)
+--- Forum: Game Cheating, Botting & Reverse Engineering (https://the.bytecode.club/forumdisplay.php?fid=97)
+--- Thread: Image search help? (/showthread.php?tid=1022)



Image search help? - knowjack - 02-24-2015

I'm trying to install a Smashed TH check into the algorithmTH.au3 module.
Been staring at the other modules that call the _ImageSearch function in ImageSearch.au3 and can't get a valid response or coordinates from _ImageSearch?

After staring at 3-4 dozen images of smashed TH, it seems they all look same regardless of the TH level.
Have tried several sizes/shapes of images cut directly from saved attack images. They are stored in BMP, and the 1 pixel tall version is same size as the TH check image. But I NEVER find a match even with 20% tolerance. I'm ready to give up.  Worry

I am sure its some kind of noob mistake, can anyone help?

Code:
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



RE: Image search help? - Snarg - 02-24-2015

I don't think you are factoring in the offset with your X/Y coords. Try the script below. It will get the coords and copy them to the clipboard. Change the first $Title line to match the title of your BlueStacks.

The F1 key will get the coords, taking into account the offset, of wherever you click.

Code:
#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



RE: Image search help? - knowjack - 02-24-2015

Thanks for the reply!
Sorry to be dense, I'm not following why I need offsets?
Doesn't existing _CaptureRegion in _CaptureRegion.au3 automatically get BS offsets, and load global variable $hHBitmap with the image to be searched?

I've been searching autoitscript forum as well, and imagesearch is still baffling me. Sad
Thanks Again!


RE: Image search help? - Snarg - 02-24-2015

Because of the border around the window (title at the top, and the thin borders on the sides and bottom) there is a certain amount of X/Y offset you need, otherwise your coordinates will be incorrect. getBSPos() is supposed to get the correct values for the play screen.

I don't know how you are using the function you posted. Are you using it stand-alone, or within a script?

If you use just _CaptureRegion() it won't get the offset. It will call getBSPos(), but getBSPos() will be missing the $Title variable. The script I posted above ensures all the values needed are filled out.

Edit: What size is your BlueStacks window? Have you changed it with the .reg file? If not, then the first line in _CaptureRegion() is screwing you up:

Code:
Func _CaptureRegion($iLeft = 0, $iTop = 0, $iRight = 860, $iBottom = 720, $ReturnBMP = False)

See the hard-coded coords? If your window is not that size, it won't work.


RE: Image search help? - knowjack - 02-24-2015

Thanks Snarg!  Appreciate your continued effort to help. Smile

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.
  Saddest


RE: Image search help? - Henk500 - 02-25-2015

(02-24-2015, 07:17 PM)knowjack Wrote:  Thanks Snarg!  Appreciate your continued effort to help. Smile

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.
  Saddest

try writing the hBitmap to an .bmp
_ScreenCapture_SaveImage("C:\COC-Bot-master\images\GdiPlus_Screen.bmp", $hHBitmap)

i have some weird screenshots...Only the captureregion background mode option works for me.


RE: Image search help? - knowjack - 02-25-2015

Thanks for the suggestion Henk500!
Added the code, checked a dozen images and they all look normal?
Sad


RE: Image search help? - Snarg - 02-25-2015

Any chance of posting all of your code? It's hard to debug a snippet.


RE: Image search help? - terminus - 02-25-2015

jack
have you given up?