Skip to content

Ponita0/PoniLCU

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ponita0 - PoniLCU

A C# League of Legends LCU library

Introduction

PoniLCU is a library to communicate with the League of Legends Client API. It gives an easy way to send requests as well as subscribe to websocket events.

Don't know about the League of Legends Client API? Learn more from Hextech Docs.

Supported platforms

Platform Version
.NET Framework 4.6.1 , 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Core 2.0, 2.1, 2.2, 3.0, 3.1
.NET 5.0, 6.0 #16
Universal Windows Platform 10.0.16299, TBD

Installation

Just run Install-Package PoniLCU in the Package Manager Console

You can find a NuGet package here https://www.nuget.org/packages/PoniLCU/

The Basics

Make an instance of LeagueClient

//At top of your code 
//using PoniLCU;
//using static PoniLCU.LeagueClient; 
  
  
//Put this in the top of your code and make it public to access it from anywhere
LeagueClient leagueClient = new LeagueClient(credentials.cmd);

//You can do either credentials.cmd or credentials.lockfile
//It doesn't really matter

Like this:

using System;
using PoniLCU;
using static PoniLCU.LeagueClient;
namespace MyApp
{
   internal class Program
   {
     //--------------
       static LeagueClient leagueClient = new LeagueClient(credentials.cmd);
     //--------------
     
       static void Main(string[] args)
       {
           Console.WriteLine("hey users");
       }
    }
}

Requests Examples

GET request

I recommend you use Async/await

var data = await leagueClient.Request(requestMethod.get, "/lol-summoner/v1/current-summoner");
Console.WriteLine(data);

get request using

If you're not going to use async, add .Result to the end of the line

var data = leagueClient.Request(requestMethod.get, "/lol-summoner/v1/current-summoner").Result;
Console.WriteLine(data);

An example on how to get specific information from the json:

var data = await leagueClient.Request(requestMethod.get, "/lol-summoner/v1/current-summoner");

var DataButJsonDeserialized = Newtonsoft.Json.Linq.JObject.Parse(data);

Console.WriteLine(DataButJsonDeserialized["displayName"]);

//The console will output your name only

PUT request

For the body, you have two options:

  • Define the body string manually
  • Let C# do that for us (with help of Newtonsoft.Json)

Both of these solutions will work, it is preference on how you would like to define it.


Using a manual body string:

string body = "{\"profileIconId\": " + 23 + "}";
await leagueClient.Request(requestMethod.put, "/lol-summoner/v1/current-summoner/icon", body);        

Using Newtonsoft Json:

var body = Newtonsoft.Json.JsonConvert.SerializeObject( new
	{
		profileIconId = 23
	});
await leagueClient.Request(requestMethod.put, "/lol-summoner/v1/current-summoner/icon", body);

PUT Request Example

Websocket Events Example

With PoniLCU you can subscribe to or unsubscribe from LCU events using the following code:

// Subscribe to event
leagueClient.Subscribe("/lol-gameflow/v1/gameflow-phase", GameFlowPhase);

// Unsubscribe from event
leagueClient.Unsubscribe("/lol-gameflow/v1/gameflow-phase", GameFlowPhase);

private void GameFlowPhase(OnWebsocketEventArgs obj)
{
	Console.WriteLine(obj.Data);
}

Websocket Request Example