Skip to content

Commit

Permalink
Use the current Xbox user's gamertag
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePixelGamer committed Apr 28, 2022
1 parent 12de498 commit be3d2ae
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
4 changes: 2 additions & 2 deletions ZenovaLauncher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
HorizontalContentAlignment="Left"
VerticalAlignment="Center"
ui:ControlHelper.CornerRadius="0,0,0,0"
SelectedItem="{Binding SelectedAccount}"
SelectedItem="{Binding CurrentXboxAccount}"
SelectionChanged="AccountChanged"
Padding="12,25,0,10">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock FontSize="11" Text="{Binding AccountName}" />
<TextBlock FontSize="11" Text="{Binding Gamertag}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Expand Down
40 changes: 17 additions & 23 deletions ZenovaLauncher/Profiles/AccountManager.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,42 @@
using Microsoft.Win32;
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Windows.Security.Authentication.Web.Core;
using Windows.Security.Credentials;

namespace ZenovaLauncher
{
public class AccountManager : ObservableCollection<MSAccount>
public class AccountManager : ObservableCollection<XboxAccount>
{
public static AccountManager instance;

public MSAccount SelectedAccount { get; set; }
public XboxAccount CurrentXboxAccount { get; set; }

public async Task AddAccounts()
{
Trace.WriteLine("AddAccounts");
WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "consumers");
RegistryKey accountIdsReg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\IdentityCRL\\UserTileData");
if (accountIdsReg != null)
Trace.WriteLine("AddAccounts");
RegistryKey currentXboxReg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\XboxLive");
if (currentXboxReg != null)
{
string[] accountsIds = Array.FindAll(accountIdsReg.GetValueNames(), s => !s.EndsWith("_ETAG"));
foreach (var accountsId in accountsIds)
{
var account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountsId);
Add(new MSAccount(account.UserName, account.Id));
}
var gamertag = currentXboxReg.GetValue("Gamertag");
var xuid = currentXboxReg.GetValue("Xuid");
if (gamertag != null && xuid != null)
Add(new XboxAccount(gamertag.ToString(), xuid.ToString()));
}
SelectedAccount = this.First();
CurrentXboxAccount = this.First();
Trace.WriteLine("AddAccounts finished");
}
}

public class MSAccount : NotifyPropertyChangedBase
public class XboxAccount : NotifyPropertyChangedBase
{
public MSAccount(string accountName, string accountId)
public XboxAccount(string gamertag, string xuid)
{
AccountName = accountName;
AccountId = accountId;
Gamertag = gamertag;
Xuid = xuid;
}

public string AccountName { get; set; }
public string AccountId { get; set; }
public string Gamertag { get; set; }
public string Xuid { get; set; }
}
}
}
13 changes: 10 additions & 3 deletions ZenovaLauncher/Utils/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ public int ModSortingId
set { ModSorting = (Mod.ModSortType)value; }
}
public string SelectedAccount
{
get { return AccountManager.instance.SelectedAccount.AccountName; }
set { AccountManager.instance.SelectedAccount = AccountManager.instance.FirstOrDefault(a => a.AccountName == value); }
{
get { return AccountManager.instance.CurrentXboxAccount.Gamertag; }
set
{
var current = AccountManager.instance.FirstOrDefault(a => a.Gamertag == value);
if (current != null)
{
AccountManager.instance.CurrentXboxAccount = current;
}
}
}
public string SelectedProfile
{
Expand Down
2 changes: 1 addition & 1 deletion ZenovaLauncher/Utils/WUProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private XElement BuildWUTickets()
new XAttribute(secutil + "id", "ClientMSA"),
new XAttribute(XNamespace.Xmlns + "wsu", secutil),
new XAttribute(XNamespace.Xmlns + "wuws", wuws));
foreach (string token in MSAUserToken)
foreach (string token in MSAUserToken ?? Enumerable.Empty<string>())
{
tickets.Add(new XElement("TicketType",
new XAttribute("Name", "MSA"),
Expand Down
1 change: 1 addition & 0 deletions ZenovaLauncher/Versions/VersionDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public async Task EnableUserAuthorization()
string[] accountsIds = Array.FindAll(accountIdsReg.GetValueNames(), s => !s.EndsWith("_ETAG"));
_protocol.MSAUserToken = await WUTokenHelper.GetWUToken(accountsIds);
}
accountIdsReg.Close();
}

public async Task Download(string updateIdentity, string revisionNumber, string destination, DownloadProgress progress, CancellationToken cancellationToken)
Expand Down

0 comments on commit be3d2ae

Please sign in to comment.