An Elite: Dangerous API library for .NET
When playing Elite: Dangerous, many in-game events are outputted to the Journal log files. EliteAPI makes use of these files to provide live information about in-game events in a .NET environment.
EliteAPI is distributed through the NuGet package manager; the recommended way to install this library. Alternatively, the library could also be compiled to retrieve the .dll file.
EliteAPI targets .NET Standard 2.0. Creating applications using the latest version of .NET Core is the most recommended. If needed, .NET Framework 4.6.1 or higher is also supported.
EliteAPI is listed as EliteAPI
on NuGet. A reference to the library can be made in a number of different ways through NuGet, here are the most common ones.
Platform | Syntax |
---|---|
Package manager | Install-Package EliteAPI |
.NET CLI | dotnet add package EliteAPI |
Package reference | <PackageReference Include="EliteAPI"/> |
Paket CLI | paket add EliteAPI |
EliteAPI is bundeled with Depedency Injection. It is recommended that you use a host when working with the API. EliteAPI contains an extension method AddEliteAPI()
that adds all the required services to your IServiceCollection
.
Below is an example of how to create a host in a .NET Core environment, and how to set up the API.
using EliteAPI;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
private static async Task Main(string[] args) {
// Create a host that uses EliteAPI
IHost host = Host.CreateDefaultBuilder()
.ConfigureServices((context, service) =>
{
service.AddEliteAPI();
service.AddTransient<MyAppService>(); // Example
})
.Build();
// Get the EliteDangerousAPI api object
var api = Host.Services.GetService<IEliteDangerousAPI>();
// Start the api
await api.StartAsync();
// Run forever
await Task.Delay(-1);
}
EliteAPI constantly scans the Journal log files for new in-game events. Whenever a new event is detected it is invoked in the api. There are multiple ways to hook into an event.
EliteAPI has an individual event for every event logged in the Journal files. These events can be found in the IEliteDangerousAPI.Events
property. The event is automatically invoked whenever the specified action is peformed in-game.
api.Events.BountyEvent += (sender, e) =>
{
// Triggered whenever we collect a bounty
Console.WriteLine("Collected {0} from {1}", e.TotalReward, e.Target);
var gear = api.Status.Gear;
};
In-game events can be assigned to specific methods using the EliteDangerousEvent
attribute. The method must be public, in a public class that derives from EliteDangerousEventModule
and must also be added through the EliteAPI configuration. This registeres this class as a service to your IServiceCollection
.
service.AddEliteAPI(config => {
config.AddEventModule<CombatModule>();
});
Which in-game event triggers the method is based on the method's first parameter type.
public class CombatModule : EliteDangerousEventModule {
public CombatModule(IServiceProvider services) : base(services) { }
[EliteDangerousEvent]
public async Task NewBounty(BountyEvent e) {
// Triggered whenever we collect a bounty
Console.WriteLine("Collected {0} from {1}", e.TotalReward, e.Target);
var gear = EliteAPI.Status.Gear;
}
}
EliteAPI can be configured using configuration files.
[EliteAPI]
Journalpath = "W:\\"
If you run through vs code, you must change the parameter Console from internal to external in launch.json. From.
"console": "internalConsole"
To.
"console": "externalTerminal"
EliteAPI is distributed under the MIT license.