Sign in to follow this  
Followers 0
Jine

Weird program, alternative idea for script?

8 posts in this topic

Hi, I'm mostly a newbie when it comes to scripting, but I can generally (and very sloppily) get what I want done.

My problem is I scripted a small little bot for my game, but the thing is I can only send commands to the game after I minimize it, then maximize (seems to only be about a second or two window that I can send commands.) The game has no controls so controlsend won't help I guess. I'm guessing it's maybe the game's anti-hacking protection (Although it doesn't catch autoit, funny) that prevents automation to the client? Does that sound right? Is there any sort of advanced way I could code around this or maybe make it more convient for myself? It's pretty annoying have to minimize and maximize every 5 seconds, but it DOES work. Any help or ideas would be appreciated, thanks!

Share this post


Link to post
Share on other sites



.. First off... Try and form better sentences...

Second what game and what u mean by certain keys...

Share this post


Link to post
Share on other sites

Uh..I don't get what's wrong with my sentences, there isn't a single error that I can see...much less, it being unreadable in the slightest. I also didn't say anything about only being able to only send certain keys. The problem is I can only send keys (any) PERIOD after I minimize the game, then maxmize the game, no other way. The game is Sword of the New World and its anti-hacking protection is Xtrap. I'm trying to figure out if something like that is preventing automation to the client, and see if there is any sort of solution around it, because I can't send keys any other way than what I described.

Share this post


Link to post
Share on other sites

Maybe try _PostMessage..Not sure if it works with 3.2.10.0, if not then use it with 3.2.8.1

;This seems to work great.. I forget whether you need either absolute coords or coords relative to the current active window
;Play around with it.. you can also add more consts for the _SendKeys :)

Global Const $VK_OEM_PLUS = 0xBB
Global Const $VK_OEM_MINUS = 0xBD
Global Const $VK_OEM_3 = 0xC0
Global Const $VK_TAB = 0x9
Global Const $VK_ESC = 0x1B
Global Const $VK_F5 = 0x74
Global Const $VK_F12 = 0x7B
Global Const $VK_Period = 0x6E
Global Const $VK_SEMICOLON = 0xBA
Global Const $VK_COLON = 0x3A

Func _MakeLong($LoWord, $HiWord)
    Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc 
Func _MouseClick($hWnd, $button, $x, $y, $times = 1, $delay = 0)
    Local $ret, $ix
    $ret = DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x200, "int", 0, "long", _MakeLong($x, $y))
    If $ret[0] = 0 Then
        SetError(-1)
        Return
    EndIf
    $button = StringLower($button)
    If $button = "left" Then
        For $ix = 1 To $times
            $ret = DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x201, "int", 1, "long", _MakeLong($x, $y))
            If $ret[0] = 0 Then
                SetError(-2)
                Return
            Else
                $ret = DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x202, "int", 0, "long", _MakeLong($x, $y))
                If $ret[0] = 0 Then
                    SetError(-3)
                    Return
                EndIf
            EndIf
            Sleep($delay)
        Next
    ElseIf $button = "right" Then
        For $ix = 1 To $times
            $ret = DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x204, "int", 2, "long", _MakeLong($x, $y))
            If $ret[0] = 0 Then
                SetError(-4)
                Return
            Else
                $ret = DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x205, "int", 0, "long", _MakeLong($x, $y))
                If $ret[0] = 0 Then
                    SetError(-5)
                    Return
                EndIf
            EndIf
            Sleep($delay)
        Next
    Else
        SetError(-6)
        Return
    EndIf
EndFunc 

