Sign in to follow this  
Followers 0
gamerman2360

Overcomplication

3 posts in this topic

#1 ·  Posted (edited)

First I made a simple script and all. But then it expanded when I wanted to add a simple feature(default value in the InputBox, after the script has restarted). I decided to post it because of all the Std stuff. I've never really worked with Std before. Are there any other examples about in/out in autoit? I've also tried to hide the game it's for. Tell me if you see anything that can give that away.

#cs
Discription: Overcomplication..
AU3Check: 4 error(s) and 1 warning(s) :)
Development stage: Gold(It works)
Author: gamerman2360
#ce
Global $username = "***********", $password = ""; password really isn't a good idea

#include <misc.au3>; Needed for _isPressed()
For $i = 1 To $CmdLine[0]
    Switch $CmdLine[$i]
        Case "/restarted"
            Assign("___restarted", "", 2)
            Dim $params[1][2]
            Dim $msgRemains
            ConsoleWrite("Ready"&@CRLF)
            While 1
                $StdTimer = TimerInit()
                Do
                    Sleep(100)
                    If TimerDiff($StdTimer) > 15000 Then ExitLoop 2; :(
                Until ConsoleRead(Default, True)
                $msg = ConsoleRead()
                $msg = StringSplit($msgRemains & $msg, @CRLF, 1)
                For $j = 1 To $msg[0]-1
                    Switch $msg[$j]; keywords
                        Case "Done"
                            ExitLoop 2
                    EndSwitch
                    If StringInStr($msg[$j], ":=") Then; assign vars
                        $nameOffset = StringInStr($msg[$j], ":=")
                        ReDim $params[UBound($params)+1][2]
                        $params[0][0] += 1
                        $params[$j][0] = StringLeft($msg[$j], $nameOffset-1)
                        $params[$j][1] = StringTrimLeft($msg[$j], $nameOffset+1)
                    EndIf
                Next
                $msgRemains = $msg[$msg[0]]
            WEnd
            For $j = 1 To $params[0][0]
                If $params[$j][0] == "left" Then $left = $params[$j][1]
            Next
    EndSwitch
Next
ToolTip("Current HotKeySet()s"&@CRLF& _
        "{ESC}: _restart(""/left ""&$left)"&@CRLF& _
        "{F3}: Send("""&$username&"{enter}[********]"")"&@CRLF& _
        "{F9}: Send(""buying *****, 100ea - "&$username&""")"&@CRLF& _
        "{F10}: Send(""selling ******, 200ea - "&$username&""")"&@CRLF& _
        ""&@CRLF& _
        "Current _IsPressed()s"&@CRLF& _
        "04(Middle mouse): Send(""28{enter}"") && AdlibEnable(""Timer"", 99)"&@CRLF& _
        "[_IsPressed() is checked ten times a second.]", _
        10, 10)
Do
    $left = InputBox("Left", "How many are left?", $left)
Until $left Or @error
$left = Number(Execute($left))
If Not IsInt($left) Then $left = Int($left)+1; Round up or Math.Ceiling()
If Not $left Then $left = ""
ToolTip($left, 10, 10); Confirm input
Global $cooldown, $msg, $timer

While 1
    If _IsPressed("04", $user32) Then Function("04")
    Sleep(100)
WEnd

Func Function($var)
    If Not IsDeclared("cooldown") Then Return; HotKey press during InputBox
    If TimerDiff($cooldown) < 3000 And @HotKeyPressed <> "{ESC}" Then Return; Only allow every 3s
    $cooldown = TimerInit()
    If IsDeclared("var") Then; From _IsPressed()
        Switch $var
            Case "04"; 04 Middle mouse button (three-button mouse)
                Send("28{enter}")
                If $left Then
                    $left -= 1
                    Global $msg = $left & " left." & @CRLF
                    If Not $left Then Global $msg = ""
                EndIf
                Global $timer = TimerInit()
                AdlibEnable("Timer", 99); One lower then lowest countdown interval(millisecond rounded to the tenth of a second)
        EndSwitch
    Else; From HotKeySet()
        Switch @HotKeyPressed
            Case "{ESC}"; Invoke when $left needs to be changed
                HotKeySet("{ESC}")
                HotKeySet("{F3}")
                HotKeySet("{F9}")
                HotKeySet("{F10}")
                $append = " /restarted"
                If IsDeclared("___restarted") Then $append = ""
                $program = _restart($append, 7); don't use the CMD too many times, use IO instead
                $msgRemains = ""
                While 1
                    $StdTimer = TimerInit()
                    Do
                        Sleep(100)
                        If TimerDiff($StdTimer) > 15000 Then ExitLoop 2; :(
                    Until StdoutRead($program, Default, True)
                    $msg = StdoutRead($program)
                    $msg = StringSplit($msgRemains & $msg, @CRLF, 1)
                    For $j = 1 To $msg[0]-1
                        Switch $msg[$j]; keywords
                            Case "Ready"
                                ExitLoop 2
                        EndSwitch
                    Next
                    $msgRemains = $msg[$msg[0]]
                WEnd
                StdinWrite($program, "left:="&$left&@CRLF)
                StdinWrite($program, "Done"&@CRLF)
                Exit
            Case "{F3}"; Not a good idea, could be pressed accidentally; also passwords in scripts are unsafe
                Send($username&"{enter}"&$password)
            Case "{F9}"
                Send("buying *****, 100ea - "&$username)
            Case "{F10}"
                Send("selling *****, 200ea - "&$username)
        EndSwitch
    EndIf
EndFunc

Func Timer(); Countdown and ToolTip()
    $time = Round(-1*(TimerDiff($timer)-51000)/1000, 1)
    If IsInt($time) Then $time &= ".0"
    ToolTip($msg & $time, 10, 10)
    If $time <= 0 Then Return ToolTip(StringTrimRight($msg, 2), 10, 10) & AdlibDisable() & DllCall($user32, "none", "MessageBeep", "int", 0x40)
EndFunc

Func _restart($appendCmd = "", $IOFlag = Default)
    If @Compiled Then
        $pid = Run($CmdLineRaw&$appendCmd, @WorkingDir, Default, $IOFlag)
    Else
        $pid = Run(@AutoItExe&" "&$CmdLineRaw&$appendCmd, @WorkingDir, Default, $IOFlag)
    EndIf
    If @error Then
        $msg = MsgBox(0x135, Default, "Couldn't restart the program.")
        If $msg == 4 Then $pid = _restart($appendCmd, $IOFlag)
    EndIf
    Return $pid
EndFunc

Func OnAutoItStart()
    Global $user32 = DllOpen("user32.dll"), $left; Alwas declare the global vars used in OnAutoItExit() here
    Opt("OnExitFunc", "OnAutoItExit"); If ever encoded
    Opt("RunErrorsFatal", 0)
    Opt("TrayIconDebug", 1)
    If Not HotKeySet("{ESC}", "Function") Then Exit 1
    If Not HotKeySet("{F3}", "Function") Then Exit 1
    If Not HotKeySet("{F9}", "Function") Then Exit 1
    If Not HotKeySet("{F10}", "Function") Then Exit 1
EndFunc

Func OnAutoItExit()
    ToolTip("")
    DllClose($user32)
    Switch @exitMethod
        Case 1
            If @exitCode Then; already running
                Send("{ESC}"); restart
            EndIf
        Case 2
            If $left Then
                ToolTip("Maybe next time.")
                Sleep(5000)
                ToolTip("")
            EndIf
    EndSwitch
EndFunc
The script passes through the Std functions the following: when it's ready, when it's done, and any params it wants to pass. If you want to skip to it, they are around when it check the CmdLine var and when it checkes if @HotKeyPressed equals "{ESC}".

Edited by gamerman2360

Share this post


Link to post
Share on other sites



Standard streams are especially useful when you are working cross-language. Like writing data to a C/Cpp console. You said you wanted to use a default value in your inputbox, why not use a IniWrite and IniRead? That would only require one additional line of code. Example:

$i = InputBox("","", IniRead("Filename.ini", "section", "key", ""))
IniWrite("Filename.ini", "section", "key", $i)

Share this post


Link to post
Share on other sites

Standard streams are especially useful when you are working cross-language. Like writing data to a C/Cpp console. You said you wanted to use a default value in your inputbox, why not use a IniWrite and IniRead? That would only require one additional line of code. Example:

$i = InputBox("","", IniRead("Filename.ini", "section", "key", ""))
IniWrite("Filename.ini", "section", "key", $i)
I know about the Ini functions. I could have done it a many number of ways. Including setting the value of the input box's control using ControlSetText(). Or have the new script search for the "x left." tooltip window. This just happenes to be the only thing I havn't tried :whistle: .

I'll keep that cross-language thing in mind when I start to learn C++. Is there a special way to form the data sent in the stream? The only reason mine dosn't work all the time is because text that included the characters 10 and 13(@CRLF) would be split incorrectly. Maybe I should use the EOT character.. But that still wouldn't work for binary information.

Thanks for posting. I was starting to think no one would post. again : (

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