Skip to content

Hexcore is a dart library which provides an interface to the League of Legends Client or LCU (League Client Update) API

License

Notifications You must be signed in to change notification settings

Lucasmaia435/hexcore

Repository files navigation

Hexcore

pub package

A Flutter package which provides an interface to the League of Legends Client API (LCU API) and LCU Socket connection.

Usage

Use Hexcore.create to create a new instance of Hexcore

Hexcore hexcore = await Hexcore.create();

await hexcore.connectToClient();

At the moment that Hexcore connect to the client, it will watch the League Client state. If the player closes the client, the package will wait until the player reopen it.

Hexcore has three states:

  1. initial: When the instance of Hexcore is created.
  2. searchingClientPath: When Hexcore is searching for the League Client path at the player's PC.
  3. waiting: Hexcore already found the League Client Path, and now is waiting for the player to open the game or trying to connect to it.
  4. connected: Hexcore is connected and ready to go.

Hexcore has a ValueNotifier that notifies about the state of the connection, so you can use an AnimatedContainer to build according to it's state.

...
AnimatedBuilder(
    animation: hexcore.status,
    builder: (BuildContext context, Widget? child) {
        if (hexcore.status.value == HexcoreStatus.waiting) {
            return const Center(
                child: CircularProgressIndicator(),
            );
        } else {
            return const Center(
                child: Text('Hexcore is ready!');
            );
        }
    },
);
...

Send custom notification

With hexcore you can send notification throw the League Client.

await hexcore.sendCustomNotification(
    title: 'Hexcore notification',
    details: 'Hello World',
    iconUrl: 'https://some_url_here',
    backgroundUrl: 'https://some_url_here',
);

Create and join a custom lobby

This method create and insert the current player in a custom lobby.

await hexcore.createCustomMatch(
    lobbyName: 'Custom game #1',
    lobbyPassword: 'hexcore_123', 
);

List custom lobbys

List all the available custom matches, so you can get the information you need to join a match.

List<Map<String,dynamic>> matches = await hexcore.listCustomMatches();

Join custom match

Use this method when you need to join a match. You can get the id of the match at listCustomMatches method.

await hexcore.joinCustomMatch(
    id: 'lobby_id',
    password: 'lobby_password'
);

HexcoreSocket Usage

In this package you can also find an interface for the LCU Socket connection, where you can subscribe and listen to events emitted by LCU.

Create an instance and use HexcoreSocket.connect to connect.

❗ You need to connect to the LCU using Hexcore.connectToClient before trying the socket connection. ❗

HexcoreSocket hexcoreSocket = HexcoreSocket();

await hexcoreSocket.connect();

Subscribing to LCU Events.

To subscribe to new events you need to call the method add.

hexcoreSocket.add('[5, "OnJsonApiEvent"]');

In this example you subscribe to all LCU Events. Here you can understand more about LCU Events.

Handling Events

Use listen method to create a StreamSubscription to handle the events that has been subscribed.

hexcoreSocket.listen((event){
    print(event);
});

Additional information

You may need to override the badCertificateCallback in way to send requests to the League Client, there is a example:

HttpOverrides.global = MyHttpOverrides();

class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) {
    return super.createHttpClient(context)
      ..badCertificateCallback =
          (X509Certificate cert, String host, int port) => true;
  }
}

About

Hexcore is a dart library which provides an interface to the League of Legends Client or LCU (League Client Update) API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages