private void accList_DoubleClick(object sender, EventArgs e) { // Window rect Rectangle rect = FormHelper.GetWindowRectangle(this, proc.MainWindowHandle); // Positional data PositionData posData = positionData[0]; if (rect.Width == 1280) { posData = positionData[0]; } if (rect.Width == 1024) { posData = positionData[1]; } if (rect.Width == 1600) { posData = positionData[2]; } // Account if (accList.LastHoveredItem != null) { Account acc = accList.LastHoveredItem.Account; string cleanPassword = Encoding.UTF8.GetString(AES.Decrypt(acc.Password, acc.Salt, GetPasskey(acc.Username))); // Execute macro LoginMacro.ExecuteMacro(posData, rect, acc.Username, cleanPassword); // Exit app Application.Exit(); } }
/// <summary> /// Runs the macro for the specific account selected. /// </summary> private void tvAccounts_DoubleClick(object sender, EventArgs e) { // Avoid possibility of user selecting region node if (tvAccounts.SelectedNode.Tag != null) { // Window rect Rectangle rect = FormHelper.GetWindowRectangle(this, proc.MainWindowHandle); // Positional data PositionData posData = positionData[0]; if (rect.Width == 1280) { posData = positionData[0]; } if (rect.Width == 1024) { posData = positionData[1]; } if (rect.Width == 1600) { posData = positionData[2]; } // Account Account acc = (Account)tvAccounts.SelectedNode.Tag; string cleanPassword = Encoding.UTF8.GetString(AES.Decrypt(acc.Password, acc.Salt, GetPasskey(acc.Username))); // Execute macro LoginMacro.ExecuteMacro(posData, rect, acc.Username, cleanPassword); // Exit app Application.Exit(); } }
public static void ExecuteMacro(PositionData pData, Rectangle window, string username, string password) { // Remember old mouse position to return to it afterwards. int oldX = Control.MousePosition.X; int oldY = Control.MousePosition.Y; // Generates relative position data to the client. pData = new PositionData(pData.Width, pData.Height, pData.UsernameX + window.X, pData.UsernameY + window.Y, pData.PasswordX + window.X, pData.PasswordY + window.Y, pData.ButtonX + window.X, pData.ButtonY + window.Y, pData.LogoX, pData.LogoY); // Avoiding a problem: { and } are special characters for SendKeys. We have to escape them. password = password.Replace("{", "^^{^^"); password = password.Replace("}", "^^}^^"); password = password.Replace("^^{^^", "{{}"); password = password.Replace("^^}^^", "{}}"); // Easy, but inefficient method. In the grand scheme of things, this doesn't make any difference. // Input username SetCursorPos(pData.UsernameX, pData.UsernameY); mouse_event(MOUSEEVENTF_LEFTDOWN, pData.UsernameX, pData.UsernameY, 0, 0); mouse_event(MOUSEEVENTF_LEFTUP, pData.UsernameX, pData.UsernameY, 0, 0); System.Threading.Thread.Sleep(50); mouse_event(MOUSEEVENTF_LEFTDOWN, pData.UsernameX, pData.UsernameY, 0, 0); mouse_event(MOUSEEVENTF_LEFTUP, pData.UsernameX, pData.UsernameY, 0, 0); SendKeys.Send("{BACKSPACE}"); System.Threading.Thread.Sleep(10); SendKeys.Send(username); System.Threading.Thread.Sleep(5); // Input password SetCursorPos(pData.PasswordX, pData.PasswordY); mouse_event(MOUSEEVENTF_LEFTDOWN, pData.PasswordX, pData.PasswordY, 0, 0); mouse_event(MOUSEEVENTF_LEFTUP, pData.PasswordX, pData.PasswordY, 0, 0); System.Threading.Thread.Sleep(50); mouse_event(MOUSEEVENTF_LEFTDOWN, pData.PasswordX, pData.PasswordY, 0, 0); mouse_event(MOUSEEVENTF_LEFTUP, pData.PasswordX, pData.PasswordY, 0, 0); SendKeys.Send("{BACKSPACE}"); System.Threading.Thread.Sleep(10); SendKeys.Send(password); System.Threading.Thread.Sleep(5); // Click login SetCursorPos(pData.ButtonX, pData.ButtonY); mouse_event(MOUSEEVENTF_LEFTDOWN, pData.ButtonX, pData.ButtonY, 0, 0); mouse_event(MOUSEEVENTF_LEFTUP, pData.ButtonX, pData.ButtonY, 0, 0); // Reset position SetCursorPos(oldX, oldY); }
/// <summary> /// Load XML and accounts, start League client. /// </summary> private void FrmWidget_Load(object sender, EventArgs e) { // Setup XML if (!System.IO.File.Exists("accounts.xml")) { var launchDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); xml = XmlConfiguration.CreateConfiguration(launchDir + "/accounts.xml"); } else { xml = new XmlConfiguration("accounts.xml"); } // Load accounts LoadAccounts(); // Load position data // Currently hard-coded positional data for the regular window size (1280x720) and the next 2 available options. positionData = new PositionData[3]; positionData[0] = new PositionData(1280, 720, 67, 284, 67, 348, 188, 495, 66, 56); positionData[1] = new PositionData(1024, 576, 53, 225, 53, 278, 150, 397, 53, 45); positionData[2] = new PositionData(1600, 900, 84, 355, 84, 435, 233, 621, 82, 70); // Focus on the label to avoid ugly selection this.ActiveControl = btnClose; // Read shortcutInfo and run the LeagueClient executable. string shortcutInfoFile = Application.StartupPath + "/shortcutInfo.txt"; string leagueClientFile = string.Empty; try { leagueClientFile = System.IO.File.ReadAllText(shortcutInfoFile) .Replace("\n", string.Empty).Replace("\r", string.Empty); } catch (Exception ex) { MessageBox.Show("An error occurred while trying to read the shortcutInfo.txt file.\n" + ex.Message); Application.Exit(); } try { Process.Start(leagueClientFile); } catch (Exception ex) { MessageBox.Show("An error occured while trying to launch the LeagueClient executable.\n" + ex.Message); } // Start looking for process tmrCheckProcess.Start(); }
/// <summary> /// Checks the screen for the League logo (checks if client is visible) /// </summary> private void tmrCheckScreen_Tick(object sender, EventArgs e) { Rectangle rect = FormHelper.GetWindowRectangle(this, proc.MainWindowHandle); if (rect.Width == 1280 || rect.Width == 1024 || rect.Width == 1600) { PositionData posData = positionData[0]; if (rect.Width == 1280) { posData = positionData[0]; } if (rect.Width == 1024) { posData = positionData[1]; } if (rect.Width == 1600) { posData = positionData[2]; } this.Size = new Size(254, posData.Height); this.accList.Size = new Size(240, this.Size.Height - 42 - 1); Relocate(); SetForegroundWindow(proc.MainWindowHandle); System.Threading.Thread.Sleep(200); this.Opacity = 1.0; this.Enabled = true; this.WindowState = FormWindowState.Minimized; this.Show(); this.WindowState = FormWindowState.Normal; tmrRelocateForm.Start(); tmrCheckScreen.Stop(); } }