Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace P101_Launcher {
- class Game {
- string dir;
- string exe;
- public Game(string dir, string exe) {
- this.dir = dir;
- this.exe = exe;
- }
- public void Run(string args) {
- Process p = new Process() {
- StartInfo = new ProcessStartInfo() {
- FileName = exe,
- Arguments = args,
- CreateNoWindow = true,
- WorkingDirectory = dir
- }
- };
- p.Start();
- }
- }
- class Save {
- [JsonProperty]
- public string Username { get; set; }
- [JsonProperty]
- public string Password { get; set; }
- }
- class Program {
- const string SVNAME = "info.json";
- private static string GetConsoleSecurePassword() {
- string pwd = "";
- while (true) {
- ConsoleKeyInfo i = Console.ReadKey(true);
- if (i.Key == ConsoleKey.Enter) {
- break;
- }
- else if (i.Key == ConsoleKey.Backspace) {
- pwd.Remove(pwd.Length - 1);
- Console.Write("\b \b");
- }
- else {
- pwd += i.KeyChar;
- Console.Write("*");
- }
- }
- Console.WriteLine();
- return pwd;
- }
- static void CheckForSave() {
- if (!File.Exists(SVNAME)) {
- Console.WriteLine("Save does not exist. Creating now.");
- Task.Delay(500);
- Save sv = new Save();
- Console.Write("Username: ");
- sv.Username = Console.ReadLine();
- Console.Write("Password: ");
- sv.Password = GetConsoleSecurePassword();
- File.WriteAllText(SVNAME, JsonConvert.SerializeObject(sv));
- Console.WriteLine("\nInformation saved.");
- Console.ReadKey();
- }
- else {
- Console.WriteLine("Save found. Starting game.");
- Save sv = JsonConvert.DeserializeObject<Save>(File.ReadAllText(SVNAME));
- Game p101 = new Game(@"C:\ProgramData\KingsIsle Entertainment\Pirate101\Bin\", @"C:\ProgramData\KingsIsle Entertainment\Pirate101\Bin\Pirate.exe");
- p101.Run($"-L login.us.pirate101.com 12000 -U {sv.Username} {sv.Password}");
- }
- }
- static void Main(string[] args) {
- CheckForSave();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement