Пример #1
0
        public void StartApp(Action <object> callback)
        {
            Task.Run(() =>
            {
                var listener   = new GameEventListener(this._configuration.GameHookPort);
                var transpiler = new MessageTranspiler();
                var injector   = new LeagueInjectionManager();

                var path = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\{EntryPoint.InjectionDll}";
                if (!injector.Inject(path))
                {
                    Console.Error.WriteLine("league appears to not be running (or injection failed)!");
                    callback?.Invoke(false);
                    return;
                }

                this._hookListenerTask = Task.Run(() =>
                {
                    this.Log?.Invoke("started listening task for league hook...");

                    while (!this._tokenSource.IsCancellationRequested)
                    {
                        var rawMessage = listener.GetMessage();
                        var messages   = transpiler.Translate(rawMessage);
                        foreach (var message in messages)
                        {
                            this._stateManager.UpdateState(message);
                        }
                    }
                },
                                                  this._tokenSource.Token);

                this._predictionTask = Task.Run(async() =>
                {
                    try
                    {
                        this.Log?.Invoke("started task for sending predictions...");

                        while (!this._tokenSource.IsCancellationRequested)
                        {
                            await Task.Delay(1000, this._tokenSource.Token);

                            var result     = await this._networkInterface.GetPrediction(this._stateManager.GameState);
                            this.WinChance = result?.team1 ?? .5;
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                },
                                                this._tokenSource.Token);

                callback?.Invoke(true);
            });
        }