Skip to content

Commit

Permalink
added option to launch legue client and exit after filling
Browse files Browse the repository at this point in the history
  • Loading branch information
MELVARDEV committed May 30, 2021
1 parent 4eb21ee commit e837d56
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 22 deletions.
9 changes: 7 additions & 2 deletions League Pass Manager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<Grid>
<Grid x:Name="mainGrid" >
<TabControl mah:HeaderedControlHelper.HeaderFontSize="16" mah:TabControlHelper.Underlined="TabPanel" Padding="0,2,0,0" Margin="-1,0,-1,0" >
<TabControl x:Name="tabControl" mah:HeaderedControlHelper.HeaderFontSize="16" mah:TabControlHelper.Underlined="TabPanel" Padding="0,2,0,0" Margin="-1,0,-1,0" >
<TabItem Header="Accounts" HorizontalAlignment="Center" Height="28" VerticalAlignment="Center" Width="79" Padding="6,2,6,2">
<Grid>
<Separator VerticalAlignment="Top" />
Expand Down Expand Up @@ -52,16 +52,21 @@

</Grid>
</TabItem>
<TabItem Header="Options" HorizontalAlignment="Center" Height="28" VerticalAlignment="Center" Width="68">
<TabItem Header="Options" HorizontalAlignment="Center" Height="28" VerticalAlignment="Center" Width="68" DataContext="{Binding settings}">
<Grid>
<StackPanel HorizontalAlignment="Left" Width="196" Margin="6,7,0,0">
<Button Content="Change password file location" Height="28" Click="Button_Click_3"/>
<Button x:Name="copyDataToClipboardBtn" Content="Copy data to clipboard" Margin="0,6,0,0" Click="copyDataToClipboardBtn_Click"/>
<Button Content="Change encryption key " Margin="0,6,0,0" Click="Button_Click_2"/>
<mah:ToggleSwitch x:Name="exitAfterFillingSwitch" Header="Exit after filling data" Height="100" OnContent="Yes" OffContent="No" Width="100" Margin="0,10,0,0" HorizontalAlignment="Center" IsEnabled="True" Toggled="exitAfterFillingSwitch_Toggled"/>
</StackPanel>
<StackPanel HorizontalAlignment="Stretch" Margin="215,7,8,0">
<TextBox x:Name="passFileLocation" Text="" TextWrapping="Wrap" HorizontalAlignment="Stretch" IsReadOnly="True" Height="28" TextChanged="passFileLocation_TextChanged" />
<TextBox x:Name="newEncryptionKey" Text="" TextWrapping="Wrap" Margin="0,39,0,0" Height="27.3" HorizontalAlignment="Stretch" mah:TextBoxHelper.Watermark="New encryption key..."/>
<mah:ToggleSwitch x:Name="autoOpenClientSwitch" Header="Auto open client" Height="56" Width="107" Margin="17,12,0,0" HorizontalAlignment="Left" OnContent="Yes" OffContent="No" Toggled="autoOpenClientSwitch_Toggled" HorizontalContentAlignment="Left" MinWidth="104"/>
<Label Content="Delay after launching client" Margin="11,3,0,0" HorizontalAlignment="Center" />
<Slider x:Name="delaySlider" Margin="10,1,8,0" Maximum="5000" Value="2000" ValueChanged="delaySlider_ValueChanged" MouseUp="delaySlider_MouseUp" Thumb.DragCompleted="delaySlider_DragCompleted" />
<Label x:Name="launchDelayLabel" Content="2000 ms" Margin="10,0,0,0" HorizontalAlignment="Left" HorizontalContentAlignment="Left" Width="96"/>
</StackPanel>

</Grid>
Expand Down
181 changes: 161 additions & 20 deletions League Pass Manager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.IO;
using System.ComponentModel;
using Microsoft.Win32;
using Path = System.IO.Path;

namespace League_Pass_Manager
{
Expand All @@ -48,13 +49,22 @@ public partial class MainWindow : MetroWindow
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool IsWindowVisible(IntPtr hWnd);

//include FindWindowEx
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

public class Settings
{

public string filePath { get; set; } = "accounts.txt";
public bool exitAfterFill { get; set; } = false;
public string leagueClientPath { get; set; } = null;
public bool autoOpenClient { get; set; } = false;
public int launchDelay { get; set; } = 2000;
}

public class Account
Expand All @@ -64,6 +74,8 @@ public class Account
public string description { get; set; }
public string userName { get; set; }
public string password { get; set; }


}

public Settings settings = new Settings();
Expand Down Expand Up @@ -144,6 +156,11 @@ public void loadSettings()
settings = JsonConvert.DeserializeObject<Settings>(settingsJson);

}

autoOpenClientSwitch.IsOn = settings.autoOpenClient;
exitAfterFillingSwitch.IsOn = settings.exitAfterFill;
delaySlider.Value = Convert.ToDouble(settings.launchDelay);
launchDelayLabel.Content = settings.launchDelay.ToString() + " ms";
}


