Advertisement
Guest User

Untitled

a guest
May 24th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. import psutil
  2. import os
  3. import shlex
  4. import subprocess
  5. import yaml
  6. import glob
  7. import sqlite3
  8.  
  9. riot_service_process_name = "RiotClientServices.exe"
  10.  
  11. # Don't need these if using lutris
  12. HOME = os.getenv("HOME")
  13. # WINEPREFIX create by https://lutris.net/games/league-of-legends/
  14. launchhelper = HOME + "/Games/league-of-legends/launchhelper.sh"
  15. WINEPREFIX = HOME + "/Games/league-of-legends"
  16.  
  17. # Game install location
  18. game_path = (
  19. HOME
  20. + "/Games/garena/drive_c/Garena/Games/32771/Riot Client/RiotClientServices.exe"
  21. )
  22.  
  23. # Wine lol download from lutris
  24. wine_exe = HOME + "/.local/share/lutris/runners/wine/lutris-lol-5.5-2-x86_64/bin/wine"
  25.  
  26. # Use gamemode
  27. use_gamemoderun = True
  28.  
  29. # Enable esync
  30. use_esync = True
  31.  
  32. # Enable fsync
  33. use_fsync = True
  34.  
  35.  
  36. def findProcessIdByName(processName):
  37. """
  38. Get a list of all the PIDs of a all the running process whose name contains
  39. the given string processName
  40. """
  41. # Iterate over the all the running process
  42. while True:
  43. for proc in psutil.process_iter():
  44. try:
  45. pinfo = proc.as_dict(attrs=["cmdline", "name", "pid"])
  46. # Check if process name contains the given name string.
  47. if processName.lower() in pinfo["name"].lower():
  48. return pinfo
  49. except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
  50. pass
  51.  
  52.  
  53. riot_process = findProcessIdByName(riot_service_process_name)
  54.  
  55. # Programmatically get RiotClientServices.exe arguments
  56. try:
  57. riot_argument = " ".join(riot_process.get("cmdline", [])[1:]).strip()
  58. except Exception:
  59. print("Cannot get Garena Token")
  60.  
  61. # Exit if no riot_argument is found
  62. if not riot_argument:
  63. quit()
  64.  
  65. print(riot_argument)
  66.  
  67. # Kill the current RiotClientServices.exe
  68. p = psutil.Process(riot_process.get("pid"))
  69. p.kill()
  70.  
  71. # Start game using lutris
  72. LUTRIS_CONFIG_FOLDER = HOME + "/.config/lutris/games/"
  73. LUTRIS_LOL_CONFIG_FILE = glob.glob(LUTRIS_CONFIG_FOLDER + "league*.yml")[0]
  74.  
  75. with open(LUTRIS_LOL_CONFIG_FILE, "r") as f:
  76. try:
  77. game_config = yaml.load(f, Loader=yaml.FullLoader)
  78. except yaml.YAMLError as exc:
  79. print(exc)
  80. quit()
  81.  
  82. with open(LUTRIS_LOL_CONFIG_FILE, "w") as f:
  83. game_config["game"]["args"] = riot_argument
  84. try:
  85. yaml.dump(game_config, f, default_flow_style=False)
  86. except yaml.YAMLError as exc:
  87. print(exc)
  88.  
  89. lutris_db_path = HOME + "/.local/share/lutris"
  90. lutris_db_name = "pga.db"
  91. conn = sqlite3.connect(lutris_db_path + "/" + lutris_db_name)
  92. c = conn.cursor()
  93. c.execute("SELECT id FROM games WHERE slug='league-of-legends'")
  94. try:
  95. game_id = c.fetchone()[0]
  96. except Exception:
  97. print("No league of legends install from lutris found")
  98. quit()
  99.  
  100. conn.close()
  101.  
  102. print(f"lutris game id: {game_id}")
  103. # Update this to your LOL game id in lutris
  104. launch_command = f"lutris lutris:rungameid/{game_id}"
  105. os.system(launch_command)
  106.  
  107. # Kill Garena
  108. # os.system("wineserver -k")
  109.  
  110. # Start game using correct setup
  111. # Keep in mind the client will take awhile to start, after that you can play like normal
  112. # No garena while playing though
  113. # launch_command = f'env WINEPREFIX={WINEPREFIX} WINEESYNC={1 if use_esync else 0} WINEFSYNC={1 if use_fsync else 0} {"gamemoderun " if use_gamemoderun else ""}"{wine_exe}" "{game_path}" {riot_argument} & "{launchhelper}"'
  114. # detached_process = subprocess.Popen(shlex.split(launch_command), start_new_session=True)
  115. # os.system(launch_command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement