-
Notifications
You must be signed in to change notification settings - Fork 0
/
Launcher.cs
104 lines (95 loc) · 4.55 KB
/
Launcher.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using TaskDialogInterop;
using tman0.Launcher.UI;
using tman0.Launcher.Utilities;
namespace tman0.Launcher.Minecraft
{
public static class Launcher
{
public static async Task LaunchSequence(this MainWindow window,string username, string password)
{
window.LoadingBox.Visibility = Visibility.Visible;
window.LoadingText.Content = "Logging in...";
string[] AuthenticationString = await AuthenticatePlayer(username, password);
if (!(AuthenticationString.Length >= 3))
{
TaskDialogOptions o = new TaskDialogOptions();
o.Title = "Unexpected Login Server Response";
o.Owner = window;
o.MainInstruction = "A login error has occurred.";
o.Content = String.Join(":", AuthenticationString);
o.MainIcon = VistaTaskDialogIcon.Warning;
TaskDialog.Show(o);
//MessageBox.Show(AuthenticationString[0], "Unexpected Login Server Response", MessageBoxButton.OK);
window.LoadingBox.Visibility = Visibility.Collapsed;
return;
}
await window.BeginDownloadMinecraft();
await Run(window, AuthenticationString[2], AuthenticationString[3]);
}
public static async Task<Process> Run(MainWindow window, string Username, string AuthCode)
{
Process p = new Process();
ProcessStartInfo i = new ProcessStartInfo();
i.FileName = LauncherSettings.Default.JavaLocation; // @"C:\Program Files\Java\jre7\bin\java.exe";
i.Arguments += "-cp \"" + Globals.LauncherDataPath + @"\Minecraft\bin\LWJGL\jinput.jar;" + Globals.LauncherDataPath + @"\Minecraft\bin\LWJGL\lwjgl.jar;" + Globals.LauncherDataPath + @"\Minecraft\bin\LWJGL\lwjgl_util.jar;" + Globals.LauncherDataPath + @"\Minecraft\bin\minecraft.jar;" + "\"";
i.Arguments += " -Xms" + LauncherSettings.Default.InitialMemory;
i.Arguments += " -Xmx" + LauncherSettings.Default.MaxMemory;
i.Arguments += " -Djava.library.path=\"" + Globals.LauncherDataPath + @"\Minecraft\bin\LWJGL\natives" + "\"";
if (LauncherSettings.Default.UseXincgc) i.Arguments += " -Xincgc";
if (LauncherSettings.Default.UseServer) i.Arguments += " -server";
i.Arguments += LauncherSettings.Default.VMArgs;
i.Arguments += " net.minecraft.client.Minecraft";
i.Arguments += " " + Username + " " + AuthCode;
log.WriteLine("[MCL] Launching " + i.FileName);
log.WriteLine("[MCL] Args: " + i.Arguments);
i.UseShellExecute = false;
i.RedirectStandardError = true;
i.RedirectStandardInput = true;
i.RedirectStandardOutput = true;
i.CreateNoWindow = true;
p.StartInfo = i;
p.Start();
log.WriteLine("[MCL] Minecraft Started");
log.WriteLine("[MCL] " + p.VirtualMemorySize64 / 1024 / 1024 + "MB Allocated at " + p.StartTime.ToString());
p.EnableRaisingEvents = true;
p.PriorityBoostEnabled = true;
p.PriorityClass = ProcessPriorityClass.AboveNormal;
p.Exited += MinecraftClosed;
p.OutputDataReceived += p_OutputDataReceived;
p.BeginOutputReadLine();
log.Show();
window.Hide();
return p;
}
private static DebugLog log = new DebugLog();
static void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
log.WriteLine(e.Data);
}
static void MinecraftClosed(object sender, EventArgs e)
{
log.WriteLine("[MCL] Minecraft died");
// DIRTY HACK INBOUND
Thread t = new Thread(new ThreadStart(() => { Globals.Windows.MainWindow.Dispatcher.Invoke(Application.Current.Shutdown); }));
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
}
public static async Task<string[]> AuthenticatePlayer(string username, string password)
{
WebClient w = new WebClient();
string res = await w.DownloadStringTaskAsync("https://login.minecraft.net/?user=" + username + "&password=" + password + "&version=9001");
return res.Split(':');
}
}
}