コード例 #1
0
        private void getProccess()
        {
            Process[] processes = Process.GetProcesses();
            Console.WriteLine("Proccesses found.");
            Regex test = new Regex(@"[fF][fF]7(_[a-z]{2}){0,1}\.exe");

            foreach (Process proc in processes)
            {
                try
                {
                    string[] procPath    = proc.MainModule.FileName.Split('\\');
                    string   procExeName = procPath[procPath.Length - 1];
                    if (test.IsMatch(procExeName))
                    {
                        ff7 = proc;
                        procPath[procPath.Length - 1] = "";
                        BasePath = String.Join("\\", procPath);
                        break;
                    }
                }
                catch (Exception) { }
            }

            try
            {
                inputSim     = new WindowsInput.InputSimulator();
                keySim       = new WindowsInput.KeyboardSimulator(inputSim);
                windowHandle = ff7.MainWindowHandle;
            }
            catch (Exception) { }
        }
コード例 #2
0
        public Form1()
        {
            InitializeComponent();

            InputSimulator    = new WindowsInput.InputSimulator();
            MouseSimulator    = new WindowsInput.MouseSimulator(InputSimulator);
            KeyboardSimulator = new WindowsInput.KeyboardSimulator(InputSimulator);

            ButtonStop.Enabled = false;

            HookEvents = Hook.GlobalEvents();

            BackgroundWorker = new BackgroundWorker()
            {
                WorkerSupportsCancellation = true
            };
            BackgroundWorker.DoWork             += BackgroundWorker_DoWork;
            BackgroundWorker.RunWorkerCompleted += BackgroundWorker_RunWorkerCompleted;

            ConfigInExecution = -1;

            RadioButtonProfitByValue.Checked      = Properties.Settings.Default.RadioButtonProfitByValue_Checked;
            RadioButtonProfitByPercentage.Checked = Properties.Settings.Default.RadioButtonProfitByPercentage_Checked;
            NumericUpDownMaxSpent.Value           = Properties.Settings.Default.NumericUpDownMaxSpent_Value;
            NumericUpDownProfitByValue.Value      = Properties.Settings.Default.NumericUpDownProfitByValue_Value;
            NumericUpDownProfitByPercentage.Value = Properties.Settings.Default.NumericUpDownProfitByPercentage_Value;

            SearchTextPosition       = Properties.Settings.Default.SearchTextPosition;
            FirstItemPosition        = Properties.Settings.Default.FirstItemPosition;
            FirstValuePositionTop    = Properties.Settings.Default.FirstValuePositionTop;
            FirstValuePositionBottom = Properties.Settings.Default.FirstValuePositionBottom;
            FirstCountPositionTop    = Properties.Settings.Default.FirstCountPositionTop;
            FirstCountPositionBottom = Properties.Settings.Default.FirstCountPositionBottom;
            ChangeCountPosition      = Properties.Settings.Default.ChangeCountPosition;
            AcceptButtonPosition     = Properties.Settings.Default.AcceptButtonPosition;

            IsSearchTextPositionConfigured   = Properties.Settings.Default.IsSearchTextPositionConfigured;
            IsFirstItemPositionConfigured    = Properties.Settings.Default.IsFirstItemPositionConfigured;
            IsFirstValuePositionConfigured   = Properties.Settings.Default.IsFirstValuePositionConfigured;
            IsFirstCountPositionConfigured   = Properties.Settings.Default.IsFirstCountPositionConfigured;
            IsChangeCountPositionConfigured  = Properties.Settings.Default.IsChangeCountPositionConfigured;
            IsAcceptButtonPositionConfigured = Properties.Settings.Default.IsAcceptButtonPositionConfigured;

            NumericUpDownDelayToRiskOperations.Value = Properties.Settings.Default.NumericUpDownDelayToRiskOperations_Value;

            AskToConfigurePositions();
        }
コード例 #3
0
ファイル: Starcraft2.cs プロジェクト: GAMP/Plugins
        protected override void OnSendInput(IntPtr hwnd, string username, string password)
        {
            #region Validation
            if (hwnd == IntPtr.Zero)
            {
                throw new ArgumentException("Hwnd", "Invalid window handle specified.");
            }
            if (String.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentNullException("Username", "Invalid username specified.");
            }
            if (String.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException("Password", "Invalid password specified.");
            }
            #endregion

            //get window info
            WindowInfo window = new WindowInfo(hwnd);

            //check if window is valid
            if (window.IsValidWindow)
            {

                try
                {
                    //block user input
                    User32.BlockInput(true);

                    //restore window (case it minimized)
                    window.Restore(false);

                    //bring window to front
                    window.BringToFront();

                    //activate window
                    window.Activate();

                    //create input simulator
                    WindowsInput.KeyboardSimulator sim = new WindowsInput.KeyboardSimulator();

                    //send tab
                    sim.KeyDown(WindowsInput.Native.VirtualKeyCode.TAB);

                    //clear username filed
                    sim.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LCONTROL, WindowsInput.Native.VirtualKeyCode.VK_A);

                    //send back to clear any possible typed value
                    sim.KeyDown(WindowsInput.Native.VirtualKeyCode.BACK);

                    //send username
                    sim.TextEntry(username);

                    //initiate auth
                    sim.KeyDown(WindowsInput.Native.VirtualKeyCode.RETURN);

                    //wait for login
                    if (this.SendWaitTime > 0)
                    {
                        System.Threading.Thread.Sleep(this.SendWaitTime);
                    }

                    //clear password filed
                    sim.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LCONTROL, WindowsInput.Native.VirtualKeyCode.VK_A);

                    //send back to clear any possible typed value
                    sim.KeyDown(WindowsInput.Native.VirtualKeyCode.BACK);

                    //send bassword
                    sim.TextEntry(password);

                    //initiate login
                    sim.KeyDown(WindowsInput.Native.VirtualKeyCode.RETURN);

                    if (this.SendWaitTime > 0)
                    {
                        //sleep few seconds to allow login
                        System.Threading.Thread.Sleep(this.SendWaitTime);
                    }
                }
                catch
                {
                    //ignore
                }
                finally
                {

                    //unblock input
                    User32.BlockInput(false);
                }
            }
        }
コード例 #4
0
ファイル: Origin.cs プロジェクト: GAMP/Plugins
        private bool FocusField(Process originProcess, OriginInputFileds field, int tries)
        {
            WindowInfo window = new WindowInfo(originProcess.MainWindowHandle);
            WindowsInput.KeyboardSimulator sim = new WindowsInput.KeyboardSimulator();

            for (int i = 0; i < tries; i++)
            {
                try
                {
            #if !DEBUG
                    User32.BlockInput(true);
            #endif

                    //reactivate window
                    window.BringToFront();
                    window.Activate();

                    //create input variables
                    OriginInputFileds focusedField = OriginInputFileds.None;
                    OriginInputFileds checkedField = OriginInputFileds.None;

                    bool aero_on = false;

                    //check if aero is on
                    if (Environment.OSVersion.Version.Major > 5)
                        Win32API.Modules.DwmApi.DwmIsCompositionEnabled(out aero_on);

                    //grab snapshot
                    var image = aero_on ? Imaging.CaptureScreenRegion(originProcess.MainWindowHandle) : Imaging.CaptureWindowImage(originProcess.MainWindowHandle);

                    if (this.GetFields(image, out focusedField, out checkedField))
                    {
                        if (focusedField == field)
                            return true;
                    }

                    //send tab
                    sim.KeyPress(WindowsInput.Native.VirtualKeyCode.TAB);

                    //pause
                    System.Threading.Thread.Sleep(250);
                }
                catch
                {
                    throw;
                }
                finally
                {
            #if !DEBUG
                    User32.BlockInput(false);
            #endif
                }
            }
            return false;
        }
コード例 #5
0
ファイル: Origin.cs プロジェクト: GAMP/Plugins
        public override void Install(IApplicationLicense license, IExecutionContext context, ref bool forceCreation)
        {
            if (context.HasCompleted | context.AutoLaunch)
            {
                #region Validation
                //get installation directory
                string originPath = this.GetOriginPath();

                if (String.IsNullOrWhiteSpace(originPath))
                {
                    context.Client.Log.AddError("Could not obtain Origin client executable path.", null, LogCategories.Configuration);
                    return;
                }

                if (!File.Exists(originPath))
                {
                    context.Client.Log.AddError(String.Format("Origin client executable not found at {0}.", originPath), null, LogCategories.Configuration);
                    return;
                }

                #endregion

                #region Clear XML Configuration

                //get folder name
                string folderName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Origin");

                //get file name
                string fileName = Path.Combine(folderName, "local.xml");

                if (!Directory.Exists(folderName))
                    Directory.CreateDirectory(folderName);

                //create new stream and write or update its configuration data
                using (var xmlStream = new FileStream(fileName, FileMode.OpenOrCreate))
                {
                    XmlDocument document = new XmlDocument();
                    //preserve white space
                    document.PreserveWhitespace = true;

                    try
                    {
                        document.Load(xmlStream);
                    }
                    catch (XmlException)
                    {
                        //could not load
                    }

                    XmlNode settingsNode = null;

                    #region Find Settings Node
                    if (document.HasChildNodes)
                    {
                        foreach (XmlNode node in document.ChildNodes)
                        {
                            if (node.Name == "Settings")
                            {
                                settingsNode = node;
                                break;
                            }
                        }
                    }
                    #endregion

                    #region Create Settings Node
                    if (settingsNode == null)
                    {
                        settingsNode = document.CreateElement("Settings");
                        document.AppendChild(settingsNode);
                    }
                    #endregion

                    bool isSet = false;

                    #region Update Existing Node
                    if (settingsNode.HasChildNodes)
                    {
                        foreach (XmlLinkedNode el in settingsNode.ChildNodes)
                        {
                            if (el is XmlElement)
                            {
                                var element = (XmlElement)el;
                                if (element.HasAttribute("key") && element.Attributes["key"].Value == "AcceptedEULAVersion")
                                {
                                    if (element.Attributes["value"].Value == "0")
                                        element.Attributes["value"].Value = (2).ToString();

                                    isSet = true;
                                    break;
                                }
                            }
                        }
                    }
                    #endregion

                    #region Clear Additional Settings
                    if (settingsNode.HasChildNodes)
                    {
                        List<XmlElement> removedElements = new List<XmlElement>();
                        foreach (XmlLinkedNode el in settingsNode.ChildNodes)
                        {
                            if (el is XmlElement)
                            {
                                var element = (XmlElement)el;
                                if (element.HasAttribute("key") &&
                                    element.Attributes["key"].Value == "AutoLogin" ||
                                    element.Attributes["key"].Value == "LoginAsInvisible" ||
                                    element.Attributes["key"].Value == "LoginEmail" ||
                                    element.Attributes["key"].Value == "LoginToken" ||
                                    element.Attributes["key"].Value == "RememberMeEmail")
                                {
                                    removedElements.Add(element);
                                }
                            }
                        }

                        foreach (var element in removedElements)
                        {
                            settingsNode.RemoveChild(element);
                        }
                    }
                    #endregion

                    #region Create new node
                    if (!isSet)
                    {
                        var setting = document.CreateElement("Setting");
                        settingsNode.AppendChild(setting);
                        setting.SetAttribute("key", "AcceptedEULAVersion");
                        setting.SetAttribute("type", "2");
                        setting.SetAttribute("value", "2");
                    }
                    #endregion

                    //reset stream
                    xmlStream.SetLength(0);

                    //save document
                    document.Save(xmlStream);
                }
                #endregion

                string processName = Path.GetFileNameWithoutExtension(originPath);

                #region Initialize Process

                //get existing origin process
                var originProcess = Process.GetProcessesByName(processName).Where(x => String.Compare(x.MainModule.FileName, originPath, true) == 0).FirstOrDefault();

                bool processExisted = originProcess != null;

                if (!processExisted)
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.FileName = originPath;
                    startInfo.Arguments = "/NoEULA";
                    startInfo.WorkingDirectory = Path.GetDirectoryName(originPath);
                    startInfo.ErrorDialog = false;
                    startInfo.UseShellExecute = false;

                    //create origin process
                    originProcess = new Process() { StartInfo = startInfo };
                }

                originProcess.EnableRaisingEvents = true;
                originProcess.Exited += new EventHandler(OnInternalProcessExited);

                #endregion

                #region Start Origin
                if (processExisted || originProcess.Start())
                {
                    //mark process created
                    forceCreation = true;

                    //atach handlers
                    context.ExecutionStateChaged += OnExecutionStateChaged;

                    //add process to context process list
                    context.AddProcess(originProcess, true);

                    if (CoreProcess.WaitForWindowCreated(originProcess, 120000, true))
                    {
                        try
                        {
                            IntPtr mainWindow = originProcess.MainWindowHandle;

                            //create input simulator
                            WindowsInput.KeyboardSimulator sim = new WindowsInput.KeyboardSimulator();

                            if (!this.FocusField(originProcess, OriginInputFileds.Username, 50))
                                return;

                            //clear username filed
                            sim.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LCONTROL, WindowsInput.Native.VirtualKeyCode.VK_A);

                            //send back to clear any possible typed value
                            sim.KeyPress(WindowsInput.Native.VirtualKeyCode.BACK);

                            //set username
                            sim.TextEntry(license.KeyAs<UserNamePasswordLicenseKeyBase>().Username);

                            if (!this.FocusField(originProcess, OriginInputFileds.Password, 50))
                                return;

                            //clear password filed
                            sim.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LCONTROL, WindowsInput.Native.VirtualKeyCode.VK_A);

                            //send back to clear any possible typed value
                            sim.KeyPress(WindowsInput.Native.VirtualKeyCode.BACK);

                            //set password
                            sim.TextEntry(license.KeyAs<UserNamePasswordLicenseKeyBase>().Password);

                            //proceed with login
                            sim.KeyPress(WindowsInput.Native.VirtualKeyCode.RETURN);

                            //set environment variable
                            Environment.SetEnvironmentVariable("LICENSEKEYUSER", license.KeyAs<OriginLicenseKey>().Username);

                            //wait for window to be destroyed
                            if (CoreProcess.WaitForWindowDestroyed(mainWindow, 120000))
                                //delay installation process
                                System.Threading.Thread.Sleep(3000);
                        }
                        catch
                        {
                            throw;
                        }
                    }
                    else
                    {
                        context.Client.Log.AddError("Origin client window was not created after specified period of time.", null, LogCategories.Configuration);
                    }
                }
                else
                {
                    context.Client.Log.AddError(String.Format("Origin client executable {0} could not be started.", originPath), null, LogCategories.Configuration);
                }
                #endregion
            }
        }
