Sign in to follow this  
Followers 0
no1Gun

Pixelscan in Flash?

6 posts in this topic

Hi.

I was wondering if I would be able to do a pixelscan in a flashgame/window to retrieve a colour?

You can see my script below - please tell me if there is anything bugged about it.

Opt("TrayMenuMode", 1)
opt("Pixelcoordmode", 2)
opt("Mousecoordmode", 2)

;HotKeySet("{SPACE}", "Shoot")
HotKeySet("{F10}", "Speed_pxcheck")
HotKeySet("{F11}", "Direction_pxcheck")

HotKeySet("{F6}", "Terminate")
HotKeySet("{F7}", "Pause")


While 1
    
WEnd ;Menu Loop 


Func Speed_pxcheck()
$Speed_Check = PixelChecksum(1190, 425, 1190, 390)  ;$ColorX, $ColorY, $ColorX, $ColorY
MsgBox(0, "Colour Scan:", $Speed_Check)
EndFunc

Func Direction_pxcheck()
$Direction_Check = PixelChecksum(1190, 390, 1190, 390)  ;$ColorX, $ColorY, $ColorX, $ColorY
MsgBox(0, "Colour Scan:", $Direction_Check)
EndFunc

;Func Shoot()
;While 1

;$Speed_Ctrl = PixelChecksum(1190, 425, 1190, 390)  ;$ColorX, $ColorY, $ColorX, $ColorY
;If $Speed_Check <> $Speed_Ctrl Then MouseClick("Left")

;$Direction_Ctrl = PixelChecksum(1190, 390, 1190, 390)  ;$ColorX, $ColorY, $ColorX, $ColorY
;If $Direction_Check <> $Direction_Ctrl Then MouseClick("Left")

;ExitLoop
;WEnd
;EndFunc

Func Pause()
    
$Pause = NOT $Pause

While $Pause
WEnd
EndFunc

Func Terminate()
Exit 0
EndFunc

Share this post


Link to post
Share on other sites



Is there no one who can help me?

Allowed to bump a topic?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This is the method I use for pulling pixel info from Flash or Java based apps.

;=================================   oL_SaveScreen_ToHex   =======================
; Function Name:    __oL_SaveScreen_ToHex
; Requires:         <WinAPI.au3>
; Description:
; Parameters:       $Array      2 deminsional Array of Hex Colors
;
; EG:               $BitHex = _ScreenCapture_ToHex($pos[0]-25,$pos[1]-25,$pos[0]+25,$pos[1]+25)
; Syntax:           _oL_SaveScreen_ToHex($Left,$Top,$Right,$Bottom)
; Author(s):        ofLight
; Returns:          $Array[$Total_X][$Total_Y]
;=================================================================================
Func _oL_SaveScreen_ToHex($Left,$Top,$Right,$Bottom)
    $X = ($Right-$Left)
    $Y = ($Bottom-$Top)
    Dim $Output[($X+1)][($Y+1)]
    $Output[0][1] = $X ;How manny colomns
    $Output[1][0] = $Y ;How manny Rows

    $hBmp = _ScreenCapture("",$Left,$Top,$Right,$Bottom)
    $aSize = DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $hBmp, 'int', 0, 'ptr', 0)
    If $aSize[0] Then
        $Bits = DllStructCreate('byte[' & $aSize[0] & ']')
        DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $hBmp, 'int', $aSize[0], 'ptr', DllStructGetPtr($Bits))
        $BitHex = Hex(DllStructGetData($Bits, 1))
    EndIf
    _WinAPI_DeleteObject($hBmp)

    For $i = 1 to $X
        For $j = 1 to $Y
            $result = StringLeft($BitHex, 8)
            $Output[$i][$j] = $result
            $BitHex = StringTrimLeft($BitHex, 8)
        Next
    Next

    Return $Output
EndFunc;==========================   oL_SaveScreen_ToHex   =======================
Edited by ofLight

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This is the method I use for pulling pixel info from Flash or Java based apps.

