Sign in to follow this  
Followers 0
riff

Function Parameters

10 posts in this topic

Hi guys and gals, running into one of my first problems with autoit, this is concerning function parameters, my buddy made this script to make stuff from it and i'm using this function but can't quite figure out how to use this parameter $aWindow correctly.

;=================================================================================================
; Function:         GetWindowInfo($aWindow, $aReturn)
; Description:      Returns Information about a Window
; Parameter(s):     $aWindow:       possible Parameters to be used:
;                                       WindowIndex (the windowindex of the window you want to retrieve
;                                                    information about going from lowest = 0 to top = X)
;                                                    If set to -1 is the topmost window is used.
;                                                    If set to -2 the main window (Guild Wars) is used.
;                                       WindowID (unique number for each window)
;                                       WindowName (id string)
;                   $aReturn        A String with the information you want to retrieve. Multiple
;                                   requests are possible and should be split using "," inside
;                                   the string. e.g. "X,Y,..."
;                                   possible Parameters to be used:
;                                       X (pixel client area)
;                                       Y (pixel client area)
;                                       Width (pixel client area)
;                                       Height (pixel client area)
;                                       WindowID (unique number for each window)
;                                       WindowName (id string)
;                                       WindowIndex (windowindex of window going from lowest = 0 to top = X)
; Requirement(s):   GW must running and Memory must have been scanned for pointers (see GWMI_MemScan)
; Return Value(s):  On Success - Returns either a Value (single request) or a zero based array of Values(multiple requests)
;                   On Failure - Returned values are 0 for invalid Parameters
;                                If window does not exist error ist set to -1
;=================================================================================================
Func GetWindowInfo($aWindow, $aReturn)
    Local $aReturnArray[1] = [0]
    Local $aNbrOfRequests
    Local $aWindowIndex = -1
    Local $aWindowID = -1
    Local $aWindowName = -1
    Local $aWindowX = -1, $aWindowY = -1, $aWindowWidth = -1, $aWindowHeight = -1
    Local $aOffset[6]
    Local $aTmpBuffer

    If $aWindow = -2 Then
        Local $aMainWindow = WinGetPos($GWWindowName)
        $aWindowX = $aMainWindow[0]
        $aWindowY = $aMainWindow[1]
        $aWindowWidth = $aMainWindow[2]
        $aWindowHeight = $aMainWindow[3]
        $aWindowName = $GWWindowName
    ElseIf $aWindow = -3 Then
        $aOffset[1] = 0x10
        $aOffset[2] = 0x54
        $aOffset[3] = 0x38
        $aOffset[4] = 0x4
        $aOffset[5] = 0x3C
        $aWindowAddress = GWMI_MemPtrRead($WindowPtr, $aOffset)
        $aTmpBuffer = DllStructCreate("float Zoom;float X;float Y;float Width;float Height")
        DllCall($aOpenProcess[0], 'int', 'ReadProcessMemory', 'int', $aOpenProcess[1], 'int', $aWindowAddress[0], 'ptr', DllStructGetPtr($aTmpBuffer), 'int', DllStructGetSize($aTmpBuffer), 'int', '')

        $aWindowX = DllStructGetData($aTmpBuffer, "X")
        $aWindowY = DllStructGetData($aTmpBuffer, "Y")
        $aWindowWidth = DllStructGetData($aTmpBuffer, "Width")
        $aWindowHeight = DllStructGetData($aTmpBuffer, "Height")
        $aWindowName = "WorldMap"
        $aWindowID = DllStructGetData($aTmpBuffer, "Zoom") ;WindowID ;) ZOOOOM
    Else
        Local $aWindowRealIndex
        Local $aWindowAddress
        Local $aClientSize = WinGetClientSize($GWWindowName)
        Local $aScaleX = $aClientSize[0] / GWMI_MemRead($MainWindowPtr, 'float')
        Local $aScaleY = $aClientSize[1] / GWMI_MemRead($MainWindowPtr + 0x4, 'float')
        $aOffset[2] = 0x64
        $aOffset[3] = 0x8
        $aOffset[4] = 0x84
        $aOffset[5] = 0x6C
        $aTmpBuffer = DllStructCreate("float X;float Y;float Width;float Height;byte unknown[16];long WindowId")

        If $aWindow = -1 Then ;get topmost realwindowindex
            ;Get the real WindowIndex
            For $aWindowRealIndex = 15 To 0 Step -1
                $aOffset[1] = 0xC + 0x4 * $aWindowRealIndex
                $aWindowAddress = GWMI_MemPtrRead($WindowPtr, $aOffset)
                DllCall($aOpenProcess[0], 'int', 'ReadProcessMemory', 'int', $aOpenProcess[1], 'int', $aWindowAddress[0], 'ptr', DllStructGetPtr($aTmpBuffer), 'int', DllStructGetSize($aTmpBuffer), 'int', '')
                $aWindowID = DllStructGetData($aTmpBuffer, "WindowId")

                ;Check for valid window
                If $aWindowID > 0 Then
                    $aWindowName = GetWindownameFromID($aWindowID)
                    If IsString($aWindowName) Then
                        $aWindow = $aWindowName
                        ExitLoop
                    EndIf
                EndIf

                If $aWindowRealIndex = 0 Then ;no window open
                    SetError(-1)
                    Return -1
                EndIf
            Next
        EndIf

        ;Get the real WindowIndex
        For $aWindowRealIndex = 0 To 15
            $aOffset[1] = 0xC + 0x4 * $aWindowRealIndex
            $aWindowAddress = GWMI_MemPtrRead($WindowPtr, $aOffset)
            DllCall($aOpenProcess[0], 'int', 'ReadProcessMemory', 'int', $aOpenProcess[1], 'int', $aWindowAddress[0], 'ptr', DllStructGetPtr($aTmpBuffer), 'int', DllStructGetSize($aTmpBuffer), 'int', '')
            $aWindowID = DllStructGetData($aTmpBuffer, "WindowId")

            ;Check for valid window
            If $aWindowID > 0 And $aWindowAddress[0] < 0x20000000 Then
                $aWindowName = GetWindownameFromID($aWindowID)
                If IsString($aWindowName) Then

                    $aWindowIndex += 1

                    ;doesn't look really nice but it works phew
                    If IsString($aWindow) Then
                        If $aWindow = $aWindowName Then
                            $aWindowX = DllStructGetData($aTmpBuffer, "X") * $aScaleX
                            $aWindowY = (GWMI_MemRead($MainWindowPtr + 0x4, 'float') - DllStructGetData($aTmpBuffer, "Height")) * $aScaleY
                            $aWindowWidth = (DllStructGetData($aTmpBuffer, "Width") - DllStructGetData($aTmpBuffer, "X")) * $aScaleX
                            $aWindowHeight = (DllStructGetData($aTmpBuffer, "Height") - DllStructGetData($aTmpBuffer, "Y")) * $aScaleY
                            ExitLoop
                        EndIf
                    ElseIf $aWindow = $aWindowIndex Or $aWindow = $aWindowID Then
                        $aWindowX = DllStructGetData($aTmpBuffer, "X") * $aScaleX
                        $aWindowY = (GWMI_MemRead($MainWindowPtr + 0x4, 'float') - DllStructGetData($aTmpBuffer, "Height")) * $aScaleY
                        $aWindowWidth = (DllStructGetData($aTmpBuffer, "Width") - DllStructGetData($aTmpBuffer, "X")) * $aScaleX
                        $aWindowHeight = (DllStructGetData($aTmpBuffer, "Height") - DllStructGetData($aTmpBuffer, "Y")) * $aScaleY
                        ExitLoop
                    EndIf
                EndIf
            EndIf

            If $aWindowRealIndex = 15 Then ;window does not exist
                SetError(-1)
                Return -1
            EndIf
        Next
    EndIf

    ;split the expected return for further use
    $aReturnArray = StringSplit($aReturn, ",")
    $aNbrOfRequests = $aReturnArray[0]

    ;refill the array with data
    For $i = 1 To $aNbrOfRequests
        Switch $aReturnArray[$i]
            Case "X"
                $aReturnArray[$i - 1] = Round($aWindowX, 0)
            Case "Y"
                $aReturnArray[$i - 1] = Round($aWindowY, 0)
            Case "Width"
                $aReturnArray[$i - 1] = Round($aWindowWidth, 0)
            Case "Height"
                $aReturnArray[$i - 1] = Round($aWindowHeight, 0)
            Case "WindowID"
                $aReturnArray[$i - 1] = $aWindowID
            Case "WindowIndex"
                $aReturnArray[$i - 1] = $aWindowIndex
            Case "WindowName"
                $aReturnArray[$i - 1] = $aWindowName
        EndSwitch
    Next

    ;resize the Array
    ReDim $aReturnArray[$aNbrOfRequests]

    ;return data
    If UBound($aReturnArray) = 1 Then
        Return $aReturnArray[0]
    Else
        Return $aReturnArray
    EndIf
EndFunc   ;==>GetWindowInfo

Func GetWindowNameFromID($WindowID)
    Switch $WindowID
        Case 21
            Return "Hero"
        Case 23
            Return "Skills"
        Case 26
            Return "Friends"
        Case 27
            Return "Guild"
        Case 29
            Return "Help"
        Case 30
            Return "Inventory"
        Case 32
            Return "Bags"
        Case 36
            Return "Map" ;mission map
        Case 37
            Return "Dialog" ;normal dialog (quests etc.)
        Case 38
            Return "Observe"
        Case 40
            Return "Party" ;party search
        Case 46
            Return "Quest" ;quest-log
        Case 60
            Return "Trade" ;trade window
        Case 61
            Return "Merchant" ;buy/sell/collector window

            ;Chestopen?
            ;...
    EndSwitch
EndFunc   ;==>GetWindowNameFromID

Share this post


Link to post
Share on other sites



That looks a whole lot like part of a game bot. (Guildwars?), which are not allowed here as per announcement.

Share this post


Link to post
Share on other sites

That looks a whole lot like part of a game bot. (Guildwars?), which are not allowed here as per announcement.

the question is about function parameters not about how to write a bot.

Share this post


Link to post
Share on other sites

the question is about function parameters not about how to write a bot.

What you say is irrelevant when your code is obviously for automating a game. Abandon this thread now if you don't want to be in trouble.

