https://github.com/BlossomiShymae/Briar
A simple wrapper for the LCU.
https://github.com/BlossomiShymae/Briar
lcu lcu-api league-of-legends
Last synced: 10 months ago
JSON representation
A simple wrapper for the LCU.
- Host: GitHub
- URL: https://github.com/BlossomiShymae/Briar
- Owner: BlossomiShymae
- License: mit
- Created: 2024-07-27T05:32:07.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-29T12:22:04.000Z (almost 2 years ago)
- Last Synced: 2024-12-01T21:45:40.193Z (over 1 year ago)
- Topics: lcu, lcu-api, league-of-legends
- Language: C#
- Homepage:
- Size: 264 KB
- Stars: 6
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-league - GrrrLCU - A simple C# wrapper for the LCU. (Developer Tools)
README
# Briar
[](https://www.nuget.org/packages/BlossomiShymae.Briar/) [](https://www.nuget.org/packages/BlossomiShymae.Briar/)
Briar is a wrapper for the League Client and Game Client APIs which are unofficially provided by Riot Games.
This library is currently compatible with .NET 8 and higher for Windows and MacOS.
## Contributors
## Usage
### Installation
```bash
dotnet install BlossomiShymae.Briar
```
### Sample application
[A demonstration of Briar with more code examples can be found here.](https://github.com/BlossomiShymae/Briar/blob/main/BlossomiShymae.Briar.Demo/Program.cs)
To run the demo, clone the repo and then do:
```bash
dotnet run --project BlossomiShymae.Briar.Demo
```
### Requesting the LCU
This library uses the `System.Net.Http.HttpClient` interface via `LcuHttpClient`. It comes with a built-in handler that takes care of the request path and authorization header.
> [!NOTE]
> The built-in handler will attempt to refresh the port and auth if a `HttpRequestException` is encountered **on request**. `InvalidOperationException` will be thrown if the port of the current LCU process cannot be found or the port cannot be connected to.
#### Getting the LcuHttpClient instance
```csharp
var client = Connector.GetLcuHttpClientInstance();
```
#### General request
```csharp
var response = await client.SendAsync(new(HttpMethod.Get, "/lol-summoner/v1/current-summoner"));
var me = await response.Content.ReadFromJsonAsync();
```
#### GET request
```csharp
var me = await client.GetFromJsonAsync("/lol-summoner/v1/current-summoner");
```
#### POST request with JSON body
```csharp
var response = await client.PostAsJsonAsync("/player-notifications/v1/notifications", playerNotificationResource);
var resource = await response.Content.ReadFromJsonAsync();
```
> [!WARNING]
> `ProcessFinder.IsActive()` does not necessarily mean that the LCU process port is open for requests. Use `ProcessFinder.IsPortOpen()` instead.
#### Utilities
```csharp
var leagueClientProcess = ProcessFinder.GetProcess();
var processInfo = ProcessFinder.GetProcessInfo();
var isActive = ProcessFinder.IsActive();
var isPortOpen = ProcessFinder.IsPortOpen();
var riotAuthentication = new RiotAuthentication(processInfo.RemotingAuthToken);
```
### Requesting the Game Client
#### Getting the GameHttpClient instance
```csharp
var client = Connector.GetGameHttpClientInstance();
```
#### General request
```csharp
var response = await client.SendAsync(new(HttpMethod.Get, "/liveclientdata/activeplayername"));
var me = await response.Content.ReadFromJsonAsync();
```
#### GET request
```csharp
var me = await client.GetFromJsonAsync("/liveclientdata/activeplayername");
```
### LCU WebSocket
This library uses the `Websocket.Client` wrapper.
Create a client:
```csharp
var client = Connector.CreateLcuWebsocketClient();
```
Listen to events, disconnections, or reconnection messages:
```csharp
using System; // Include to avoid compiler errors CS1503, CS1660.
// You may or may not need this.
client.EventReceived.Subscribe(msg =>
{
Console.WriteLine(msg?.Data?.Uri);
});
client.DisconnectionHappened.Subscribe(msg =>
{
if (msg.Exception != null) throw msg.Exception;
});
client.ReconnectionHappened.Subscribe(msg =>
{
Console.WriteLine(msg.Type);
});
```
Use it:
```csharp
// This starts the client in a background thread. You will need an event loop
// to listen to messages.
await client.Start();
// Subscribe to every event that the League Client sends.
var message = new EventMessage(EventRequestType.Subscribe, EventKinds.OnJsonApiEvent);
client.Send(message);
// We will need an event loop for the background thread to process.
while(true) await Task.Delay(TimeSpan.FromSeconds(1));
```