Skip to content

Commit

Permalink
Remove forced -vgui parameter
Browse files Browse the repository at this point in the history
* -login parameter seems to now be working with the new SteamUI and no longer requires the -vgui parameter, which seems to have been deperecated. #180
* Introduce code to handle the account selection window.
* Update NuGet package
* Still need to refactor and consolidate window interaction code
  • Loading branch information
rex706 committed Aug 9, 2023
1 parent d53f5f7 commit 33faa49
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
1 change: 1 addition & 0 deletions Core/LoginWindowState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enum LoginWindowState
None,
Invalid,
Error,
Selection,
Login,
Code,
Loading,
Expand Down
43 changes: 31 additions & 12 deletions Core/WindowUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,26 @@ public static LoginWindowState GetLoginWindowState(WindowHandle loginWindow)
return LoginWindowState.Loading;
}

AutomationElement[] elements = document.FindAllChildren(e => e.ByControlType(ControlType.Edit));
AutomationElement[] inputs = document.FindAllChildren(e => e.ByControlType(ControlType.Edit));
AutomationElement[] buttons = document.FindAllChildren(e => e.ByControlType(ControlType.Button));
AutomationElement[] groups = document.FindAllChildren(e => e.ByControlType(ControlType.Group));
AutomationElement[] images = document.FindAllChildren(e => e.ByControlType(ControlType.Image));

if (elements != null)
if (inputs != null)
{
if (elements.Length == 0 && buttons.Length == 1)
if (inputs.Length == 0 && images.Length > 0 && images[0].AutomationId == "Layer_2")
{
return LoginWindowState.Selection;
}
if (inputs.Length == 0 && buttons.Length == 1)
{
return LoginWindowState.Error;
}
else if (elements.Length == 5)
else if (inputs.Length == 5)
{
return LoginWindowState.Code;
}
else if (elements.Length == 2 && buttons.Length == 1)
else if (inputs.Length == 2 && buttons.Length == 1)
{
return LoginWindowState.Login;
}
Expand Down Expand Up @@ -264,16 +270,27 @@ public static LoginWindowState TryCredentialsEntry(WindowHandle loginWindow, str
AutomationElement[] inputs = document.FindAllChildren(e => e.ByControlType(ControlType.Edit));
AutomationElement[] buttons = document.FindAllChildren(e => e.ByControlType(ControlType.Button));
AutomationElement[] groups = document.FindAllChildren(e => e.ByControlType(ControlType.Group));
AutomationElement[] images = document.FindAllChildren(e => e.ByControlType(ControlType.Image));

if (inputs != null)
{
if (inputs.Length == 0 && images.Length > 0 && images[0].AutomationId == "Layer_2")
{
Button addAccountButton = groups[groups.Length - 1].AsButton();
addAccountButton.Invoke();

Console.WriteLine("Window State: Selection");
return LoginWindowState.Selection;
}
if (inputs.Length == 0 && buttons.Length == 1)
{
Console.WriteLine("Window State: Error");
return LoginWindowState.Error;
}

if (inputs.Length == 5)
{
Console.WriteLine("Window State: Code");
return LoginWindowState.Code;
}

Expand Down Expand Up @@ -357,29 +374,31 @@ public static LoginWindowState TryCodeEntry(WindowHandle loginWindow, string sec
return LoginWindowState.Loading;
}

AutomationElement[] elements = document.FindAllChildren(e => e.ByControlType(ControlType.Edit));
AutomationElement[] inputs = document.FindAllChildren(e => e.ByControlType(ControlType.Edit));
AutomationElement[] buttons = document.FindAllChildren(e => e.ByControlType(ControlType.Button));
AutomationElement[] groups = document.FindAllChildren(e => e.ByControlType(ControlType.Group));
AutomationElement[] images = document.FindAllChildren(e => e.ByControlType(ControlType.Image));

if (elements != null)
if (inputs != null)
{
if (elements.Length == 0 && buttons.Length == 1)
if (inputs.Length == 0 && buttons.Length == 1)
{
return LoginWindowState.Error;
}
else if (elements.Length == 2 && buttons.Length == 1)
else if (inputs.Length == 2 && buttons.Length == 1)
{
return LoginWindowState.Login;
}

if (elements.Length == 5)
if (inputs.Length == 5)
{
string code = Generate2FACode(secret);

try
{
for (int i = 0; i < elements.Length; i++)
for (int i = 0; i < inputs.Length; i++)
{
TextBox textBox = elements[i].AsTextBox();
TextBox textBox = inputs[i].AsTextBox();
textBox.Text = code[i].ToString();
}
}
Expand Down
2 changes: 1 addition & 1 deletion SAM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="HtmlAgilityPack">
<Version>1.11.50</Version>
<Version>1.11.51</Version>
</PackageReference>
<PackageReference Include="MahApps.Metro">
<Version>1.6.5</Version>
Expand Down
8 changes: 4 additions & 4 deletions Views/AccountsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1407,11 +1407,10 @@ private void Login(int index, int tryCount)

foreach (string parameter in parameters)
{
// Not working with new UI as of 6/14/2022
// Add -vgui parameter to use old UI for now
if (parameter.Equals("-login"))
{
parametersBuilder.Append(" -vgui ").Append(parameter).Append(" ");
// Not working as of August 2023
//parametersBuilder.Append(" -vgui ").Append(parameter).Append(" ");

StringBuilder passwordBuilder = new StringBuilder();

Expand Down Expand Up @@ -1477,6 +1476,7 @@ private void Login(int index, int tryCount)
}
else
{
// -noreactlogin parameter has been depecrated as of January 2023
if (noReactLogin)
{
TypeCredentials(steamProcess, index, tryCount);
Expand Down Expand Up @@ -1698,7 +1698,7 @@ private void EnterReact2FA(Process steamProcess, Account account, int tryCount)
{
return;
}
else if (state == LoginWindowState.Login)
else if (state == LoginWindowState.Login || state == LoginWindowState.Selection)
{
EnterCredentials(steamProcess, account, retry);
return;
Expand Down

0 comments on commit 33faa49

Please sign in to comment.