From 64822ae705e4f2648d2e91697175dce18a97f718 Mon Sep 17 00:00:00 2001 From: remi Date: Fri, 15 Jul 2022 21:13:12 +0200 Subject: [PATCH] initial commit! --- main.py | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 10 ++++ 2 files changed, 166 insertions(+) create mode 100644 main.py create mode 100644 readme.md diff --git a/main.py b/main.py new file mode 100644 index 0000000..8207317 --- /dev/null +++ b/main.py @@ -0,0 +1,156 @@ +import requests, psutil, sys, requests.auth, urllib3, time + +print("tinyrunes starting") + +port = 0 +token = 0 +page = 0 +userid = 0 +champ = 0 + +urllib3.disable_warnings() + +def get_port_and_token(): + global port,token + for proc in psutil.process_iter(['name', 'cmdline']): + if "LeagueClientUx" in proc.info['name']: + for c in proc.cmdline(): + str = c.split("=")[0][2:] + if (str == "remoting-auth-token"): + token = c.split("=")[1] + if (str == "app-port"): + port = c.split("=")[1] + if port != 0 and token != 0: + print(f"found league! port {port}, token {token}") + else: + print("could not find league :( is the game running, or are you on anything-but-macos?") + sys.exit() + +def setup_tinyrunes_page(): + global page + r = local_req("get", "lol-perks/v1/pages") + chk = False + for rune in r: + if rune["name"] == "tinyrunes": + chk = True + page = rune["id"] + if (chk == False): + print("trying to make a tinyrunes page...") + success = make_tinyrunes(8200, [8214, + 8009, + 8017, + 8210, + 8226, + 8237, + 5005, + 5008, + 5002], 8000) + if (success): + print("made tinyrunes page!") + else: + print("tinyrunes rune page not found, and we couldent make one. please make a rune page called \"tinyrunes\"! (are you below level 10?)") + sys.exit() + else: + print("rune page found!") + +def setup_user_id(): + global userid + r = local_req("get", "lol-summoner/v1/current-summoner") + if ("summonerId" in r and "displayName" in r): + userid = r["summonerId"] + print(f"welcome, {r['displayName']}!") + else: + print("couldent find summonerId... are you logged in?") + sys.exit() + +def make_tinyrunes(primary, selected, sub): + global page + rune = { + "name": "tinyrunes", + "primaryStyleId": primary, + "selectedPerkIds": selected, + "subStyleId": sub + } + r = local_req("post", "lol-perks/v1/pages", rune) + if ("id" in r and r["isValid"] == True): + page = r["id"] + return True + else: + return False + +def delete_tinyrunes(): + local_req("delete", f"lol-perks/v1/pages/{page}") + pass + +def wait_for_chara(): + global champ + done = False + state = 0 # 0 = waiting for champ select, + # 1 = waiting for champ pick + # 2 = waiting for lock in, + print("waiting for you to enter champion select...!") + while (not done): + champselect = local_req("get", "lol-champ-select/v1/session") + if (state == 0): + if ("errorCode" in champselect): + #wait to enter champ select... + pass + elif ("myTeam" in champselect): + state = 1 + print("waiting for you to pick a champion...!") + else: + print("?????? what is going on") + if (state == 1): + if ("errorCode" in champselect): + state = 0 + print("oh! i guess you got kicked out of champ select... back to the start~") + else: + for member in champselect["myTeam"]: + if (member["summonerId"] == userid and member["championId"] != 0): + print("okay! i'll wait for everyone to lock in, and then go grab your runes~") + state = 2 + if (state == 2): + if ("errorCode" in champselect): + state = 0 + print("oh! i guess you got kicked out of champ select... back to the start~") + elif (champselect["timer"]["phase"] == "FINALIZATION"): + print("everyones locked in, i'll go fetch your runes!") + for member in champselect["myTeam"]: + if (member["summonerId"] == userid): + champ = member["championId"] + return + time.sleep(1) + +def gettem_runes(): + print("fetching the runes...") + roons = requests.get(f"https://axe.lolalytics.com/mega/?ep=rune&p=d&v=1&cid={champ}&lane=default").json() + roon = roons["summary"]["runes"]["pick"]["set"] + pag = roons["summary"]["runes"]["pick"]["page"] + pri = 8000 + 100 * pag["pri"] + sub = 8000 + 100 * pag["sec"] + sel = [*roon["pri"], *roon["sec"], *roon["mod"]] + print("setting the runes...") + delete_tinyrunes() + make_tinyrunes(pri, sel, sub) + print("all ready! glhf <3") + +def local_req(type, url, data = ""): + if type == "post": + r = requests.post(f"https://127.0.0.1:{port}/{url}", auth=requests.auth.HTTPBasicAuth("riot", token), verify=False, json=data) + elif type == "get": + r = requests.get(f"https://127.0.0.1:{port}/{url}", auth=requests.auth.HTTPBasicAuth("riot", token), verify=False) + elif type == "delete": + r = requests.delete(f"https://127.0.0.1:{port}/{url}", auth=requests.auth.HTTPBasicAuth("riot", token), verify=False) + ret = "bruh" + try: + ret = r.json() + except: + ret = r.text() + finally: + return ret + +get_port_and_token() +setup_user_id() +setup_tinyrunes_page() +wait_for_chara() +gettem_runes() \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..28d270d --- /dev/null +++ b/readme.md @@ -0,0 +1,10 @@ +# tinyrunes + +shmol python program that gives u lol runes +basically a proof of concept before i delve into making a cooler version of this with gui and stuff + +how 2 use: + +* be on macos (*may work on other operating systems) +* make sure u have a runes page called "tinyrunes" (without quotes) +* run the program \ No newline at end of file