Skip to content

Commit

Permalink
Add fix for Flowers - Le Volume Sur Hiver
Browse files Browse the repository at this point in the history
  • Loading branch information
R1kaB3rN committed Jul 9, 2024
1 parent c454e67 commit 84ed190
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions gamefixes-gog/umu-1564851593.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 84ed190

Please sign in to comment.