mirror of
https://gitlab.com/nullmax17/PlombirLauncher.git
synced 2025-03-15 02:11:11 +03:00
Feature done: Licensed minecraft support
This commit is contained in:
parent
d5c8d36d61
commit
7a8d262aed
@ -17,17 +17,15 @@ namespace Plombir;
|
|||||||
public class Launcher
|
public class Launcher
|
||||||
{
|
{
|
||||||
private readonly string _version;
|
private readonly string _version;
|
||||||
private readonly string _nickname;
|
|
||||||
static private MinecraftPath? _mcPath;
|
static private MinecraftPath? _mcPath;
|
||||||
static private MinecraftLauncher? _mcLauncher;
|
static private MinecraftLauncher? _mcLauncher;
|
||||||
|
|
||||||
public int DownloadProgress;
|
public int DownloadProgress;
|
||||||
public string? DownloadStatus;
|
public string? DownloadStatus;
|
||||||
|
|
||||||
public Launcher(string userName, string version, string? location = null)
|
public Launcher(string version, string? location = null)
|
||||||
{
|
{
|
||||||
_version = version;
|
_version = version;
|
||||||
_nickname = userName;
|
|
||||||
_mcPath = new($"{location}/{version}/minecraft");
|
_mcPath = new($"{location}/{version}/minecraft");
|
||||||
_mcLauncher = new(_mcPath);
|
_mcLauncher = new(_mcPath);
|
||||||
}
|
}
|
||||||
@ -51,15 +49,29 @@ public class Launcher
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async public Task RunLauncher()
|
public MSession CreateOfflineSession(string nickname)
|
||||||
|
{
|
||||||
|
var s = MSession.CreateOfflineSession(nickname);
|
||||||
|
if (s is null) throw new NullReferenceException("Tried creating offline session, but it's resulted in null!");
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MSession CreateLicensedSession(string uuid, string accsessToken, string nickname)
|
||||||
|
{
|
||||||
|
var s = new MSession(nickname, accsessToken, uuid);
|
||||||
|
if (s is null) throw new NullReferenceException("Tried creating licensed session, but it's resulted in null!");
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
async public Task RunLauncher(MSession session)
|
||||||
{
|
{
|
||||||
if (_mcLauncher is null)
|
if (_mcLauncher is null)
|
||||||
throw new NullReferenceException("Failed to run launcher! Launcher is null!");
|
throw new NullReferenceException("Failed to run launcher! Launcher is null!");
|
||||||
|
|
||||||
var process = await _mcLauncher.BuildProcessAsync(_version, new MLaunchOption
|
var process = await _mcLauncher.BuildProcessAsync(_version, new MLaunchOption
|
||||||
{
|
{
|
||||||
|
// Passing session, to support offline and licensed login methods.
|
||||||
Session = MSession.CreateOfflineSession(_nickname),
|
Session = session,
|
||||||
MaximumRamMb = 4096,
|
MaximumRamMb = 4096,
|
||||||
|
|
||||||
}) ?? throw new Exception("Failed to start minecraft process!");
|
}) ?? throw new Exception("Failed to start minecraft process!");
|
||||||
|
@ -10,12 +10,11 @@ public class ConfigManager
|
|||||||
static private readonly string defaultVersion = "1.20.1";
|
static private readonly string defaultVersion = "1.20.1";
|
||||||
static private readonly string defaultNickname = "slugcat";
|
static private readonly string defaultNickname = "slugcat";
|
||||||
|
|
||||||
static private readonly string currentTweaksVersion = "1.2.0";
|
static private readonly string currentTweaksVersion = "1.2.1";
|
||||||
|
|
||||||
static private readonly string defaultLoginType = "offline";
|
static private readonly string defaultLoginType = "offline";
|
||||||
static private readonly string defaultUuid = "offline";
|
static private readonly string defaultUuid = "offline";
|
||||||
static private readonly string defaultAccsessToken = "offline";
|
static private readonly string defaultAccsessToken = "offline";
|
||||||
static private readonly string defaultClientToken = "offline";
|
|
||||||
|
|
||||||
public static void BuildDefault()
|
public static void BuildDefault()
|
||||||
{
|
{
|
||||||
@ -40,7 +39,6 @@ public class ConfigManager
|
|||||||
["login-method"] = defaultLoginType,
|
["login-method"] = defaultLoginType,
|
||||||
["uuid"] = defaultUuid,
|
["uuid"] = defaultUuid,
|
||||||
["accsess-token"] = defaultAccsessToken,
|
["accsess-token"] = defaultAccsessToken,
|
||||||
["client-token"] = defaultClientToken,
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -87,7 +85,6 @@ public class ConfigManager
|
|||||||
case "nickname": { WriteInConfig(key, defaultNickname); return defaultNickname; }
|
case "nickname": { WriteInConfig(key, defaultNickname); return defaultNickname; }
|
||||||
|
|
||||||
case "accsess-token": { WriteInConfig(key, defaultAccsessToken); return defaultAccsessToken; }
|
case "accsess-token": { WriteInConfig(key, defaultAccsessToken); return defaultAccsessToken; }
|
||||||
case "client-token": { WriteInConfig(key, defaultClientToken); return defaultClientToken; }
|
|
||||||
case "uuid": { WriteInConfig(key, defaultUuid); return defaultUuid; }
|
case "uuid": { WriteInConfig(key, defaultUuid); return defaultUuid; }
|
||||||
case "login-method": { WriteInConfig(key, defaultLoginType); return defaultLoginType; }
|
case "login-method": { WriteInConfig(key, defaultLoginType); return defaultLoginType; }
|
||||||
case "tweaks-version":
|
case "tweaks-version":
|
||||||
|
@ -10,18 +10,23 @@ public class LauncherUtils
|
|||||||
{
|
{
|
||||||
public async static Task CreateMinecraftInstance(MainWindowViewModel vm, Window windowCaller)
|
public async static Task CreateMinecraftInstance(MainWindowViewModel vm, Window windowCaller)
|
||||||
{
|
{
|
||||||
|
var licenseStatus = ConfigManager.ReadConfig("login-method");
|
||||||
|
|
||||||
if (vm.Usernick is null) throw new NullReferenceException("Failed to create minecraft instance! Nickname is null!");
|
if (vm.Usernick is null) throw new NullReferenceException("Failed to create minecraft instance! Nickname is null!");
|
||||||
if (vm.SelectedVersion is null) throw new NullReferenceException("Failed to create minecraft instance! Selected version is null!");
|
if (vm.SelectedVersion is null) throw new NullReferenceException("Failed to create minecraft instance! Selected version is null!");
|
||||||
|
|
||||||
System.Console.WriteLine($"Creating minecraft instance for {vm.Usernick}, {vm.SelectedVersion} in {vm.RuntimeLocation}");
|
System.Console.WriteLine($"Creating minecraft instance for {vm.Usernick}, {vm.SelectedVersion} in {vm.RuntimeLocation}");
|
||||||
LoadingWindow loading = new(vm.Usernick, vm.SelectedVersion, vm.RuntimeLocation);
|
LoadingWindow loading = new(vm);
|
||||||
ConfigManager.WriteInConfig("last-version-launched", vm.SelectedVersion);
|
|
||||||
ConfigManager.WriteInConfig("nickname", vm.Usernick);
|
SaveCurrentVariablesToConfig(vm);
|
||||||
|
|
||||||
loading.Show();
|
loading.Show();
|
||||||
await loading.InitLoading();
|
await loading.InitLoading();
|
||||||
loading.Close();
|
loading.Close();
|
||||||
await loading.RunMinecraft();
|
|
||||||
|
if (licenseStatus == "microsoft") await loading.RunMinecraft(true);
|
||||||
|
else await loading.RunMinecraft(false);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,4 +34,9 @@ public class LauncherUtils
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void SaveCurrentVariablesToConfig(MainWindowViewModel vm)
|
||||||
|
{
|
||||||
|
ConfigManager.WriteInConfig("last-version-launched", vm.SelectedVersion);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,6 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
private string? _accsessToken = ConfigManager.ReadConfig("accsess-token");
|
private string? _accsessToken = ConfigManager.ReadConfig("accsess-token");
|
||||||
public string? AccsesToken { get => _accsessToken; set { _accsessToken = value; OnPropertyChanged(nameof(AccsesToken)); } }
|
public string? AccsesToken { get => _accsessToken; set { _accsessToken = value; OnPropertyChanged(nameof(AccsesToken)); } }
|
||||||
|
|
||||||
private string? _clientToken = ConfigManager.ReadConfig("client-token");
|
|
||||||
public string? ClientToken { get => _clientToken; set { _clientToken = value; OnPropertyChanged(nameof(ClientToken)); } }
|
|
||||||
|
|
||||||
private string? _uuid = ConfigManager.ReadConfig("uuid");
|
private string? _uuid = ConfigManager.ReadConfig("uuid");
|
||||||
public string? UUID { get => _uuid; set { _uuid = value; OnPropertyChanged(nameof(UUID)); } }
|
public string? UUID { get => _uuid; set { _uuid = value; OnPropertyChanged(nameof(UUID)); } }
|
||||||
|
|
||||||
|
@ -13,12 +13,14 @@ public partial class LoadingWindow : Window
|
|||||||
{
|
{
|
||||||
private Launcher ln;
|
private Launcher ln;
|
||||||
private Task? _buildingTask;
|
private Task? _buildingTask;
|
||||||
|
private readonly MainWindowViewModel _mainWindowVM;
|
||||||
|
|
||||||
// Tokens for controlling download task.
|
// Tokens for controlling download task.
|
||||||
CancellationTokenSource tokenSource = new CancellationTokenSource();
|
CancellationTokenSource tokenSource = new CancellationTokenSource();
|
||||||
public LoadingWindow(string nickname, string? version = null, string? location = null)
|
public LoadingWindow(MainWindowViewModel mainWindowVM)
|
||||||
{
|
{
|
||||||
ln = new Launcher(nickname, version ?? "1.20.1", location ?? "./runtime");
|
_mainWindowVM = mainWindowVM;
|
||||||
|
ln = new Launcher(_mainWindowVM.SelectedVersion ?? "1.20.1", _mainWindowVM.RuntimeLocation ?? "./runtime");
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
DataContext = new LoadingWindowViewModel();
|
DataContext = new LoadingWindowViewModel();
|
||||||
}
|
}
|
||||||
@ -52,9 +54,14 @@ public partial class LoadingWindow : Window
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RunMinecraft()
|
public async Task RunMinecraft(bool IsLicensed)
|
||||||
{
|
{
|
||||||
await ln.RunLauncher();
|
var session = ln.CreateOfflineSession(_mainWindowVM.Usernick);
|
||||||
|
if (IsLicensed)
|
||||||
|
{
|
||||||
|
session = ln.CreateLicensedSession(_mainWindowVM.UUID, _mainWindowVM.AccsesToken, _mainWindowVM.Usernick);
|
||||||
|
}
|
||||||
|
await ln.RunLauncher(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onStopDownloadClick(object sender, RoutedEventArgs e)
|
private void onStopDownloadClick(object sender, RoutedEventArgs e)
|
||||||
|
@ -50,6 +50,14 @@
|
|||||||
<TextBlock x:Name="loginMethod" />
|
<TextBlock x:Name="loginMethod" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<TextBlock
|
||||||
|
Text="Session uuid: "
|
||||||
|
FontFamily="{StaticResource QuicksandFont}"
|
||||||
|
/>
|
||||||
|
<TextBlock x:Name="currentUuid" />
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
</Border>
|
</Border>
|
||||||
@ -86,6 +94,13 @@
|
|||||||
HorizontalAlignment="Left"
|
HorizontalAlignment="Left"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
FontFamily="{StaticResource QuicksandFont}"
|
||||||
|
Content="Save"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Click="OnSaveButtonClick"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
@ -132,13 +147,6 @@
|
|||||||
|
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
<Button
|
|
||||||
FontFamily="{StaticResource QuicksandFont}"
|
|
||||||
Content="Save"
|
|
||||||
HorizontalAlignment="Center"
|
|
||||||
Click="OnSaveButtonClick"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
</Window>
|
</Window>
|
||||||
|
@ -13,9 +13,15 @@ public partial class SessionManagmentWindow : Window
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_mainWindowVM = mainWindowVM;
|
_mainWindowVM = mainWindowVM;
|
||||||
|
PopulateInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PopulateInfo()
|
||||||
|
{
|
||||||
inputNickname.Text = _mainWindowVM.Usernick; // setting default nickname.
|
inputNickname.Text = _mainWindowVM.Usernick; // setting default nickname.
|
||||||
currentNickname.Text = _mainWindowVM.Usernick;
|
currentNickname.Text = _mainWindowVM.Usernick;
|
||||||
loginMethod.Text = _mainWindowVM.LoginMethod;
|
loginMethod.Text = _mainWindowVM.LoginMethod;
|
||||||
|
currentUuid.Text = _mainWindowVM.UUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSaveButtonClick(object sender, RoutedEventArgs e)
|
private void OnSaveButtonClick(object sender, RoutedEventArgs e)
|
||||||
@ -26,6 +32,8 @@ public partial class SessionManagmentWindow : Window
|
|||||||
Console.WriteLine($"Changing nickname to {inputNickname.Text}");
|
Console.WriteLine($"Changing nickname to {inputNickname.Text}");
|
||||||
|
|
||||||
button.Content = "Saved!";
|
button.Content = "Saved!";
|
||||||
|
SaveSessionInfo();
|
||||||
|
PopulateInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
async private void OnMicrosoftLoginClick(object sender, RoutedEventArgs e)
|
async private void OnMicrosoftLoginClick(object sender, RoutedEventArgs e)
|
||||||
@ -35,6 +43,15 @@ public partial class SessionManagmentWindow : Window
|
|||||||
_mainWindowVM.Usernick = session.Username;
|
_mainWindowVM.Usernick = session.Username;
|
||||||
_mainWindowVM.UUID = session.UUID;
|
_mainWindowVM.UUID = session.UUID;
|
||||||
_mainWindowVM.AccsesToken = session.AccessToken;
|
_mainWindowVM.AccsesToken = session.AccessToken;
|
||||||
_mainWindowVM.ClientToken = session.ClientToken;
|
SaveSessionInfo();
|
||||||
|
PopulateInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveSessionInfo()
|
||||||
|
{
|
||||||
|
ConfigManager.WriteInConfig("nickname", _mainWindowVM.Usernick);
|
||||||
|
ConfigManager.WriteInConfig("login-method", _mainWindowVM.LoginMethod);
|
||||||
|
ConfigManager.WriteInConfig("uuid", _mainWindowVM.UUID);
|
||||||
|
ConfigManager.WriteInConfig("accsess-token", _mainWindowVM.AccsesToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user