From 0b4bc827e735ddba236f1940142a3cae217b80b3 Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Fri, 6 Nov 2026 20:39:37 -0500 Subject: [PATCH] fix(battlenet): stop Battle.net's pages playing videos on the CPU (#2195) --- .../overlay/usr/local/bin/droiddeck-battlenet | 43 ++++++++++++++++--- tools/tests/test_battlenet.py | 42 ++++++++++++++++++ 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet b/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet index 2f93eeaaf..1ea487e87 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet @@ -31,6 +31,9 @@ WALLPAPER_DIR = ("users", "steamuser", "AppData", "Local", "DroidDeck") DESKTOP_KEY = "[Control Panel\\\\Desktop]" COLORS_KEY = "[Control Panel\\\\Colors]" WALLPAPER_EDGE = (4, 6, 11) +USER_PREFERENCES = "UserPreferencesMask" +WINE_USER_PREFERENCES = bytes((0x10, 0x00, 0x00, 0x80, 0x12, 0x00, 0x00, 0x00)) +CLIENT_AREA_ANIMATION = (4, 0x02) WALLPAPER_MAX = (1280, 720) FEX_REQUEST = "battlenet-fex.request" FEX_RESULT = "battlenet-fex.result" @@ -331,24 +334,47 @@ def reg_dword(reg, key, name, number): return reg_line(reg, key, name, '"%s"=dword:%08x' % (name, number)) -def reg_line(reg, key, name, line): - try: - with open(reg, encoding="utf-8", errors="replace") as f: - rows = f.read().splitlines() - except OSError: - return False +def reg_read(reg, key, name): + with open(reg, encoding="utf-8", errors="replace") as f: + rows = f.read().splitlines() inside, last = False, None for row in rows: if row.startswith("["): inside = row.startswith(key + " ") or row == key elif inside and row.startswith('"%s"=' % name): last = row + return last + + +def reg_line(reg, key, name, line): + try: + last = reg_read(reg, key, name) + except OSError: + return False if last != line: with open(reg, "a", encoding="utf-8") as out: out.write("\n%s %d\n%s\n" % (key, int(time.time()), line)) return True +def still_pages(root): + reg = os.path.join(prefix(root), "pfx", "user.reg") + if not os.path.isfile(reg): + return False + row = reg_read(reg, DESKTOP_KEY, USER_PREFERENCES) + found = re.fullmatch(r'"%s"=hex:([0-9a-fA-F]{2}(?:,[0-9a-fA-F]{2})*)' % USER_PREFERENCES, row or "") + mask = bytearray(bytes.fromhex(found.group(1).replace(",", "")) if found else WINE_USER_PREFERENCES) + at, bit = CLIENT_AREA_ANIMATION + if len(mask) <= at or not mask[at] & bit: + return False + mask[at] &= ~bit + if wine_processes(os.path.join(prefix(root), "pfx")): + say("Battle.net's prefix is in use; Windows animations go off the next time it starts on its own") + return False + reg_line(reg, DESKTOP_KEY, USER_PREFERENCES, '"%s"=hex:%s' % (USER_PREFERENCES, ",".join("%02x" % b for b in mask))) + return True + + def desktop_size(): width, height = os.environ.get("BL_WIDTH", ""), os.environ.get("BL_HEIGHT", "") if width.isdigit() and height.isdigit() and 0 < int(width) <= 7680 and 0 < int(height) <= 4320: @@ -515,6 +541,11 @@ def configure(root, library=None): dpi(root) except OSError as error: say("Battle.net's desktop scale not set: %s" % error) + try: + if still_pages(root): + say("Battle.net's desktop: Windows animations off, so its pages do not play videos the CPU has to draw") + except OSError as error: + say("Battle.net's desktop animations not set: %s" % error) wow_settings(root) if change == "first": say("wrote Battle.net's first config: hardware acceleration off, streaming off, closing itself as it launches a game, " diff --git a/tools/tests/test_battlenet.py b/tools/tests/test_battlenet.py index c99cb3e68..5f3d72c1b 100644 --- a/tools/tests/test_battlenet.py +++ b/tools/tests/test_battlenet.py @@ -909,6 +909,48 @@ class LaunchTest(Harness): self.assertEqual(image.read_bytes(), b"BM1152x720") self.assertIn('"WallpaperStyle"="2"', (pfx / "user.reg").read_text()) + def test_battle_nets_desktop_turns_windows_animations_off_once(self): + self.install() + reg = Path(self.root) / ("steamapps/compatdata/%s/pfx/user.reg" % BNET["APP_ID"]) + reg.write_text('WINE REGISTRY Version 2\n\n[Control Panel\\\\Desktop] 1\n"UserPreferencesMask"=hex:30,00,02,80,12,00,00,00\n') + self.assertTrue(BNET["still_pages"](self.root)) + self.assertFalse(BNET["still_pages"](self.root)) + text = reg.read_text() + self.assertEqual(text.count('"UserPreferencesMask"=hex:30,00,02,80,10,00,00,00'), 1) + self.assertEqual(BNET["reg_read"](str(reg), BNET["DESKTOP_KEY"], "UserPreferencesMask"), + '"UserPreferencesMask"=hex:30,00,02,80,10,00,00,00') + + def test_a_new_prefix_gets_wines_default_preferences_without_animations(self): + self.install() + reg = Path(self.root) / ("steamapps/compatdata/%s/pfx/user.reg" % BNET["APP_ID"]) + reg.write_text("WINE REGISTRY Version 2\n") + self.assertTrue(BNET["still_pages"](self.root)) + self.assertEqual(BNET["reg_read"](str(reg), BNET["DESKTOP_KEY"], "UserPreferencesMask"), + '"UserPreferencesMask"=hex:10,00,00,80,10,00,00,00') + + def test_animations_already_off_and_other_preferences_are_left_alone(self): + self.install() + reg = Path(self.root) / ("steamapps/compatdata/%s/pfx/user.reg" % BNET["APP_ID"]) + before = 'WINE REGISTRY Version 2\n\n[Control Panel\\\\Desktop] 1\n"UserPreferencesMask"=hex:9e,3e,07,80,31,00,00,00\n' + reg.write_text(before) + self.assertFalse(BNET["still_pages"](self.root)) + self.assertEqual(reg.read_text(), before) + reg.write_text('WINE REGISTRY Version 2\n\n[Control Panel\\\\Desktop] 1\n"UserPreferencesMask"=hex:9e,3e,07,80,33,00,00,00\n') + self.assertTrue(BNET["still_pages"](self.root)) + self.assertEqual(BNET["reg_read"](str(reg), BNET["DESKTOP_KEY"], "UserPreferencesMask"), + '"UserPreferencesMask"=hex:9e,3e,07,80,31,00,00,00') + self.assertFalse(BNET["still_pages"](self.root + "/missing")) + + def test_a_prefix_in_use_keeps_its_registry_until_it_starts_on_its_own(self): + self.install() + reg = Path(self.root) / ("steamapps/compatdata/%s/pfx/user.reg" % BNET["APP_ID"]) + before = 'WINE REGISTRY Version 2\n\n[Control Panel\\\\Desktop] 1\n"UserPreferencesMask"=hex:30,00,02,80,12,00,00,00\n' + reg.write_text(before) + with mock.patch.dict(BNET, {"wine_processes": lambda pfx: [(1, ["C:\\Games\\game.exe"])]}): + self.assertFalse(BNET["still_pages"](self.root)) + self.assertEqual(reg.read_text(), before) + self.assertTrue(BNET["still_pages"](self.root)) + def test_a_large_desktop_scales_battle_net_to_fit_it(self): sizes = {("1280", "720"): 96, ("1920", "1080"): 96, ("2400", "1504"): 120, ("2448", "1848"): 120, ("1080", "2400"): 96, ("3840", "2160"): 192, ("2560", "1600"): 120}