Ejemplo n.º 1
0
 public IRelogWorker DoWork(Account account)
 {
     if (Check(account))
     {
         try
         {
             Process[] processes;
             if (account.UseCustomGW2Path == true)
             {
                 processes = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(account.CustomGW2Path));
             }
             else
             {
                 processes = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(Config.Singleton.GeneralSettings.GW2Path));
             }
             if (processes.Any(p => p.Id == account.PID))
             {
                 _done = GW2MinionLauncher.KillInstance(account.PID);
             }
             Thread.Sleep(3000);
         }
         catch
         {
         }
     }
     return(this);
 }
Ejemplo n.º 2
0
        private bool CheckIfProcessAlreadyExists(IEnumerable <Process> gw2Processes, Account account, bool attached,
                                                 ref uint newPID)
        {
            foreach (Process p in gw2Processes)
            {
                if (GW2MinionLauncher.GetAccountName((uint)p.Id) == account.LoginName)
                {
                    Logger.LoggingObject.Log(ELogType.Verbose,
                                             LanguageManager.Singleton.GetTranslation(
                                                 ETranslations.StartWorkerFoundWantedProcess),
                                             account.LoginName);
                    try
                    {
                        Logger.LoggingObject.Log(ELogType.Verbose,
                                                 LanguageManager.Singleton.GetTranslation(
                                                     ETranslations.StartWorkerAttachingTo),
                                                 account.LoginName, account.BotPath + "\\GW2MinionLauncherDLL.dll");
                        attached = GW2MinionLauncher.AttachToPid((uint)p.Id, Config.Singleton.GeneralSettings.UseBeta);
                    }
                    catch (Exception ex)
                    {
                        Logger.LoggingObject.Log(ELogType.Critical, ex.Message);
                    }
                    newPID = (uint)p.Id;

                    account.SetLastStartTime(DateTime.Now);
                    account.SetShouldBeRunning(true);
                }
            }
            return(attached);
        }
Ejemplo n.º 3
0
        public static bool CheckVersionBot()
        {
            const string remoteUri = "http://patcher.gw2.mmominion.com/Gw2MinionFiles/";
            const string fileName  = "GameVersion.txt";

            try
            {
                var myWebClient = new WebClient
                {
                    Proxy       = null,
                    CachePolicy =
                        new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore)
                };
                uint minionVersion = Convert.ToUInt32(myWebClient.DownloadString(remoteUri + fileName));
                uint apiVer        = GW2MinionLauncher.BuildNumberFromApi();
                if (minionVersion != apiVer)
                {
                    return(false);
                }
                return(true);
            }
            catch
            {
                return(true);
            }
        }
 private static void UpdateProcessIdForMatchingScheduler(Process gw2Process)
 {
     if (Config.Singleton.AccountSettings.All(a => a.PID != gw2Process.Id))
     {
         string  name   = GW2MinionLauncher.GetAccountName((uint)gw2Process.Id);
         Account wanted =
             Config.Singleton.AccountSettings.FirstOrDefault(a => a.LoginName == name);
         if (wanted != null)
         {
             wanted.SetPID((uint)gw2Process.Id);
             wanted.SetLastStartTime(DateTime.Now);
         }
     }
 }
Ejemplo n.º 5
0
 public IObject DoWork()
 {
     try
     {
         if (Process != null && !Process.HasExited)
         {
             GW2MinionLauncher.KillInstance((uint)Process.Id);
             Thread.Sleep(3000);
         }
     }
     catch (Exception)
     {
     }
     Update();
     return(this);
 }
 public IObject DoWork()
 {
     if (!Process.HasExited)
     {
         try
         {
             GW2MinionLauncher.KillInstance((uint)Process.Id);
             Thread.Sleep(3000);
         }
         catch
         {
         }
     }
     Update();
     return(this);
 }
Ejemplo n.º 7
0
 public IRelogWorker DoWork(Account account)
 {
     if (Check(account))
     {
         try
         {
             Process[] processes = Process.GetProcessesByName("GW2");
             if (processes.Any(p => p.Id == account.PID))
             {
                 _done = GW2MinionLauncher.KillInstance(account.PID);
             }
             Thread.Sleep(3000);
         }
         catch
         {
         }
     }
     return(this);
 }
 public InstanceThread()
 {
     _instanceThread = new Thread(DoWork)
     {
         IsBackground = true,
     };
     _delay                 = 0;
     _needDelay             = false;
     _isRunning             = false;
     _keepAlive             = false;
     _enableViewStateChecks = true;
     try
     {
         _buildNumber = GW2MinionLauncher.BuildNumberFromApi();
     }
     catch
     {
         _buildNumber = 0;
     }
 }
Ejemplo n.º 9
0
 private uint CreateNewProcess(bool attached, Account account, ref uint newPID)
 {
     if (!attached)
     {
         try
         {
             try
             {
                 Logger.LoggingObject.Log(ELogType.Verbose,
                                          LanguageManager.Singleton.GetTranslation(
                                              ETranslations.StartWorkerLaunchingInstance),
                                          account.LoginName,
                                          account.BotPath + "\\MinionFiles\\GW2MinionLauncherDLL.dll");
                 string directory = Config.Singleton.GeneralSettings.GW2Path.Replace("GW2.exe", "");
                 if (Directory.Exists(directory))
                 {
                     if (File.Exists(directory + "ArenaNet.log"))
                     {
                         File.Delete(directory + "ArenaNet.log");
                     }
                     if (File.Exists(directory + "Crash.dmp"))
                     {
                         File.Delete(directory + "Crash.dmp");
                     }
                 }
                 if (Directory.Exists(directory))
                 {
                     if (File.Exists(directory + "ArenaNet.log"))
                     {
                         File.Delete(directory + "ArenaNet.log");
                     }
                     if (File.Exists(directory + "Crash.dmp"))
                     {
                         File.Delete(directory + "Crash.dmp");
                     }
                 }
                 string mydocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                 if (Directory.Exists(mydocuments))
                 {
                     if (Directory.Exists(mydocuments + "\\Guild Wars 2"))
                     {
                         if (File.Exists(mydocuments + "\\Guild Wars 2\\" + "ArenaNet.log"))
                         {
                             File.Delete(mydocuments + "\\Guild Wars 2\\" + "ArenaNet.log");
                         }
                         const string filesToDelete = @"*Corrupt*.dat";
                         string[]     fileList      = Directory.GetFiles(mydocuments + "\\Guild Wars 2", filesToDelete);
                         foreach (string file in fileList)
                         {
                             File.Delete(file);
                         }
                     }
                 }
                 string pwd = account.Password;
                 if (!pwd.Contains(@""""))
                 {
                     pwd = @"""" + pwd + @"""";
                 }
                 if (!account.AttachBot2)
                 {
                     newPID = GW2MinionLauncher.LaunchAccount(Config.Singleton.GeneralSettings.GW2Path,
                                                              account.LoginName, pwd, account.NoSound,
                                                              Config.Singleton.GeneralSettings.UseBeta);
                 }
                 else
                 {
                     newPID = GW2MinionLauncher.LaunchGW(Config.Singleton.GeneralSettings.GW2Path,
                                                         account.LoginName, pwd, false, account.NoSound);
                 }
             }
             catch (Exception ex)
             {
                 Logger.LoggingObject.Log(ELogType.Error, ex.Message);
             }
             account.SetLastStartTime(DateTime.Now);
             account.SetShouldBeRunning(true);
         }
         catch (DllNotFoundException ex)
         {
             Logger.LoggingObject.Log(ELogType.Error, ex.Message);
         }
         catch (BadImageFormatException ex)
         {
             Logger.LoggingObject.Log(ELogType.Error, ex.Message);
         }
     }
     return(newPID);
 }
        public void DoWork()
        {
            while (_keepAlive)
            {
                while (_isRunning)
                {
                    try
                    {
                        if (_needDelay)
                        {
                            Thread.Sleep(_delay);
                        }

                        foreach (Account account in Config.Singleton.AccountSettings.ToArray())
                        {
                            var results = new List <ComponentResult>();
                            foreach (
                                ComponentClass component in
                                ComponentManager.Singleton.GetComponents().ToArray().Where(c => c.IsEnabled))
                            {
                                var result = new ComponentResult();
                                component.Component.DoWork(account, ref result);
                                results.Add(result);
                            }
                            if (results.Any(r => r.Result == EComponentResult.KillForced))
                            {
                                if (Config.Singleton.GeneralSettings.ExtensiveLogging)
                                {
                                    foreach (
                                        ComponentResult componentResult in
                                        results.Where(r => r.Result == EComponentResult.KillForced))
                                    {
                                        Logger.LoggingObject.Log(ELogType.Debug, componentResult.LogMessage,
                                                                 account.LoginName);
                                    }
                                }
                                new KillWorker().DoWork(account).Update(account);
                            }
                            else if (results.Any(r => r.Result == EComponentResult.HaltForced))
                            {
                                if (Config.Singleton.GeneralSettings.ExtensiveLogging)
                                {
                                    foreach (
                                        ComponentResult componentResult in
                                        results.Where(r => r.Result == EComponentResult.HaltForced))
                                    {
                                        Logger.LoggingObject.Log(ELogType.Debug, componentResult.LogMessage,
                                                                 account.LoginName);
                                    }
                                }
                                account.SetLastStopTime(DateTime.Now);
                            }
                            else if (results.Any(r => r.Result == EComponentResult.StartForced))
                            {
                                if (Config.Singleton.GeneralSettings.ExtensiveLogging)
                                {
                                    foreach (
                                        ComponentResult componentResult in
                                        results.Where(r => r.Result == EComponentResult.StartForced))
                                    {
                                        Logger.LoggingObject.Log(ELogType.Debug, componentResult.LogMessage,
                                                                 account.LoginName);
                                    }
                                }
                                new StartWorker().DoWork(account);
                            }
                            else if (results.Any(r => r.Result == EComponentResult.ContinueForced))
                            {
                            }
                            else if (results.Any(r => r.Result == EComponentResult.Kill))
                            {
                                if (Config.Singleton.GeneralSettings.ExtensiveLogging)
                                {
                                    foreach (
                                        ComponentResult componentResult in
                                        results.Where(r => r.Result == EComponentResult.Kill))
                                    {
                                        Logger.LoggingObject.Log(ELogType.Debug, componentResult.LogMessage,
                                                                 account.LoginName);
                                    }
                                }
                                new KillWorker().DoWork(account).Update(account);
                            }
                            else if (results.Any(r => r.Result == EComponentResult.Halt))
                            {
                                if (Config.Singleton.GeneralSettings.ExtensiveLogging)
                                {
                                    foreach (
                                        ComponentResult componentResult in
                                        results.Where(r => r.Result == EComponentResult.Halt))
                                    {
                                        Logger.LoggingObject.Log(ELogType.Debug, componentResult.LogMessage,
                                                                 account.LoginName);
                                    }
                                }
                            }
                            else if (results.Any(r => r.Result == EComponentResult.Start))
                            {
                                if (VersionControl.CheckVersionBot())
                                {
                                    new StartWorker().DoWork(account).Update(account);
                                }
                                else
                                {
                                    VersionControl.Update();
                                }
                            }
                            else if (results.Any(r => r.Result == EComponentResult.Continue))
                            {
                            }
                            else if (results.Any(r => r.Result == EComponentResult.Ignore))
                            {
                            }
                            else if (results.Any(r => r.Result == EComponentResult.Default))
                            {
                            }
                        }
                        User32.EnumWindows(EnumTheWindows, IntPtr.Zero);

                        IEnumerable <Process> gw2Processes = UpdateListWithRemainingGW2Processes();

                        if (_checkAll || Config.Singleton.GeneralSettings.PollingDelay >= 60)
                        {
                            Process[] enumerable = gw2Processes as Process[] ?? gw2Processes.ToArray();
                            foreach (Process gw2Process in enumerable)
                            {
                                UpdateProcessIdForMatchingScheduler(gw2Process);
                                if (!gw2Process.Responding)
                                {
                                    if (FrozenGW2Windows.All(p => p.Key.Id != gw2Process.Id))
                                    {
                                        AddUnresponsiveProcessToTheList(gw2Process);
                                    }
                                    else
                                    {
                                        GetRidOfProcessesThatHaveBeenFrozenForLong(gw2Process);
                                    }
                                }
                                else
                                {
                                    if (_enableViewStateChecks)
                                    {
                                        var viewState = (EViewState)GW2MinionLauncher.ViewState((uint)gw2Process.Id);
                                        //GetViewState(gw2Process);
                                        if (viewState != EViewState.ViewGameplay &&
                                            DeadGW2Windows.All(p => p.Key.Id != gw2Process.Id))
                                        {
                                            AddDeadProcessToTheList(gw2Process, viewState);
                                        }
                                        else if (viewState != EViewState.ViewGameplay)
                                        {
                                            GetRidOfProcessesThatHaveBeenIdleForLong(gw2Process, viewState);
                                        }
                                        else
                                        {
                                            RemoveWorkingWindowsFromTheList(gw2Process);
                                        }
                                    }
                                    RemoveRespondingWindowsFromTheList(gw2Process);
                                    MinimizeGW2Windows(gw2Process);
                                }
                            }
                            //if (_buildNumberNeedUpdate == 0)
                            //{
                            //    try
                            //    {
                            //        _buildNumber = GW2MinionLauncher.BuildNumberFromApi();
                            //        //VersionChecker.CheckForUpdates();
                            //    }
                            //    catch
                            //    {
                            //        _buildNumber = 0;
                            //    }
                            //    _buildNumberNeedUpdate = 0;
                            //    try
                            //    {
                            //        if (enumerable.Any())
                            //            _enableViewStateChecks =
                            //                GW2MinionLauncher.BuildNumber((uint) enumerable.First().Id) == _buildNumber;
                            //        && _buildNumber == Pointers.BuildNumber;
                            //    }
                            //    catch
                            //    {
                            //        _enableViewStateChecks = false;
                            //    }
                            //}
                            //_buildNumberNeedUpdate++;
                            //if (_buildNumberNeedUpdate > 30)
                            //    _buildNumberNeedUpdate = 0;
                        }
                        _checkAll = !_checkAll;
                    }
                    catch (Exception)
                    {
                    }
                    Thread.Sleep(Config.Singleton.GeneralSettings.PollingDelay * 1000);
                }
                Thread.Sleep(10000);
            }
        }