Created
March 15, 2022 20:44
-
-
Save JoaoFelipe/339d9a3f62348f164cfda41a83242971 to your computer and use it in GitHub Desktop.
Epic Account Switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script is a simple remake of TcNo-Acc-Switcher for epic launcher | |
# I made it to avoid installing a third party software that could manage sensitive account data | |
# Original configuraton: https://github.com/TcNobo/TcNo-Acc-Switcher/blob/e36fe87a3e96a23e5a56447c6407121a6245c3aa/TcNo-Acc-Switcher-Server/Platforms.json | |
import os | |
import shutil | |
import json | |
import winreg | |
import psutil | |
import subprocess | |
import argparse | |
import time | |
from pathlib import Path | |
EXECUTE_PROGRAM = "C:\\Program Files (x86)\\Epic Games\\Launcher\\Portal\\Binaries\\Win32\\EpicGamesLauncher.exe" | |
EXES_TO_END = ["EpicGamesLauncher.exe"] | |
copy = { | |
r"%LOCALAPPDATA%\EpicGamesLauncher\Saved\Config\Windows\GameUserSettings.ini": "GameUserSettings.ini", | |
r"%LOCALAPPDATA%\Epic Games\Epic Online Services\UI Helper\Cache\Cache": "Cache", | |
r"%LOCALAPPDATA%\Epic Games\Epic Online Services\UI Helper\Cache\GPUCache": "GPUCache", | |
r"%LOCALAPPDATA%\Epic Games\EOSOverlay\BrowserCache\Cache": "BrowserCache" | |
} | |
def saveu(username): | |
cdir = Path(username) | |
if cdir.exists(): | |
shutil.rmtree(cdir) | |
os.makedirs(cdir, exist_ok=True) | |
for source, target in copy.items(): | |
path1 = Path(os.path.expandvars(source)) | |
if path1.exists(): | |
path2 = cdir / target | |
os.makedirs(str((path2 / "..").resolve()), exist_ok=True) | |
if path1.is_dir(): | |
shutil.copytree(path1, path2) | |
else: | |
shutil.copy(path1, path2) | |
print(path1, '->', path2) | |
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Epic Games\Unreal Engine\Identifiers") | |
with open(cdir / "reg.json", "w") as f: | |
value, rtype = winreg.QueryValueEx(key, "AccountId") | |
json.dump({ | |
'value': value, | |
'type': rtype | |
}, f) | |
print(cdir / "reg.json") | |
def loadu(username): | |
cdir = Path(username) | |
if not cdir.exists(): | |
print(f"{username} is not saved") | |
return | |
for target, source in copy.items(): | |
path1 = cdir / source | |
if path1.exists(): | |
path2 = Path(os.path.expandvars(target)) | |
if path2.is_dir(): | |
shutil.rmtree(path2) | |
os.makedirs(str((path2 / "..").resolve()), exist_ok=True) | |
if path1.is_dir(): | |
shutil.copytree(path1, path2) | |
else: | |
shutil.copy(path1, path2) | |
print(path1, '->', path2) | |
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Epic Games\Unreal Engine\Identifiers", 0, winreg.KEY_SET_VALUE) | |
with open(cdir / "reg.json", "r") as f: | |
data = json.load(f) | |
winreg.SetValueEx(key, "AccountId", 0, data["type"], data["value"]) | |
print(cdir / "reg.json") | |
def clearu(): | |
for source in copy: | |
path1 = Path(os.path.expandvars(source)) | |
if path1.is_dir(): | |
shutil.rmtree(path1) | |
elif path1.exists(): | |
os.remove(path1) | |
print(path1) | |
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Epic Games\Unreal Engine\Identifiers", 0, winreg.KEY_SET_VALUE) | |
winreg.DeleteValue(key, "AccountId") | |
print("registry") | |
def close_program(): | |
for proc in psutil.process_iter(): | |
# check whether the process name matches | |
if proc.name() in EXES_TO_END: | |
proc.kill() | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("profile", type=str, nargs="?") | |
parser.add_argument("-s", "--save", action="store_true") | |
parser.add_argument("-l", "--logout", action="store_true") | |
args = parser.parse_args() | |
if args.save: | |
if args.profile: | |
saveu(args.profile) | |
else: | |
print("You must specify a directory") | |
if args.logout: | |
close_program() | |
time.sleep(0.5) | |
clearu() | |
time.sleep(0.5) | |
if not args.save: | |
if args.profile: | |
close_program() | |
time.sleep(0.5) | |
loadu(args.profile) | |
time.sleep(0.5) | |
subprocess.call([EXECUTE_PROGRAM]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment