Ejemplo n.º 1
0
        public void Start(string overlayFolder, PatcherMessageCallback messageCallback, PatcherErrorCallback errorCallback)
        {
            this.Prefix           = overlayFolder;
            this._messageCallback = messageCallback;
            this._errorCallback   = errorCallback;
            this._thread          = new Thread(() =>
            {
                messageCallback?.Invoke("Starting patcher");
                this.PrintConfig();
                messageCallback?.Invoke("Looking for league process...");
                try
                {
                    while (true)
                    {
                        Process process = GetLeagueProcess();
                        if (process == null)
                        {
                            Thread.Sleep(3000);
                            continue;
                        }
                        messageCallback?.Invoke("Found League process");
                        bool offsetsUpdated = false;
                        using (LeagueProcess league = new LeagueProcess(process))
                        {
                            bool needsUpdate = NeedsUpdate(league);
                            if (process.WaitForInputIdle())
                            {
                                if (needsUpdate)
                                {
                                    messageCallback?.Invoke("Updating offsets");
                                    UpdateOffsets(league);
                                    offsetsUpdated = true;
                                    messageCallback?.Invoke("Offsets updated");
                                }
                                messageCallback?.Invoke("Patching League...");
                                Patch(league);
                            }
                            else
                            {
                                messageCallback?.Invoke("Failed to wait for idle input from process");
                            }
                        }
                        if (offsetsUpdated)
                        {
                            WriteConfig(_configPath);
                        }
                        process.WaitForExit();
                        Thread.Sleep(1000);
                        messageCallback?.Invoke("Looking for league process...");
                    }
                } catch (Exception exception)
                {
                    errorCallback?.Invoke(exception);
                }
            });

            this._thread.IsBackground = true; //Thread needs to be background so it closes when the parent process dies
            this._thread.Start();
        }
        public void Start(string overlayFolder, PatcherMessageCallback messageCallback, PatcherErrorCallback errorCallback)
        {
            this.Prefix           = overlayFolder;
            this._messageCallback = messageCallback;
            this._errorCallback   = errorCallback;

            this._thread = new Thread(delegate()
            {
                try
                {
                    messageCallback?.Invoke("Starting patcher");

                    while (true)
                    {
                        foreach (Process process in Process.GetProcessesByName("League of Legends"))
                        {
                            if (!IsLeague(process))
                            {
                                break;
                            }

                            messageCallback?.Invoke("Found League process");

                            bool offsetsUpdated = false;
                            using (LeagueProcess league = new LeagueProcess(process))
                            {
                                bool needsUpdate = NeedsUpdate(league);

                                if (process.WaitForInputIdle(PROCESS_IDLE_TIMEOUT))
                                {
                                    if (needsUpdate)
                                    {
                                        messageCallback?.Invoke("Updating offsets");

                                        UpdateOffsets(league);
                                        offsetsUpdated = true;
                                        messageCallback?.Invoke("Offsets updated");
                                    }

                                    messageCallback?.Invoke("Patching League...");
                                    Patch(league);
                                }
                                else
                                {
                                    messageCallback?.Invoke("Patcher timed out while waiting for idle input");
                                }
                            }

                            if (offsetsUpdated)
                            {
                                WriteConfig();
                            }

                            process.WaitForExit();
                            break;
                        }
                        Thread.Sleep(1000);
                    }
                }
                catch (Exception exception)
                {
                    errorCallback?.Invoke(exception);
                }
            });

            this._thread.IsBackground = true; //Thread needs to be background so it closes when the parent process dies
            this._thread.Start();
        }