Created
July 17, 2026 00:31
-
-
Save CalebWhiting/b271ca7dcdfc592f9eb2a31f3e3fc005 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """OSRS Official client auto-update launcher for rs3tk. | |
| Uses Jagex Direct6 CDN with piece-based download. | |
| """ | |
| import base64 | |
| import gzip | |
| import json | |
| import os | |
| import shutil | |
| import sys | |
| import urllib.request | |
| from pathlib import Path | |
| DIRECT6_URL = "https://jagex.akamaized.net/direct6/" | |
| META_PATH = "osrs-win" | |
| UA = "OSRS-client/1.0" | |
| def fetch(url: str) -> bytes: | |
| req = urllib.request.Request(url, headers={"User-Agent": UA}) | |
| with urllib.request.urlopen(req, timeout=30) as r: | |
| data: bytes = r.read() | |
| return data | |
| def fetch_jwt(url: str) -> dict[str, object]: | |
| raw = fetch(url).decode("ascii").strip() | |
| b64 = raw.split(".")[1] | |
| pad = 4 - len(b64) % 4 | |
| if pad != 4: | |
| b64 += "=" * pad | |
| result: dict[str, object] = json.loads(base64.urlsafe_b64decode(b64)) | |
| return result | |
| def download_client(target: Path, version_file: Path) -> None: | |
| meta = fetch_jwt(f"{DIRECT6_URL}{META_PATH}/{META_PATH}.json") | |
| prod = meta.get("environments", {}).get("production", {}) | |
| meta_id = prod.get("id", "") | |
| version = prod.get("version", "") | |
| if not meta_id: | |
| print("Could not determine latest version", file=sys.stderr) | |
| sys.exit(1) | |
| if target.exists() and version_file.exists() and version_file.read_text().strip() == version: | |
| print(f"OSRS {version} \u2014 up to date") | |
| return | |
| print(f"New version: {version}, downloading...") | |
| catalog = fetch_jwt(f"{DIRECT6_URL}{META_PATH}/catalog/{meta_id}/catalog.json") | |
| mf_url = catalog.get("metafile") or catalog.get("metaFile", "") | |
| if not mf_url.startswith("http"): | |
| mf_url = f"{DIRECT6_URL}{META_PATH}/{mf_url.lstrip('/')}" | |
| metafile = fetch_jwt(mf_url) | |
| exe = next((f for f in metafile.get("files", []) if f["name"].endswith(".exe")), None) | |
| if not exe: | |
| print("No executable found in metafile", file=sys.stderr) | |
| sys.exit(1) | |
| base = catalog.get("config", {}).get("remote", {}).get("baseUrl", "") | |
| fmt = catalog.get("config", {}).get("remote", {}).get("pieceFormat", "{TargetDigest}") | |
| pieces = metafile.get("pieces", metafile.get("chunks", {})) | |
| if isinstance(pieces, dict) and "digests" in pieces: | |
| digests = pieces["digests"] | |
| elif isinstance(pieces, list): | |
| digests = pieces | |
| else: | |
| digests = [] | |
| exe_off = sum(f.get("size", 0) for f in metafile.get("files", []) if not f["name"].endswith(".exe")) | |
| assembled = b"" | |
| for d in digests: | |
| ds = d.get("digest", "") if isinstance(d, dict) else str(d) | |
| if not ds or len(ds) < 2: | |
| continue | |
| try: | |
| hd = base64.b64decode(ds).hex() | |
| except Exception: | |
| hd = ds | |
| url = base + fmt.replace("{SubString:0,2,{TargetDigest}}", hd[:2]).replace("{TargetDigest}", hd) | |
| raw = fetch(url) | |
| try: | |
| assembled += gzip.decompress(raw[6:]) | |
| except Exception: | |
| assembled += raw | |
| exe_bytes = assembled[exe_off : exe_off + exe.get("size", 0)] if exe.get("size") else assembled | |
| tmp = target.with_suffix(".exe.tmp") | |
| tmp.write_bytes(exe_bytes) | |
| tmp.rename(target) | |
| target.chmod(0o755) | |
| version_file.write_text(version) | |
| print(f"OSRS {version} installed") | |
| def main() -> None: | |
| d = Path(__file__).resolve().parent | |
| exe = d / "osclient.exe" | |
| version_file = d / ".version" | |
| download_client(exe, version_file) | |
| wine = shutil.which("umu-run") or shutil.which("wine") | |
| if not wine: | |
| print("wine or umu-run not found in PATH", file=sys.stderr) | |
| sys.exit(1) | |
| env = os.environ.copy() | |
| env.setdefault("WINEPREFIX", str(d / "prefix")) | |
| env["GAMEID"] = "1343370" | |
| env["PROTONPATH"] = "GE-Latest" | |
| env["PROTON_VERB"] = "runinprefix" | |
| os.execve(wine, [wine, str(exe), *sys.argv[1:]], env) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment