Skip to content

Commit

Permalink
Background setter
Browse files Browse the repository at this point in the history
  • Loading branch information
lipeeeee committed Feb 7, 2024
1 parent 8016e7b commit 24ca0a3
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 19 deletions.
71 changes: 53 additions & 18 deletions sightstone/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import string
import random
from threading import Thread
import dearpygui.dearpygui as dpg
from sightstone.background_thread import BackgroundThread
import sightstone.sightstone_constants as SC
Expand Down Expand Up @@ -62,6 +63,10 @@
"""Friend groups"""
friend_groups: list

"""Champ skins"""
global champ_skins
champ_skins: dict[str, dict]

### Threads
update_friend_groups_thread: BackgroundThread
UPDATE_FRIEND_GROUPS_TIMEOUT = 5
Expand All @@ -84,11 +89,39 @@ def update_info_label(sightstone_hook: Sightstone):
info += " | Connected to: " + str(sightstone_hook.get_current_user()) # User info
dpg.set_value("info", info)

update_champ_skins_thread: Thread
def update_champ_skins(sightstone_hook: Sightstone):
"""Update champ skins varaiable for skin & champion storing"""
global champ_skins
champ_skins = sightstone_hook.get_champion_skins()

# Sort
champ_skins = dict(sorted(champ_skins.items()))

# Update background collapse with info
for champ in champ_skins:
with dpg.tree_node(parent="backgroundCollapse", label=champ):
for skin in champ_skins[champ]["skins"]:
# How is this lambda working? I have no idea.
# it is probably something dumb with python JIT memory,
# if we dont set the button tag to skin[0], we get the wrong number on set_background(),
# even though we do not ever touch the button's tag.
# But if we "refresh" the memory with tag=skin[0] we get the right id to search.
# Any setting like _skin[0] will set `s` to that.
# DO NOT TOUCH THIS =P.
dpg.add_button(label=skin, tag=skin[0], callback=lambda s=skin: sightstone_hook.set_background(s))


# pylint: disable=R0915
def init_gui(sightstone_hook: Sightstone):
"""Inits dearpygui window"""
dpg.create_context()

# Create champ skins thread firstly
global update_champ_skins_thread
update_champ_skins_thread = Thread(target=lambda:update_champ_skins(sightstone_hook), daemon=True)
update_champ_skins_thread.start()

with dpg.window(
label=SC.SIGHTSTONE,
width=WIDTH, height=HEIGHT,
Expand Down Expand Up @@ -311,38 +344,40 @@ def init_gui(sightstone_hook: Sightstone):
dpg.add_button(label="Submit", callback=lambda:sightstone_hook.set_mastery_points(dpg.get_value("masteryInput")))
dpg.add_button(label="Max", callback=lambda:sightstone_hook.set_mastery_points(-1))
dpg.add_button(label="None", callback=lambda:sightstone_hook.set_mastery_points(0))
dpg.add_separator()

with dpg.group():
dpg.add_text("Icon:")
with dpg.group(horizontal=True):
dpg.add_input_int(tag="iconInput", width=125, min_value=0, min_clamped=True)
dpg.add_button(label="Submit", callback=lambda:sightstone_hook.set_icon(dpg.get_value("iconInput")))
dpg.add_button(label="Glitched", callback=lambda:sightstone_hook.set_icon("31"))
dpg.add_separator()

with dpg.collapsing_header(label="Backgrounds", tag="backgroundCollapse"):
# This will be created at runtime by a champ skins thread
pass

with dpg.tab(label="Info"):
pass

with dpg.tab(label="Champs"):
pass

with dpg.tab(label="Skins"):
pass

with dpg.tab(label="Misc"):
pass

with dpg.tab(label="Custom"):
pass

with dpg.tab(label="Settings"):
pass

with dpg.tab(label="Test"):
dpg.add_button(label="gamemodes",
callback=sightstone_hook.get_queues)
dpg.add_button(label="create arurf",
callback=lambda:sightstone_hook.create_lobby("450"))
dpg.add_button(label="pos",
callback=lambda:sightstone_hook.set_positions(
ROLE_TO_INT_MAPPING[dpg.get_value("pos1")],
ROLE_TO_INT_MAPPING[dpg.get_value("pos2")]))
dpg.add_button(label="Reveal Lobby",
callback=lambda:sightstone_hook.open_website(
website=dpg.get_value("revealWebsite"),
multi=True,
query=sightstone_hook.transform_participants_into_query(set(["lipe#69420", "MISSING KERIA ON#000", "naive#444", "wolfs child#EUW"]))))
dpg.add_button(label="get group",
callback=sightstone_hook.get_groups)

dpg.add_button(label="QUEUE", callback=sightstone_hook.get_queues)
dpg.add_button(label="muselfg", callback=lambda:sightstone_hook.search_myself(SC.OP_GG))
dpg.add_button(label="Get champ skins", callback=sightstone_hook.get_champion_skins)
dpg.set_primary_window("p1", True)

# safe title for riot detection sake
Expand Down
17 changes: 16 additions & 1 deletion sightstone/lca_hook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Hook for league api HACK'ing"""

import sys
import re
import requests
import urllib3
Expand Down Expand Up @@ -259,6 +258,7 @@ def riot_get(self, path: str) -> Response | None:
return response
except Exception as e:
print(f"ERROR IN RIOT_GET: {e}")
return None

def post(self, path: str, data: dict | None = None, json: dict | list[dict] | None = None) -> Response | None:
"""Post into LCA"""
Expand Down Expand Up @@ -288,6 +288,21 @@ def put(self, path: str, data: dict | None = None, json: dict | None = None) ->
except Exception:
return None

def riot_put(self, path: str, data: dict | None = None, json: dict | None = None) -> Response | None:
"""Riot-Level Put request"""
if not self.connected:
return None

try:
return requests.put(
self.build_url(path, self.riot_port),
data=data, json=json,
auth=self.riot_auth, verify=False,
headers=self.riot_header)
except Exception as e:
print(f"ERROR IN RIOT_PUT: {e}")
return None

def delete(self, path: str, data: dict | None = None, json: dict | None = None) -> Response | None:
"""Delete to LCA"""
if not self.connected:
Expand Down
46 changes: 46 additions & 0 deletions sightstone/sightstone.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Main cheat engine

from typing import Any
import requests
import webbrowser
from sightstone.lca_hook import LeagueConnection
Expand Down Expand Up @@ -57,6 +58,33 @@ def get_groups(self) -> list[dict]:
else:
return list()

def get_champion_skins(self) -> dict[str, dict]:
"""Get champion & their skins
returned structure:
dict[champName][id] = json_id
dict[champName][key] = json_id / 100
dict[champName][skins] = list(tuple(id, name))
"""
response = requests.get("https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/skins.json")
json = response.json()
current_champ_name = str()
champ_skins: dict[str, dict] = dict()

for id in json:
element = json[id]
if element["isBase"] == True:
current_champ_name = element["name"]
champ_skins[current_champ_name] = dict()
champ_skins[current_champ_name]["id"] = id
champ_skins[current_champ_name]["key"] = int(id) // 100
champ_skins[current_champ_name]["skins"] = list()
champ_skins[current_champ_name]["skins"].append((id, "Default"))
else:
champ_skins[current_champ_name]["skins"].append((id, element["name"]))

return champ_skins

def get_current_patch(self) -> str:
"""Get current patch from external source"""
# If this request fails, something has gone very wrong
Expand Down Expand Up @@ -174,6 +202,24 @@ def set_mastery_points(self, mastery_points: int) -> bool:

return self.is_valid_response(response)

def set_background(self, background_id: int) -> bool:
"""Set's profile background splashart"""
response = self.lca_hook.post(
path="lol-summoner/v1/current-summoner/summoner-profile/",
json={"key":"backgroundSkinId", "value": background_id}
)

return self.is_valid_response(response)

def set_icon(self, icon_id: str) -> bool:
"""Set icon"""
response = self.lca_hook.put(
path="lol-summoner/v1/current-summoner/icon/",
json={"profileIconId": icon_id}
)

return self.is_valid_response(response)

def set_positions(self, pos1: str, pos2: str) -> bool:
"""Sets positions in lobby"""
response = self.lca_hook.put(
Expand Down

0 comments on commit 24ca0a3

Please sign in to comment.