Skip to content

Instantly share code, notes, and snippets.

@CheeseStick
Last active August 2, 2023 10:17
Show Gist options
  • Save CheeseStick/0c27e89e06bb4005ce811785afe71937 to your computer and use it in GitHub Desktop.
Save CheeseStick/0c27e89e06bb4005ce811785afe71937 to your computer and use it in GitHub Desktop.
Launch LoL client with different locale on Mac OS X (Default: Korean, Oceania Server)
#!/usr/bin/env python
import yaml
import subprocess
from os import path, system
##
# Settings
##
DEFAULT_LOL_CLIENT_PATH: str = "/Applications/League of Legends.app"
DESIRED_LOL_REGION: str = "OC1"
DESIRED_LOL_LOCALE: str = "ko_KR"
##
# Some constant variables
##
WORK_DIR: str = "Contents/LoL"
REGION_DATA_PATH: str = f"{DEFAULT_LOL_CLIENT_PATH}/{WORK_DIR}/system.yaml"
CLIENT_SETTING_PATH: str = f"{DEFAULT_LOL_CLIENT_PATH}/{WORK_DIR}/Config/LeagueClientSettings.yaml"
##
# 0. Check LoL Client and other files exist
##
if not path.exists(DEFAULT_LOL_CLIENT_PATH):
print("League of Legend client does not exists! Please check client path.")
exit(-1)
else:
print("League of Legend client found.")
if not path.exists(REGION_DATA_PATH) or not path.exists(CLIENT_SETTING_PATH):
print("Cannot find region data or client setting file from client! - Client might now using different setting format?")
exit(-1)
else:
print("Found region data and client setting.")
print("\n\n==== Current Script Settings ====")
print(f"LOCALE: {DESIRED_LOL_LOCALE}")
print(f"REGION: {DESIRED_LOL_REGION}")
print("=================================\n\n")
print(f"Reading region data...")
##
# 1. Patch the region data - Find region and locale
##
with open(REGION_DATA_PATH, "r+", encoding="utf8") as f:
try: # Try to parse region data yaml to dict,
regions = yaml.safe_load(f.read())
is_patched = False
if not DESIRED_LOL_REGION in regions["region_data"].keys(): # Check region exists,
print(f"Given region {DESIRED_LOL_REGION} does not exists!")
exit(-1)
if not DESIRED_LOL_LOCALE in regions["player_support_url"].keys(): # Check local exists,
print(f"Given locale {DESIRED_LOL_LOCALE} does not exists!")
exit(-1)
else: # If region exists, add language to region
print(f"Region {DESIRED_LOL_REGION} found.")
print("Supported locales: {}".format(regions["region_data"][DESIRED_LOL_REGION]["available_locales"]))
if not DESIRED_LOL_LOCALE in regions["region_data"][DESIRED_LOL_REGION]["available_locales"]:
print("Patching supported locales...")
regions["region_data"][DESIRED_LOL_REGION]["available_locales"].append(DESIRED_LOL_LOCALE)
is_patched = True
else: # If locale already exists,
print(f"Desired locale {DESIRED_LOL_LOCALE} already exists in region {DESIRED_LOL_REGION}.")
if is_patched:
print("Applying changes to the file...")
try:
# Clear file data
f.seek(0)
f.truncate()
f.write("---\n") # Add special line from original setting,
f.write(yaml.safe_dump(regions)) # And write updated YAML
print("Successfully patched region data.")
except yaml.YAMLError as e:
print("Failed to apply patch! - Failed to write changes to file.")
exit(-1)
print("Closing file...")
f.close()
except KeyError as e:
print("Failed to edit region data! - Couldn't find keys. Game may now use different format!")
exit(-1)
except yaml.YAMLError as e:
print("Failed to parse region data! - Please check game client's integrity.")
exit(-1)
print(f"Reading client settings...")
##
# 2. Patch client global settings - Change default region, locale setting
##
with open(CLIENT_SETTING_PATH, "r+", encoding="utf8") as f:
try: # Try to parse client settings data yaml to dict,
settings = yaml.safe_load(f.read())
is_patched = False
print("Current locale setting: {}".format(settings["install"]["globals"]["locale"]))
print("Current region setting: {}".format(settings["install"]["globals"]["region"]))
if settings["install"]["globals"]["locale"] != DESIRED_LOL_LOCALE:
print("Patching locale...")
settings["install"]["globals"]["locale"] = DESIRED_LOL_LOCALE
is_patched = True
if settings["install"]["globals"]["region"] != DESIRED_LOL_REGION:
print("Patching region...")
settings["install"]["globals"]["region"] = DESIRED_LOL_REGION
is_patched = True
if is_patched:
print("Applying changes to the file...")
try:
# Clear file data
f.seek(0)
f.truncate()
# And write updated YAML
f.write(yaml.safe_dump(settings))
print("Successfully patched client settings.")
except yaml.YAMLError as e:
print("Failed to apply patch! - Failed to write changes to file.")
exit(-1)
print("Closing file...")
f.close()
except KeyError as e:
print("Failed to edit client settings! - Couldn't find keys. Game may now use different format!")
exit(-1)
except yaml.YAMLError as e:
print("Failed to parse client settings! - Please check game client's integrity.")
exit(-1)
##
# 3. Lanuch LoL Client
##
print("Starting League of Legends client...")
p = subprocess.Popen(["open", "-n", DEFAULT_LOL_CLIENT_PATH], stdout=subprocess.PIPE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment