Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace P101_Launcher {
  11.     class Game {
  12.         string dir;
  13.         string exe;
  14.  
  15.         public Game(string dir, string exe) {
  16.             this.dir = dir;
  17.             this.exe = exe;
  18.         }
  19.  
  20.         public void Run(string args) {
  21.             Process p = new Process() {
  22.                 StartInfo = new ProcessStartInfo() {
  23.                     FileName = exe,
  24.                     Arguments = args,
  25.                     CreateNoWindow = true,
  26.                     WorkingDirectory = dir
  27.                 }
  28.             };
  29.             p.Start();
  30.         }
  31.     }
  32.  
  33.     class Save {
  34.         [JsonProperty]
  35.         public string Username { get; set; }
  36.         [JsonProperty]
  37.         public string Password { get; set; }
  38.     }
  39.  
  40.     class Program {
  41.         const string SVNAME = "info.json";
  42.  
  43.         private static string GetConsoleSecurePassword() {
  44.             string pwd = "";
  45.  
  46.             while (true) {
  47.                 ConsoleKeyInfo i = Console.ReadKey(true);
  48.                 if (i.Key == ConsoleKey.Enter) {
  49.                     break;
  50.                 }
  51.                 else if (i.Key == ConsoleKey.Backspace) {
  52.                     pwd.Remove(pwd.Length - 1);
  53.                     Console.Write("\b \b");
  54.                 }
  55.                 else {
  56.                     pwd += i.KeyChar;
  57.                     Console.Write("*");
  58.                 }
  59.             }
  60.             Console.WriteLine();
  61.             return pwd;
  62.         }
  63.  
  64.         static void CheckForSave() {
  65.             if (!File.Exists(SVNAME)) {
  66.                 Console.WriteLine("Save does not exist. Creating now.");
  67.                 Task.Delay(500);
  68.                 Save sv = new Save();
  69.  
  70.                 Console.Write("Username: ");
  71.                 sv.Username = Console.ReadLine();
  72.                 Console.Write("Password: ");
  73.                 sv.Password = GetConsoleSecurePassword();
  74.  
  75.                 File.WriteAllText(SVNAME, JsonConvert.SerializeObject(sv));
  76.                 Console.WriteLine("\nInformation saved.");
  77.                 Console.ReadKey();
  78.             }
  79.             else {
  80.                 Console.WriteLine("Save found. Starting game.");
  81.                 Save sv = JsonConvert.DeserializeObject<Save>(File.ReadAllText(SVNAME));
  82.                 Game p101 = new Game(@"C:\ProgramData\KingsIsle Entertainment\Pirate101\Bin\", @"C:\ProgramData\KingsIsle Entertainment\Pirate101\Bin\Pirate.exe");
  83.  
  84.                 p101.Run($"-L login.us.pirate101.com 12000 -U {sv.Username} {sv.Password}");
  85.             }
  86.         }
  87.  
  88.         static void Main(string[] args) {
  89.             CheckForSave();
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement