using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
namespace LoLAutoLogin
{
public partial class Form1 : Form
{
#region Native Methods & Variables
[DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, long wParam, long lParam);
[DllImportAttribute("User32.dll")]
private static extern int FindWindow(String ClassName, String WindowName);
[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int WS_SHOWNORMAL = 1;
#endregion
private string Password;
int desksHeights, desksWidths, X, X2, Y, Y2;
int TimeOutCounter;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
desksHeights = Screen.PrimaryScreen.Bounds.Height;
desksWidths = Screen.PrimaryScreen.Bounds.Width;
X = desksWidths - (desksWidths / 2);
X = X + (X / 3);
Y = desksHeights - (desksHeights / 2);
Y = Y + (Y / 2);
CheckScreens.Start();
EndProcess("LoLLauncher");
CheckSettings("settings.txt");
}
private void Save_Click(object sender, EventArgs e)
{
if (tbPass.Text == tbPassCheck.Text)
{
StreamWriter SW;
SW = File.CreateText("settings.txt");
SW.Close();
string Encrypted = EncryptString(tbPass.Text, "secret");
AppendToFile(Encrypted, "settings.txt");
tbPass.Text = "";
string path = Environment.CurrentDirectory + @/settings.txt;
File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
Application.Restart();
}
else
{
MessageBox.Show("The passwords you entered did not match!");
}
}
private void CheckScreens_Tick(object sender, EventArgs e)
{
int hWnd1 = FindWindow("RADSWindowClass", "PVP.net Patcher");
if (hWnd1 > 0)
{
foreach (Process p in System.Diagnostics.Process.GetProcessesByName("LoLLauncher"))
{
try
{
SetForegroundWindow(p.MainWindowHandle);
ShowWindowAsync(p.MainWindowHandle, WS_SHOWNORMAL);
}
catch
{ }
}
Cursor.Position = new Point(X, Y);
mouse_event(MOUSEEVENTF_LEFTDOWN, Cursor.Position.X, Cursor.Position.Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, Cursor.Position.X, Cursor.Position.Y, 0, 0);
}
int hWnd2 = FindWindow("ApolloRuntimeContentWindow", "PVP.net Client");
if (hWnd2 > 0)
{
foreach (Process p in System.Diagnostics.Process.GetProcessesByName("LolClient"))
{
try
{
SetForegroundWindow(p.MainWindowHandle);
ShowWindowAsync(p.MainWindowHandle, WS_SHOWNORMAL);
}
catch
{ }
}
CheckScreens.Stop();
SetPassword();
}
}
private void SetPassword()
{
if (File.Exists("settings.txt"))
{
StreamReader SR;
string S;
SR = File.OpenText("settings.txt");
S = SR.ReadLine();
while (S != null)
{
Password = S;
S = SR.ReadLine();
}
SR.Close();
if (Password != null)
{
string Decrypted = DecryptString(Password, "secret");
System.Threading.Thread.Sleep(2000);
SendKeys.SendWait(Decrypted);
SendKeys.SendWait("{ENTER}");
System.Threading.Thread.Sleep(2000);
Application.Exit();
}
else
{
EndProcess("LolClient");
MessageBox.Show("Password not set correctly");
File.Delete("settings.txt");
Application.Exit();
}
}
}
private void EndProcess(string Name)
{
foreach (Process p in System.Diagnostics.Process.GetProcessesByName(Name))
{
try
{
p.Kill();
p.WaitForExit();
}
catch
{ }
}
}
private void CheckSettings(string settings)
{
if (File.Exists(settings))
{
try { Process LoLLauncher = Process.Start("lol.launcher.exe", ""); }
catch
{
MessageBox.Show("This executable has to be in the root of your League of Legends folder.");
Application.Exit();
}
}
else
{
Panel.Visible = true;
this.TransparencyKey = Color.YellowGreen;
this.BackColor = Color.LightGray;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.BackgroundImage = new Bitmap(Properties.Resources.bg);
}
}
private void AppendToFile(string Password, string settings)
{
try
{
StreamWriter SW;
SW = File.AppendText(settings);
SW.WriteLine(Password);
SW.Close();
}
catch
{
MessageBox.Show("Something went wrong while writing the password to the settings textfile.\r\n" +
"You could set this manually by creating a textfile named 'settings'.\r\n" +
"Put your password in the first line of the textfile.");
}
}
public static string EncryptString(string Message, string Passphrase)
{
byte[] Results;
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
// Step 1. We hash the passphrase using MD5
// We use the MD5 hash generator as the result is a 128 bit byte array
// which is a valid length for the TripleDES encoder we use below
MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));
// Step 2. Create a new TripleDESCryptoServiceProvider object
TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
// Step 3. Setup the encoder
TDESAlgorithm.Key = TDESKey;
TDESAlgorithm.Mode = CipherMode.ECB;
TDESAlgorithm.Padding = PaddingMode.PKCS7;
// Step 4. Convert the input string to a byte[]
byte[] DataToEncrypt = UTF8.GetBytes(Message);
// Step 5. Attempt to encrypt the string
try
{
ICryptoTransform Encryptor = TDESAlgorithm.CreateEncryptor();
Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length);
}
finally
{
// Clear the TripleDes and Hashprovider services of any sensitive information
TDESAlgorithm.Clear();
HashProvider.Clear();
}
// Step 6. Return the encrypted string as a base64 encoded string
return Convert.ToBase64String(Results);
}
public static string DecryptString(string Message, string Passphrase)
{
byte[] Results;
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
// Step 1. We hash the passphrase using MD5
// We use the MD5 hash generator as the result is a 128 bit byte array
// which is a valid length for the TripleDES encoder we use below
MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));
// Step 2. Create a new TripleDESCryptoServiceProvider object
TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
// Step 3. Setup the decoder
TDESAlgorithm.Key = TDESKey;
TDESAlgorithm.Mode = CipherMode.ECB;
TDESAlgorithm.Padding = PaddingMode.PKCS7;
// Step 4. Convert the input string to a byte[]
byte[] DataToDecrypt = Convert.FromBase64String(Message);
// Step 5. Attempt to decrypt the string
try
{
ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();
Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
}
finally
{
// Clear the TripleDes and Hashprovider services of any sensitive information
TDESAlgorithm.Clear();
HashProvider.Clear();
}
// Step 6. Return the decrypted string in UTF8 format
return UTF8.GetString(Results);
}
private void TimeOut_Tick(object sender, EventArgs e)
{
TimeOutCounter++;
if (TimeOutCounter >= 20)
{
Application.Exit();
}
}
}
}