~ruther/NosTale-Gfless

ref: 2a270dbe0dd48e0b64fdd9993ea7adba93112bd8 NosTale-Gfless/NostaleGfless.Example/Program.cs -rw-r--r-- 3.5 KiB
2a270dbe — František Boháček fix: raise process exited event 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
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);
                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();
        }
    }
}
Do not follow this link