Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using System.Threading;
- using System.IO;
- namespace steamautologin
- {
- public partial class Form1 : Form
- {
- #region DLL IMPORTS
- [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 long SetCursorPos(int x, int y);
- [DllImport("user32.dll")]
- private static extern bool SetWindowPos(IntPtr hWnd,
- int hWndInsertAfter, int x, int y, int cx, int cy, int uFlags);
- #endregion
- #region enums
- private const int MOUSEEVENT_LEFTDOWN = 0x02;
- private const int MOUSEEVENT_LEFTUP = 0x04;
- private const int HWND_TOPMOST = -1;
- private const int SWP_NOMOVE = 0x0002;
- private const int SWP_NOSIZE = 0x0001;
- #endregion
- /* temporary file path (to store username and passwords)
- * Example :
- *
- * username,password
- * username2,password2
- *
- */
- static string path = @"C:\18nakedcowboys.txt";
- /* user struct, can add things such as nicknames.
- * Example : username = mainaccount
- * password = badpass123
- * nickname = main
- * In this case we could select the nickname instead of the account username
- */
- struct user
- {
- public user(string user, string pass)
- {
- username = user;
- password = pass;
- }
- public string username { get; }
- public string password { get; }
- }
- // List of users
- List<user> userlist = new List<user>();
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- CheckForIllegalCrossThreadCalls = false;
- // if client does not have a datafile create a new
- if (!File.Exists(path))
- {
- StreamWriter sw = File.CreateText(path);
- sw.Flush();
- sw.Dispose();
- }
- // Load data to combobox and userlist
- List<string> lines = File.ReadAllLines(path).ToList();
- foreach (var line in lines)
- {
- string[] entries = line.Split(',');
- user newuser = new user(entries[0], entries[1]);
- comboBox1.Items.Add(entries[0]);
- userlist.Add(newuser);
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- // add new user to datafile
- List<string> lines = File.ReadAllLines(path).ToList();
- var User = new user(textBox1.Text, textBox2.Text);
- userlist.Add(User);
- lines.Add(User.username + "," + User.password);
- File.WriteAllLines(path, lines);
- //refresh combobox
- comboBox1.Items.Clear();
- foreach (user v in userlist)
- {
- comboBox1.Items.Add(v.username);
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- // separate thread to not freeze the window
- var ds = new Thread(login) { IsBackground = true };
- ds.Start();
- }
- void login()
- {
- // kill current steam process if there is one
- foreach (var process in Process.GetProcessesByName("steam"))
- {
- process.Kill();
- }
- // Start steam, default installation dir
- Process.Start(@"C:\Program Files (x86)\Steam\steam.exe");
- // Retard loop by me, wait for updates to finish then set steam ontop + to the coordinates 200,200
- bool cont = false;
- while (true)
- {
- foreach (var process in Process.GetProcessesByName("steam"))
- {
- if (process.MainWindowTitle == "Steam Login")
- {
- cont = true;
- SetWindowPos(process.MainWindowHandle, HWND_TOPMOST, 200, 200, 0, 0, SWP_NOSIZE);
- break;
- }
- }
- if (cont == true)
- break;
- Thread.Sleep(100);
- }
- Thread.Sleep(200);
- // username textbox is at the coordinates (530,300) when we set the steam login window's coordinates to (200,200)
- SetCursorPos(530, 300);
- // double click so we select all the text
- leftclick();
- leftclick();
- Thread.Sleep(10); // a little delay because it seemed to break if no delay.
- SendKeys.SendWait(userlist[comboBox1.SelectedIndex].username);
- // Password textbox is located 30 pixels below the username textbox.
- SetCursorPos(530, 330);
- leftclick();
- leftclick();
- Thread.Sleep(10);
- SendKeys.SendWait(userlist[comboBox1.SelectedIndex].password);
- // click login button
- SetCursorPos(350, 396);
- Thread.Sleep(10);
- leftclick();
- leftclick();
- }
- // I don't think I have to explain this one
- void leftclick()
- {
- mouse_event(MOUSEEVENT_LEFTDOWN, 0, 0, 0, 0);
- mouse_event(MOUSEEVENT_LEFTUP, 0, 0, 0, 0);
- }
- }
- }
Add Comment
Please, Sign In to add comment