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

猜你喜欢

转载自blog.csdn.net/zhaohongfei_358/article/details/126927888
今日推荐