public async Task <NostaleProcess> Launch(GameforgeAccount account, string nostalePath) { NostaleProcess process = await Launcher.Launch(account, await Api.GetSessionToken(account, true), nostalePath); if (process != null) { ActiveProcesses.Add(process); } return(process); }
public NostaleProcess RunProcess(GameforgeAccount account, string nostalePath) { Guid sessionId = Guid.NewGuid(); Environment.SetEnvironmentVariable("_TNT_CLIENT_APPLICATION_ID", "d3b2a0c1-f0d0-4888-ae0b-1c5e1febdafb"); Environment.SetEnvironmentVariable("_TNT_SESSION_ID", sessionId.ToString()); string path = GetNostaleClientPath(nostalePath); Process process = Process.Start(path, $"gf {(int)account.GetRegionType()}"); return(new NostaleProcess(process, account) { SessionId = sessionId }); }
public async Task <string> GetSessionToken(GameforgeAccount gameforgeAccount, bool raw = false) { var request = new GameforgeRequest <SessionRequest, string>(HttpMethod.Post, "/auth/thin/codes", InstallationId, AuthToken); var sessionRequest = new SessionRequest { PlatformGameAccountId = gameforgeAccount.Id }; Dictionary <string, string> response = await request.Send(sessionRequest); if (response == null) { return(string.Empty); } string data = (response.GetValueOrDefault("code") ?? string.Empty); return(raw ? data : data.ToHex()); }
public Task <NostaleProcess> Launch(GameforgeAccount account, string sessionToken, string nostalePath) { return(Task.Run(() => { lock (_lock) { NostaleProcess process = RunProcess(account, nostalePath); process.Initialized = ProcessPipeServer(process, sessionToken).GetAwaiter().GetResult(); if (process.Initialized) { while (true) { List <IntPtr> handles = new List <IntPtr>(); // wait for main window open User32.EnumDesktopWindows(IntPtr.Zero, (hWnd, lParam) => { User32.GetWindowThreadProcessId(hWnd, out uint processId); if (processId == process.ProcessId) { handles.Add(hWnd); } return true; }, IntPtr.Zero); if (handles.Count > 6 || process.HasExited) { break; } Task.Delay(50).GetAwaiter().GetResult(); } } return process; } })); }
public static void Main(string[] args) { string installationIdString = (string)Registry.GetValue( @"HKEY_CURRENT_USER\Software\Gameforge4d\TNTClient\MainApp", "InstallationId", null); Guid?installationId = null; if (installationIdString != null) { installationId = Guid.Parse(installationIdString); } Parser.Default.ParseArguments <Options>(args).WithParsed(async options => { if (options.InstallationId != null) { installationId = Guid.Parse(options.InstallationId); } var authenticator = new GameforgeAuthenticator(); authenticator.InstallationId = installationId; var launcher = await authenticator.Authenticate(options.Email, options.Password); if (launcher.Accounts.Count == 0) { throw new InvalidOperationException("There are no nostale account on the gameforge account"); } List <GameforgeAccount> accounts = new List <GameforgeAccount>(); if (options.AccountName != null) { foreach (string accountName in options.AccountName.Split(',')) { GameforgeAccount account = launcher.Accounts.FirstOrDefault(x => x.Name == accountName); if (account == null) { account = launcher.Accounts.FirstOrDefault(x => x.Name.Contains(accountName)); if (account == null) { throw new InvalidOperationException($"Account {accountName} not found"); } } accounts.Add(account); } } if (accounts.Count == 0) { accounts.Add(launcher.Accounts.FirstOrDefault()); } foreach (GameforgeAccount account in accounts) { Console.WriteLine($"Selected account: {account.Name}"); Console.WriteLine("Launching nostale with the selected account ..."); Console.WriteLine("Waiting for nostale ..."); var result = await launcher.Launch(account, options.NostalePath); if (result != null && result.Initialized) { Console.WriteLine( $"Nostale launched successfully. Process id: {result.ProcessId}, Session id: {result.SessionId}"); } else { Console.WriteLine("There was an error launching nostale"); } } ewh.Set(); }).WithNotParsed((err) => { ewh.Set(); }); ewh.WaitOne(); }
public NostaleProcess(Process process, GameforgeAccount account) { Account = account; Process = process; }