private async void ImageRecognitionLoginToLeague() { bool leagueFullyLoaded = false; bool rememberMeChecked = false; bool addedUsername = false; bool addedPassword = false; bool successfullyLoggedIn = false; bool failLoggedIn = false; bool clickedPlayButton = false; if (!UsernamePasswordIsValid()) { ShowMessageBox(@"Please make sure you've added your Username and Password.\r\nPlease check the Auto Login tab.", "Unable To Login", MessageBoxIcon.Error); SetLiveStatusText("Please double check the Username and Password.", Color.Green); return; } while (!leagueFullyLoaded) { leagueFullyLoaded = await ImageRecognitionCheckIfLeagueLoaded(); } TakeFullDesktopScreenShot(); rememberMeChecked = await ImageRecognition.RememberMeCheckedImageRecognition(); while (!successfullyLoggedIn || !failLoggedIn || !CancelAutoLogin) { if (rememberMeChecked) { TakeFullDesktopScreenShot(); if (!addedPassword) { addedPassword = await ImageRecognition.LoginPasswordImageRecognition(); } TakeFullDesktopScreenShot(); if (!addedPassword) { addedPassword = await ImageRecognition.LoginPasswordFocusedImageRecognition(); } if (addedPassword) { Actions.EnterPassword(); } } else { TakeFullDesktopScreenShot(); if (!addedUsername) { addedUsername = await ImageRecognition.LoginUsernameImageRecognition(); } TakeFullDesktopScreenShot(); if (!addedUsername) { addedUsername = await ImageRecognition.LoginUsernameFocusedImageRecognition(); } if (addedUsername) { Actions.EnterUsername(); } TakeFullDesktopScreenShot(); if (!addedPassword) { addedPassword = await ImageRecognition.LoginPasswordImageRecognition(); } TakeFullDesktopScreenShot(); if (!addedPassword) { addedPassword = await ImageRecognition.LoginPasswordFocusedImageRecognition(); } if (addedPassword) { Actions.EnterPassword(); } } if (addedPassword) { KeyboardEvents.PressEnter(); return; } TakeFullDesktopScreenShot(); if (!clickedPlayButton) { clickedPlayButton = await ImageRecognition.AutoClickPlayButtonImageRecognition(); } if (clickedPlayButton) { successfullyLoggedIn = true; SetLiveStatusText("Successfully logged into league.", Color.Green); return; } TakeFullDesktopScreenShot(); if (!failLoggedIn) { failLoggedIn = await ImageRecognition.LoginFailedImageRecognition(); } if (failLoggedIn) { AutoLoginToggle.Checked = false; ShowMessageBox(@"Please make sure your Username and Password is correct.", "Unable To Login", MessageBoxIcon.Error); SetLiveStatusText("Please double check the Username and Password.", Color.Green); return; } } }
private async void LoginToLeague() { bool leagueFullyLoaded = false; bool rememberMeChecked = false; bool addedUsername = false; bool addedPassword = false; bool clickedSignIn = false; bool failLoggedIn = false; if (!CheckUsernamePasswordTextIsValid()) { MessageBox.Show(@"Please make sure you've added your Username and Password.\r\nPlease check the Auto Login tab.", "Unable To Login", MessageBoxButtons.OK, MessageBoxIcon.Error); SetLiveStatusText("Please double check the Username and Password.", Color.Green); return; } while (!leagueFullyLoaded) { leagueFullyLoaded = await CheckIfLeagueLoaded(); } TakeFullDesktopScreenShot(); rememberMeChecked = await ImageRecognition.RememberMeCheckedImageRecognition(); while (!clickedSignIn || !failLoggedIn) { if (rememberMeChecked) { TakeFullDesktopScreenShot(); if (!addedPassword) { addedPassword = await ImageRecognition.LoginPasswordImageRecognition(); } TakeFullDesktopScreenShot(); if (!addedPassword) { addedPassword = await ImageRecognition.LoginPasswordFocusedImageRecognition(); } if (addedPassword) { string password = Options.IsPasswordEncrypted ? Encryption.Decrypt(Options.Password, Encryption.ConvertRijndaelKeyToByte(Options.EncryptedKey), Encryption.ConvertRijndaelIVToByte(Options.EncryptedIV)) : Options.Password; int[] coordinates = HelpFile.GetXYCoordinatesRegex(Options.LoginPasswordCoordinates); KeyboardEvents.SetClipboardText(password); HelpFile.Log("Login Password: Copied Text To Clipboard."); Thread.Sleep(Options.ImageRecognitionInterval); MouseEvent.MoveMouseXYToAndClick(coordinates[0], coordinates[1]); HelpFile.Log("Login Password: Moved Mouse To Textbox And Clicked X:" + coordinates[0] + ", Y:" + coordinates[1] + "."); Thread.Sleep(Options.ImageRecognitionInterval); KeyboardEvents.PressControlV(); HelpFile.Log("Login Password: Pressed Control+V To Paste Password."); Thread.Sleep(Options.ImageRecognitionInterval); KeyboardEvents.ClearClipboard(); HelpFile.Log("Login Password: Cleared Clipboard Of Password."); } } else { TakeFullDesktopScreenShot(); if (!addedUsername) { addedUsername = await ImageRecognition.LoginUsernameImageRecognition(); } TakeFullDesktopScreenShot(); if (!addedUsername) { addedUsername = await ImageRecognition.LoginUsernameFocusedImageRecognition(); } if (addedUsername) { int[] coordinates = HelpFile.GetXYCoordinatesRegex(Options.LoginUsernameCoordinates); KeyboardEvents.SetClipboardText(Options.Username); HelpFile.Log("Login Username: Copied Username To Clipboard."); Thread.Sleep(Options.ImageRecognitionInterval); MouseEvent.MoveMouseXYToAndClick(coordinates[0], coordinates[1]); HelpFile.Log("Login Username: Moved Mouse To And Clicked Username Textbox X:" + coordinates[0] + ", Y:" + coordinates[1] + "."); Thread.Sleep(Options.ImageRecognitionInterval); KeyboardEvents.PressControlV(); HelpFile.Log("Login Username: Pressed Control+V To Paste Username."); Thread.Sleep(Options.ImageRecognitionInterval); KeyboardEvents.ClearClipboard(); HelpFile.Log("Login Username: Cleared Clipboard Of Username."); } TakeFullDesktopScreenShot(); if (!addedPassword) { addedPassword = await ImageRecognition.LoginPasswordImageRecognition(); } TakeFullDesktopScreenShot(); if (!addedPassword) { addedPassword = await ImageRecognition.LoginPasswordFocusedImageRecognition(); } if (addedPassword) { string password = Options.IsPasswordEncrypted ? Encryption.Decrypt(Options.Password, Encryption.ConvertRijndaelKeyToByte(Options.EncryptedKey), Encryption.ConvertRijndaelIVToByte(Options.EncryptedIV)) : Options.Password; int[] coordinates = HelpFile.GetXYCoordinatesRegex(Options.LoginPasswordCoordinates); KeyboardEvents.SetClipboardText(password); HelpFile.Log("Login Password: Copied Text To Clipboard."); Thread.Sleep(Options.ImageRecognitionInterval); MouseEvent.MoveMouseXYToAndClick(coordinates[0], coordinates[1]); HelpFile.Log("Login Password: Moved Mouse To Textbox And Clicked X:" + coordinates[0] + ", Y:" + coordinates[1] + "."); Thread.Sleep(Options.ImageRecognitionInterval); KeyboardEvents.PressControlV(); HelpFile.Log("Login Password: Pressed Control+V To Paste Password."); Thread.Sleep(Options.ImageRecognitionInterval); KeyboardEvents.ClearClipboard(); HelpFile.Log("Login Password: Cleared Clipboard Of Password."); } } if (addedPassword) { KeyboardEvents.PressEnter(); clickedSignIn = true; AutoLogin = true; return; } TakeFullDesktopScreenShot(); if (!failLoggedIn) { failLoggedIn = await ImageRecognition.LoginFailedImageRecognition(); } } if (failLoggedIn) { AutoLoginToggle.Checked = false; MessageBox.Show(@"Please make sure your Username and Password is correct.", "Unable To Login", MessageBoxButtons.OK, MessageBoxIcon.Error); SetLiveStatusText("Please double check the Username and Password.", Color.Green); return; } if (clickedSignIn) { SetLiveStatusText("Successfully logged into league.", Color.Green); AutoLogin = true; return; } }