Expand All @@ -161,36 +178,104 @@ public MainWindow()
passFileLocation.Text = settings.filePath;
}

private void Button_Click(object sender, RoutedEventArgs e)
void simulateFill(Process pr)
{
IntPtr hWnd = pr.MainWindowHandle;
//ShowWindow(hWnd, 3);
SetForegroundWindow(hWnd);
var inputSimulator = new InputSimulator();
Account selectedAccount = new Account();
try
{
selectedAccount = (Account)datagrid1.SelectedItem;
}
catch (Exception exce)
{
MessageBox.Show("You need to select an account first!");
return;
}

Account result = accounts.Find(x => x.userName == selectedAccount.userName);

if (!String.IsNullOrEmpty(result.userName))
{
inputSimulator.Keyboard.TextEntry(result.userName);
}

inputSimulator.Keyboard.KeyPress((VirtualKeyCode.TAB));

if (!String.IsNullOrEmpty(result.password))
{
inputSimulator.Keyboard.TextEntry(result.password);
}

inputSimulator.Keyboard.KeyPress((VirtualKeyCode.RETURN));

if (settings.exitAfterFill)
{

this.Close();

}
return;
}

private async void Button_Click(object sender, RoutedEventArgs e)
{
IntPtr hWnd;
Process[] processRunning = Process.GetProcesses();
Process leagueClientProcess = null;
foreach (Process pr in processRunning)
{
if (pr.ProcessName == "RiotClientUx")
{
hWnd = pr.MainWindowHandle;
//ShowWindow(hWnd, 3);
SetForegroundWindow(hWnd);
var inputSimulator = new InputSimulator();
Account selectedAccount = new Account();
try
{
selectedAccount = (Account)datagrid1.SelectedItem;
} catch (Exception exce)
{
MessageBox.Show("You need to select an account first!");
return;
}

Account result = accounts.Find(x => x.userName == selectedAccount.userName);
leagueClientProcess = pr;
}
}

if (leagueClientProcess != null)
{
simulateFill(leagueClientProcess);
} else if (settings.autoOpenClient)
{

string sessionFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Riot Games" + Path.DirectorySeparatorChar + "Riot Client" + Path.DirectorySeparatorChar + "Data" + Path.DirectorySeparatorChar + "RiotClientPrivateSettings.yaml");

try
{
File.Delete(sessionFilePath);
} catch (Exception ex)
{
MessageBox.Show("Cannot Delete");
Console.WriteLine(ex.Message);
}



inputSimulator.Keyboard.TextEntry(result.userName);
inputSimulator.Keyboard.KeyPress((VirtualKeyCode.TAB));
inputSimulator.Keyboard.TextEntry(result.password);
inputSimulator.Keyboard.KeyPress((VirtualKeyCode.RETURN));


leagueClientProcess = Process.Start(settings.leagueClientPath, "--launch-product=league_of_legends --launch-patchline=live");


Process[] pname = Process.GetProcessesByName("RiotClientUx");
while (pname.Length == 0)
{
await Task.Delay(200);
pname = Process.GetProcessesByName("RiotClientUx");
}




await Task.Delay(settings.launchDelay);
simulateFill(leagueClientProcess);
} else
{
MessageBox.Show("League of Legends login screen not found...");
}



}


Expand Down Expand Up @@ -308,5 +393,61 @@ private void datagrid1_SelectionChanged(object sender, SelectionChangedEventArgs
{

}

private void exitAfterFillingSwitch_Toggled(object sender, RoutedEventArgs e)
{


settings.exitAfterFill = exitAfterFillingSwitch.IsOn;
saveSettings();
}

private void autoOpenClientSwitch_Toggled(object sender, RoutedEventArgs e)
{

if (String.IsNullOrWhiteSpace(settings.leagueClientPath) && tabControl.SelectedIndex == 1 && autoOpenClientSwitch.IsOn == true)
{

OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.AddExtension = true;
openFileDialog.DefaultExt = "exe";
openFileDialog.Filter = "RiotClientServices.exe|RiotClientServices.exe";
if (openFileDialog.ShowDialog() == true)
{

settings.leagueClientPath = openFileDialog.FileName;
settings.autoOpenClient = true;
autoOpenClientSwitch.IsOn = true;

} else
{
settings.autoOpenClient = false;
autoOpenClientSwitch.IsOn = false;
}
}

saveSettings();
}

private void delaySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if(tabControl.SelectedIndex == 1)
{
settings.launchDelay = Convert.ToInt32(delaySlider.Value);
launchDelayLabel.Content = String.Concat(settings.launchDelay.ToString(), " ms");
}

}

private void delaySlider_MouseUp(object sender, MouseButtonEventArgs e)
{

saveSettings();
}

private void delaySlider_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
{
saveSettings();
}
}
}

0 comments on commit e837d56

Please sign in to comment.