From 33faa49a0d45133e7a6809316232238ea2522c8b Mon Sep 17 00:00:00 2001 From: rex706 Date: Wed, 9 Aug 2023 10:49:32 -0400 Subject: [PATCH] Remove forced -vgui parameter * -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 --- Core/LoginWindowState.cs | 1 + Core/WindowUtils.cs | 43 ++++++++++++++++++++++++++---------- SAM.csproj | 2 +- Views/AccountsWindow.xaml.cs | 8 +++---- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Core/LoginWindowState.cs b/Core/LoginWindowState.cs index 8dff14e..c5e96c3 100644 --- a/Core/LoginWindowState.cs +++ b/Core/LoginWindowState.cs @@ -5,6 +5,7 @@ enum LoginWindowState None, Invalid, Error, + Selection, Login, Code, Loading, diff --git a/Core/WindowUtils.cs b/Core/WindowUtils.cs index a8a2381..1ccb4f7 100644 --- a/Core/WindowUtils.cs +++ b/Core/WindowUtils.cs @@ -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; } @@ -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; } @@ -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(); } } diff --git a/SAM.csproj b/SAM.csproj index c679ea1..b1ae9b8 100644 --- a/SAM.csproj +++ b/SAM.csproj @@ -214,7 +214,7 @@ 1.1.0 - 1.11.50 + 1.11.51 1.6.5 diff --git a/Views/AccountsWindow.xaml.cs b/Views/AccountsWindow.xaml.cs index 967d2eb..320e980 100644 --- a/Views/AccountsWindow.xaml.cs +++ b/Views/AccountsWindow.xaml.cs @@ -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(); @@ -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); @@ -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;