aboutsummaryrefslogtreecommitdiffstats
path: root/src/steamvr_patches/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/steamvr_patches/__init__.py')
-rw-r--r--src/steamvr_patches/__init__.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/steamvr_patches/__init__.py b/src/steamvr_patches/__init__.py
index be3b696..8ad589a 100644
--- a/src/steamvr_patches/__init__.py
+++ b/src/steamvr_patches/__init__.py
@@ -6,13 +6,10 @@ import hashlib
import sys
import tempfile
import tomllib
-from base64 import b85encode
from importlib.resources import files
from io import BytesIO
-from json import dumps
from pathlib import Path
from typing import Annotated, BinaryIO, Self
-from zlib import compress
from pydantic import BaseModel, ConfigDict, Field, field_validator
@@ -95,9 +92,27 @@ def render(patches: dict[str, dict]) -> str:
placeholder = "PATCH_DATA = {}"
if template.count(placeholder) != 1:
raise ValueError("missing or duplicate runtime patch-table placeholder")
- data = dumps(patches, default=bytes.hex, separators=(",", ":")).encode()
- encoded = b85encode(compress(data, level=9))
- return template.replace(placeholder, f"PATCH_DATA = decode_patch_data({encoded!r})")
+ lines = ["PATCH_DATA = {"]
+ for path, patch in patches.items():
+ lines.append(f" {path!r}: {{")
+ for key in ("original_hash", "patched_hash"):
+ lines.append(f' "{key}": "{patch[key].hex()}",')
+ lines.append(' "edits": [')
+ for offset, replacement in patch["edits"]:
+ data = replacement.hex()
+ line = f' ({offset:#x}, "{data}"),'
+ if len(line) <= 88:
+ lines.append(line)
+ else:
+ lines.extend([" (", f" {offset:#x},"])
+ lines.extend(
+ f' "{data[start : start + 64]}"'
+ for start in range(0, len(data), 64)
+ )
+ lines.append(" ),")
+ lines.extend([" ],", " },"])
+ lines.append("}")
+ return template.replace(placeholder, "\n".join(lines))
def generate(patch_data: Path, input_root: Path) -> str: