Esempio n. 1
0
 protected override void OnClose()
 {
     _mapSelectorViewModel.RequestClose();
     CloseHeroSelectorWindows();
     OcrUtil?.Dispose();
     base.OnClose();
 }
Esempio n. 2
0
 internal void ReInitializeOcr()
 {
     try
     {
         OcrUtil.Initialize();
         OcrAvailable = true;
     }
     catch (Exception)
     {
         // ignored
     }
 }
Esempio n. 3
0
        private async Task LookForMap()
        {
            _hasLookedForMap = true;
            try
            {
                _scanningCancellationToken = new CancellationTokenSource();
                var map = await OcrUtil.LookForMap(_scanningCancellationToken.Token).ConfigureAwait(false);

                // false positive
                if (string.IsNullOrEmpty(map))
                {
                    Execute.OnUIThread(() => Reset());
                    return;
                }

                if (_scanningCancellationToken.IsCancellationRequested)
                {
                    return;
                }

                if (!IsAutoMode)
                {
                    Execute.OnUIThread(() => { BpScreenLoaded = true; });
                }

                Execute.OnUIThread(() => SwitchMapSelector(true, false));
                if (!string.IsNullOrEmpty(map))
                {
                    var mapInUi =
                        _mapSelectorViewModel.ItemsInfos.First(
                            m => m.Id == App.OcrMapInfos.First(om => om.Name == map).Code).Name;

                    Execute.OnUIThread(() => SelectMap(mapInUi));
                }

                await ScanBpAsync();
            }
            finally
            {
                _hasLookedForMap = false;
            }
        }
Esempio n. 4
0
        private async Task LookForBpScreen()
        {
            _scanningCancellationToken?.Cancel();
            // cancel the other thread
            MapOnlyCancellationToken?.Cancel();
            CancellationTokenSource currentCancellationToken;

            lock (LookForBpTokenLock)
            {
                MapOnlyCancellationToken = new CancellationTokenSource();
                currentCancellationToken = MapOnlyCancellationToken;
            }
            await OcrUtil.LookForBpScreen(MapOnlyCancellationToken.Token);

            if (!currentCancellationToken.IsCancellationRequested)
            {
                Execute.OnUIThread(() =>
                {
                    LoadMapUi();
                    if (!IsAutoMode)
                    {
                        BpScreenLoaded = true;
                    }
                });
            }
            else
            {
                return;
            }

            if (IsAutoMode)
            {
                _hasLookedForMap = true;
                if (currentCancellationToken.IsCancellationRequested)
                {
                    return;
                }

                await LookForMap().ConfigureAwait(false);
            }
        }
Esempio n. 5
0
        public BpViewModel(ViewModelFactory viewModelFactory, IEventAggregator eventAggregator, ISecurityProvider securityProvider, IRestApi restApi, IToastService toastService)
        {
            _viewModelFactory = viewModelFactory;
            _restApi          = restApi;
            _eventAggregator  = eventAggregator;
            _toastService     = toastService;
            _securityProvider = securityProvider;
            _eventAggregator.Subscribe(this);
            _scanningCancellationToken = new CancellationTokenSource();

            try
            {
                var folder        = @".\hashlist.json";
                var sourceContent = File.ReadAllText(folder);

                AllHero.HeroInfo = JsonConvert.DeserializeObject <List <EachHero> >(sourceContent);

                OcrUtil = new OcrUtil();
                OcrUtil.Initialize();
                OcrAvailable = true;
            }
            catch (Exception)
            {
                // ignored
            }

            var unitPos = App.AppSetting.Position.BpHelperPosition.ToUnitPoint();

            Left = unitPos.X;
            Top  = unitPos.Y;

            _heroSelectorWindowViewModel = _viewModelFactory.CreateViewModel <HeroSelectorWindowViewModel>();

            var filePath = @Path.Combine(App.AppPath, Const.LOCAL_WEB_FILE_DIR, "index.html#") + App.Language;

            LocalFileUri = filePath;

            WebCallbackListener.PresetRequested += WebCallbackListenerOnPresetRequested;
        }
Esempio n. 6
0
        private async Task OcrAsync(IEnumerable <int> steps, CancellationToken cancellationToken)
        {
            var stepToProcess = new List <int>();

            foreach (var i in steps)
            {
                if (ProcessingThreads.ContainsKey(i) && ProcessingThreads[i])
                {
                    continue;
                }

                if (HeroSelectorViewModels.Any(v => v.Id == i && v.Selected))
                {
                    continue;
                }

                stepToProcess.Add(i);
                ProcessingThreads[i] = true;
            }
            if (!stepToProcess.Any())
            {
                return;
            }

            try
            {
                if (stepToProcess[0] <= 6 && OcrUtil.IsInitialized)
                {
                    await OcrUtil.ScanLabelAsync(stepToProcess, this, OcrUtil.ScanSide.Left, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    await OcrUtil.ScanLabelAsync(stepToProcess, this, OcrUtil.ScanSide.Right, cancellationToken).ConfigureAwait(false);
                }
            }
            catch (Exception)
            {
                Logger.Trace("OcrAsync failed first attempt on {0}", string.Join(",", stepToProcess));
                try
                {
                    foreach (var i in stepToProcess)
                    {
                        ProcessingThreads[i] = false;
                    }

                    if (stepToProcess[0] <= 6 && OcrUtil.IsInitialized)
                    {
                        await OcrUtil.ScanLabelAsync(stepToProcess, this, OcrUtil.ScanSide.Left, cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        await OcrUtil.ScanLabelAsync(stepToProcess, this, OcrUtil.ScanSide.Right, cancellationToken).ConfigureAwait(false);
                    }
                }
                catch (Exception)
                {
                    Logger.Trace("OcrAsync failed 2nd attempt on {0}", string.Join(",", stepToProcess));
                    Execute.OnUIThread(() => { Reset(); });
                }
            }
            finally
            {
                foreach (var i in stepToProcess)
                {
                    ProcessingThreads[i] = false;
                }
            }
        }