def run(self): self.presence.update_presence("startup") Checker.check_version(self.config) if not Processes.are_processes_running(): color_print([("Red", Localizer.get_localized_text("prints","startup","starting_valorant"))]) self.start_game() self.setup_client() self.systray = Systray(self.client,self.config) self.dispatch_systray() if self.client.fetch_presence() is None: self.wait_for_presence() self.check_run_cli() self.dispatch_presence() self.dispatch_webserver() color_print([("LimeGreen",f"{Localizer.get_localized_text('prints','startup','startup_successful')}\n")]) time.sleep(5) user32.ShowWindow(hWnd, 0) #hide window self.systray_thread.join() self.presence_thread.stop()
def init_loop(self): try: self.content_data = Loader.load_all_content(self.client) color_print([("LimeGreen bold", Localizer.get_localized_text("prints", "presence", "presence_running"))]) presence_data = self.client.fetch_presence() if presence_data is not None: self.update_presence(presence_data["sessionLoopState"], presence_data) loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) #asyncio.ensure_future(self.main_loop()) self.main_loop() except Exception as e: user32.ShowWindow(hWnd, 1) kernel32.SetConsoleMode( kernel32.GetStdHandle(-10), (0x4 | 0x80 | 0x20 | 0x2 | 0x10 | 0x1 | 0x40 | 0x100)) color_print([("Red bold", Localizer.get_localized_text("prints", "errors", "error_message"))]) traceback.print_exc() input(Localizer.get_localized_text("prints", "errors", "exit")) os._exit(1)
def config_menu(self, section, choices, callback=None, callback_args=None): # recursion makes me want to die but its for a good cause prompt_choices = [{ "name": f"{setting}" + (f" ({value[0]})" if isinstance(value, list) else f" ({value})" if not isinstance(value, dict) else " (>>)"), "value": setting } for setting, value in choices.items()] prompt_choices.insert(0, { "name": "back" if section != "main" else "done", "value": "back" }) choice = inquirer.select( message= f"[{section}] {Localizer.get_localized_text('prints','config_modification','select_option')}", choices=prompt_choices, pointer=">") choice = choice.execute() if choice == "back": if section != "main": callback(*callback_args) elif callback is None: Config.modify_config(self.config) color_print([ ("LimeGreen", Localizer.get_localized_text("prints", "config_modification", "config_saved")) ]) return else: if isinstance(choices[choice], dict): self.config_menu(choice, choices[choice], callback=self.config_menu, callback_args=(section, choices, callback, callback_args)) else: if choice == Localizer.get_config_key("locale"): #translate config old_locale = choices[choice] new_locale = self.config_set(choice, choices[choice])[0] self.config = Config.localize_config(self.config, True) self.config["locale"][0] = new_locale Localizer.locale = new_locale self.config = Config.localize_config(self.config, False) Localizer.config = self.config else: choices[choice] = self.config_set(choice, choices[choice]) self.config_menu(section, choices, callback, callback_args)
def test_color_print(self, mocked_running, mocked_term, mocked_print): mocked_running.return_value = True color_print([("class:aa", "haha")], style={"aa": "#ffffff"}) mocked_term.assert_called_once() mocked_term.reset_mock() mocked_running.return_value = False color_print([("class:aa", "haha")], style={"aa": "#ffffff"}) mocked_term.assert_not_called() mocked_print.assert_called_once()
def modify_config(): user32.ShowWindow(hWnd, 1) Config_Editor() if not window_shown: color_print([( "LimeGreen", f"{Localizer.get_localized_text('prints','systray','hiding_window')}\n" )]) time.sleep(1) user32.ShowWindow(hWnd, 0)
def add_log(self, log, command=""): if type(log) == list: self.instance().logBook.append( f"{command}:\n{log}" if command != "" else log) if command != "": print(f"{command}:\n") color_print(log) else: self.instance().logBook.append( f"{command}:\n{log}" if command != "" else log) print(self.instance().logBook[-1])
def wait_for_presence(self): presence_timeout = Localizer.get_config_value("startup","presence_timeout") presence_timer = 0 print() while self.client.fetch_presence() is None: Startup.clear_line() color_print([("Cyan", "["),("White",f"{presence_timer}"),("Cyan", f"] {Localizer.get_localized_text('prints','startup','waiting_for_presence')}")]) presence_timer += 1 if presence_timer >= presence_timeout: self.systray.exit() os._exit(1) time.sleep(1) Startup.clear_line() Startup.clear_line()
def update_file_location(): Program_Data.check_for_folder() if getattr(sys, 'frozen', False): path = sys.executable else: color_print([( "Yellow", "running in a testing environment, cannot update installation path" )]) path = None if path is not None: installs = Program_Data.fetch_installs() installs["valorant-rpc"] = path Program_Data.modify_isntalls(installs)
def check_region(self): color_print([("Red bold",Localizer.get_localized_text("prints","startup","autodetect_region"))]) client = valclient.Client(region="na") client.activate() sessions = client.riotclient_session_fetch_sessions() for _,session in sessions.items(): if session["productId"] == "valorant": launch_args = session["launchConfiguration"]["arguments"] for arg in launch_args: if "-ares-deployment" in arg: region = arg.replace("-ares-deployment=","") self.config[Localizer.get_config_key("region")][0] = region Config.modify_config(self.config) color_print([("LimeGreen",f"{Localizer.get_localized_text('prints','startup','autodetected_region')} {Localizer.get_config_value('region',0)}")]) time.sleep(5) Systray.restart()
def start_game(self): path = Riot_Client_Services.get_rcs_path() launch_timeout = Localizer.get_config_value("startup","game_launch_timeout") launch_timer = 0 psutil.subprocess.Popen([path, "--launch-product=valorant", "--launch-patchline=live"]) print() while not Processes.are_processes_running(): Startup.clear_line() color_print([("Cyan", "["),("White",f"{launch_timer}"),("Cyan", f"] {Localizer.get_localized_text('prints','startup','waiting_for_valorant')}")]) launch_timer += 1 if launch_timer >= launch_timeout: self.systray.exit() os._exit(1) time.sleep(1) Startup.clear_line()
def check_version(config): try: current_version = Localizer.get_config_value("version") data = requests.get( "https://api.github.com/repos/colinhartigan/valorant-rpc/releases/latest" ) latest = data.json()["tag_name"] if latest != current_version: color_print([ ("Yellow bold", f"({current_version} -> {latest}) {Localizer.get_localized_text('prints','version_checker','update_available')} " ), ("Cyan underline", f"https://github.com/colinhartigan/valorant-rpc/releases/tag/{latest}" ) ]) except: color_print([("Yellow bold", Localizer.get_localized_text("prints", "version_checker", "checker_error"))])
def __init__(self): if not Processes.is_program_already_running(): cursor.hide() Logger.create_logger() Program_Data.update_file_location() self.config = Config.fetch_config() if "locale" in self.config.keys(): if self.config["locale"][0] == "": config = Localizer.prompt_locale(self.config) Config.modify_config(config) Systray.restart() self.installs = Program_Data.fetch_installs() Localizer.set_locale(self.config) self.config = Config.check_config() Localizer.config = self.config Logger.debug(self.config) self.client = None if Localizer.get_config_value("region",0) == "": # try to autodetect region on first launch self.check_region() ctypes.windll.kernel32.SetConsoleTitleW(f"valorant-rpc {Localizer.get_config_value('version')}") color_print([("Red", Localizer.get_localized_text("prints","startup","wait_for_rpc"))]) try: self.presence = Presence(self.config) Startup.clear_line() except Exception as e: traceback.print_exc() color_print([("Cyan",f"{Localizer.get_localized_text('prints','startup','discord_not_detected')} ({e})")]) if not Processes.are_processes_running(): color_print([("Red", Localizer.get_localized_text("prints","startup","starting_valorant"))]) self.start_game() os._exit(1) self.run()
import ctypes, os, traceback from src.startup import Startup from src.utilities.config.app_config import default_config from src.localization.localization import Localizer kernel32 = ctypes.WinDLL('kernel32') user32 = ctypes.WinDLL('user32') hWnd = kernel32.GetConsoleWindow() if __name__ == "__main__": color_print([ ("Tomato", f""" _ _____ __ ____ ___ ___ _ ________ | | / / _ | / / / __ \/ _ \/ _ | / |/ /_ __/__________ ____ | |/ / __ |/ /__/ /_/ / , _/ __ |/ / / / /___/ __/ _ \/ __/ |___/_/ |_/____/\____/_/|_/_/ |_/_/|_/ /_/ /_/ / .__/\__/ /_/ """), ("White", f"{default_config['version']}\n") ]) try: app = Startup() except: user32.ShowWindow(hWnd, 1) kernel32.SetConsoleMode( kernel32.GetStdHandle(-10), (0x4 | 0x80 | 0x20 | 0x2 | 0x10 | 0x1 | 0x40 | 0x100)) color_print([("Red bold", Localizer.get_localized_text("prints", "errors", "error_message"))]) traceback.print_exc()