Share this post


Link to post
Share on other sites

You could give a similar argument for most, if not all questions about game automation:

"My question is about reading and modifying the memory of a process, not game automation"

"My question is about waiting for a certain color to appear and then clicking that pixel, not fishbotting / aimbotting)"

You're linking two functions that are specifically made to interract with Guild Wars and don't seem to have any other use besides that.

I can't speak for the moderators, but from what I've seen in the past they're not going to approve of this, so just consider yourself warned.

You can take my advise and drop the topic, or leave it up and deal with a moderator if and when one sees this.

Share this post


Link to post
Share on other sites

You could give a similar argument for most, if not all questions about game automation:

"My question is about reading and modifying the memory of a process, not game automation"

"My question is about waiting for a certain color to appear and then clicking that pixel, not fishbotting / aimbotting)"

You're linking two functions that are specifically made to interract with Guild Wars and don't seem to have any other use besides that.

I can't speak for the moderators, but from what I've seen in the past they're not going to approve of this, so just consider yourself warned.

You can take my advise and drop the topic, or leave it up and deal with a moderator if and when one sees this.

well i would still like to know how to use a function parameter like that. Thats just an example. All it actually does is get window locations.

Share this post


Link to post
Share on other sites

People (you happen to be a perfect example, but it's very common here) need to learn to give simple working examples, rather than posting all the code. That way you'd be asking a simple question and would get a simple answer. What you must realise is that we have a strict 'no bots allowed' policy here, for good reason as well. It doesn't matter what you are asking, if it's for a bot, we won't help.

As usual, the docs for the function tell you everything you need to know.

Mat

Share this post


Link to post
Share on other sites

People (you happen to be a perfect example, but it's very common here) need to learn to give simple working examples, rather than posting all the code. That way you'd be asking a simple question and would get a simple answer. What you must realise is that we have a strict 'no bots allowed' policy here, for good reason as well. It doesn't matter what you are asking, if it's for a bot, we won't help.

As usual, the docs for the function tell you everything you need to know.

Mat

yes but the docs them selves confuse me. with Functionx($stringa,$stringb) it has parameters for stringa which i don't know how to use.

Share this post


Link to post
Share on other sites

What exactly is confusing? Is it the value you are supposed to be using? I assume if you play the game then the id's and names should mean something to you, I'm not sure if we could help you if we wanted to.

Share this post


Link to post
Share on other sites

What exactly is confusing? Is it the value you are supposed to be using? I assume if you play the game then the id's and names should mean something to you, I'm not sure if we could help you if we wanted to.

no its not the value i'm supposed to be using. The function lets you know that, the problem i'm having is the function always returns the same value of -1. The part i'm confused about is for $stringb you just put "blah blah" but for $stringa it just says these parameters. I've tried a few different ways, like adding it to the string like $stringaInfo, but it says the string was not declared.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0