~ruther/NosTale-Gfless

ref: 1fb9e061a3334d492540fdb4c67dd8b3c5a47dda NosTale-Gfless/NostaleGfless.Example/Program.cs -rw-r--r-- 2.8 KiB
1fb9e061 — František Boháček fix: wait for main nostale window to open 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Linq;
using System.Threading;
using CommandLine;
using Microsoft.Win32;
using NostaleAuth.Models;
using NosTaleGfless;

namespace NostaleGfless.Example
{
    internal class Program
    {
        static EventWaitHandle ewh = new ManualResetEvent(false);
        
        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);

                GameforgeAccount account = launcher.Accounts.FirstOrDefault();
                if (account == null)
                {
                    throw new InvalidOperationException("There are no nostale account on the gameforge account");
                }

                if (options.AccountName != null)
                {
                    account = launcher.Accounts.FirstOrDefault(x => x.Name == options.AccountName);

                    if (account == null)
                    {
                        account = launcher.Accounts.FirstOrDefault(x => x.Name.Contains(options.AccountName));

                        if (account == null)
                        {
                            throw new InvalidOperationException("Account not found");
                        }
                    }
                }
                
                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();
            });
            
            ewh.WaitOne();
        }
    }
}
Do not follow this link