Example #1
0
        /// <summary>
        /// Starts Wow, assigns GameProcess and Memory after lauch and releases lock. Can only call from a valid token
        /// </summary>
        /// <exception cref="System.InvalidOperationException">Lock token is not valid</exception>
        public void StartWoW()
        {
            lock (LockObject)
            {
                if (!IsValid)
                {
                    throw new InvalidOperationException("Lock token is not valid");
                }

                if (_wowProcess != null && Utility.Is64BitProcess(_wowProcess))
                {
                    _lockOwner.Profile.Log("64 bit Wow is not supported. Delete or rename the WoW-64.exe file in your WoW install folder");
                    _lockOwner.Stop();
                }

                // check if a batch file or any .exe besides WoW.exe is used and try to get the child WoW process started by this process.

                if (_launcherProc != null)
                {
                    System.Diagnostics.Process wowProcess;
                    // Two methods are used to find the WoW process if a launcher is used;
                    // Method one: launcher exit code return the WoW process ID or a negative if an error occured.
                    //			   If launcher does not use return the expected return values then a batch file or console app
                    //			   must be used to start the launcher and return the expected return codes.
                    // Method two: Find a child WoW process of the launcher process.

                    if (_launcherProc.HasExited && _launcherProc.ExitCode < 0)
                    {
                        _lockOwner.Profile.Log("Pausing profile because launcher exited with error code: {0}", _launcherProc.ExitCode);
                        _lockOwner.Profile.Pause();
                        return;
                    }

                    if (!_launcherProc.HasExited || _launcherProc.ExitCode == 0 ||
                        !Utility.TryGetProcessById(_launcherProc.ExitCode, out wowProcess))
                    {
                        var executablePath = Path.GetFileNameWithoutExtension(_lockOwner.Profile.Settings.WowSettings.WowPath);
                        wowProcess = Utility.GetChildProcessByName(_launcherProc.Id, "Wow")
                                     ?? Utility.GetChildProcessByName(_launcherProc.Id, "WowB")                     // Beta
                                     ?? Utility.GetChildProcessByName(_launcherProc.Id, "WowT")                     // PTR
                                     ?? Utility.GetChildProcessByName(_launcherProc.Id, executablePath);            // Renamed executables
                    }
                    if (wowProcess != null)
                    {
                        _lockOwner.Profile.Log($"WoW Launcher Pid: {_launcherProc.Id} launched WoW Pid: {wowProcess.Id}");
                        _launcherProc.Dispose();
                        _launcherProc       = null;
                        _dialogDisplayTimer = null;
                        Helpers.ResumeProcess(wowProcess.Id);
                        _wowProcess = wowProcess;
                    }
                    else
                    {
                        _lockOwner.Profile.Log("Waiting on external application to start WoW");
                        _lockOwner.Profile.Status = "Waiting on external application to start WoW";
                        return;
                    }
                }

                if (_wowProcess == null || _wowProcess.HasExitedSafe())
                {
                    // throttle the number of times wow is launched.
                    if (_wowProcess != null && _wowProcess.HasExitedSafe() &&
                        DateTime.Now - _startTime < TimeSpan.FromSeconds(HbRelogManager.Settings.WowDelay))
                    {
                        return;
                    }

                    StartWowProcess();
                    return;
                }
                // need to refresh everytime because of the dialog at startup
                _wowProcess.Refresh();
                // return if wow isn't ready for input.
                IntPtr wowWindow = FindWowWindowHandle(_wowProcess);
                if (wowWindow == IntPtr.Zero)
                {
                    _lockOwner.Profile.Status = "Waiting for Wow to start";
                    _lockOwner.Profile.Log(_lockOwner.Profile.Status);
                    return;
                }
                var isPopup = (NativeMethods.GetWindowStyle(_wowProcess.MainWindowHandle) & NativeMethods.WindowStyle.Popup) != 0;

                if (isPopup)
                {
                    // WoW is now shown as a dialog very breifly everytime it's started,
                    // so we only care if it's a dialog window longer than normal
                    if (_dialogDisplayTimer == null)
                    {
                        _dialogDisplayTimer = Stopwatch.StartNew();
                    }
                    else if (_dialogDisplayTimer.ElapsedMilliseconds > 10000)
                    {
                        _lockOwner.Profile.Log($"WoW v{_wowProcess.VersionString()} failed to load and is a popup. " +
                                               $"Make sure your WoW installation is updated and WoW is using windowed mode. Pausing profile.");
                        _lockOwner.Profile.Pause();
                        ReleaseLock();
                    }
                    return;
                }
                _lockOwner.GameWindow      = wowWindow;
                _lockOwner.GameProcessId   = _wowProcess.Id;
                _lockOwner.GameProcessName = _wowProcess.ProcessName;
                _lockOwner.Processsharp    = new ProcessSharp(_wowProcess, MemoryType.Remote);
                _wowProcess = null;
                _lockOwner.Profile.Log("Wow is ready to login.");
            }
        }
