Guest User

simple steam account manager

a guest
May 4th, 2021
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. using System.Windows.Forms;
  7. using System.Threading;
  8. using System.IO;
  9.  
  10. namespace steamautologin
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         #region DLL IMPORTS
  15.  
  16.         [DllImport("user32.dll")]
  17.         public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
  18.  
  19.  
  20.         [DllImport("User32.Dll")]
  21.         public static extern long SetCursorPos(int x, int y);
  22.  
  23.         [DllImport("user32.dll")]
  24.  
  25.         private static extern bool SetWindowPos(IntPtr hWnd,
  26.         int hWndInsertAfter, int x, int y, int cx, int cy, int uFlags);
  27.  
  28.         #endregion
  29.  
  30.         #region enums
  31.         private const int MOUSEEVENT_LEFTDOWN = 0x02;
  32.         private const int MOUSEEVENT_LEFTUP = 0x04;
  33.         private const int HWND_TOPMOST = -1;
  34.         private const int SWP_NOMOVE = 0x0002;
  35.         private const int SWP_NOSIZE = 0x0001;
  36.         #endregion
  37.  
  38.        
  39.         /* temporary file path (to store username and passwords)
  40.          * Example :
  41.          *
  42.          * username,password
  43.          * username2,password2
  44.          *
  45.          */
  46.         static string path = @"C:\18nakedcowboys.txt";
  47.  
  48.  
  49.  
  50.         /* user struct, can add things such as nicknames.
  51.          * Example : username = mainaccount
  52.          * password = badpass123
  53.          * nickname = main
  54.          * In this case we could select the nickname instead of the account username
  55.          */
  56.         struct user
  57.         {
  58.             public user(string user, string pass)
  59.             {
  60.                 username = user;
  61.                 password = pass;
  62.             }
  63.             public string username { get; }
  64.             public string password { get; }
  65.         }
  66.  
  67.         // List of users
  68.         List<user> userlist = new List<user>();
  69.  
  70.  
  71.  
  72.         public Form1()
  73.         {
  74.             InitializeComponent();
  75.         }
  76.  
  77.         private void Form1_Load(object sender, EventArgs e)
  78.         {
  79.  
  80.             CheckForIllegalCrossThreadCalls = false;
  81.          
  82.             // if client does not have a datafile create a new
  83.  
  84.             if (!File.Exists(path))
  85.             {
  86.                
  87.                 StreamWriter sw = File.CreateText(path);
  88.                 sw.Flush();
  89.                 sw.Dispose();
  90.             }
  91.  
  92.             // Load data to combobox and userlist
  93.             List<string> lines = File.ReadAllLines(path).ToList();
  94.  
  95.             foreach (var line in lines)
  96.             {
  97.                 string[] entries = line.Split(',');
  98.                 user newuser = new user(entries[0], entries[1]);
  99.                 comboBox1.Items.Add(entries[0]);
  100.                 userlist.Add(newuser);
  101.             }
  102.            
  103.         }
  104.  
  105.         private void button1_Click(object sender, EventArgs e)
  106.         {
  107.              // add new user to datafile
  108.             List<string> lines = File.ReadAllLines(path).ToList();
  109.             var User = new user(textBox1.Text, textBox2.Text);
  110.             userlist.Add(User);
  111.             lines.Add(User.username + "," + User.password);
  112.             File.WriteAllLines(path, lines);
  113.  
  114.             //refresh combobox
  115.             comboBox1.Items.Clear();
  116.             foreach (user v in userlist)
  117.             {
  118.                 comboBox1.Items.Add(v.username);
  119.             }
  120.         }
  121.  
  122.         private void button2_Click(object sender, EventArgs e)
  123.         {
  124.             // separate thread to not freeze the window
  125.             var ds = new Thread(login) { IsBackground = true };
  126.             ds.Start();
  127.         }
  128.  
  129.         void login()
  130.         {
  131.             // kill current steam process if there is one
  132.             foreach (var process in Process.GetProcessesByName("steam"))
  133.             {
  134.                 process.Kill();
  135.             }
  136.  
  137.             // Start steam, default installation dir
  138.             Process.Start(@"C:\Program Files (x86)\Steam\steam.exe");
  139.  
  140.  
  141.             // Retard loop by me, wait for updates to finish then set steam ontop + to the coordinates 200,200
  142.             bool cont = false;
  143.             while (true)
  144.             {
  145.                 foreach (var process in Process.GetProcessesByName("steam"))
  146.                 {
  147.  
  148.                     if (process.MainWindowTitle == "Steam Login")
  149.                     {
  150.                         cont = true;
  151.                         SetWindowPos(process.MainWindowHandle, HWND_TOPMOST, 200, 200, 0, 0, SWP_NOSIZE);
  152.                         break;
  153.                     }
  154.                 }
  155.                 if (cont == true)
  156.                     break;
  157.                 Thread.Sleep(100);
  158.             }
  159.  
  160.             Thread.Sleep(200);
  161.  
  162.  
  163.             // username textbox is at the coordinates (530,300) when we set the steam login window's coordinates to (200,200)
  164.             SetCursorPos(530, 300);
  165.             // double click so we select all the text
  166.             leftclick();
  167.             leftclick();
  168.             Thread.Sleep(10); // a little delay because it seemed to break if no delay.
  169.             SendKeys.SendWait(userlist[comboBox1.SelectedIndex].username);
  170.  
  171.             // Password textbox is located 30 pixels below the username textbox.
  172.  
  173.             SetCursorPos(530, 330);
  174.             leftclick();
  175.             leftclick();
  176.             Thread.Sleep(10);
  177.             SendKeys.SendWait(userlist[comboBox1.SelectedIndex].password);
  178.  
  179.             // click login button
  180.             SetCursorPos(350, 396);
  181.             Thread.Sleep(10);
  182.             leftclick();
  183.             leftclick();
  184.         }
  185.  
  186.         // I don't think I have to explain this one
  187.         void leftclick()
  188.         {
  189.             mouse_event(MOUSEEVENT_LEFTDOWN, 0, 0, 0, 0);
  190.             mouse_event(MOUSEEVENT_LEFTUP, 0, 0, 0, 0);
  191.         }
  192.  
  193.     }
  194. }
Add Comment
Please, Sign In to add comment