コード例 #6
0
		public MotionResult ActSequenceMotion(IEnumerable<Motion> SeqMotion)
		{
			try
			{
				if (null == SeqMotion)
				{
					return null;
				}

				var MousePosition = BotEngine.Windows.Extension.User32GetCursorPos() ?? new Vektor2DInt(0, 0);

				var InputSimulator = new WindowsInput.InputSimulator();
				var KeyboardSimulator = new WindowsInput.KeyboardSimulator(InputSimulator);

				foreach (var Motion in SeqMotion)
				{
					var MotionMousePosition = Motion?.MousePosition;

					if (MotionMousePosition.HasValue)
					{
						POINT PositionOnScreen;

						EnsureWindowIsForeground(WindowHandle);

						MouseMoveToPointInClientRect(WindowHandle, MotionMousePosition.Value, out PositionOnScreen);

						MousePosition = PositionOnScreen.AsVektor2DInt();

						Thread.Sleep(MouseMoveDelay);
					}

					if (0 < Motion?.MouseButtonDown?.Count() || 0 < Motion?.MouseButtonUp?.Count())
					{
						EnsureWindowIsForeground(WindowHandle);

						User32MouseEvent(MousePosition, Motion?.MouseButtonDown, Motion?.MouseButtonUp);

						Thread.Sleep(MouseEventDelay);
					}

					Motion?.KeyDown?.ForEachNullable(KeyDown =>
					{
						EnsureWindowIsForeground(WindowHandle);
						InputSimulator.Keyboard.KeyDown(KeyDown);
					});

					Motion?.KeyUp?.ForEachNullable(KeyUp =>
					{
						EnsureWindowIsForeground(WindowHandle);
						InputSimulator.Keyboard.KeyUp(KeyUp);
					});
				}

				return new MotionResult(true);
			}
			catch (Exception Exception)
			{
				return new MotionResult(Exception);
			}
		}
