感谢吾爱破解论坛上 叫我ChEn1啦丶 提供的 lol api 有关的教程资料,用 c# 实现的 自动接受对局 和 快速锁定英雄。
- 选择框支持一定的模糊搜索
- 选定英雄之后,点击自动接受即可
-
获取 lol 客户端暴露的 端口 和 密码,使用管理员身份运行 cmd,输入一下命令:
WMIC PROCESS WHERe name="LeagueClientUx.exe" GET commandline
// 使用 c# 也是如此,模拟命令行,执行命令,获取输入结果,因此程序也需要以管理员的身份运行 //获取cmd.exe程序 var startInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe"); //设置启动的一些参数 startInfo.UseShellExecute = false; startInfo.RedirectStandardInput = true; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.CreateNoWindow = true; //获取Process类的新实例 var myProcess = new System.Diagnostics.Process(); myProcess.StartInfo = startInfo; //启动 cmd.exe myProcess.Start(); // 输入命令 myProcess.StandardInput.WriteLine(command); // 此处很关键,需要输入 exit 表示命令结束,不然会一直阻塞,获取不到输出结果 myProcess.StandardInput.WriteLine("exit"); StreamReader reader = myProcess.StandardOutput; // 读取命令执行的结果 string strOuput = reader.ReadToEnd(); reader.Close(); myProcess.WaitForExit(); myProcess.Close(); // 再使用正则表达式从读取结果中解析出 端口号 和 密码 // 规则匹配 Regex portRegex = new Regex("--app-port=([0-9]*)"); Regex tokenRegex = new Regex("--remoting-auth-token=([\w-]*)"); port = portRegex.Match(strOuput).Value; token = tokenRegex.Match(strOuput).Value;
-
构建 request 请求
-
ip 地址是本机
-
端口是解析出来的 port
-
请求头中需要条件 Authorization,用户名是 riot,密码是解析出来的 password
// {用户名:密码} 的 base64 编码 string authorize = Convert.Tobase64String(Encoding.ASCII.GetBytes($"{username}:{password}")); request.Headers.Add("Authorization", "Basic " + authorize);
-
-
接口说明
简单介绍一下自己使用到的接口
-
获取已拥有的英雄的信息(GET /lol-champions/v1/owned-champions-minimal),下面是返回结果(只选取了一个出来分析):
[ { "active": true, "alias": "Annie", "banVoPath": "/lol-game-data/assets/v1/champion-ban-vo/1.ogg", "baseLoadScreenPath": "/lol-game-data/assets/ASSETS/Characters/Annie/Skins/base/AnnieLoadScreen.jpg", "baseSplashPath": "/lol-game-data/assets/v1/champion-splashes/1/1000.jpg", "botEnabled": true, "chooseVoPath": "/lol-game-data/assets/v1/champion-choose-vo/1.ogg", "disabledQueues": [], "freeToPlay": false, "id": 1, "name": "黑暗之女", "ownership": { "freeToPlayReward": false, "owned": true, "rental": { "endDate": 0, "purchaseDate": 1526968649000, "rented": false, "winCountRemaining": 0 } }, "purchased": 1526968649000, "rankedPlayEnabled": true, "roles": [ "mage" ], "squarePortraitPath": "/lol-game-data/assets/v1/champion-icons/1.png", "stingerSfxPath": "/lol-game-data/assets/v1/champion-sfx-audios/1.ogg", "title": "安妮" }, ...... ]
其中 squarePortraitPath可以获取英雄头像,stingerSfxPath可以获取英雄的声音,id 很是自动锁定英雄的关键
-
接受对局(GET /lol-matchmaking/v1/ready-check/accept)我是直接在定时器里轮询访问这个接口
-
获取用户信息(GET /lol-login/v1/session),获取其中的 summonerId
{ "accountId": 2964199082, "connected": true, "error": null, "gasToken": null, ....... "isInLoginQueue": false, "isNewPlayer": false, "puuid": "81fc717d-67a8-513d-891e-d20fd3b47bf7", "state": "SUCCEEDED", "summonerId": 2964199082, ...... "username": "2964199082" }
-
锁定英雄
-
首先要获取队伍信息(GET /lol-champ-select/v1/session),json 格式如下:
// 只保留了一部分关键的数据,关键的就是 actions 数组 和 myTeam 数组 { "actions": [ [ { "actorCellId": 0, "championId": 0, "completed": false, "id": 1, "isAllyAction": true, "isInProgress": true, "pickTurn": 1, "type": "pick" } ] ], ....... "myTeam": [ { "assignedPosition": "", "cellId": 0, // 与 actions 中 actorCellId 一致 "championId": 0, "championPickIntent": 0, "entitledFeatureType": "", "selectedSkinId": 0, "spell1Id": 1, "spell2Id": 3, "summonerId": 2964199082, "team": 1, "wardSkinId": 91 } ] ........ }
-
首先遍历 myTeam 数组,根据用户的 summonerId 获取 myTeam中自己的那项信息
-
从该项中获取 cellId的值
-
再遍历 actions数组,根据 cellId和 actorCellId 的关系,获取该项
-
获取 actions 中的 id
-
发送请求锁定英雄
-
请求的地址(PATCH /lol-champ-select/v1/session/actions/{actions 中的 id})
-
构建发送请求的数据
// 只需要将 atcions 数组中获取的自己的那项中的 championId 换成 想要选择的英雄的 id 即可 { "actorCellId": 0, "championId": {此处为上面获取已拥有的英雄信息中的英雄 id}, "completed": false, "id": 1, "isAllyAction": true, "isInProgress": true, "pickTurn": 1, "type": "pick" }
-
-
-
- 总体来说功能还是很简单的,实现也不复杂
- 锁定英雄这个功能搞了好久,之前在 url后面都没有加上 id的
- 经历了技术选型,从 c# 到 electron再到 java fx,最后回归到 c#,想换的原因是主职是 java,c# 只是个一知半解的状态,而且好像轮子也不多,写起来很不顺手,最重要的原因是 vs2019 实在是太难用了,对于用惯了 idea的我来说,简直是灾难。换回来的原因是,electron 和java fx 都需要学习成本,然后我发现的 jetbrains 家的 rider,虽然有一点小 bug,还是网上关于它的使用资料也不多,但是不愧是 jetbrains家的产品,太香了,开发体验直线上升。
- 码云仓库地址 : https://gitee.com/hqzqaq/LOLHelper.git
- 蓝奏云下载地址:外链: https://hqzqaq.lanzouq.com/b011563jg 密码: acdv
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)