using System.Diagnostics; using System.Text.Json; using XFEWarframe.Client.Runtime; using XFEWarframe.Player.Profiles.CrossVersionProfiles; namespace XFEWarframe.Player.Utilities.Diagnostics; internal static partial class DesktopVerification { private static async Task VerifyGameLoginAsync(string reportPath) { var checks = new List(); string? error = null; try { if (AppPath.Argument("profile-root") is null) throw new InvalidOperationException("An isolated launcher profile is required."); var api = AppPath.Argument("verify-api") ?? throw new InvalidOperationException("A test server is required."); var origin = new Uri(api); if (!origin.IsLoopback || origin.Port == 8444) throw new InvalidOperationException("Use an isolated local server port."); var game = AppPath.Argument("verify-game") ?? throw new InvalidOperationException("An isolated game copy is required."); var credentialFile = AppPath.Argument("verify-login-file") ?? throw new InvalidOperationException("Test account file is required."); using var credentials = JsonDocument.Parse(await File.ReadAllTextAsync(credentialFile)); await App.Service.InitializeAsync(); App.Service.State.GameDirectory = game; App.Service.State.ServerUrl = api; App.Service.State.AutoLoginToGame = true; await App.Accounts.LoginAsync(credentials.RootElement.GetProperty("email").GetString()!, credentials.RootElement.GetProperty("password").GetString()!); checks.Add("launcher-account-authenticated"); var request = await App.Accounts.GameLoginAsync(); request.Validate(); if (request.ServerUrl != api) throw new InvalidOperationException("Credential origin mismatch."); checks.Add("windows-protected-session-to-native-whirlpool-credential"); await App.Service.PlayAsync(); var sessions = await RuntimeDiscovery.FindAsync(game); var session = sessions.Single(x => x.StartedAt > DateTimeOffset.UtcNow.AddMinutes(-3)); using var runtime = new RuntimeControlClient(session); var native = await runtime.GameLoginStatusAsync(); if (native.Phase != "succeeded") throw new InvalidOperationException("Native game login has not completed."); if ((await runtime.StatusAsync()).Capabilities.Any(x => x.Key == "game_test_control" && x.Available)) throw new InvalidOperationException("Diagnostic game control must remain disabled."); checks.Add("production-native-login-reached-profile-state-4-with-diagnostics-disabled"); var config = await File.ReadAllTextAsync(Path.Combine(game, "XFEWarframe", "client.json")); if (config.Contains(request.PasswordHash, StringComparison.Ordinal) || config.Contains(credentials.RootElement.GetProperty("password").GetString()!, StringComparison.Ordinal)) throw new InvalidOperationException("Credentials were written into the installed configuration."); checks.Add("installed-configuration-has-no-account-secrets"); await File.WriteAllTextAsync(reportPath + ".game-pid", session.ProcessId.ToString(System.Globalization.CultureInfo.InvariantCulture)); } catch (Exception ex) { error = ex.GetType().Name + ": " + ex.Message; } Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(reportPath))!); await File.WriteAllTextAsync(reportPath, JsonSerializer.Serialize(new { success = error is null, error, checks, bindingErrors = BindingErrors }, new JsonSerializerOptions { WriteIndented = true })); } }