Func _SendKeys($hWnd, $keys)
    If $hWnd <= 0 Or StringLen($keys) = 0 Then
        SetError(-1)
        Return False
    EndIf
    $keys = StringUpper($keys)
    $keys = StringReplace($keys, "`", Chr($VK_OEM_3))
    $keys = StringReplace($keys, "~", Chr($VK_OEM_3))
    $keys = StringReplace($keys, "-", Chr($VK_OEM_MINUS))
    $keys = StringReplace($keys, "=", Chr($VK_OEM_PLUS))
    $keys = StringReplace($keys, "{ENTER}", Chr(0xD))
    $keys = StringReplace($keys, "{TAB}", Chr(0x9))
    $keys = StringReplace($keys, "{ESC}", Chr($VK_ESC))
    $keys = StringReplace($keys, "{F5}", Chr($VK_F5))
    $keys = StringReplace($keys, "{F12}", Chr($VK_F12))
    $keys = StringReplace($keys, "{SHIFT}", "+")
    $keys = StringReplace($keys, ".", Chr($VK_Period))
    $keys = StringReplace($keys, ";", Chr($VK_SEMICOLON))
    ;$keys = StringReplace($keys, ":", chr($VK_SEMICOLON))
    Local $i, $ret
    Local $shiftdown = False
    For $i = 1 To StringLen($keys)
        If StringMid($keys, $i, 1) = "+" Then
            DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x100, "int", 0x10, "long", 0x002A0001)
            DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x100, "int", 0x10, "long", 0x402A0001)
            $shiftdown = True
            Sleep(1)
            ContinueLoop
        Else
            $ret = DllCall("user32.dll", "int", "MapVirtualKey", "int", Asc(StringMid($keys, $i, 1)), "int", 0)
            If IsArray($ret) Then
                DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x100, "int", Asc(StringMid($keys, $i, 1)), "long", _MakeLong(1, $ret[0]))
                Sleep(1)
                DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x101, "int", Asc(StringMid($keys, $i, 1)), "long", _MakeLong(1, $ret[0]) + 0xC0000000)
            EndIf
        EndIf
        If $shiftdown Then
            Sleep(1)
            DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x101, "int", 0x10, "long", 0xC02A0001)
            $shiftdown = False
        EndIf
    Next
    Return True
EndFunc 

Func _ArrowKey($hWnd, $key)
    If $hWnd <= 0 Or ($key <> "left" And $key <> "right" And $key <> "up" And $key <> "down") Then
        SetError(-1)
        Return
    EndIf
    Local $wParam, $lParam, $ret
    If $key = "left" Then
        $wParam = 0x25
        $lParam = 0x14B0001
    ElseIf $key = "right" Then
        $wParam = 0x27
        $lParam = 0x14D0001
    ElseIf $key = "down" Then
        $wParam = 0x28
        $lParam = 0x1500001
    ElseIf $key = "up" Then
        $wParam = 0x26
        $lParam = 0x1480001
    EndIf
    $ret = DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x100, "int", $wParam, "int", $lParam)
    If $ret[0] = 0 Then
        MsgBox(16, "_ArrowKey Error", "There was an error posting the WM_KEYDOWN message")
        SetError(-2)
        Return
    EndIf
    Sleep(2)
    $ret = DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, "int", 0x101, "int", $wParam, "int", ($lParam + 0xC0000000))
    If $ret[0] = 0 Then
        MsgBox(16, "_ArrowKey Error", "There was an error posting the WM_KEYUP message")
        SetError(-3)
        Return
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

I don't..quite understand what I do with that, sorry. I realized my autoit was kinda out of date, so I downloaded both of those versions and I didn't see _Postmessage anywhere..sooo I'm guessing that code IS _Postmessage. Sorry, but could you explain to me how I'd go about trying to use that? Do I save it in my autoit folder and then call it or something? Bare with me here I've never done anything but my own sloppy, and very basic, coding. :/

Share this post


Link to post
Share on other sites

I don't..quite understand what I do with that, sorry. I realized my autoit was kinda out of date, so I downloaded both of those versions and I didn't see _Postmessage anywhere..sooo I'm guessing that code IS _Postmessage. Sorry, but could you explain to me how I'd go about trying to use that? Do I save it in my autoit folder and then call it or something? Bare with me here I've never done anything but my own sloppy, and very basic, coding. :/

Copy and paste the codes and make an include file. Then call the functions.

Share this post


Link to post
Share on other sites

Most of your first post isn't clear to me.. Do you have any code to show?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Most of your first post isn't clear to me.. Do you have any code to show?

Sure, although I'm not having problems with my code really (As far as I know.) I'll show you so I can better explain my problem:

CODE
If $counter < 40 Then

Sleep(1000 * Random(10, 20, 1))

WinActivate("Sword of the New World")

send("{CTRLDOWN}")

Send("{SPACE}")

sleep(500)

$counter = $counter + 1

send("{CTRLUP}")

WinMinimizeAll()

Else

WinActivate("Sword of the New World")

send("z")

sleep(500)

$counter = 0

WinMinimizeAll()

EndIf

See how I have to constantly minimize then maximize the game before I can send keys? That is my problem. I can't just have the game's window on focus and send keys, it'll ONLY work if I do it like this. After doing a little more digging I'm pretty sure it's the game's anti-hacking program preventing me to send keys normally, but I'll try out this _Postmessage whenever I can. If that doesn't work...I dunno it doesn't seem like I can really optimize it any further.

Just to re-cap. My code is doing what I want it to do, it's just really inconvenient because that's the ONLY way it'll work, constantly minimizing and maximizing it so I can't even really watch the bot work or do anything else. Sorry for the bad explanation in the my first post I guess.

Edited by Jine

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