;=================================   oL_SaveScreen_ToHex   =======================
; Function Name:    __oL_SaveScreen_ToHex
; Requires:         <WinAPI.au3>
; Description:
; Parameters:       $Array      2 deminsional Array of Hex Colors
;
; EG:               $BitHex = _ScreenCapture_ToHex($pos[0]-25,$pos[1]-25,$pos[0]+25,$pos[1]+25)
; Syntax:           _oL_SaveScreen_ToHex($Left,$Top,$Right,$Bottom)
; Author(s):        ofLight
; Returns:          $Array[$Total_X][$Total_Y]
;=================================================================================
Func _oL_SaveScreen_ToHex($Left,$Top,$Right,$Bottom)
    $X = ($Right-$Left)
    $Y = ($Bottom-$Top)
    Dim $Output[($X+1)][($Y+1)]
    $Output[0][1] = $X ;How manny colomns
    $Output[1][0] = $Y ;How manny Rows

    $hBmp = _ScreenCapture("",$Left,$Top,$Right,$Bottom)
    $aSize = DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $hBmp, 'int', 0, 'ptr', 0)
    If $aSize[0] Then
        $Bits = DllStructCreate('byte[' & $aSize[0] & ']')
        DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $hBmp, 'int', $aSize[0], 'ptr', DllStructGetPtr($Bits))
        $BitHex = Hex(DllStructGetData($Bits, 1))
    EndIf
    _WinAPI_DeleteObject($hBmp)

    For $i = 1 to $X
        For $j = 1 to $Y
            $result = StringLeft($BitHex, 8)
            $Output[$i][$j] = $result
            $BitHex = StringTrimLeft($BitHex, 8)
        Next
    Next

    Return $Output
EndFunc;==========================   oL_SaveScreen_ToHex   =======================

This sounds helpful - but this is a lot more advanced scripting than what I am capable of understanding :S

As said - I'm pretty new at this and what I understand, scripting wise, is very limited.

Is there a way for you to possibly generate a scan where I could set the pixelcoords, that would be able to drag any colour results from a flash window onto a msgbox?

Edited by no1Gun

Share this post


Link to post
Share on other sites

I dont fully understand what you are asking :D. I can provide basic Example Use code:

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <Array.au3>


While 1
    $pos = MouseGetPos()
    $pix = _oL_SaveScreen_ToHex($pos[0]-1,$pos[1]-1,$pos[0],$pos[1])
    ;_ArrayDisplay($pix)
    ToolTip($pix[1][1])
    Sleep(10)
WEnd


Func _oL_SaveScreen_ToHex($Left,$Top,$Right,$Bottom)
    $X = ($Right-$Left)
    $Y = ($Bottom-$Top)
    Dim $Output[($X+1)][($Y+1)]
    $Output[0][1] = $X ;How manny colomns
    $Output[1][0] = $Y ;How manny Rows

    $hBmp = _ScreenCapture("",$Left,$Top,$Right,$Bottom)
    ;$hBmp = _ScreenCapture_Capture("",$Left,$Top,$Right,$Bottom)
    $aSize = DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $hBmp, 'int', 0, 'ptr', 0)
    If $aSize[0] Then
        $Bits = DllStructCreate('byte[' & $aSize[0] & ']')
        DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $hBmp, 'int', $aSize[0], 'ptr', DllStructGetPtr($Bits))
        $BitHex = Hex(DllStructGetData($Bits, 1))
    EndIf
    _WinAPI_DeleteObject($hBmp)

    For $i = 1 to $X
        For $j = 1 to $Y
            $result = StringLeft($BitHex, 8)
            $Output[$i][$j] = $result
            $BitHex = StringTrimLeft($BitHex, 8)
        Next
    Next

    Return $Output
EndFunc

Func _ScreenCapture($sFileName = "", $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1)
    Local $iH, $iW, $hWnd, $hDDC, $hCDC, $hBMP, $aCursor, $aIcon

    If $iRight = -1 Then $iRight = _WinAPI_GetSystemMetrics($SM_CXSCREEN)
    If $iBottom = -1 Then $iBottom = _WinAPI_GetSystemMetrics($SM_CYSCREEN)
    If $iRight < $iLeft Then Return SetError(-1, 0, 0)
    If $iBottom < $iTop Then Return SetError(-2, 0, 0)

    $iW = $iRight - $iLeft
    $iH = $iBottom - $iTop
    $hWnd = _WinAPI_GetDesktopWindow()
    $hDDC = _WinAPI_GetDC($hWnd)
    $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
    $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH)
    _WinAPI_SelectObject($hCDC, $hBMP)
    _WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, $SRCCOPY)

    _WinAPI_ReleaseDC($hWnd, $hDDC)
    _WinAPI_DeleteDC($hCDC)
    If $sFileName = "" Then Return $hBMP
    _ScreenCapture_SaveImage($sFileName, $hBMP)
    _WinAPI_DeleteObject($hBMP)
EndFunc

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0