mirror of
https://github.com/gurrgur/er-patcher.git
synced 2026-06-13 09:47:54 +00:00
replace argparse.BooleanOptionalAction as it requires python 3.9, ubuntu 20.04 lts based distros are still stuck on Python 3.8.xx
84 lines
No EOL
3.3 KiB
Python
Executable file
84 lines
No EOL
3.3 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import argparse
|
|
from pathlib import Path
|
|
import struct
|
|
import re
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
patcher_args = sys.argv[1:sys.argv.index("--")]
|
|
|
|
parser = argparse.ArgumentParser(description="Patch Elden Ring executable and launch it without EAC.")
|
|
parser.add_argument("-r", "--rate", type=int, default=60, help="Modify the frame rate limit (e.g. 30, 120, 165 or whatever).")
|
|
parser.add_argument("-u", "--ultrawide", action='store_true', help="Removes black bars when using a resolution with an aspect ratio other than 16:9.")
|
|
parser.add_argument("-v", "--disable-vigniette", action='store_true', help="Disables the vigniette overlay.")
|
|
parser.add_argument("-c", "--disable-ca", action='store_true', help="Disables chromatic abberation.")
|
|
parser.add_argument("-a", "--increase-animation-distance", action='store_true', help="Increase animation distance.")
|
|
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:
|
|
exe_hex = f.read().hex()
|
|
|
|
if patch.rate != 60 and patch.rate > 0:
|
|
exe_hex = exe_hex.replace(
|
|
"c743208988883ceb43897318ebca897318",
|
|
"c743208988883ceb43897318ebca897318".replace(
|
|
"8988883c", struct.pack('<f', 1 / patch.rate).hex()
|
|
)
|
|
)
|
|
|
|
if patch.ultrawide:
|
|
exe_hex = exe_hex.replace(
|
|
"8b0185c07442448b5904",
|
|
"8b0185c0eb42448b5904"
|
|
)
|
|
|
|
if patch.disable_vigniette:
|
|
v_pattern = 'f3 0f 10 .. .. f3 0f 59 .. .. .. .. .. e8 .. .. .. .. f3 41 0f .. .. f3 45 0f .. .. 4c 8d .. .. .. .. .. .. 48'.replace(" ", "")
|
|
v_addr = re.search(v_pattern, exe_hex).span()[0]
|
|
v_offset = 46
|
|
v_patch = "f3 0f 5c c0 90".replace(" ", "") # SUBSS XMM0,XMM0; NOP; all NOP does work too
|
|
exe_hex = exe_hex[:v_addr + v_offset] + v_patch + exe_hex[v_addr + v_offset + len(v_patch):]
|
|
|
|
if patch.disable_ca:
|
|
ca_addr = 94 + exe_hex.index("0f114360488d8b800000000f1087a00000000f1141f0488d87b00000000f10080f1109")
|
|
if exe_hex[ca_addr:ca_addr + 8] == "0f114920":
|
|
exe_hex = exe_hex[:ca_addr] + "660fefc9" + exe_hex[ca_addr + 8:] # PXOR XMM1,XMM1
|
|
|
|
if patch.increase_animation_distance:
|
|
# DIVSS XMM1,dword ptr [R12 + 0x54] -> XORPS XMM1,XMM1; PXOR XMM1,XMM1
|
|
exe_hex = exe_hex.replace(
|
|
"e82b309c010f28f80f28c6e820359c01f30f5ef80f28cff3410f5e4c2454",
|
|
"e82b309c010f28f80f28c6e820359c01f30f5ef80f28cf0f57c9660fefc9"
|
|
)
|
|
|
|
if patch.remove_60hz_fullscreen:
|
|
exe_hex = exe_hex.replace(
|
|
"c745ef3c000000",
|
|
"c745ef00000000"
|
|
)
|
|
|
|
patched_exe_dir = Path("./er-patcher-tmp")
|
|
if not patched_exe_dir.is_dir():
|
|
patched_exe_dir.mkdir()
|
|
|
|
with open(patched_exe_dir / exe_name, "wb") as f:
|
|
f.write(bytes.fromhex(exe_hex))
|
|
|
|
del exe_hex
|
|
|
|
# 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)
|
|
|
|
os.remove(patched_exe_dir / exe_name)
|
|
os.rmdir(patched_exe_dir)
|
|
|