Exemplo n.º 1
0
        private static async Task <string> ReadToOutput(StreamReader reader, ScriptOutput output, ConsoleColor color)
        {
            var builder = new StringBuilder();

            while (!reader.EndOfStream)
            {
                var line = await reader.ReadLineAsync();

                builder.AppendLine(line);
                output?.AppendLine(line, color);
            }

            return(builder.ToString());
        }
Exemplo n.º 2
0
        // Returns 'true' if more commands can be immediately processed
        // Returns 'false' if we should wait until the next tick to process more commands
        bool ProcessScriptCommand(string command, int lineNumber)
        {
            /*
             *  Var/Num/0
             *  Var/AutoClickDuration/600
             *  Label/Start
             *  Recording/Level Up and Buy Upgrades.mou
             *  Recording/Advance Level and Toggle Progression Mode.mou
             *  Recording/UseSkills.mou
             *  Recording/MoveToCenter.mou
             *  AutoClick/%AutoClickDuration%
             *  Math/Num/Num/+/1
             *  Compare/%Num%/</10
             *  JumpIf/Start
             *  Jump/End
             *  Label/End
             */
            bool canProcessMoreCommands = true;     // most commands can be processed on the same update

            UpdateConstants();
            string[] args = GetArgsFromScriptCommand(command);

            LineNumberDisplay.Value = lineNumber;
            string debugOutputLine = lineNumber.ToString();

            foreach (string arg in args)
            {
                debugOutputLine += "/" + arg;
                string trimmedArg = arg.Trim();
                if (m_scriptVariables.ContainsKey(trimmedArg))
                {
                    string value = m_scriptVariables[trimmedArg];
                    debugOutputLine += "(" + value + ")";
                }
            }
            string timeString = string.Format("{0:0.00}", (DateTime.Now - m_scriptStartTime).TotalSeconds);

            m_scriptOutput.AppendLine(timeString + " - " + debugOutputLine);

            try
            {
                if (args.Length >= 2)
                {
                    switch (args[0].ToLower())
                    {
                    case "var":
                        string val = (args.Length >= 3) ? args[2] : "";
                        SetScriptVariable(args[1], val);
                        break;

                    case "label":
                        // No processing needs to be done for labels
                        break;

                    case "math":
                        if (args.Length >= 5)
                        {
                            string computedValue = PerformScriptMath(args[2], args[3], args[4]);
                            SetScriptVariable(args[1], computedValue);
                        }
                        break;

                    case "compare":
                        if (args.Length >= 4)
                        {
                            m_lastComparison = ScriptCompare(args[1], args[2], args[3]);
                        }
                        break;

                    case "recording":
                        LoadRecordingFromFile(args[1]);
                        HK_StartPlayback();
                        canProcessMoreCommands = false;
                        break;

                    case "autoclick":
                        double autoClickDurationInSeconds = 0.0;
                        if (GetScriptDouble(args[1], out autoClickDurationInSeconds))
                        {
                            HK_StartAutoClicking();
                            m_scriptTimeToStopAutoClicking = DateTime.Now.AddSeconds(autoClickDurationInSeconds);
                        }
                        canProcessMoreCommands = false;
                        break;

                    case "jump":
                    {
                        int nextInstruction = 0;
                        if (GetLineNumberFromJumpParam(args[1], out nextInstruction))
                        {
                            m_scriptNextLine = nextInstruction;
                        }
                    }
                    break;

                    case "jumpif":
                        if (m_lastComparison == true)
                        {
                            int nextInstruction = 0;
                            if (GetLineNumberFromJumpParam(args[1], out nextInstruction))
                            {
                                m_scriptNextLine = nextInstruction;
                            }
                        }
                        break;

                    case "clickcandy":
                        List <SubImageSearchResult> candy = FindCandy();
                        List <Point> pointsToClick        = GetScreenPositionsFromSubImageSearchResults(candy);
                        bool         startedAnAction      = PerformOneOffMouseClicks(pointsToClick);
                        canProcessMoreCommands = (startedAnAction == false);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                string outputMessage = "===============================================================================\r\n";
                outputMessage += "Exception while processing script!\r\n";
                outputMessage += "Line = " + lineNumber + "\r\n";
                outputMessage += "Command = " + debugOutputLine + "\r\n";
                outputMessage += e.Message + "\r\n";
                outputMessage += "===============================================================================\r\n";
                m_scriptOutput.AppendLine(outputMessage);
                canProcessMoreCommands = false;
                CancelPlayingScript();
            }

            return(canProcessMoreCommands);
        }