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
98
99
//
// DllMain.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.Runtime.InteropServices;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NosSmooth.ChatCommands;
using NosSmooth.Core.Extensions;
using NosSmooth.Data.NOSFiles.Extensions;
using NosSmooth.Extensions.Combat.Extensions;
using NosSmooth.Extensions.Pathfinding.Extensions;
using NosSmooth.Extensions.SharedBinding.Extensions;
using NosSmooth.Game.Extensions;
using NosSmooth.LocalClient.Extensions;
using Remora.Commands.Extensions;
using SimplePiiBot.Commands;
using SimplePiiBot.Responders;
namespace SimplePiiBot;
/// <summary>
/// The entrypoint class.
/// </summary>
public class DllMain
{
/// <summary>
/// Allocate console.
/// </summary>
/// <returns>Whether the operation was successful.</returns>
[DllImport("kernel32")]
public static extern bool AllocConsole();
/// <summary>
/// Represents the dll entrypoint method.
/// </summary>
[UnmanagedCallersOnly(EntryPoint = "Main")]
public static void Main()
{
AllocConsole();
new Thread
(
() =>
{
try
{
MainEntry().GetAwaiter().GetResult();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
).Start();
}
/// <summary>
/// The entrypoint method.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
private static async Task MainEntry()
{
var host = Host.CreateDefaultBuilder()
.UseConsoleLifetime()
.ConfigureLogging
(
b =>
{
b
.ClearProviders()
.AddConsole();
}
)
.ConfigureServices
(
s =>
{
s.AddNostaleCore()
.AddNostaleGame()
.AddLocalClient()
.AddNostaleDataFiles()
.ShareNosSmooth()
.AddNostaleCombat()
.AddNostalePathfinding()
.AddSingleton<Bot>()
.AddNostaleChatCommands()
.AddGameResponder<EntityJoinedResponder>()
.AddCommandTree()
.WithCommandGroup<ControlCommands>()
.WithCommandGroup<EntityCommands>();
s.AddHostedService<HostedService>();
}
).Build();
await host.RunAsync();
}
}