Example #1
0
        private static Package CheckSemantics(PackageSyntax packageSyntax)
        {
            DeclarationNumberAssigner.AssignIn(packageSyntax.AllEntityDeclarations);

            // Resolve symbols for the entities
            EntitySymbolBuilder.BuildFor(packageSyntax);

            var stringSymbol = packageSyntax.SymbolTrees
                               .GlobalSymbols
                               .OfType <ObjectTypeSymbol>()
                               .SingleOrDefault(s => s.Name == "String");

            // Basic Analysis includes: Name Binding, Type Checking, Constant Folding
            BasicAnalyzer.Check(packageSyntax, stringSymbol);

            // If there are errors from the basic analysis phase, don't continue on
            packageSyntax.Diagnostics.ThrowIfFatalErrors();

#if DEBUG
            new SymbolValidator(packageSyntax.SymbolTree).Validate(packageSyntax.AllEntityDeclarations);
            new TypeFulfillmentValidator().Validate(packageSyntax.AllEntityDeclarations);
            new TypeKnownValidator().Validate(packageSyntax.AllEntityDeclarations);
            new ExpressionSemanticsValidator().Validate(packageSyntax.AllEntityDeclarations);
#endif

            var package = new ASTBuilder().BuildPackage(packageSyntax);

            // From this point forward, analysis focuses on executable declarations (i.e. invocables and field initializers)
            var executableDeclarations = package.AllDeclarations.OfType <IExecutableDeclaration>().ToFixedSet();

            ShadowChecker.Check(executableDeclarations, package.Diagnostics);

            DataFlowAnalysis.Check(DefiniteAssignmentAnalyzer.Instance, executableDeclarations, package.SymbolTree, package.Diagnostics);

            DataFlowAnalysis.Check(BindingMutabilityAnalyzer.Instance, executableDeclarations, package.SymbolTree, package.Diagnostics);

            DataFlowAnalysis.Check(UseOfMovedValueAnalyzer.Instance, executableDeclarations, package.SymbolTree, package.Diagnostics);

            // TODO use DataFlowAnalysis to check for unused variables and report use of variables starting with `_`

            // Compute variable liveness needed by reachability analyzer
            DataFlowAnalysis.Check(LivenessAnalyzer.Instance, executableDeclarations, package.SymbolTree, package.Diagnostics);

            ReachabilityAnalyzer.Analyze(executableDeclarations, package.SymbolTree, package.Diagnostics);

            // TODO remove live variables if SaveLivenessAnalysis is false

            return(package);
        }
Example #2
0
 public void Init()
 {
     _basicThoughts = new BasicAnalyzer();
 }
Example #3
0
        public void Start()
        {
            analyzer        = new BasicAnalyzer();
            referenceImages = new Dictionary <string, Bitmap>();
            State currentState = DefineStates();

            if (DEBUG_MODE)
            {
                Console.WriteLine("DEBUG MODE");
                Console.WriteLine("ESC - Close");
                Console.WriteLine("S - Save screenshot");
                Console.WriteLine("C - Show coordinates");
                Console.WriteLine("Enter - Run");
                Console.WriteLine("D - Run in debug mode (Press any key for next check)");
                Console.WriteLine("F - Save references");
                int savedImages = 0;
                while (true)
                {
                    ConsoleKey k = Console.ReadKey().Key;
                    Console.Write("\n");

                    if (k == ConsoleKey.Escape)
                    {
                        return;
                    }

                    if (k == ConsoleKey.T)
                    {
                        TesseractTest.Run();
                    }
                    else if (k == ConsoleKey.S)
                    {
                        Bitmap b = User32.CaptureApplication(PROCESS_NAME);
                        b.Save(PATH + "images\\saved\\saved_" + savedImages++ + ".png");
                        Console.WriteLine("Image saved");
                    }
                    else if (k == ConsoleKey.C)
                    {
                        Point p;
                        User32.GetCursorPos(out p);
                        Point p2 = ClickOnPointTool.GetWindowCoordinates(Process.GetProcessesByName("mobizen")[0].MainWindowHandle, p);
                        Console.WriteLine(p2);
                    }
                    else if (k == ConsoleKey.Enter)
                    {
                        break;
                    }
                    else if (k == ConsoleKey.D)
                    {
                        RUN_DEBUG = true;
                        break;
                    }
                    else if (k == ConsoleKey.F)
                    {
                        foreach (var pattern in Pattern.All)
                        {
                            pattern.reference.Save(PATH + "images\\references\\" + pattern.name + ".png");
                        }

                        Console.WriteLine("References saved");
                    }
                }
            }

            Console.Write("Repeat: ");
            string repeat      = Console.ReadLine();
            int    maxDungeons = 0;

            int.TryParse(repeat, out maxDungeons);

            Comparer c      = new Comparer();
            bool     active = true;

            while (active)
            {
                if (RUN_DEBUG)
                {
                    ConsoleKey k = Console.ReadKey().Key;
                }
                else
                {
                    Thread.Sleep(currentState.cooldown * 1000);
                }

                Bitmap screen = User32.CaptureApplication(PROCESS_NAME);
                Console.WriteLine("Checking...");
                foreach (Road r in currentState.roads)
                {
                    if (r.pattern != null && r.pattern.reference != null && c.IsValid(r.pattern, screen))
                    {
                        Console.WriteLine("Found pattern");
                        if (r.clickX != 0 || r.clickY != 0)
                        {
                            if (r.wait > 0)
                            {
                                Thread.Sleep(r.wait * 1000);
                            }

                            Execute(r, screen);
                        }

                        // waits a second
                        Thread.Sleep(1000);

                        Console.WriteLine("Changing to " + r.destination.name);

                        // Counts dungeons completed
                        if (r.destination.name.Equals("Team selection") &&
                            !currentState.name.Equals("Energy shop leave"))
                        {
                            completedDungeons++;
                            Console.WriteLine("Dungeons completed: " + completedDungeons);

                            if (maxDungeons > 0 && completedDungeons >= maxDungeons)
                            {
                                Console.WriteLine("Maximum amount of dungeons reached");
                                active = false;
                            }
                        }

                        currentState = r.destination;

                        break;
                    }
                }
            }

            Console.WriteLine("VenomSW is done working, press any key to exit.");
            Console.ReadKey();
        }