diff --git a/docs/development/game-environment.md b/docs/development/game-environment.md index 8d366151e6..916fa30dc6 100644 --- a/docs/development/game-environment.md +++ b/docs/development/game-environment.md @@ -212,6 +212,12 @@ more, so its fix removes both variables, also from its launch options, and sets `vk_x11_strict_image_count=true`, the option Mesa's driconf gives the game. A per-game value in the environment editor still wins. +Dragon Quest Monsters 4 does not draw slime bodies at its default monster mesh +detail, leaving only their tips. Before each launch, DroidDeck sets +`r.SkeletalMeshLODBias=-4` and `r.SkeletalMeshLODRadiusScale=0.25` under +`[SystemSettings]` in the game's `Engine.ini`. It does this every time because the +game ignores `-ini:` overrides and deletes a writable `Engine.ini` after reading it. + ## Defaults and available suggestions The initial configuration enables Mesa shader caching with diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index e620d47b2f..e1bee1c12a 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -242,6 +242,57 @@ def skip_red_launcher(command): return command +DQM4_MESH_DETAIL = {"r.SkeletalMeshLODBias": "-4", "r.SkeletalMeshLODRadiusScale": "0.25"} + + +def with_system_settings(text, settings): + lines = text.splitlines() + try: + section = lines.index("[SystemSettings]") + except ValueError: + if lines and lines[-1].strip(): + lines.append("") + lines.append("[SystemSettings]") + section = len(lines) - 1 + end = next((i for i in range(section + 1, len(lines)) if lines[i].startswith("[")), len(lines)) + block = [line for line in lines[section + 1:end] if line.split("=", 1)[0].strip() not in settings] + while block and not block[-1].strip(): + block.pop() + block += ["%s=%s" % item for item in settings.items()] + tail = lines[end:] + return "\n".join(lines[:section + 1] + block + ([""] if tail else []) + tail) + "\n" + + +# The game ignores -ini: overrides and deletes a writable Engine.ini after reading it, so this runs at every launch. +def dragon_quest_monsters_4_mesh_detail(exe, env): + project = Path(exe).stem.split("-", 1)[0] + if not project.lower().startswith("dragonquestmonsters4"): + return + prefix = Path(env.get("STEAM_COMPAT_DATA_PATH", "/nonexistent")) / "pfx" + config = prefix / "drive_c/users/steamuser/AppData/Local" / project / "Saved/Config/Windows/Engine.ini" + try: + if not prefix.is_dir(): + return + text = config.read_text(encoding="utf-8") if config.exists() else "" + updated = with_system_settings(text, DQM4_MESH_DETAIL) + if updated == text: + return + config.parent.mkdir(parents=True, exist_ok=True) + handle, staged = tempfile.mkstemp(prefix=".engine-", dir=config.parent) + try: + with os.fdopen(handle, "w", encoding="utf-8") as target: + target.write(updated) + if config.exists(): + os.chmod(staged, config.stat().st_mode & 0o7777) + os.replace(staged, config) + except BaseException: + os.unlink(staged) + raise + print("droiddeck-game-env: Dragon Quest Monsters 4: full-detail monster meshes", file=sys.stderr) + except (OSError, UnicodeDecodeError) as error: + print("droiddeck-game-env: Dragon Quest Monsters 4 mesh detail left as is (%s)" % error, file=sys.stderr) + + UBISOFT_LAUNCHER = "drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher" UBISOFT_SETTINGS = "drive_c/users/steamuser/AppData/Local/Ubisoft Game Launcher/settings.yaml" @@ -1412,6 +1463,7 @@ def main(): command = skip_red_launcher(command) if len(command) > 2: death_stranding_allocator(app_id, command[2]) + dragon_quest_monsters_4_mesh_detail(command[2], effective_env) ubisoft_overlay_off(env) project_zomboid_jvm(command) fixes, extra, notes = engine_fixes(command[2], command[3:], app_id) if len(command) > 2 else ({}, [], []) diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index d17fc737b7..453346281d 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -1,3 +1,4 @@ +import contextlib import hashlib import io import json @@ -1548,6 +1549,65 @@ class GameEnvironmentTest(unittest.TestCase): self.assertEqual(MODULE["engine_fixes"](game, [], "42"), ({}, [], [])) self.assertEqual(MODULE["engine_fixes"](game, []), ({}, [], [])) + def test_dragon_quest_monsters_4_writes_full_detail_mesh_settings(self): + apply = MODULE["dragon_quest_monsters_4_mesh_detail"] + wanted = "r.SkeletalMeshLODBias=-4\nr.SkeletalMeshLODRadiusScale=0.25\n" + for exe, project in (("DragonQuestMonsters4Demo.exe", "DragonQuestMonsters4Demo"), + ("DragonQuestMonsters4-Win64-Shipping.exe", "DragonQuestMonsters4")): + with self.subTest(exe=exe), tempfile.TemporaryDirectory() as tmp: + (Path(tmp) / "pfx").mkdir() + config = Path(tmp) / "pfx/drive_c/users/steamuser/AppData/Local" / project / "Saved/Config/Windows/Engine.ini" + with contextlib.redirect_stderr(io.StringIO()): + apply("/game/" + exe, {"STEAM_COMPAT_DATA_PATH": tmp}) + self.assertEqual(config.read_text(), "[SystemSettings]\n" + wanted) + + def test_dragon_quest_monsters_4_keeps_other_engine_settings(self): + with tempfile.TemporaryDirectory() as tmp: + (Path(tmp) / "pfx").mkdir() + config = Path(tmp) / "pfx/drive_c/users/steamuser/AppData/Local/DragonQuestMonsters4Demo/Saved/Config/Windows/Engine.ini" + config.parent.mkdir(parents=True) + config.write_text("[Core.Log]\nLogTemp=Log\n\n[SystemSettings]\nr.Fog=0\nr.SkeletalMeshLODBias=0\n\n[Other]\nKey=1\n") + config.chmod(0o444) + with contextlib.redirect_stderr(io.StringIO()): + MODULE["dragon_quest_monsters_4_mesh_detail"]("/game/DragonQuestMonsters4Demo.exe", {"STEAM_COMPAT_DATA_PATH": tmp}) + self.assertEqual(config.read_text(), "[Core.Log]\nLogTemp=Log\n\n[SystemSettings]\nr.Fog=0\n" + "r.SkeletalMeshLODBias=-4\nr.SkeletalMeshLODRadiusScale=0.25\n\n[Other]\nKey=1\n") + self.assertEqual(config.stat().st_mode & 0o777, 0o444) + + def test_dragon_quest_monsters_4_settings_use_the_game_profile_prefix(self): + with tempfile.TemporaryDirectory() as tmp: + home = Path(tmp) + exe = home / "game/DragonQuestMonsters4Demo.exe" + exe.parent.mkdir() + exe.touch() + proton = home / "fake-proton" + proton.write_text("#!" + sys.executable + "\nimport json, sys\nprint(json.dumps(sys.argv[1:]))\n") + proton.chmod(0o755) + inherited, chosen = home / "compatdata/42", home / "profile/42" + for data in (inherited, chosen): + (data / "pfx").mkdir(parents=True) + config = home / ".config/droiddeck/game-environment.json" + config.parent.mkdir(parents=True) + config.write_text(json.dumps({"version": 1, "games": {"42": {"STEAM_COMPAT_DATA_PATH": str(chosen)}}})) + subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(proton), "waitforexitandrun", str(exe)], + env=dict(os.environ, HOME=tmp, STEAM_COMPAT_DATA_PATH=str(inherited)), + text=True, capture_output=True, check=True) + engine = "pfx/drive_c/users/steamuser/AppData/Local/DragonQuestMonsters4Demo/Saved/Config/Windows/Engine.ini" + self.assertIn("r.SkeletalMeshLODBias=-4", (chosen / engine).read_text()) + self.assertFalse((inherited / engine).exists()) + + def test_dragon_quest_monsters_4_prefix_errors_do_not_stop_the_launch(self): + errors = io.StringIO() + with mock.patch.object(Path, "is_dir", side_effect=PermissionError("denied")), contextlib.redirect_stderr(errors): + MODULE["dragon_quest_monsters_4_mesh_detail"]("/game/DragonQuestMonsters4Demo.exe", {"STEAM_COMPAT_DATA_PATH": "/compatdata/42"}) + self.assertIn("left as is", errors.getvalue()) + + def test_other_games_do_not_get_the_dragon_quest_monsters_4_settings(self): + with tempfile.TemporaryDirectory() as tmp: + (Path(tmp) / "pfx").mkdir() + MODULE["dragon_quest_monsters_4_mesh_detail"]("/game/DragonQuestMonsters3.exe", {"STEAM_COMPAT_DATA_PATH": tmp}) + self.assertEqual(list((Path(tmp) / "pfx").iterdir()), []) + def test_arkham_city_gets_full_x87_precision_over_the_preset(self): with tempfile.TemporaryDirectory() as tmp: city = Path(tmp) / "Batman Arkham City GOTY/Binaries/Win32"