文章目錄
- 1. 本文内容
- 2. LOL LCU接口
- 2.1 擷取LOL用戶端資訊
- 2.2 LCU接口調用
- 3. LCU天賦接口實戰
- 4. 總結
- 參考資料
1. 本文内容
本文會介紹如何編寫一個LOL一鍵載入自定義天賦。
最終效果如下:
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiI0gTMx81dsQWZ4lmZf1GLlpXazVmcvwFciV2dsQXYtJ3bm9CX9s2RkBnVHFmb1clWvB3MaVnRtp1XlBXe0xCMy81dvRWYoNHLwEzX5xCMx8FesU2cfdGLwMzX0xiRGZkRGZ0Xy9GbvNGLpZTY1EmMZVDUSFTU4VFRR9Fd4VGdsYTMfVmepNHLrJXYtJXZ0F2dvwVZnFWbp1zczV2YvJHctM3cv1Ce-cmbw5SM4cTNzEGOhVTM0UTOlRmMzYzX2UzMxEDM0IzLclDMyIDMy8CXn9Gbi9CXzV2Zh1WavwVbvNmLvR3YxUjLyM3Lc9CX6MHc0RHaiojIsJye.png)
源代碼位址:https://github.com/iioSnail/lol_custom_rune
exe下載下傳位址:百度網盤
本節會重點介紹有關LOL接口的部分,對GUI部分不進行過多介紹。
2. LOL LCU接口
要想和LOL用戶端進行互動,需要使用官方提供的LCU接口,所有的第三方工具都是通過這些接口實作的。
在使用LCU接口前需要擷取IP、端口和Token。
2.1 擷取LOL用戶端資訊
- 首先登入遊戲
- 登入遊戲後使用管理者權限運作cmd,然後輸入如下指令:
wmic PROCESS WHERE name='LeagueClientUx.exe'
之後你會的得到如下輸出:
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 " +
當建構好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
,其中增删改查分别對應的是
POST
、
GET
和
DELET
。
擷取天賦
- 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, # 主系第1個
8446, # 主系第2個
8429, # 主系第3個
8451, # 主系第4個
8345, # 副系第1個
8347, # 副系第2個
5007, # 通用第1個
5002, # 通用第2個
5001 # 通用第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