mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-02 20:21:59 -05:00
fix(game-env): run Inno Setup installers with the FEX Stability settings (#3069)
* fix(game-env): run Inno Setup installers with the FEX Stability settings An Inno Setup installer added as a game stops with Wine's "Path not fpund." dialog under the default FEX preset. The 32-bit setup stub corrupts its own paths before it opens its archive (#1277, #3067). #1174 avoids the stub only for GOG installs, by extracting them natively. droiddeck-game-env now finds the stub by the setup loader's offset-table ID in its resources, or the "Inno" marker older loaders keep at 0x30, and launches it with the Stability preset's FEX settings. A FEX preset chosen for the game itself still wins. Fixes #3067 * fix(game-env): name only the preset seen to corrupt Inno Setup paths The launch note and the docs said the faster presets corrupt the setup stub. Only the default Performance + TSO preset was seen doing it. * fix(game-env): give Inno Setup installers started with run the Stability settings The run verb skips engine_fixes and gets only the sync settings, so an installer started that way kept the inherited Performance + TSO preset. Apply the Stability values on that path too; explicit game settings still win in apply_config. * fix(game-env): keep the game's own FEX settings for installers started with run The run path filtered the game entry down to sync keys, so a FEX preset chosen for the game was replaced by the installer's Stability settings, and a null could not unset a preset key. Copy the game's Stability FEX keys into the synced config before applying it, so the game's own settings still win on every launch path. --------- Co-authored-by: Kurt Himebauch <[email protected]>
This commit is contained in:
1 parent
90df30f4d7
commit
c91b100bc1
3 files changed
+128
-2
No files matched your search
@@ -193,6 +193,15 @@ A Unity game under FEX (`UnityPlayer.dll` for Windows builds under Proton,
|
||||
turns it off: without TSO such games can deadlock or crash (seen with Megabonk
|
||||
and Crab Game). A FEX preset chosen for the game itself still applies.
|
||||
|
||||
An Inno Setup installer added as a game runs with the Stability preset's FEX
|
||||
settings (full TSO, full x87 precision, no multiblock). Under the default
|
||||
Performance + TSO preset the 32-bit setup stub corrupts its own paths and stops
|
||||
with Wine's "Path not fpund." dialog (#1277, #3067). The stub is found by the
|
||||
setup loader's offset-table ID in its resources, or by the `Inno` marker that
|
||||
loaders older than 5.1.5 keep at offset 0x30. GOG installs avoid the stub by
|
||||
extracting natively. A FEX preset chosen for the installer's own entry still
|
||||
applies.
|
||||
|
||||
Games launched through Proton get `vblank_mode=0`, so OpenGL does not wait for
|
||||
each screen refresh. Wine asks for a swap interval of 1 on every OpenGL window, and WineD3D's front-buffer
|
||||
drawing (DirectDraw, Direct3D 1–7) never lowers it, so those games ran at the
|
||||
|
||||
@@ -66,6 +66,35 @@ DOTNET_FEX = {
|
||||
"FEX_HALFBARRIERTSOENABLED": "1",
|
||||
"FEX_X87REDUCEDPRECISION": "0",
|
||||
}
|
||||
STABILITY_FEX = dict(DOTNET_FEX, FEX_MULTIBLOCK="0")
|
||||
# Setup loader offset-table IDs, as innoextract's known_setup_loader_versions lists them. Loaders
|
||||
# from 5.1.5 keep the table in a resource; older ones also put "Inno" at file offset 0x30.
|
||||
INNO_LOADER_IDS = (b"rDlPtS", b"nS5W7dT\x83\xaa\x1b\x0fj")
|
||||
INNO_RESOURCE_LIMIT = 4 << 20
|
||||
|
||||
|
||||
def is_inno_setup(path):
|
||||
try:
|
||||
with open(path, "rb") as exe:
|
||||
head = exe.read(4096)
|
||||
if head[:2] != b"MZ":
|
||||
return False
|
||||
if head[0x30:0x34] == b"Inno":
|
||||
return True
|
||||
pe = int.from_bytes(head[0x3C:0x40], "little")
|
||||
if head[pe:pe + 4] != b"PE\0\0" or int.from_bytes(head[pe + 4:pe + 6], "little") != 0x14C:
|
||||
return False
|
||||
count = int.from_bytes(head[pe + 6:pe + 8], "little")
|
||||
table = pe + 24 + int.from_bytes(head[pe + 20:pe + 22], "little")
|
||||
for entry in range(table, table + 40 * count, 40):
|
||||
if head[entry:entry + 8].rstrip(b"\0") == b".rsrc":
|
||||
exe.seek(int.from_bytes(head[entry + 20:entry + 24], "little"))
|
||||
size = int.from_bytes(head[entry + 16:entry + 20], "little")
|
||||
resources = exe.read(min(size, INNO_RESOURCE_LIMIT))
|
||||
return any(marker in resources for marker in INNO_LOADER_IDS)
|
||||
except OSError:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def game_files(exe):
|
||||
@@ -191,6 +220,12 @@ def split_second_x87_fip(game):
|
||||
return {"FEX_JITFEATURES": "enablex87fip"}, [], "Split/Second: FEX x87 FIP emulation on (its SecuROM stops with error 8016 without it)"
|
||||
|
||||
|
||||
@fix
|
||||
def inno_setup_stability(game):
|
||||
if is_inno_setup(game.exe):
|
||||
return STABILITY_FEX, [], "Inno Setup installer: FEX Stability settings (under Performance + TSO the 32-bit setup stub corrupts its own paths)"
|
||||
|
||||
|
||||
@fix
|
||||
def doom_2016_swapchain_images(game):
|
||||
if "doomx64vk.exe" in game.files and game.stem in ("doomx64", "doomx64vk"):
|
||||
@@ -1676,14 +1711,26 @@ def main():
|
||||
if note:
|
||||
print("droiddeck-game-env: " + note, file=sys.stderr)
|
||||
else:
|
||||
# An installer started with the run verb gets the same Stability settings as one started with
|
||||
# waitforexitandrun; explicit game settings still win over them in apply_config.
|
||||
installer = {}
|
||||
if len(command) > 2 and command[1] == "run" and is_inno_setup(command[2]):
|
||||
installer = dict(STABILITY_FEX)
|
||||
print("droiddeck-game-env: Inno Setup installer: FEX Stability settings", file=sys.stderr)
|
||||
path = Path.home() / ".config/droiddeck/game-environment.json"
|
||||
try:
|
||||
with path.open(encoding="utf-8") as source:
|
||||
config = json.load(source)
|
||||
env = apply_config(env, sync_config(config, app_id), app_id)
|
||||
synced = sync_config(config, app_id)
|
||||
if installer:
|
||||
# A FEX preset chosen for the game itself still wins, as on every other launch path.
|
||||
game = config.get("games", {}).get(app_id, {})
|
||||
synced["games"][app_id].update({k: v for k, v in game.items() if k in STABILITY_FEX})
|
||||
env = apply_config(env, synced, app_id, installer)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
env = dict(env, **installer)
|
||||
except (OSError, ValueError, TypeError, AttributeError):
|
||||
env = dict(env, **installer)
|
||||
print("droiddeck-game-env: invalid configuration; using inherited environment", file=sys.stderr)
|
||||
if waiting:
|
||||
before_debug = env
|
||||
|
||||
@@ -1762,6 +1762,76 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
config["games"] = {"297860": {"FEX_JITFEATURES": "off"}}
|
||||
self.assertEqual(MODULE["apply_config"]({}, config, "297860", env)["FEX_JITFEATURES"], "off")
|
||||
|
||||
def test_inno_setup_installers_get_the_stability_preset_over_the_default(self):
|
||||
stability = {"FEX_TSOENABLED": "1", "FEX_VECTORTSOENABLED": "1", "FEX_MEMCPYSETTSOENABLED": "1",
|
||||
"FEX_HALFBARRIERTSOENABLED": "1", "FEX_X87REDUCEDPRECISION": "0", "FEX_MULTIBLOCK": "0"}
|
||||
performance_tso = {"FEX_TSOENABLED": "1", "FEX_VECTORTSOENABLED": "0", "FEX_MEMCPYSETTSOENABLED": "0",
|
||||
"FEX_HALFBARRIERTSOENABLED": "0", "FEX_X87REDUCEDPRECISION": "1", "FEX_MULTIBLOCK": "1"}
|
||||
|
||||
def loader(path, resources=b"", machine=0x14C, section=b".rsrc", legacy=False):
|
||||
dos = bytearray(0x80)
|
||||
dos[:2] = b"MZ"
|
||||
dos[0x3C:0x40] = (0x80).to_bytes(4, "little")
|
||||
if legacy:
|
||||
dos[0x30:0x34] = b"Inno"
|
||||
header = b"PE\0\0" + machine.to_bytes(2, "little") + (1).to_bytes(2, "little") + bytes(12) \
|
||||
+ (0xE0).to_bytes(2, "little") + bytes(2)
|
||||
entry = section.ljust(8, b"\0") + bytes(8) + len(resources).to_bytes(4, "little") \
|
||||
+ (0x400).to_bytes(4, "little") + bytes(16)
|
||||
path.write_bytes((bytes(dos) + header + bytes(0xE0) + entry).ljust(0x400, b"\0") + resources)
|
||||
return str(path)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
folder = Path(tmp)
|
||||
table = bytes(64) + b"rDlPtS\xcd\xe6\xd7{\x0b*" + bytes(64)
|
||||
installers = [
|
||||
loader(folder / "setup.exe", table),
|
||||
loader(folder / "setup_game_1.0.exe", bytes(64) + b"nS5W7dT\x83\xaa\x1b\x0fj"),
|
||||
loader(folder / "old_setup.exe", legacy=True),
|
||||
]
|
||||
for installer in installers:
|
||||
env, extra, notes = MODULE["engine_fixes"](installer, [])
|
||||
self.assertEqual((env, extra), (stability, []), installer)
|
||||
self.assertTrue(notes)
|
||||
config = {"version": 1, "shared": performance_tso}
|
||||
self.assertEqual({k: v for k, v in MODULE["apply_config"]({}, config, "42", env).items() if k in stability},
|
||||
stability)
|
||||
config["games"] = {"42": {"FEX_MULTIBLOCK": "1"}}
|
||||
self.assertEqual(MODULE["apply_config"]({}, config, "42", env)["FEX_MULTIBLOCK"], "1")
|
||||
|
||||
not_installers = [
|
||||
loader(folder / "Game.exe", bytes(256)),
|
||||
loader(folder / "Game64.exe", table, machine=0x8664),
|
||||
loader(folder / "Data.exe", table, section=b".data"),
|
||||
folder / "missing.exe",
|
||||
]
|
||||
(folder / "notes.exe").write_bytes(b"rDlPtS\xcd\xe6\xd7{\x0b*")
|
||||
not_installers.append(folder / "notes.exe")
|
||||
for other in not_installers:
|
||||
self.assertEqual(MODULE["engine_fixes"](str(other), []), ({}, [], []), other)
|
||||
|
||||
# The run verb skips engine_fixes; an installer started that way still gets Stability.
|
||||
probe = folder / "proton"
|
||||
probe.write_text("#!" + sys.executable + "\nimport json, os\nprint(json.dumps(dict(os.environ)))\n")
|
||||
probe.chmod(0o755)
|
||||
base = {**os.environ, **performance_tso, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": str(folder / "compatdata/42")}
|
||||
|
||||
def run_verb(program):
|
||||
out = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "run", program],
|
||||
env=base, text=True, capture_output=True, check=True).stdout
|
||||
return {name: value for name, value in json.loads(out).items() if name in stability}
|
||||
|
||||
self.assertEqual(run_verb(installers[0]), stability)
|
||||
self.assertEqual(run_verb(str(folder / "Game.exe")), performance_tso)
|
||||
config_path = folder / ".config/droiddeck/game-environment.json"
|
||||
config_path.parent.mkdir(parents=True)
|
||||
config_path.write_text(json.dumps({"version": 1, "shared": {"WINEESYNC": "1"}}))
|
||||
self.assertEqual(run_verb(installers[0]), stability)
|
||||
config_path.write_text(json.dumps({"version": 1, "games": {"42": {"FEX_MULTIBLOCK": "1"}}}))
|
||||
self.assertEqual(run_verb(installers[0]), {**stability, "FEX_MULTIBLOCK": "1"})
|
||||
config_path.write_text(json.dumps({"version": 1, "games": {"42": {"FEX_MULTIBLOCK": None}}}))
|
||||
self.assertNotIn("FEX_MULTIBLOCK", run_verb(installers[0]))
|
||||
|
||||
def test_d3dgear_capture_hook_beside_the_game_is_turned_off(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
game = Path(tmp) / "The Crew 2"
|
||||
|
||||
Reference in new issue
Block a user