From 84ed190ae7c37c0b69dbd4659e34520d49604f32 Mon Sep 17 00:00:00 2001 From: R1kaB3rN <100738684+R1kaB3rN@users.noreply.github.com> Date: Tue, 9 Jul 2024 08:56:15 -0700 Subject: [PATCH] Add fix for Flowers - Le Volume Sur Hiver --- gamefixes-gog/umu-1564851593.py | 88 +++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 gamefixes-gog/umu-1564851593.py diff --git a/gamefixes-gog/umu-1564851593.py b/gamefixes-gog/umu-1564851593.py new file mode 100644 index 00000000..09f14201 --- /dev/null +++ b/gamefixes-gog/umu-1564851593.py @@ -0,0 +1,88 @@ +"""Game fix for Flowers - Le Volume Sur Hiver + +This fixes the crash on startup by replacing the text injection framework +files +""" + +import os +from hashlib import sha256 +from tempfile import mkdtemp +from urllib.request import urlopen +from zipfile import ZipFile, is_zipfile + +from protonfixes import util +from protonfixes.logger import log + + +def main(): + tmp = f"{mkdtemp()}/d3d9-2206220222.zip" + install_dir = util.get_game_install_path() + + # Archive containing the text injecting framework + arc = "https://github.com/user-attachments/files/16136393/d3d9-2206220222.zip" + + # Digest of the archive, d3d9.dll proxy and JSON + hashsum_arc = "caed98ec44d4270290f0652502344a40c1d45216caa8935b41e7d9f461ae2d24" + hashsum_d3d9 = "17e1c6706c684b19d05e89b588ba5101bf3ee40429cecf803c6e98af9b342129" + hashsum_config = "aecb441fdc9c9e2ba78df63dfbe14f48c31dfd5ad571adba988ba362fc814377" + + path_config = f"{install_dir}/config.json" + path_dll = f"{install_dir}/d3d9.dll" + + # Download the archive + with urlopen(arc) as resp: + if resp.status != 200: + log.warning(f"github returned the status code: {resp.status}") + return + + data = resp.read() + + if hashsum_arc != sha256(data).hexdigest(): + log.warning(f"Digest mismatch: {arc}") + log.warn(f"Expected '{hashsum_arc}', skipping...") + return + + with open(tmp, mode="wb") as file: + file.write(data) + + if not is_zipfile(tmp): + log.warn(f"Archive {tmp} is not zip, skipping...") + return + + # Ensure that the text injection files do not already exist + if not os.path.isfile(path_config): + log.warn(f"File 'config.json' not found in '{install_dir}', skipping...") + return + + if not os.path.isfile(path_dll): + log.warn(f"File 'd3d9.dll' not found in '{install_dir}', skipping...") + return + + config = open(path_config, mode="rb") + dll = open(path_dll, mode="rb") + + # Check if the text injecting files have already been replaced + if ( + sha256(config.read()).hexdigest() == hashsum_config + and sha256(dll.read()).hexdigest() == hashsum_d3d9 + ): + log.info("Fix for in-game font has already been applied, skipping...") + config.close() + dll.close() + return + + config.close() + dll.close() + + # Rename the old files and apply the fix + randstr = os.urandom(16).hex() + log.info(f"Renaming 'config.json' -> '.{randstr}.config.json.bak'") + log.info(f"Renaming 'd3d9.dll' -> '.{randstr}.d3d9.dll.bak'") + os.rename(path_config, f"{install_dir}/.{randstr}.config.json.bak") + os.rename(path_dll, f"{install_dir}/.{randstr}.d3d9.dll.bak") + + with ZipFile(tmp, mode="r") as zip: + log.info("Fixing in-game font for 'Flowers - Le Volume Sur Hiver'...") + zip.extractall(install_dir) + + os.unlink(tmp)