Play Windows games on Apple Silicon Macs. Free, open-source app that installs the official Battle.net, Steam, Epic and GOG launchers and lists your games in one library.
HTML apple-siliconbattle-netcrossover-alternatived3dmetaldiablo-ii-resurrecteddxmtea-appepic-gamesgame-porting-toolkitgogmac-gamingmacosmacos-gamingrockstar-gamessteamubisoft-connectwhisky-alternativewindows-gameswinewine-wrapper
Steam: NW.js games (RPG Maker MV/MZ) draw in their own process (#129)
Mikek8ba8cd302960
diff --git a/scripts/play.sh b/scripts/play.shindex 4c0642023de..eaea3edb8c8 100755--- a/scripts/play.sh+++ b/scripts/play.sh@@ -344,6 +344,9 @@ case "$MODE" in# starts; the renderer switch refuses while this bottle is running anyway.pgrep -f "$WINESTABLE_SERVER" >/dev/null 2>&1 || \python3 "$(dirname "${BASH_SOURCE[0]}")/steam-profiles.py" apply || true+ # NW.js games (RPG Maker MV/MZ) need --in-process-gpu or their window stays empty;+ # Steam restores package.json on updates, so check every launch.+ python3 "$(dirname "${BASH_SOURCE[0]}")/steam-profiles.py" nwjs || true# 1) Clean crash leftovers (a stale lock makes the next launch a windowless --silent one)find "$WINEPREFIX/drive_c/users/"*/AppData/Local/Steam/htmlcache -maxdepth 2 \\( -name "Singleton*" -o -name "*.lock" \) -delete 2>/dev/null || truediff --git a/scripts/steam-profiles.py b/scripts/steam-profiles.pyindex 00964a803c1..578f371e271 100644--- a/scripts/steam-profiles.py+++ b/scripts/steam-profiles.py@@ -3,12 +3,20 @@steam-profiles.py apply switch matching games (play.sh runs this before Steam starts)steam-profiles.py list show what would change, change nothing+ steam-profiles.py nwjs NW.js games (RPG Maker MV/MZ): draw in the game's own processresources/steam-profiles.json lists Direct3D 11 games that run better on DXVKthan on the default DXMT. A game is switched once, through steam-renderer.py(which keeps the original files and can reset them). A game the player alreadyset up with `soju steam-games renderer`, or switched back, is left alone: thechoice is recorded in <bottle>/.soju-auto-profiles.json.++NW.js games (RPG Maker MV and MZ ship as nw.dll + package.json next to Game.exe)+open an empty window: Chromium draws in a separate GPU process, and DXMT cannot+make a swap chain for a window that belongs to another process. `nwjs` adds+--in-process-gpu to the game's "chromium-args" (the original package.json is kept+as package.json.soju-orig). Steam restores the file on updates, so it runs before+every Steam start."""import jsonimport os@@ -56,6 +64,38 @@ def installed(steamapps):yield appid.group(1), steamapps / "common" / folder.group(1)+NWJS_FLAG = "--in-process-gpu"+++def nwjs_games(steamapps):+ """package.json files of installed NW.js games: next to nw.dll, at most two folders deep."""+ for _, folder in installed(steamapps) if steamapps.is_dir() else []:+ for depth in range(3):+ for dll in folder.glob("/".join(["*"] * depth + ["nw.dll"])):+ manifest = dll.parent / "package.json"+ if manifest.is_file() and not manifest.is_symlink():+ yield manifest+++def nwjs_fix(manifest):+ """Add NWJS_FLAG to chromium-args; True when the file changed."""+ try:+ data = json.loads(manifest.read_text(encoding="utf-8-sig"))+ except (OSError, ValueError):+ return False+ if not isinstance(data, dict):+ return False+ args = data.get("chromium-args", "")+ if not isinstance(args, str) or NWJS_FLAG in args.split():+ return False+ backup = manifest.with_name("package.json.soju-orig")+ if not backup.exists():+ backup.write_bytes(manifest.read_bytes())+ data["chromium-args"] = (args + " " + NWJS_FLAG).strip()+ manifest.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")+ return True++def plan():profiles = json.loads((ROOT / "resources/steam-profiles.json").read_text())["profiles"]steamapps = PREFIX / "drive_c/Program Files (x86)/Steam/steamapps"@@ -81,13 +121,18 @@ def plan():def main():action = sys.argv[1] if len(sys.argv) > 1 else "list"+ if action == "nwjs":+ for manifest in nwjs_games(PREFIX / "drive_c/Program Files (x86)/Steam/steamapps"):+ if nwjs_fix(manifest):+ print(f"soju: {manifest.parent.name}: NW.js game set to draw in its own process ({NWJS_FLAG})")+ returntodo, state, state_file = plan()if action == "list":for appid, p, exe in todo:print(f"{p['title']} ({appid}): {p['renderer']} for {exe.name} - {p['why']}")returnif action != "apply":- sys.exit("usage: steam-profiles.py apply|list")+ sys.exit("usage: steam-profiles.py apply|list|nwjs")if not (PREFIX / ".soju-steam-games").is_file():return # renderer components not prepared yet (soju steam-games)for appid, p, exe in todo:diff --git a/tests/test_steam_profiles.py b/tests/test_steam_profiles.pyindex 23666851173..768b22b9feb 100644--- a/tests/test_steam_profiles.py+++ b/tests/test_steam_profiles.py@@ -56,5 +56,40 @@ class Profiles(unittest.TestCase):self.assertTrue(all(p["renderer"] == "dxvk" and p["why"] for p in data.values()))+class NWJS(unittest.TestCase):+ def setUp(self):+ self.tmp = tempfile.TemporaryDirectory()+ self.prefix = Path(self.tmp.name)+ self.apps = self.prefix / "drive_c/Program Files (x86)/Steam/steamapps"+ (self.apps / "common/Termina").mkdir(parents=True)+ (self.apps / "appmanifest_2171440.acf").write_text(+ '"AppState"\n{\n\t"appid"\t\t"2171440"\n\t"installdir"\t\t"Termina"\n}\n')+ game = self.apps / "common/Termina"+ (game / "nw.dll").write_bytes(b"MZ")+ self.manifest = game / "package.json"+ self.original = '\ufeff{"name":"rmmz-game","main":"index.html","chromium-args":"--force-color-profile=srgb"}'+ self.manifest.write_text(self.original, encoding="utf-8")++ def tearDown(self):+ self.tmp.cleanup()+ os.environ.pop("WINEPREFIX", None)++ def test_adds_flag_once_and_keeps_original(self):+ m = load(self.prefix)+ found = list(m.nwjs_games(self.apps))+ self.assertEqual(found, [self.manifest])+ self.assertTrue(m.nwjs_fix(self.manifest))+ data = json.loads(self.manifest.read_text())+ self.assertEqual(data["chromium-args"], "--force-color-profile=srgb --in-process-gpu")+ self.assertEqual(data["main"], "index.html")+ self.assertFalse(m.nwjs_fix(self.manifest))+ self.assertEqual((self.manifest.parent / "package.json.soju-orig").read_text(encoding="utf-8"), self.original)++ def test_leaves_unreadable_manifest(self):+ self.manifest.write_text("not json")+ self.assertFalse(load(self.prefix).nwjs_fix(self.manifest))+ self.assertEqual(self.manifest.read_text(), "not json")++if __name__ == "__main__":unittest.main()