From ec9573643a71d6b55e623dfa13c6725924077aab Mon Sep 17 00:00:00 2001
From: The412Banner <205237651+The412Banner@users.noreply.github.com>
Date: Sun, 1 Nov 2026 01:22:36 -0500
Subject: [PATCH] fix(game-env): give Codemasters EGO games a thread plan for
the core count Windows sees (#1936)
Codemasters EGO games (DiRT 3, DiRT Showdown, GRID, F1 ...) pick their thread plan by core count from system/hardware_settings_restrictions.xml, which only has plans for 2, 3, 4, 6 and 8+ cores. When DroidDeck leaves a phone's slow cores out Windows can see 5 (Retroid Pocket Duo), and DiRT 3 then puts every worker on one core and stops on a loading screen; Showdown closes at start.
When a game starts with WINE_CPU_TOPOLOGY set and its restrictions have no cpu rule for that count, droiddeck-game-env adds one copied from the nearest smaller plan (5 -> the game's 4-core plan), only if that plan's worker map file exists. The file as it was is kept as .droiddeck-original; later launches change nothing. Only ASCII digits count as a core count, and the edited file is staged under a unique name.
Tested on a Retroid Pocket Duo: with DiRT 3's shipped file, the plan is added at launch and the game loads to its menus and races.
---
.../overlay/usr/local/bin/droiddeck-game-env | 62 +++++++++++++
tools/tests/test_game_environment.py | 89 +++++++++++++++++++
2 files changed, 151 insertions(+)
diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env
index b25ccf255..91305b86c 100755
--- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env
+++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env
@@ -856,6 +856,61 @@ def restore_dirt_ws2(prefix, proton):
return False
+EGO_RESTRICTIONS = "system/hardware_settings_restrictions.xml"
+EGO_CORE_RULE = re.compile(r'[ \t]*.*?[ \t]*\r?\n', re.S)
+EGO_OPS = {"int_eq": int.__eq__, "int_ne": int.__ne__, "int_ge": int.__ge__, "int_gt": int.__gt__,
+ "int_le": int.__le__, "int_lt": int.__lt__}
+
+
+def windows_core_count(env):
+ count = (env.get("WINE_CPU_TOPOLOGY") or "").split(":", 1)[0]
+ return int(count) if count.isascii() and count.isdigit() and int(count) > 0 else None
+
+
+def ego_core_plan(command, env):
+ """Codemasters EGO games (DiRT 3, DiRT Showdown, GRID, F1 ...) pick their thread plan by core count from
+ system/hardware_settings_restrictions.xml. A count with no plan (5 when a phone's slow cores are left out) puts
+ every worker on one core, and DiRT 3 then stops on a loading screen. Adds a plan for the count Windows sees,
+ copied from the nearest smaller one; the file as it was is kept beside it. Returns a note, or None."""
+ count = windows_core_count(env)
+ if not count or len(command) < 3:
+ return None
+ folder = Path(command[2]).parent
+ path = folder / EGO_RESTRICTIONS
+ try:
+ raw = path.read_bytes()
+ except OSError:
+ return None
+ text = raw.decode("latin-1")
+ start, end = text.find(""), text.find("")
+ if start < 0 or end < start:
+ return None
+ rules = list(EGO_CORE_RULE.finditer(text, start, end))
+ if not rules or any(EGO_OPS.get(rule.group(1), lambda a, b: True)(count, int(rule.group(2))) for rule in rules):
+ return None
+ smaller = [rule for rule in rules if rule.group(1) == "int_eq" and int(rule.group(2)) < count]
+ if not smaller:
+ return None
+ source = max(smaller, key=lambda rule: int(rule.group(2)))
+ worker_map = re.search(r'workerMapFile="([^"]+)"', source.group(0))
+ if worker_map and not (folder / worker_map.group(1)).is_file():
+ return None
+ plan = source.group(0).replace('value="%s"' % source.group(2), 'value="%d"' % count, 1)
+ saved = path.with_name(path.name + DIRT_SAVED)
+ if not os.path.lexists(saved):
+ saved.write_bytes(raw)
+ handle, staged = tempfile.mkstemp(prefix=path.name + ".", suffix=".droiddeck-tmp", dir=str(path.parent))
+ try:
+ with os.fdopen(handle, "wb") as out:
+ out.write((text[:source.end()] + plan + text[source.end():]).encode("latin-1"))
+ os.replace(staged, path)
+ except BaseException:
+ if os.path.lexists(staged):
+ os.unlink(staged)
+ raise
+ return "%s had no thread plan for %d cores; added a copy of its %s-core plan" % (EGO_RESTRICTIONS, count, source.group(2))
+
+
def wait_forwarding_signals(process):
def forward(signum, frame):
try:
@@ -963,6 +1018,13 @@ def main():
env = force_ssbs(command, env)
game_cores(env)
cpu_topology(env, command)
+ if app_id and len(command) > 2 and command[1] == "waitforexitandrun":
+ try:
+ note = ego_core_plan(command, env)
+ except OSError as error:
+ note = "no thread plan added for this core count (%s)" % error
+ if note:
+ print("droiddeck-game-env: " + note, file=sys.stderr)
try:
xbox = runpy.run_path(str(Path(__file__).with_name("droiddeck-xbox")))
except Exception as error:
diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py
index 8e6af2c56..d27520dd4 100644
--- a/tools/tests/test_game_environment.py
+++ b/tools/tests/test_game_environment.py
@@ -245,6 +245,95 @@ class DirtTelemetryFixTest(unittest.TestCase):
self.assertEqual(calls, ["restored"])
+class EgoCorePlanTest(unittest.TestCase):
+ """DiRT 3's restrictions as shipped: plans for 2, 3, 4, 6 and 8+ cores, one core for anything else."""
+
+ @staticmethod
+ def rule(op, value, worker_map):
+ return (' \r\n \r\n'
+ ' \r\n'
+ ' \r\n \r\n' % (op, value, worker_map))
+
+ def setUp(self):
+ self.tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(self.tmp.cleanup)
+ self.system = Path(self.tmp.name) / "DiRT 3/system"
+ self.system.mkdir(parents=True)
+ cpu = "".join(self.rule("int_eq", n, "workerMap%dCore.xml" % n) for n in (2, 3, 4, 6)) + self.rule("int_ge", 8, "workerMap8Core.xml")
+ self.shipped = ('\r\n\r\n \r\n'
+ ' \r\n' + cpu +
+ ' \r\n \r\n'
+ ' \r\n'
+ ' \r\n \r\n \r\n \r\n'
+ ' \r\n' + self.rule("int_eq", 5, "audio.xml") + ' \r\n'
+ '').encode("latin-1")
+ self.path = self.system / "hardware_settings_restrictions.xml"
+ self.path.write_bytes(self.shipped)
+ for name in ("workerMap.xml", "workerMap2Core.xml", "workerMap3Core.xml", "workerMap4Core.xml", "workerMap6Core.xml", "workerMap8Core.xml"):
+ (self.system / name).write_text("")
+ self.command = ["/proton", "waitforexitandrun", str(self.system.parent / "dirt3_game.exe")]
+ self.saved = self.path.with_name(self.path.name + ".droiddeck-original")
+
+ def plan(self, topology, command=None):
+ env = {} if topology is None else {"WINE_CPU_TOPOLOGY": topology}
+ return MODULE["ego_core_plan"](command or self.command, env)
+
+ def test_five_cores_get_a_copy_of_the_four_core_plan(self):
+ note = self.plan("5:7,3,4,5,6")
+ self.assertIn("5 cores", note)
+ self.assertIn("4-core plan", note)
+ text = self.path.read_bytes()
+ four = self.rule("int_eq", 4, "workerMap4Core.xml").encode("latin-1")
+ five = self.rule("int_eq", 5, "workerMap4Core.xml").encode("latin-1")
+ self.assertEqual(text, self.shipped.replace(four, four + five))
+ self.assertNotIn(b"\n", text.replace(b"\r\n", b""))
+ self.assertEqual(self.saved.read_bytes(), self.shipped)
+ self.assertEqual(sorted(p.name for p in self.system.glob("*droiddeck-tmp*")), [])
+ self.assertIsNone(self.plan("5:7,3,4,5,6"))
+ self.assertEqual(self.path.read_bytes(), text)
+ self.assertEqual(self.saved.read_bytes(), self.shipped)
+
+ def test_seven_cores_get_the_six_core_plan(self):
+ self.assertIn("6-core plan", self.plan("7:7,1,2,3,4,5,6"))
+ self.assertIn(b'value="7">\r\n \r\n