Merge remote-tracking branch 'origin/main' into fix/vanilla-camera-cracks-clouds

This commit is contained in:
Cosmic
2026-10-13 14:51:09 -04:00
6 changed files with 211 additions and 56 deletions
+87 -9
View File
@@ -8,6 +8,7 @@ from collections import Counter
import hashlib
import json
import os
import platform
from pathlib import Path, PurePosixPath
import re
import shutil
@@ -99,23 +100,37 @@ def import_copy(source, destination, checksum, algorithm="sha1", hint=""):
return destination
def manifest_accepted(lock, checksum):
"""Mojang republishes a version JSON for asset-index changes; every known one is accepted."""
game = lock["minecraft"]
return checksum == game["manifest_sha1"] or checksum in game.get("accepted_manifest_sha1", [])
def import_manifest(lock, directory, minecraft=None):
"""The pinned version JSON, from the launcher's versions/ directory."""
"""The pinned version JSON, from the launcher's versions/ directory.
The launcher's copy wins over the cached one so the manifest matches the asset index the
launcher installed alongside it."""
game = lock["minecraft"]
version = game["version"]
destination = directory / "manifest.json"
source = minecraft_dir(minecraft) / "versions" / version / f"{version}.json"
if not (destination.exists() and digest(destination, "sha1") == game["manifest_sha1"]):
if not source.is_file():
raise FileNotFoundError(f"Missing {source}. {LAUNCHER_HINT.format(version=version)}")
if source.is_file():
manifest = json.loads(source.read_text(encoding="utf-8"))
downloads = manifest.get("downloads", {})
if (manifest.get("id") != version
or downloads.get("client", {}).get("sha1") != game["client_sha1"]
or downloads.get("server", {}).get("sha1") != game["server_sha1"]):
raise ValueError(f"{source} does not describe the pinned {version} release")
destination.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(source, destination)
checksum = digest(source, "sha1")
if not manifest_accepted(lock, checksum):
raise ValueError(f"{source} is a {version} version file Horizon does not know yet (sha1 {checksum}); "
f"Mojang may have republished it. Update Horizon, or report it if this is the latest release.")
if not (destination.exists() and digest(destination, "sha1") == checksum):
destination.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(source, destination)
elif not (destination.exists() and manifest_accepted(lock, digest(destination, "sha1"))):
raise FileNotFoundError(f"Missing {source}. {LAUNCHER_HINT.format(version=version)}")
manifest = json.loads(destination.read_text(encoding="utf-8"))
if manifest["javaVersion"]["majorVersion"] != game["java_major"]:
raise ValueError("Manifest Java version does not match lock file")
@@ -146,6 +161,71 @@ def import_server(lock, directory, server_jar=None):
return import_copy(Path(source).expanduser(), destination, checksum, hint=hint)
def rule_system(system=None):
"""The launcher's os.name for this machine: linux, osx or windows."""
return system or {"Darwin": "osx", "Linux": "linux", "Windows": "windows"}[platform.system()]
ARCHITECTURE_ALIASES = [{"x86_64", "amd64", "x64"}, {"arm64", "aarch64"}]
def rule_architectures(architecture=None):
"""platform.machine() and its aliases: Windows reports AMD64/ARM64, Linux aarch64, macOS arm64."""
architecture = (architecture or platform.machine()).lower()
return next((names for names in ARCHITECTURE_ALIASES if architecture in names), {architecture})
def library_allowed(library, system=None, architecture=None):
"""The official launcher's rules: the last matching rule decides, no rules means allowed."""
system, architectures = rule_system(system), rule_architectures(architecture)
rules = library.get("rules", [])
allowed = not rules
for rule in rules:
operating_system = rule.get("os", {})
if operating_system.get("name", system) != system:
continue
if "arch" in operating_system and not any(re.fullmatch(operating_system["arch"], name)
for name in architectures):
continue
if "version" in operating_system and not re.search(operating_system["version"], platform.release()):
continue
if rule.get("features"):
continue
allowed = rule["action"] == "allow"
return allowed
ARM_CLASSIFIER = re.compile(r"(?:^|-)(?:arm64|aarch64|aarch_64)$")
X86_CLASSIFIER = re.compile(r"(?:^|-)(?:x86_64|x64)$")
def native_library_matches(library, architecture=None, names=None):
"""Modern manifests list x64 and ARM natives with OS-only rules; keep this machine's.
A plain natives-<os> jar is the x64 build when the manifest's library names also hold
an ARM variant of it (assumed when names is None), and the only build otherwise."""
arm = "arm64" in rule_architectures(architecture)
parts = library["name"].split(":")
classifier = parts[3] if len(parts) > 3 else ""
if ARM_CLASSIFIER.search(classifier):
return arm
if X86_CLASSIFIER.search(classifier):
return not arm
if arm and classifier.startswith("natives-"):
return names is not None and not any(f"{library['name']}-{suffix}" in names
for suffix in ("arm64", "aarch64"))
return True
def client_library_artifacts(manifest, system=None, architecture=None):
"""The client libraries the official launcher installs on this OS and architecture."""
names = {library["name"] for library in manifest["libraries"]}
return [library["downloads"]["artifact"] for library in manifest["libraries"]
if "artifact" in library.get("downloads", {})
and library_allowed(library, system, architecture)
and native_library_matches(library, architecture, names)]
def import_library(artifact, destination_root, minecraft=None):
"""One library jar from the launcher's libraries/ directory."""
relative = PurePosixPath(artifact["path"])
@@ -307,10 +387,8 @@ def prepare(minecraft=None, server_jar=None):
print(f"Imported client {manifest['id']} from {minecraft_dir(minecraft)}", flush=True)
jars = {"client": client, "server": import_server(lock, directory, server_jar)}
jars["server"], server_libraries = unpack_server(jars["server"], directory, manifest["id"])
client_artifacts = [library["downloads"]["artifact"] for library in manifest["libraries"]
if "artifact" in library.get("downloads", {})]
client_libraries = [import_library(artifact, directory / "libraries" / "client", minecraft)
for artifact in client_artifacts]
for artifact in client_library_artifacts(manifest)]
vf = lock["vineflower"]
download(vf["url"], LOCAL / "tools" / f"vineflower-{vf['version']}.jar", vf["sha256"], "sha256")
for side, jar in jars.items():
+3 -37
View File
@@ -21,6 +21,8 @@ except ImportError:
import lab
ROOT = lab.ROOT
library_allowed = lab.library_allowed
native_library_matches = lab.native_library_matches
def install_original_mod(source, mod_dir, filename=None):
@@ -74,25 +76,6 @@ def fabric_libraries():
return jars
def library_allowed(library, system=None, architecture=None):
system = system or {"Darwin": "osx", "Linux": "linux", "Windows": "windows"}[platform.system()]
architecture = (architecture or platform.machine()).lower()
rules = library.get("rules", [])
allowed = not rules
for rule in rules:
operating_system = rule.get("os", {})
if operating_system.get("name", system) != system:
continue
if "arch" in operating_system and not re.fullmatch(operating_system["arch"], architecture):
continue
if "version" in operating_system and not re.search(operating_system["version"], platform.release()):
continue
if rule.get("features"):
continue
allowed = rule["action"] == "allow"
return allowed
def conditional_client_jvm_options(manifest, system=None, architecture=None):
"""Use official OS/architecture flags alongside our managed JVM/classpath options."""
options = []
@@ -107,18 +90,6 @@ def conditional_client_jvm_options(manifest, system=None, architecture=None):
return options
def native_library_matches(library, architecture=None):
"""Modern manifests list both x64 and ARM natives with OS-only rules."""
architecture = (architecture or platform.machine()).lower()
name = library["name"]
if ":natives-" not in name:
return True
arm = architecture in {"arm64", "aarch64"}
if "-arm64" in name or "-aarch64" in name:
return arm
return not arm
def prepare_client(assets=True):
"""Classpath and natives from the user's own launcher install; nothing of the game is downloaded."""
lock, directory = lab.config()
@@ -126,12 +97,7 @@ def prepare_client(assets=True):
jars = [client]
natives = CACHE / "natives"
natives.mkdir(parents=True, exist_ok=True)
for library in manifest["libraries"]:
if not library_allowed(library) or not native_library_matches(library):
continue
artifact = library.get("downloads", {}).get("artifact")
if not artifact:
continue
for artifact in lab.client_library_artifacts(manifest):
jar = lab.import_library(artifact, directory / "libraries/client")
jars.append(jar)
with zipfile.ZipFile(jar) as archive:
+6 -8
View File
@@ -59,14 +59,12 @@ def client_libraries():
_, directory=lab.config()
manifest=json.loads((directory/'manifest.json').read_text())
libraries=[]
for library in manifest['libraries']:
artifact=library.get('downloads',{}).get('artifact')
if artifact:
relative=Path(artifact['path'])
if relative.is_absolute() or '..' in relative.parts: raise ValueError('Unsafe client library path')
path=directory/'libraries/client'/relative
if lab.digest(path,'sha1')!=artifact['sha1']: raise ValueError('Client dependency checksum changed: '+str(relative))
libraries.append(path)
for artifact in lab.client_library_artifacts(manifest):
relative=Path(artifact['path'])
if relative.is_absolute() or '..' in relative.parts: raise ValueError('Unsafe client library path')
path=directory/'libraries/client'/relative
if lab.digest(path,'sha1')!=artifact['sha1']: raise ValueError('Client dependency checksum changed: '+str(relative))
libraries.append(path)
return libraries
+1 -1
View File
@@ -74,7 +74,7 @@ def verify_artifacts():
"""Authenticate against the lock and the bundled checksums, not generated reports."""
lock, directory = lab.config()
manifest_path = directory / "manifest.json"
if lab.digest(manifest_path, "sha1") != lock["minecraft"]["manifest_sha1"]:
if not lab.manifest_accepted(lock, lab.digest(manifest_path, "sha1")):
raise ValueError("Manifest checksum changed; run tools/lab.py prepare")
manifest = json.loads(manifest_path.read_text())
if manifest["id"] != lock["minecraft"]["version"]: