From 62cb574ced526372932fa09b6e2db0be5f262727 Mon Sep 17 00:00:00 2001 From: Marcus Gursch Date: Fri, 25 Mar 2022 20:24:26 +0100 Subject: [PATCH 1/2] improve mod compatibility --- er-patcher | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/er-patcher b/er-patcher index 7ec549c..28f1e58 100755 --- a/er-patcher +++ b/er-patcher @@ -7,6 +7,7 @@ import argparse from pathlib import Path import struct import re +from shutil import rmtree if __name__ == "__main__": @@ -26,8 +27,8 @@ if __name__ == "__main__": parser.add_argument("-f", "--remove-60hz-fullscreen", action='store_true', help="Remove 60hz lock in fullscreen.") patch = parser.parse_args(patcher_args) - exe_name = Path("eldenring.exe") - with open(exe_name, "rb") as f: + game_dir = Path(".") + with open(game_dir / "eldenring.exe", "rb") as f: exe_hex = f.read().hex() if patch.rate != 60 and patch.rate > 0: @@ -82,19 +83,36 @@ if __name__ == "__main__": "c745ef00000000" ) - patched_exe_dir = Path("./er-patcher-tmp") - if not patched_exe_dir.is_dir(): - patched_exe_dir.mkdir() + game_dir_patched = Path("er-patcher-tmp") + if not game_dir_patched.is_dir(): + game_dir_patched.mkdir() - with open(patched_exe_dir / exe_name, "wb") as f: + with open(game_dir_patched / "eldenring.exe", "wb") as f: f.write(bytes.fromhex(exe_hex)) del exe_hex + # recreate game directory tree in game_dir_patched + game_dirs = [d for d in game_dir.rglob("*") if d.is_dir()] + for d in game_dirs: + if d == game_dir_patched: + continue + if not (game_dir_patched / d).is_dir(): + (game_dir_patched / d).mkdir(parents=True) + + # hard link game files to game_dir_patched; symbolic links would be easier + # to handle but by default windows 10 doesn't allow them + game_files = [f for f in game_dir.rglob("*") if f.is_file()] + for f in game_files: + if f.name in ["eldenring.exe", "start_protected_game.exe", "er-patcher"]: + continue + if not (game_dir_patched / f).is_file(): + (game_dir_patched / f).hardlink_to(f) + # start patched exe directly to avoid EAC steam_cmd = sys.argv[1 + sys.argv.index("--"):] - steam_cmd[-1] = Path(steam_cmd[-1]).parent.absolute() / patched_exe_dir / exe_name - subprocess.run(steam_cmd) + steam_cmd[-1] = Path(steam_cmd[-1]).parent.absolute() / game_dir_patched / "eldenring.exe" + subprocess.run(steam_cmd, cwd=steam_cmd[-1].parent.absolute()) - os.remove(patched_exe_dir / exe_name) - os.rmdir(patched_exe_dir) \ No newline at end of file + # cleanup + rmtree(game_dir_patched) \ No newline at end of file From a531256c0a540ce42655e11d00db4188048549b5 Mon Sep 17 00:00:00 2001 From: Marcus Gursch Date: Fri, 25 Mar 2022 20:47:52 +0100 Subject: [PATCH 2/2] use old hard link api for python 3.8 compatibility --- er-patcher | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/er-patcher b/er-patcher index 28f1e58..58cfb08 100755 --- a/er-patcher +++ b/er-patcher @@ -107,7 +107,7 @@ if __name__ == "__main__": if f.name in ["eldenring.exe", "start_protected_game.exe", "er-patcher"]: continue if not (game_dir_patched / f).is_file(): - (game_dir_patched / f).hardlink_to(f) + f.link_to(game_dir_patched / f) # start patched exe directly to avoid EAC steam_cmd = sys.argv[1 + sys.argv.index("--"):]