static void Main(string[] args)
        {
            Logger.OnStartup();

            Logger.Write("Loading LeagueBot...");

            Configuration.LoadConfig();

            PatternsManager.Initialize();

            PixelCache.Initialize();

            TextRecognition.Initialize();

            try
            {
                LeagueManager.ApplySettings();
            }
            catch
            {
                Logger.Write("Unable to set league of legends settings. (Probably due to permission restrictions.)", MessageState.WARNING);
            }

            HandleCommand();

            Console.Read();
        }
Esempio n. 2
0
        public void Setup(string fileName)
        {
            Repository = new Repository();
            Repository.Load();
            _window = Substitute.For <IEmulatorWindow>();
            var settings      = Substitute.For <ISettings>();
            var recognition   = new TextRecognition();
            var loggerFactory = Substitute.For <ILoggerFactory>();

            _videoProvider = Substitute.For <IVideoProvider>();
            Game           = new GameImpl(_window, _videoProvider, Repository, loggerFactory, recognition, settings);
#if DEBUG
            Settings.SaveImages    = true;
            Settings.SaveRawImages = true;
#endif

            using var bitmap = new Bitmap(fileName);
            _window.Width.Returns(bitmap.Width);
            _window.Height.Returns(bitmap.Height);
            _window.GrabScreen(Arg.Any <int>(), Arg.Any <int>(), Arg.Any <int>(), Arg.Any <int>())
            .Returns(info =>
            {
                using var bitmapLocal = new Bitmap(fileName);
                return(bitmapLocal.Crop(info.ArgAt <int>(0), info.ArgAt <int>(1), info.ArgAt <int>(2), info.ArgAt <int>(3)));
            });
            _videoProvider.GetCurrentFrame().Returns(info => bitmap);
        }
Esempio n. 3
0
        public void leftClickText(string text)
        {
            if (TextRecognition.TextExists(text))
            {
                Point coords = TextRecognition.TextCoords(text);

                Mouse.Move(coords.X, coords.Y);
                Mouse.PressButton(Mouse.MouseKeys.Left, 150);
            }
        }
Esempio n. 4
0
        public void waitForText2(string processName, string text)
        {
            bool exists = TextRecognition.TextExists2(processName, text);

            while (!exists)
            {
                Thread.Sleep(1000);
                exists = TextRecognition.TextExists2(processName, text);
            }
        }
Esempio n. 5
0
        public void waitForText(string text)
        {
            bool exists = TextRecognition.TextExists(text);

            while (!exists)
            {
                exists = TextRecognition.TextExists(text);
                Thread.Sleep(1000);
            }
        }
Esempio n. 6
0
        public static void WaitForText(int x, int y, int width, int heigth, string text)
        {
            Rectangle rect = new Rectangle(x, y, width, heigth);

            bool exists = TextRecognition.TextExists2(rect, text);

            while (!exists)
            {
                BotHelper.Wait(1000);
                exists = TextRecognition.TextExists2(rect, text);
            }
        }
Esempio n. 7
0
        internal static int GetTextFromImage(int x, int y, int width, int heigth)
        {
            Rectangle rect;

            try
            {
                rect = new Rectangle(x, y, width, heigth);
            }
            catch
            {
                return(0);
            }
            return(TextRecognition.GetTextValue(rect));
        }
Esempio n. 8
0
        public static bool TextExists(int x, int y, int width, int heigth, string text)
        {
            bool exist;

            try
            {
                exist = TextRecognition.TextExists2(new Rectangle(x, y, width, heigth), text);
            }
            catch
            {
                exist = false;
            }

            return(exist);
        }
Esempio n. 9
0
 public static bool TextExists(int x, int y, int width, int heigth, string text)
 {
     return(TextRecognition.TextExists2(new Rectangle(x, y, width, heigth), text));
 }
Esempio n. 10
0
        private void ConfigureSerivces(ServiceCollection serviceCollection)
        {
            var            uiLogger      = new CustomUiLoggerProvider();
            ILoggerFactory loggerFactory = LoggerFactory.Create(
                (builder) =>
            {
                builder
                .AddProvider(new CustomConsoleProvider())
                .AddProvider(new CustomTraceProvider())
                .AddProvider(uiLogger)
                .SetMinimumLevel(LogLevel.Debug);
            });

            Directory.CreateDirectory("Settings");
            var path = Path.Combine("Settings", "config.json");

            var setupDefaultConfig = !File.Exists(path);

            var settings = new ConfigurationBuilder <ISettings>()
                           .UseJsonFile(path).
                           Build();

            if (setupDefaultConfig)
            {
                SetupDefaultConfiguration(settings);
            }
            else
            {
                EnsureValidValues(settings);
            }

            serviceCollection.AddSingleton(settings);

            var recognition = new TextRecognition();

            var executioner   = new TaskExecutioner(loggerFactory.CreateLogger <TaskExecutioner>());
            var window        = SetupWindow(settings, loggerFactory, recognition);
            var videoProvider = new VideoProvider(window, settings.VideoCapture.FrameRate);

            serviceCollection.AddSingleton <IVideoProvider>(videoProvider);
            serviceCollection.AddSingleton <IVideoCapture, VideoCapture>();

            var repository = new Repository();

            repository.Load();
            var game = new GameImpl(window, videoProvider, repository, loggerFactory, recognition, settings);

            var overlay = new ImGuiOverlay(game, window, repository);

            if (settings.EnableOverlay)
            {
                //circular dependency. find better solution.
                game.Overlay = overlay;
                overlay.Setup();
            }
            serviceCollection.AddSingleton <IEmulatorOverlay>(overlay);

            var picker = new AreaPicker(window, overlay);

            serviceCollection.AddSingleton <ITaskExecutioner>(executioner);
            serviceCollection.AddSingleton <ITaskQueue>(executioner);
            serviceCollection.AddSingleton <IGame>(game);
            serviceCollection.AddSingleton <IAreaPicker>(picker);
            serviceCollection.AddSingleton <IUiRepository>(repository);
            serviceCollection.AddSingleton(window);
            serviceCollection.AddSingleton <IUiLogger>(uiLogger);
            ViewModelLocator.ConfigureServices(serviceCollection);

            if (settings.EnableOverlay)
            {
                Dispatcher.BeginInvoke(async() => await UpdateOverlay(overlay));
            }
        }
Esempio n. 11
0
 public bool textExists(string processName, string text)
 {
     return(TextRecognition.TextExists2(processName, text));
 }