aboutsummaryrefslogtreecommitdiffstats
path: root/frame-steamos/template.py
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2026-11-17 17:03:49 +0000
committerTomasz Kramkowski <tomasz@kramkow.ski>2026-11-17 17:03:49 +0000
commit363fe07ad4cd514d907647ee0eda2310f6efa3c0 (patch)
tree31cc927f256747e17887c8bb049b800457fe3208 /frame-steamos/template.py
parentc750b7298bddab8f273365a96ec482538cd39201 (diff)
downloadsteamvr-patches-363fe07ad4cd514d907647ee0eda2310f6efa3c0.tar.gz
steamvr-patches-363fe07ad4cd514d907647ee0eda2310f6efa3c0.tar.xz
steamvr-patches-363fe07ad4cd514d907647ee0eda2310f6efa3c0.zip
frame-steamos: fix a couple of bugs
It's possible to hang after a reset waiting for the first frame if that frame never arrives. This adds calls to the existing decoder watchdog handler to ensure this is recoverable. Sub-optimal but better than nothing. Shouldn't happen normally anyway, and the patch is still worth it as it fixes genuine repeat resets in much more common cases. Additionally, the headset can send an ack even when there is nothing to ack, and it acks frame ID 0 in that case, this breaks the steamvr patch which keeps the ACK cutoff at all times (it can cause things to get stuck in 3.3FPS mode).
Diffstat (limited to 'frame-steamos/template.py')
-rw-r--r--frame-steamos/template.py138
1 files changed, 138 insertions, 0 deletions
diff --git a/frame-steamos/template.py b/frame-steamos/template.py
new file mode 100644
index 0000000..eff1810
--- /dev/null
+++ b/frame-steamos/template.py
@@ -0,0 +1,138 @@
+#!/usr/bin/python3 -I
+# SPDX-FileCopyrightText: 2026 Tomasz Kramkowski <tomasz@kramkow.ski>
+# SPDX-License-Identifier: CC0-1.0
+
+"""A minimally intrusive Frame SteamOS patcher.
+
+This file is generated.
+
+See https://kramkow.ski/project/steamvr-patches.html and
+https://the-tk.com/cgit/steamvr-patches/about/ for more information.
+"""
+
+import argparse
+import hashlib
+import json
+import os
+import subprocess
+import sys
+from dataclasses import dataclass
+from io import BytesIO
+from pathlib import Path
+
+MARKER = "x-valve-please-fix"
+RUNTIME = Path(os.environ.get("RUNTIME_DIRECTORY", "/run/patcher"))
+
+
+@dataclass(frozen=True)
+class Edit:
+ offset: int
+ replacement: bytes
+
+
+@dataclass(frozen=True)
+class Patch:
+ original_hash: bytes
+ patched_hash: bytes
+ edits: tuple[Edit, ...]
+
+ @classmethod
+ def from_dict(cls, data: dict) -> "Patch":
+ return cls(
+ bytes.fromhex(data["original_hash"]),
+ bytes.fromhex(data["patched_hash"]),
+ tuple(
+ Edit(offset, bytes.fromhex(replacement))
+ for offset, replacement in data["edits"]
+ ),
+ )
+
+ def apply_to(self, data: bytes) -> bytes:
+ result = BytesIO(data)
+ for edit in self.edits:
+ result.seek(edit.offset)
+ result.write(edit.replacement)
+ patched = result.getvalue()
+ if hashlib.sha256(patched).digest() != self.patched_hash:
+ raise ValueError("patched file checksum mismatch")
+ return patched
+
+
+# Please refer to the source code (linked at the top of this file) if you want
+# to know how this data was generated
+PATCH_DATA = {}
+PATCHES = {name: Patch.from_dict(data) for name, data in PATCH_DATA.items()}
+
+
+def start():
+ skipped = False
+ for name, patch in PATCHES.items():
+ target = Path(name).resolve(strict=True)
+ data = target.read_bytes()
+ checksum = hashlib.sha256(data).digest()
+ if checksum != patch.original_hash:
+ print(
+ f"Skipping {target}: unrecognised checksum {checksum.hex()}",
+ file=sys.stderr,
+ )
+ skipped = True
+ continue
+ patched = patch.apply_to(data)
+ source = RUNTIME / hashlib.sha256(os.fsencode(target)).hexdigest()
+ source.parent.mkdir(parents=True, exist_ok=True)
+ source.write_bytes(patched)
+ attributes = target.stat()
+ os.chown(source, attributes.st_uid, attributes.st_gid)
+ source.chmod(attributes.st_mode)
+ subprocess.run(
+ ["mount", "-o", f"bind,ro,{MARKER}", str(source), str(target)],
+ check=True,
+ )
+ print(f"Patched {target}", file=sys.stderr)
+ if skipped:
+ raise SystemExit(1)
+
+
+def stop():
+ result = subprocess.run(
+ [
+ "findmnt",
+ "--mtab",
+ "--options",
+ MARKER,
+ "--json",
+ "--output",
+ "TARGET",
+ ],
+ capture_output=True,
+ text=True,
+ )
+ if (
+ result.returncode == 1
+ and not result.stdout.strip()
+ and not result.stderr.strip()
+ ):
+ return
+ result.check_returncode()
+ for target in reversed(
+ [
+ Path(row["target"])
+ for row in json.loads(result.stdout).get("filesystems", [])
+ ]
+ ):
+ subprocess.run(["umount", str(target)], check=True)
+ print(f"Unmounted {target}", file=sys.stderr)
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("action", choices=("start", "stop"))
+ args = parser.parse_args()
+ if args.action == "start":
+ start()
+ else:
+ stop()
+
+
+if __name__ == "__main__":
+ main()