Example #2
0
		/// <summary>
		/// Starts Wow, assigns GameProcess and Memory after lauch and releases lock. Can only call from a valid token
		/// </summary>
		/// <exception cref="System.InvalidOperationException">Lock token is not valid</exception>
		public void StartWoW()
		{
			lock (LockObject)
			{
				if (!IsValid)
					throw new InvalidOperationException("Lock token is not valid");

				if (_wowProcess != null && Utility.Is64BitProcess(_wowProcess))
				{
					_lockOwner.Profile.Log("64 bit Wow is not supported. Delete or rename the WoW-64.exe file in your WoW install folder");
					_lockOwner.Stop();
				}

				// check if a batch file or any .exe besides WoW.exe is used and try to get the child WoW process started by this process.

				if (_launcherProc != null)
				{
					Process wowProcess;
					// Two methods are used to find the WoW process if a launcher is used;
					// Method one: launcher exit code return the WoW process ID or a negative if an error occured. 
					//			   If launcher does not use return the expected return values then a batch file or console app
					//			   must be used to start the launcher and return the expected return codes.	
					// Method two: Find a child WoW process of the launcher process.

					if (_launcherProc.HasExited && _launcherProc.ExitCode < 0)
					{
						_lockOwner.Profile.Log("Pausing profile because launcher exited with error code: {0}", _launcherProc.ExitCode);
						_lockOwner.Profile.Pause();
						return;
					}

					if (!_launcherProc.HasExited || _launcherProc.ExitCode  == 0 || (wowProcess = TryGetProcessById(_launcherProc.ExitCode)) == null)
					{
						var executablePath = Path.GetFileNameWithoutExtension(_lockOwner.Profile.Settings.WowSettings.WowPath);
						wowProcess = Utility.GetChildProcessByName(_launcherProc.Id, "Wow") 
							?? Utility.GetChildProcessByName(_launcherProc.Id, "WowB")  // Beta
							?? Utility.GetChildProcessByName(_launcherProc.Id, "WowT")	// PTR
							?? Utility.GetChildProcessByName(_launcherProc.Id, executablePath); // Renamed executables
					}
					if (wowProcess != null)
					{
						_launcherProc = null;
                        Helpers.ResumeProcess(wowProcess.Id);
						_wowProcess = wowProcess;
					}
					else
					{
						_lockOwner.Profile.Log("Waiting on external application to start WoW");
						_lockOwner.Profile.Status = "Waiting on external application to start WoW";
						return;
					}

				}

                if (_wowProcess == null || _wowProcess.HasExitedSafe())
				{
					// throttle the number of times wow is launched.
                    if (_wowProcess != null && _wowProcess.HasExitedSafe() && DateTime.Now - _startTime < TimeSpan.FromSeconds(HbRelogManager.Settings.WowDelay))
					{
						return;
					}
					AdjustWoWConfig();
					_lockOwner.Profile.Log("Starting {0}", _lockOwner.Settings.WowPath);
					_lockOwner.Profile.Status = "Starting WoW";

					_lockOwner.StartupSequenceIsComplete = false;
					_lockOwner.Memory = null;

					bool lanchingWoW = IsWoWPath(_lockOwner.Settings.WowPath);

					// force 32 bit client to start.
					if (lanchingWoW && _lockOwner.Settings.WowArgs.IndexOf("-noautolaunch64bit", StringComparison.InvariantCultureIgnoreCase) == -1)
					{
						// append a space to WoW arguments to separate multiple arguments if user is already pasing arguments ..
						if (!string.IsNullOrEmpty(_lockOwner.Settings.WowArgs))
							_lockOwner.Settings.WowArgs += " ";
						_lockOwner.Settings.WowArgs += "-noautolaunch64bit";
					}

					var pi = new ProcessStartInfo() { UseShellExecute = false };

					if (lanchingWoW)
					{
						var launcherPath = Path.Combine(Utility.AssemblyDirectory, "Launcher.exe");
						pi.FileName = launcherPath;
                        HBRelog.Settings.ProxyInfo info = HBRelog.Settings.GlobalSettings.Instance.GetProxyByName(_lockOwner.Settings.ProxyName);
                        if ( info == null )
                        {
                            System.Windows.Forms.MessageBox.Show("Not fineded socks info in list. Check name and file socks.\n Game NOT started!");
                            return;
                        }
						var args = string.Format("\"{0}\" \"{1}\" \"{2}\"", _lockOwner.Settings.WowPath, _lockOwner.Settings.WowArgs, info.GenerateUri() );
						pi.Arguments = args;
					}
					else
					{
						pi.FileName = _lockOwner.Settings.WowPath;
						pi.Arguments = _lockOwner.Settings.WowArgs;
					}

					_launcherProc = Process.Start(pi);
					_lockOwner.ProcessIsReadyForInput = false;
					_lockOwner.LoginTimer.Reset();
				}
				else
				{
					// return if wow isn't ready for input.
					if (_wowProcess.MainWindowHandle == IntPtr.Zero)
					{
						_wowProcess.Refresh();
						_lockOwner.Profile.Status = "Waiting for Wow to start";
						_lockOwner.Profile.Log(_lockOwner.Profile.Status);
						return;
					}
					var isPopup = (NativeMethods.GetWindowStyle(_wowProcess.MainWindowHandle) & NativeMethods.WindowStyle.Popup) != 0;
					if (isPopup)
					{
						_lockOwner.Profile.Log("WoW failed to load and is an error popup; Restarting");
						ReleaseLock();
						return;
					}

					_lockOwner.GameProcess = _wowProcess;
					_lockOwner.Memory = new ExternalProcessReader(_wowProcess);
					_wowProcess = null;
					_lockOwner.Profile.Log("Wow is ready to login.");
				}
			}
		}
