~ruther/NosSmooth.Local

ref: d5b3c3ffb40aa86f582a0f26fc0376caa245f220 NosSmooth.Local/src/Samples/External/ExternalBrowser/Program.cs -rw-r--r-- 2.2 KiB
d5b3c3ff — Rutherther Merge pull request #18 from Rutherther/feat/optional-binding 2 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
//
//  Program.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Diagnostics;
using NosSmooth.Core.Extensions;
using NosSmooth.LocalBinding;
using NosSmooth.LocalBinding.Options;
using NosSmooth.LocalBinding.Structs;

namespace ExternalBrowser;

/// <summary>
/// The entrypoint class for ExternalBrowser.
/// </summary>
public class Program
{
    /// <summary>
    /// The entrypoint method for ExternalBrowser.
    /// </summary>
    /// <param name="arguments">The arguments.</param>
    public static void Main(string[] arguments)
    {
        foreach (var argument in arguments)
        {
            Process[] processes;

            if (int.TryParse(argument, out var processId))
            {
                processes = new[] { Process.GetProcessById(processId) };
            }
            else
            {
                processes = Process
                    .GetProcesses()
                    .Where(x => x.ProcessName.Contains(argument))
                    .ToArray();
            }

            foreach (var process in processes)
            {
                var externalBrowser = new NosBrowserManager(process);

                if (!externalBrowser.IsNostaleProcess)
                {
                    Console.Error.WriteLine($"Process {process.Id} is not a nostale process.");
                    continue;
                }

                var initializationResult = externalBrowser.Initialize();
                if (!initializationResult.IsSuccess)
                {
                    Console.Error.WriteLine(initializationResult.ToFullString());
                }

                var length = externalBrowser.PetManagerList.Get().Length;
                Console.WriteLine(length);

                if (!externalBrowser.IsInGame.Get())
                {
                    Console.Error.WriteLine("The player is not in game, cannot get the name of the player.");
                    continue;
                }

                Console.WriteLine
                    ($"Player in process {process.Id} is named {externalBrowser.PlayerManager.Get().Player.Name}");
            }
        }
    }
}
Do not follow this link