コード例 #7
0
ファイル: Uplay.cs プロジェクト: GAMP/Plugins
        public override void Install(IApplicationLicense license, IExecutionContext context, ref bool forceCreation)
        {
            if (context.HasCompleted | context.AutoLaunch)
            {
                #region Validation
                //get installation directory
                string uplayPath = this.GetUplayPath();

                if (String.IsNullOrWhiteSpace(uplayPath) || !File.Exists(uplayPath))
                {
                    context.Client.Log.AddError(String.Format("Uplay client executable not found at {0}.", uplayPath), null, LogCategories.Configuration);
                    return;
                }

                #endregion

                string processName = Path.GetFileNameWithoutExtension(uplayPath);

                #region Initialize Process

                //get existing uplay process
                var uplayProcess = Process.GetProcessesByName(processName).Where(x => String.Compare(x.MainModule.FileName, uplayPath, true) == 0).FirstOrDefault();

                bool processExisted = uplayProcess != null;

                if(!processExisted)
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.FileName = uplayPath;
                    startInfo.WorkingDirectory = Path.GetDirectoryName(uplayPath);
                    startInfo.ErrorDialog = false;
                    startInfo.UseShellExecute = false;

                    //create uplay process
                    uplayProcess = new Process() { StartInfo = startInfo };
                }

                uplayProcess.EnableRaisingEvents = true;
                uplayProcess.Exited += new EventHandler(OnInternalProcessExited);

                #endregion

                #region Start Uplay
                if (uplayProcess.Start())
                {
                    //mark process created
                    forceCreation = true;

                    //atach handlers
                    context.ExecutionStateChaged += OnExecutionStateChaged;

                    //add process to context process list
                    context.AddProcess(uplayProcess, true);

                    if (CoreProcess.WaitForWindowCreated(uplayProcess, 120000, true))
                    {
                        try
                        {
                            //disable input
                            User32.BlockInput(true);

                            //get window
                            WindowInfo uplayWindow = new WindowInfo(uplayProcess.MainWindowHandle);

                            //activate origin window
                            uplayWindow.BringToFront();
                            uplayWindow.Activate();

                            //give some time to activate fields
                            System.Threading.Thread.Sleep(5000);

                            //disable input
                            User32.BlockInput(true);
                            //activate origin window
                            uplayWindow.BringToFront();
                            uplayWindow.Activate();

                            //create input simulator
                            WindowsInput.KeyboardSimulator sim = new WindowsInput.KeyboardSimulator();

                            //send tab
                            sim.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LCONTROL, WindowsInput.Native.VirtualKeyCode.TAB);

                            //clear username filed
                            sim.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LCONTROL, WindowsInput.Native.VirtualKeyCode.VK_A);

                            //disable input
                            User32.BlockInput(true);
                            //activate origin window
                            uplayWindow.BringToFront();
                            uplayWindow.Activate();

                            //send back to clear any possible typed value
                            sim.KeyDown(WindowsInput.Native.VirtualKeyCode.BACK);

                            //disable input
                            User32.BlockInput(true);
                            //activate origin window
                            uplayWindow.BringToFront();
                            uplayWindow.Activate();

                            //set username
                            sim.TextEntry(license.KeyAs<UserNamePasswordLicenseKeyBase>().Username);

                            //disable input
                            User32.BlockInput(true);
                            //activate origin window
                            uplayWindow.BringToFront();
                            uplayWindow.Activate();

                            //swicth field
                            sim.KeyDown(WindowsInput.Native.VirtualKeyCode.TAB);

                            //disable input
                            User32.BlockInput(true);
                            //activate origin window
                            uplayWindow.BringToFront();
                            uplayWindow.Activate();

                            //clear password filed
                            sim.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LCONTROL, WindowsInput.Native.VirtualKeyCode.VK_A);

                            //disable input
                            User32.BlockInput(true);
                            //activate origin window
                            uplayWindow.BringToFront();
                            uplayWindow.Activate();

                            //send back to clear any possible typed value
                            sim.KeyDown(WindowsInput.Native.VirtualKeyCode.BACK);

                            //disable input
                            User32.BlockInput(true);
                            //activate origin window
                            uplayWindow.BringToFront();
                            uplayWindow.Activate();

                            //set password
                            sim.TextEntry(license.KeyAs<UserNamePasswordLicenseKeyBase>().Password);

                            //disable input
                            User32.BlockInput(true);
                            //activate origin window
                            uplayWindow.BringToFront();
                            uplayWindow.Activate();

                            //proceed with login
                            sim.KeyDown(WindowsInput.Native.VirtualKeyCode.RETURN);

                            //disable input
                            User32.BlockInput(true);

                            //activate origin window
                            uplayWindow.BringToFront();
                            uplayWindow.Activate();

                            //set environment variable
                            Environment.SetEnvironmentVariable("LICENSEKEYUSER", license.KeyAs<UplayLicenseKey>().Username);

                            //delay installation process
                            System.Threading.Thread.Sleep(5000);
                        }
                        catch
                        {
                            throw;
                        }
                        finally
                        {
                            //enable input
                            User32.BlockInput(false);
                        }

                    }
                    else
                    {
                        context.Client.Log.AddError("Uplay client window was not created after specified period of time.", null, LogCategories.Configuration);
                    }
                }
                else
                {
                    context.Client.Log.AddError(String.Format("Uplay client executable {0} could not be started.", uplayPath), null, LogCategories.Configuration);
                }
                #endregion
            }
        }