From 363fe07ad4cd514d907647ee0eda2310f6efa3c0 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Tue, 17 Nov 2026 17:03:49 +0000 Subject: 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). --- frame-steamos/template.py | 138 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 frame-steamos/template.py (limited to 'frame-steamos/template.py') 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 +# 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() -- cgit v1.3.1