Update patcher.py to reflect the most recent update to the game

Removed support for Ubisoft exe (unless it happens to be at the exact same offset) as I only analyzed the Steam version of the game
This commit is contained in:
Kyle Mohr authored and GitHub committed 2025-05-09 17:15:41 -05:00
1 parent 229a058208
commit c7a0470585
1 file changed
+15 -9
+15 -9
View File
@@ -3,10 +3,10 @@ import shutil
import getpass import getpass
def modify_exe(input_path): def modify_exe(input_path):
steam_version_offset = 0x0178ACC0 steam_version_offset = 0x0178bac2
ubisoft_connect_version_offset = 0x01789EE0 #ubisoft_connect_version_offset = 0x01789EE0
expected_bytes = bytes.fromhex("48 89 54 24 10 55 56 57 48 81 EC F0 00 00 00 48") expected_bytes = bytes.fromhex("40 0f b6 c7 0f 28 74 24 50 48 83 c4 68 5f 5b c3")
replacement_bytes = bytes.fromhex("B0 01 C3 24 10 55 56 57 48 81 EC F0 00 00 00 48") replacement_bytes = bytes.fromhex("31 C0 B0 01 0f 28 74 24 50 48 83 c4 68 5f 5b c3")
expected_path_linux = '/home/' + getpass.getuser() + '/.local/share/Steam/steamapps/common/Trials Rising/datapack/trialsrising.exe' expected_path_linux = '/home/' + getpass.getuser() + '/.local/share/Steam/steamapps/common/Trials Rising/datapack/trialsrising.exe'
if not os.path.exists(input_path): if not os.path.exists(input_path):
@@ -24,21 +24,27 @@ def modify_exe(input_path):
if offset + len(expected_bytes) > len(data): if offset + len(expected_bytes) > len(data):
return False, "Offset exceeds file size" return False, "Offset exceeds file size"
read_bytes = bytes(data[offset: offset + len(expected_bytes)]) read_bytes = bytes(data[offset: offset + len(expected_bytes)])
# Search for the expected bytes throughout the entire file, not just at the offset
# for i in range(len(data) - len(expected_bytes)):
# read_bytes = bytes(data[i: i + len(expected_bytes)])
# if read_bytes == expected_bytes:
# print(f"Found expected bytes at offset: {hex(i)}")
# offset = i
# continue
# exit()
if read_bytes == expected_bytes: if read_bytes == expected_bytes:
print(f"Bytes matched at offset: {hex(offset)}. Modifying...") print(f"Bytes matched at offset: {hex(offset)}. Modifying...")
for i, byte in enumerate(replacement_bytes): for i, byte in enumerate(replacement_bytes):
data[offset + i] = byte data[offset + i] = byte
return True, None return True, None
else:
print(f"These bytes: {read_bytes.hex()} did not match expected bytes: {expected_bytes.hex()}")
return False, "Bytes did not match" return False, "Bytes did not match"
modified, message = check_and_patch(steam_version_offset) modified, message = check_and_patch(steam_version_offset)
if not modified: if not modified:
print("This does not appear to be a Steam version of the game. Checking if it's Ubisoft Connect version...") print(f"Error: {message}")
modified, message = check_and_patch(ubisoft_connect_version_offset)
if not modified:
print("Error: could not find bytes to patch. Is it possible that the file is already patched?")
print("Ensure you're only trying to patch the original trialsrising.exe file.")
return False return False
if modified: if modified: