Python利用LCU接口实现LOL(英雄联盟)一键载入自定义天赋(符文)

1. 本文内容

本文会介绍如何编写一个LOL一键载入自定义天赋。

最终效果如下:

在这里插入图片描述

源代码地址:https://github.com/iioSnail/lol_custom_rune


exe下载地址:百度网盘


本节会重点介绍有关LOL接口的部分,对GUI部分不进行过多介绍。

2. LOL LCU接口

要想和LOL客户端进行交互,需要使用官方提供的LCU接口,所有的第三方工具都是通过这些接口实现的。

在使用LCU接口前需要获取IP、端口和Token。

2.1 获取LOL客户端信息

  1. 首先登录游戏

  2. 登录游戏后使用管理员权限运行cmd,然后输入如下命令:

wmic PROCESS WHERE name='LeagueClientUx.exe' GET commandline

之后你会的得到如下输出:

C:\Users\XHXIAIEIN>wmic PROCESS WHERE name='LeagueClientUx.exe' GET commandline
CommandLine

"D:/Game/league of legends cn/英雄联盟/LeagueClient/LeagueClientUx.exe"
"--riotclient-auth-token=PVBsuiBiaNdAdIAnDoNg7yisxg"
"--riotclient-app-port=63381"
"--riotclient-tencent"
"--no-rads"
"--disable-self-update"
"--region=TENCENT"
"--locale=zh_CN"
"--t.lcdshost=hn1-sz-feapp.lol.qq.com"
"--t.chathost=hn1-sz-ejabberd.lol.qq.com"
"--t.lq=https://hn1-sz-login.lol.qq.com:8443"
"--t.storeurl=https://hn1-sr.lol.qq.com:8443"
"--t.rmsurl=wss://sz-rms-bcs.lol.qq.com:443"
"--rso-auth.url=https://prod-rso.lol.qq.com:3000"
"--rso_platform_id=HN1"
"--rso-auth.client=lol"
"--t.location=loltencent.sz.HN1"
"--tglog-endpoint=https://tglogsz.datamore.qq.com/lolcli/report/"
"--t.league_edge_url=https://ledge-hn1.lol.qq.com:22019"
"--ccs=https://cc-hn1.lol.qq.com:8093"
"--dradis-endpoint=http://some.url"
"--remoting-auth-token=lgxHX-LuAnDaXbyzA08w"        <---⭐ 找到这个参数 `--remoting-auth-token=XXX`
"--app-port=63405"                                  <---⭐ 找到这个参数 `--app-port=XXX`
"--install-directory=d:\game\league of legends cn\鑻遍泟鑱旂洘\LeagueClient"
"--app-name=LeagueClient"
"--ux-name=LeagueClientUx"
"--ux-helper-name=LeagueClientUxHelper"
"--log-dir=LeagueClient Logs"
"--crash-reporting=none"
"--crash-environment=HN1"
"--app-log-file-path=d:/game/league of legends cn/英雄联盟/LeagueClient/../Game/Logs/LeagueClient Logs/2022-08-03T14-38-37_8368_LeagueClient.log"
"--app-pid=8368"
"--output-base-dir=d:/game/league of legends cn/鑻遍泟鑱旂洘/LeagueClient/../Game"
"--no-proxy-server"

我们需要从这些输出中提取出以下三项:

--remoting-auth-token=lgxHX-LuAnDaXbyzA08w
--app-pid=8368
--app-port=63405

之后我们就可以调用LCU接口了,IP固定为127.0.0.1,端口为--app-port,这里是63405,例如:

获取当前天赋:

GET https://127.0.0.1:63405/lol-perks/v1/currentpage

2.2 LCU接口调用

我们获取到端口后,就可以通过https调用了,注意:必须用https

LCU接口可以在LCU API 速查手册这里查询到,你也可以参考LOL第三方工具frank(github)项目的lcu.js文件。

在调用前,还需要构造http headers,需要包含如下三条内容:

{
	"Accept": "application/json",
	"Content-Type": "application/json",
	"Authorization": "Basic " + auth
}

其中auth是使用base64对riot:${remoting-auth-token}进行加密后的得到的结果,使用过Python实现为:

import base64

token = "lgxHX-LuAnDaXbyzA08w"
auth = base64.b64encode(("riot:" + token).encode("UTF-8")).decode("UTF-8")
authorization = "Basic " + auth

当构建好headers后,就可以按照API文档调用了,使用Python实现如下:

import requests

url = "https://127.0.0.1:63405/lol-perks/v1/pages"

headers = {
	"Accept": "application/json",
	"Content-Type": "application/json",
	"Authorization": "Basic " + auth
}

resp = requests.get(url, headers=headers, verify=False)
if not resp.ok:
   utils.error("获取符文页失败!")
   return

resp_content = resp.text

3. LCU天赋接口实战

知道LCU接口的基本用法,就可以进行实战了,本项目使用了天赋接口。其path为 /lol-perks/v1/pages,其中增删改查分别对应的是POSTGETDELET


获取天赋

  • Method: GET
  • Path: /lol-perks/v1/pages

请求参数:无

请求响应:

[
    {
        "autoModifiedSelections": [],
        "current": false, # 是否是当前选择的天赋页
        "id": 1934761678, # 天赋页id,删除时需要用到
        "isActive": false, 
        "isDeletable": true,
        "isEditable": true,
        "isValid": true,
        "lastModified": 1658841402785,
        "name": "布里茨 By Frank", # 符文页的名称
        "order": 0, # 符文页顺序,第一页
        "primaryStyleId": 8400, # 主系id
        "subStyleId": 8300, # 副系id
        "selectedPerkIds": [ 
            8439, # 主系第18446, # 主系第28429, # 主系第38451, # 主系第48345, # 副系第18347, # 副系第25007, # 通用第15002, # 通用第25001  # 通用第3],
    },
 	...
]

Python实现:

url = self.url + "/lol-perks/v1/pages"

resp = requests.get(url, headers=self.headers, verify=False)
if not resp.ok:
    utils.error("获取符文页失败!")
    return

resp_content = resp.text

删除天赋

  • Method: DELETE
  • Path: /lol-perks/v1/pages/${runeId}

请求参数:请求参数在path上,${runeId}就是上面天赋页中的id

请求响应:无

python实现:

url = self.url + "/lol-perks/v1/pages/" + str(runes[index]['id'])
resp = requests.delete(url, headers=self.headers, verify=False)
if not resp.ok:
    utils.error("删除符文失败!")
    return

写入天赋

  • Method: POST
  • Path: /lol-perks/v1/pages/${runeId}

请求参数:

{
    "autoModifiedSelections": [],
    "current": true,
    "name": "测试符文页",
    "order": 0,
    "primaryStyleId": 8400,
    "subStyleId": 8300,
    "selectedPerkIds": [
        8439,
        8446,
        8429,
        8451,
        8345,
        8347,
        5007,
        5002,
        5001
    ]
}

请求响应:无

python实现:

url = self.url + "/lol-perks/v1/pages"
resp = requests.post(url, json=rune_json, headers=self.headers, verify=False)
if not resp.ok:
    utils.error("载入符文页失败!")
    return

4. 总结

根据上面的LCU接口,再结合简单的封装与GUI设计,即可实现自定义天赋工具。代码详情请参考项目源码





参考资料

LeagueCustomLobby(github): https://github.com/XHXIAIEIN/LeagueCustomLobby

LCU API 速查手册: http://www.mingweisamuel.com/lcu-schema/tool/#/

LOL第三方工具frank(github): https://github.com/Java-S12138/frank

  • 7
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
好的,以下是一个利用C语言和树形数据结构实现五级目录的示例代码: ```c #include <stdio.h> #include <stdlib.h> #include <time.h> // 定义节点结构体 struct TreeNode { char name[20]; // 目录名称 struct TreeNode* firstChild; // 第一个子节点 struct TreeNode* nextSibling; // 下一个兄弟节点 }; // 创建节点函数 struct TreeNode* createNode(char* name) { struct TreeNode* newNode = (struct TreeNode*)malloc(sizeof(struct TreeNode)); if (newNode != NULL) { strcpy(newNode->name, name); newNode->firstChild = NULL; newNode->nextSibling = NULL; } return newNode; } // 添加子节点函数 void addChild(struct TreeNode* parentNode, struct TreeNode* childNode) { if (parentNode->firstChild == NULL) { parentNode->firstChild = childNode; } else { struct TreeNode* currentNode = parentNode->firstChild; while (currentNode->nextSibling != NULL) { currentNode = currentNode->nextSibling; } currentNode->nextSibling = childNode; } } // 随机生成目录名称 void generateName(char* name) { const char* chars = "abcdefghijklmnopqrstuvwxyz"; int length = rand() % 10 + 5; for (int i = 0; i < length; i++) { name[i] = chars[rand() % 26]; } name[length] = '\0'; } // 生成五级目录函数 struct TreeNode* generateDirectory() { struct TreeNode* root = createNode("root"); struct TreeNode* currentNode = root; for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 3; j++) { char name[20]; generateName(name); struct TreeNode* newNode = createNode(name); addChild(currentNode, newNode); currentNode = newNode; } currentNode = root; } return root; } // 打印目录结构函数 void printDirectory(struct TreeNode* node, int level) { for (int i = 0; i < level; i++) { printf(" "); } printf("|-- %s\n", node->name); if (node->firstChild != NULL) { printDirectory(node->firstChild, level + 1); } if (node->nextSibling != NULL) { printDirectory(node->nextSibling, level); } } int main() { srand(time(NULL)); // 初始化随机数生成器 struct TreeNode* directory = generateDirectory(); printf("随机生成的五级目录结构如下:\n"); printDirectory(directory, 0); return 0; } ``` 运行结果: ``` 随机生成的五级目录结构如下: |-- root |-- nlqj |-- lqzww |-- yxq |-- ymnw |-- bncbe |-- lvkzq |-- eyr |-- wwuva |-- loiki |-- tti |-- owl |-- fjj |-- xoor |-- pnr |-- dbk |-- qgy |-- jrfv |-- qoqwe |-- gzk |-- fby |-- yoih |-- qdug |-- knk |-- zyv |-- xob |-- yqic |-- ekmqg |-- lcu |-- lryva |-- xys |-- qdho |-- jgv |-- zon |-- xpe |-- yjw |-- ljp |-- yusl |-- zjv |-- xpt |-- xlu |-- nnz |-- tgk |-- yhpn |-- eek |-- qpv |-- pvj |-- jvd |-- bgm |-- qld |-- mjs |-- ijs |-- yvq ``` 以上代码生成了一个包含五级目录的树形结构,并随机输出了目录结构。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

iioSnail

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值