Example #3
0
        /// <summary>
        /// Starts Wow, assigns GameProcess and Memory after lauch and releases lock. Can only call from a valid token
        /// </summary>
        /// <exception cref="System.InvalidOperationException">Lock token is not valid</exception>
        public void StartWoW()
        {
            lock (LockObject)
            {
                if (!IsValid)
                {
                    throw new InvalidOperationException("Lock token is not valid");
                }

                if (_wowProcess != null && Utility.Is64BitProcess(_wowProcess))
                {
                    _lockOwner.Profile.Log("64 bit Wow is not supported. Delete or rename the WoW-64.exe file in your WoW install folder");
                    _lockOwner.Stop();
                }

                // check if a batch file or any .exe besides WoW.exe is used and try to get the child WoW process started by this process.

                if (_launcherPid > 0)
                {
                    Process wowProcess = Utility.GetChildProcessByName(_launcherPid, "Wow")
                                         ?? Utility.GetChildProcessByName(_launcherPid, "WowB")  // Beta
                                         ?? Utility.GetChildProcessByName(_launcherPid, "WowT"); // PTR
                    if (wowProcess != null)
                    {
                        _launcherPid = 0;
                        Helpers.ResumeProcess(wowProcess.Id);
                        _wowProcess = wowProcess;
                    }
                    else
                    {
                        _lockOwner.Profile.Log("Waiting on external application to start WoW");
                        _lockOwner.Profile.Status = "Waiting on external application to start WoW";
                        return;
                    }
                }

                if (_wowProcess == null || _wowProcess.HasExitedSafe())
                {
                    // throttle the number of times wow is launched.
                    if (_wowProcess != null && _wowProcess.HasExitedSafe() && DateTime.Now - _startTime < TimeSpan.FromSeconds(HbRelogManager.Settings.WowDelay))
                    {
                        return;
                    }
                    AdjustWoWConfig();
                    _lockOwner.Profile.Log("Starting {0}", _lockOwner.Settings.WowPath);
                    _lockOwner.Profile.Status = "Starting WoW";

                    _lockOwner.StartupSequenceIsComplete = false;
                    _lockOwner.Memory = null;

                    bool lanchingWoW = _lockOwner.Settings.WowPath.IndexOf("WoW.exe", StringComparison.InvariantCultureIgnoreCase) != -1 ||
                                       _lockOwner.Settings.WowPath.IndexOf("WoWB.exe", StringComparison.InvariantCultureIgnoreCase) != -1 || // Beta WoW
                                       _lockOwner.Settings.WowPath.IndexOf("WoWT.exe", StringComparison.InvariantCultureIgnoreCase) != -1;// PTR WoW

                    // force 32 bit client to start.
                    if (lanchingWoW && _lockOwner.Settings.WowArgs.IndexOf("-noautolaunch64bit", StringComparison.InvariantCultureIgnoreCase) == -1)
                    {
                        // append a space to WoW arguments to separate multiple arguments if user is already pasing arguments ..
                        if (!string.IsNullOrEmpty(_lockOwner.Settings.WowArgs))
                        {
                            _lockOwner.Settings.WowArgs += " ";
                        }
                        _lockOwner.Settings.WowArgs += "-noautolaunch64bit";
                    }

                    var pi = new ProcessStartInfo()
                    {
                        UseShellExecute = false
                    };

                    if (lanchingWoW)
                    {
                        var launcherPath = Path.Combine(Utility.AssemblyDirectory, "Launcher.exe");
                        pi.FileName = launcherPath;
                        var args = string.Format("\"{0}\" \"{1}\"", _lockOwner.Settings.WowPath, _lockOwner.Settings.WowArgs);
                        pi.Arguments = args;
                    }
                    else
                    {
                        pi.FileName  = _lockOwner.Settings.WowPath;
                        pi.Arguments = _lockOwner.Settings.WowArgs;
                    }

                    _launcherPid = Process.Start(pi).Id;
                    _lockOwner.ProcessIsReadyForInput = false;
                    _lockOwner.LoginTimer.Reset();
                }
                else
                {
                    // return if wow isn't ready for input.
                    if (_wowProcess.MainWindowHandle == IntPtr.Zero)
                    {
                        _wowProcess.Refresh();
                        _lockOwner.Profile.Status = "Waiting for Wow to start";
                        _lockOwner.Profile.Log(_lockOwner.Profile.Status);
                        return;
                    }
                    _lockOwner.GameProcess = _wowProcess;
                    _lockOwner.Memory      = new ExternalProcessReader(_wowProcess);
                    _wowProcess            = null;
                    _lockOwner.Profile.Log("Wow is ready to login.");
                }
            }
        }