diff --git a/.gitattributes b/.gitattributes index 13584e4d9..358aeae7a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,3 +3,4 @@ docs/launcher-commands.md text eol=lf docs/horizon-ctl-commands.md text eol=lf website/src/tokens.css text eol=lf +docs/api/*-reference.md text eol=lf diff --git a/.githooks/pre-push b/.githooks/pre-push index a886ccf0c..d067dd226 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -1,2 +1,2 @@ #!/bin/sh -exec python3 tools/check_public_tree.py --history +exec python3 tools/check_public_tree.py --pre-push diff --git a/.github/workflows/mod-registry.yml b/.github/workflows/mod-registry.yml new file mode 100644 index 000000000..0f252bb68 --- /dev/null +++ b/.github/workflows/mod-registry.yml @@ -0,0 +1,34 @@ +name: mod-registry +# The submission service is its own workspace (crates/horizon-mod-registry), so the checks job doesn't build +# it: this one does, when it or horizon-mods (the checks it shares with the launcher and the game) changes. +on: + push: + branches: [main] + paths: + - 'crates/horizon-mods/**' + - 'crates/horizon-mod-registry/**' + - '.github/workflows/mod-registry.yml' + pull_request: + paths: + - 'crates/horizon-mods/**' + - 'crates/horizon-mod-registry/**' + - '.github/workflows/mod-registry.yml' +permissions: + contents: read +jobs: + check: + runs-on: ubuntu-latest + timeout-minutes: 20 + defaults: + run: + working-directory: crates/horizon-mod-registry + steps: + - uses: actions/checkout@v4 + - run: rustup toolchain install stable --profile minimal --component rustfmt --component clippy + - uses: Swatinem/rust-cache@v2 + with: + workspaces: crates/horizon-mod-registry + save-if: ${{ github.ref == 'refs/heads/main' }} + - run: cargo +stable fmt --check + - run: cargo +stable clippy --all-targets --locked -- -D warnings + - run: cargo +stable test --locked diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6b0fb2e0f..4cba851fa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -367,10 +367,15 @@ jobs: TAG: ${{ needs.decide.outputs.tag }} run: | signature=(); [[ -f dist/SHA256SUMS.sig ]] && signature=(dist/SHA256SUMS.sig) - # The release and the latest at once: there is one channel (docs/release-flow.md). + # The release and the latest at once: there is one channel (docs/release-flow.md). Each archive gets a + # label (file#label), which GitHub's page shows instead of the file name, so nobody takes the game's + # files for the download (#1647). Launchers, servers and install.sh match the name, which stays. gh release create "$TAG" --target "${{ needs.decide.outputs.head }}" --title "$(cat notes/title.txt)" \ - --notes-file notes/body.md --latest dist/horizon-linux-x86_64.tar.gz \ - dist/horizon-windows-x64.zip dist/horizon-macos-arm64.zip dist/horizon-server-linux-x86_64.tar.gz \ + --notes-file notes/body.md --latest \ + "dist/horizon-linux-x86_64.tar.gz#Game files the launcher installs: Linux (horizon-linux-x86_64.tar.gz)" \ + "dist/horizon-windows-x64.zip#Game files the launcher installs: Windows (horizon-windows-x64.zip)" \ + "dist/horizon-macos-arm64.zip#Game files the launcher installs: macOS (horizon-macos-arm64.zip)" \ + "dist/horizon-server-linux-x86_64.tar.gz#Dedicated server for Linux (horizon-server-linux-x86_64.tar.gz)" \ dist/SHA256SUMS "${signature[@]}" dist/smoke-test.json - name: Dry run, the release that would be published if: needs.decide.outputs.dry_run == 'true' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index af44d89f8..e6e959186 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,6 +39,17 @@ probe against Horizon, and compares their outputs. There are about 290 of them. Never commit game files, decompiled source or prepared resources (`.local/`): `tools/check_public_tree.py` rejects them (`git config core.hooksPath .githooks` runs it before every commit). +The pre-push hook checks the full history reachable from the branches and tags being pushed. Run +`python3 tools/check_public_tree.py --history` to audit the history of all local refs. + +## Only original code + +Horizon's code is written from Minecraft 26.3 itself and from public documentation, never from another mod, loader +or renderer. Don't read, copy, translate or paraphrase the source of Iris, OptiFine, Sodium or any other project, +and don't send code an AI tool wrote from it. Their user documentation and file formats are fine to read, and their +packs and mods are fine to run and observe. Shader packs were removed on 24 October 2026 (#1561) because their code +had been written from another project's source; they come back only as a clean-room rewrite from a written +description of the pack format. ## Before asking for review diff --git a/Cargo.lock b/Cargo.lock index 46aa212a1..2d09d2d0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -155,7 +155,7 @@ dependencies = [ "objc2-foundation 0.3.2", "parking_lot", "percent-encoding", - "windows-sys 0.59.0", + "windows-sys 0.60.2", "wl-clipboard-rs", "x11rb", ] @@ -1281,6 +1281,7 @@ dependencies = [ "rustix 1.1.5", "serde", "serde_json", + "sha1", "sha2", "symphonia", "ureq", @@ -1317,7 +1318,7 @@ dependencies = [ "serde", "serde_json", "sha2", - "socket2", + "socket2 0.5.10", "spake2", ] @@ -1333,8 +1334,10 @@ name = "horizon-mods" version = "0.1.0" dependencies = [ "log", + "minisign-verify", "serde", "serde_json", + "sha2", "toml", "wasmtime", "wit-component 0.239.0", @@ -1380,6 +1383,7 @@ dependencies = [ "getrandom 0.3.4", "horizon-core", "horizon-world", + "ipconfig", "serde_json", "sha1", "sha2", @@ -1665,6 +1669,19 @@ dependencies = [ "generic-array", ] +[[package]] +name = "ipconfig" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d40460c0ce33d6ce4b0630ad68ff63d6661961c48b6dba35e5a4d81cfb48222" +dependencies = [ + "socket2 0.6.5", + "widestring", + "windows-registry", + "windows-result 0.4.1", + "windows-sys 0.61.2", +] + [[package]] name = "itertools" version = "0.14.0" @@ -1909,6 +1926,12 @@ dependencies = [ "libc", ] +[[package]] +name = "minisign-verify" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "871285dc19d8d0ebe0eef3d0e99a205f2a71363b122632cbbfa4a6c370a960ce" + [[package]] name = "miniz_oxide" version = "0.8.9" @@ -3159,6 +3182,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + [[package]] name = "spake2" version = "0.4.0" @@ -4316,6 +4349,12 @@ dependencies = [ "web-sys", ] +[[package]] +name = "widestring" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72069c3113ab32ab29e5584db3c6ec55d416895e60715417b5b883a357c3e471" + [[package]] name = "winapi-util" version = "0.1.11" @@ -4448,6 +4487,17 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" +dependencies = [ + "windows-link", + "windows-result 0.4.1", + "windows-strings", +] + [[package]] name = "windows-result" version = "0.1.2" diff --git a/Cargo.toml b/Cargo.toml index b8e6b044e..c6f2bc581 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -exclude = ["launcher", "crates/horizon-telemetry-server", "third_party/wgpu-hal"] +exclude = ["launcher", "crates/horizon-telemetry-server", "crates/horizon-mod-registry", "third_party/wgpu-hal"] members = ["crates/horizon-core", "crates/horizon-dualsense", "crates/horizon-threads", "crates/horizon-world", "crates/horizon-client", "crates/horizon-server-files", "crates/horizon-server", "crates/horizon-bots", "crates/horizon-assets", "crates/horizon-protocol", "crates/horizon-theme", "crates/horizon-prepare", "crates/horizon-telemetry", "crates/horizon-bench", "crates/horizon-friends", "crates/horizon-relay", "crates/horizon-mod-sdk", "crates/horizon-mods", "crates/horizon-mods/tests/guest", "crates/cargo-horizon-mod", "crates/horizon-port-pack", "crates/horizon-shaders", "crates/horizon-release-sign", "crates/horizon-mod-sdk/examples/coords-hud", "xtask"] resolver = "2" diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 88d3197af..63a1f7da3 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -1,35 +1,5 @@ # Third-party notices -## CullLeaves - -The optional leaf and mangrove-root face-culling behavior is adapted from -[CullLeaves](https://github.com/TeamMidnightDust/CullLeaves) by MidnightDust. -Its MIT license is reproduced below. - -```text -MIT License - -Copyright (c) 2020 MidnightDust - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -``` - ## wgpu-hal `third_party/wgpu-hal` is [wgpu-hal](https://github.com/gfx-rs/wgpu) 30.0.1 by the gfx-rs diff --git a/crates/cargo-horizon-mod/Cargo.toml b/crates/cargo-horizon-mod/Cargo.toml index 6d0a231ec..34eefe227 100644 --- a/crates/cargo-horizon-mod/Cargo.toml +++ b/crates/cargo-horizon-mod/Cargo.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition.workspace = true license.workspace = true rust-version = "1.86" -description = "cargo horizon-mod new/build/run: make Horizon mods in Rust (docs/mods.md)" +description = "cargo horizon-mod new/build/run/check: make Horizon mods in Rust (docs/mods.md)" [dependencies] -horizon-mods = { path = "../horizon-mods", default-features = false, features = ["pack"] } +horizon-mods = { path = "../horizon-mods", default-features = false, features = ["pack", "runtime", "index"] } serde_json = "1.0.151" [lints] diff --git a/crates/cargo-horizon-mod/src/check.rs b/crates/cargo-horizon-mod/src/check.rs new file mode 100644 index 000000000..0294bec98 --- /dev/null +++ b/crates/cargo-horizon-mod/src/check.rs @@ -0,0 +1,268 @@ +//! `cargo horizon-mod check `: what the registry checks of a submission, +//! run anywhere: its kind's own checks (docs/api/mod-index.md), its signature +//! when given a key, and for a mod a trial run in the sandbox: it must start, +//! survive ticks, frames, a chat line and each of its commands, and import +//! no more than its capabilities. +use horizon_mods::{ + Clock, Mods, Output, Package, Player, Snapshot, Status, + index::{self, Facts, Kind}, + manifest::component_imports, +}; +use serde_json::{Value, json}; +use std::path::Path; + +/// How long the trial run plays: two seconds of game. +const TICKS: u64 = 40; +const FRAMES_PER_TICK: u64 = 3; + +pub struct Report { + pub kind: Kind, + pub facts: Facts, + pub sha256: String, + pub size: u64, + pub signed: bool, + /// A mod's component imports. + pub imports: Vec, + /// A mod's commands, each run once. + pub commands: Vec, + /// What the mod showed during the trial run. + pub output: Vec, +} + +impl Report { + pub fn json(&self) -> Value { + let requires: Vec = self + .facts + .requires + .iter() + .map(|r| json!({"id": r.id, "version": r.version, "sha256": r.sha256})) + .collect(); + json!({ + "kind": self.kind.name(), + "id": self.facts.id, + "version": self.facts.version, + "api": self.facts.api, + "side": self.facts.side, + "capabilities": self.facts.capabilities, + "game": self.facts.game, + "requires": requires, + "sha256": self.sha256, + "size": self.size, + "signed": self.signed, + "imports": self.imports, + "commands": self.commands, + "output": self.output, + }) + } + + pub fn text(&self) -> String { + let f = &self.facts; + let mut out = format!( + "{} {} ({}", + f.id.as_deref().unwrap_or("resource pack"), + f.version.as_deref().unwrap_or(""), + self.kind.name() + ); + if let Some(side) = f.side { + let side = serde_json::to_value(side).unwrap_or_default(); + out += &format!(", API {}, {}", f.api, side.as_str().unwrap_or("?")); + } else if !f.api.is_empty() { + out += &format!(", format {}", f.api); + } + if let Some(game) = &f.game { + out += &format!(", for {game}"); + } + let signed = if self.signed { + "signature verified" + } else { + "unsigned" + }; + out += &format!( + ")\n {} bytes, SHA-256 {}, {signed}\n", + self.size, self.sha256 + ); + for c in &f.capabilities { + out += &format!(" may {}\n", c.describe()); + } + for r in &f.requires { + out += &format!(" needs {} {} ({})\n", r.id, r.version, &r.sha256[..12]); + } + if self.kind == Kind::Mod { + let commands = if self.commands.is_empty() { + String::new() + } else { + format!(", /{}", self.commands.join(", /")) + }; + out += &format!( + " trial run: started, {TICKS} ticks, {} frames, a chat line{commands}: ok\n", + TICKS * FRAMES_PER_TICK + ); + } + out + } +} + +/// The kind a file's extension says. +pub fn kind_of(path: &Path) -> Option { + match path.extension()?.to_str()? { + "hmod" => Some(Kind::Mod), + "hpack" => Some(Kind::Modpack), + "zip" => Some(Kind::ResourcePack), + _ => None, + } +} + +/// Checks the file at `path` as `kind`; `key` and `signature` (the +/// `.minisig` text) check its signature. +pub fn check( + path: &Path, + kind: Kind, + key: Option<&str>, + signature: Option<&str>, +) -> Result { + let size = std::fs::metadata(path) + .map_err(|e| format!("{}: {e}", path.display()))? + .len(); + if size > index::MAX_FILE { + return Err(format!("over {} MiB", index::MAX_FILE >> 20)); + } + index::open(&kind)?; + let facts = index::inspect(&kind, path)?; + let signed = match (key, signature) { + (Some(key), Some(sig)) => { + index::verify_signature(key, sig, path)?; + true + } + (None, None) => false, + _ => return Err("--key and --signature go together".into()), + }; + let mut report = Report { + kind, + facts, + sha256: index::sha256_file(path)?, + size, + signed, + imports: Vec::new(), + commands: Vec::new(), + output: Vec::new(), + }; + if report.kind == Kind::Mod { + trial_run(path, &mut report)?; + } + Ok(report) +} + +/// Runs a mod in the sandbox, as the game does, from a scratch copy so its +/// storage lands in a folder removed afterwards. +fn trial_run(path: &Path, report: &mut Report) -> Result<(), String> { + let package = Package::read(path)?; + let wasm = package.wasm.as_deref().ok_or("the .hmod has no mod.wasm")?; + report.imports = component_imports(wasm)?; + package + .manifest + .check_imports(report.imports.iter().map(String::as_str))?; + let dir = std::env::temp_dir().join(format!("horizon-mod-check-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).map_err(|e| e.to_string())?; + let copy = dir.join("mod.hmod"); + let result = std::fs::copy(path, ©) + .map_err(|e| e.to_string()) + .and_then(|_| play(©, report)); + let _ = std::fs::remove_dir_all(&dir); + result +} + +fn play(path: &Path, report: &mut Report) -> Result<(), String> { + let mut mods = Mods::load(&[path.to_path_buf()], |_| true, |_| false); + let failed = |mods: &Mods| match &mods.entries()[0].status { + Status::Failed(reason) => Some(reason.clone()), + _ => None, + }; + if let Some(reason) = failed(&mods) { + return Err(format!("it didn't start: {reason}")); + } + report.commands = mods.commands().map(str::to_owned).collect(); + for t in 0..TICKS { + mods.set_snapshot(Snapshot { + player: Some(Player { + x: 0.5 + t as f64 * 0.1, + y: 64.0, + z: 0.5, + yaw: 90.0, + pitch: 0.0, + health: 20.0, + food: 20, + dimension: "minecraft:overworld".into(), + }), + clock: Some(Clock { + game_time: t, + day_time: 1000 + t, + }), + }); + mods.tick(t); + for _ in 0..FRAMES_PER_TICK { + mods.frame(1.0 / 60.0); + } + } + mods.chat(" hello"); + for name in report.commands.clone() { + mods.command(&name); + } + for out in mods.drain() { + report.output.push(match out { + Output::Chat { text, .. } => format!("chat: {text}"), + Output::Feedback { text, error } => { + format!("{}: {text}", if error { "error" } else { "feedback" }) + } + Output::Stopped { reason, .. } => return Err(format!("it stopped: {reason}")), + }); + } + match failed(&mods) { + Some(reason) => Err(format!("it stopped: {reason}")), + None => Ok(()), + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn fixture(name: &str) -> std::path::PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../horizon-mods/tests/index") + .join(name) + } + + #[test] + fn checks_each_kind_its_own_way() { + let pack = fixture("cozy-1.0.0.hpack"); + let report = check(&pack, kind_of(&pack).unwrap(), None, None).unwrap(); + assert_eq!(report.facts.requires[0].id, "coords_hud"); + assert!( + report + .text() + .contains("cozy 1.0.0 (modpack, format 1, for 26.3)") + ); + // The fixture mod's code is a stand-in: its manifest reads, its run fails. + let hmod = fixture("coords_hud-0.1.0.hmod"); + let key = std::fs::read_to_string(fixture("test.pub")).unwrap(); + let sig = std::fs::read_to_string(fixture("coords_hud-0.1.0.hmod.minisig")).unwrap(); + let key = key.lines().last().unwrap(); + let e = check(&hmod, Kind::Mod, Some(key), Some(&sig)) + .err() + .unwrap(); + assert!(e.contains("didn't start"), "{e}"); + let e = check( + &hmod, + Kind::Mod, + Some(key), + Some("untrusted comment: x\nRUQ=\n"), + ) + .err() + .unwrap(); + assert!(e.contains("signature"), "{e}"); + let e = check(&pack, Kind::Shader, None, None).err().unwrap(); + assert!(e.contains("shader packs open"), "{e}"); + assert!(check(&pack, Kind::Mod, None, None).is_err()); + } +} diff --git a/crates/cargo-horizon-mod/src/main.rs b/crates/cargo-horizon-mod/src/main.rs index 6b088d278..925633930 100644 --- a/crates/cargo-horizon-mod/src/main.rs +++ b/crates/cargo-horizon-mod/src/main.rs @@ -4,10 +4,16 @@ //! - `build [--debug]`: the `.hmod` in `target/horizon-mod/`. //! - `run [--game ] [-- ]`: build, then play with //! the mod; run `build` again and the game reloads it. +//! - `check [--json]`: what the registry checks of a submission +//! (`.hmod`, `.hpack`, resource pack `.zip`), with a trial run for a mod. +//! - `registry build|review|check|list`: the registry repository's CI. use horizon_mods::{ Manifest, Package, manifest::{MANIFEST, component_imports, componentize}, }; +mod check; +mod registry; + use std::{ path::{Path, PathBuf}, process::{Command, ExitCode, Stdio}, @@ -28,7 +34,9 @@ fn main() -> ExitCode { println!("Built {}", p.display()); }), Some("run") => run(&args[1..]), - _ => Err("usage: cargo horizon-mod new | build [--debug] | run [--game ] [-- ]".into()), + Some("check") => check(&args[1..]), + Some("registry") => registry::main(&args[1..]), + _ => Err("usage: cargo horizon-mod new | build [--debug] | run [--game ] [-- ] | check [--kind ] [--key --signature ] [--json] | registry build|review|check|list".into()), }; match result { Ok(()) => ExitCode::SUCCESS, @@ -150,6 +158,37 @@ fn build(release: bool) -> Result { Ok(path) } +/// `check `: the registry's checks of a submission, printed; fails +/// when one does. +fn check(args: &[String]) -> Result<(), String> { + let file = args + .first() + .filter(|a| !a.starts_with("--")) + .ok_or("cargo horizon-mod check ")?; + let path = Path::new(file); + let kind = match flag(args, "--kind") { + Some(k) => horizon_mods::index::Kind::from(k.to_string()), + None => check::kind_of(path) + .ok_or("pass --kind mod|modpack|resourcepack: the extension doesn't say")?, + }; + let signature = flag(args, "--signature") + .map(|p| std::fs::read_to_string(p).map_err(|e| format!("{p}: {e}"))) + .transpose()?; + let report = check::check(path, kind, flag(args, "--key"), signature.as_deref()); + if args.iter().any(|a| a == "--json") { + let json = match &report { + Ok(r) => serde_json::json!({"ok": true, "report": r.json()}), + Err(e) => serde_json::json!({"ok": false, "error": e}), + }; + println!("{json}"); + } + let report = report?; + if !args.iter().any(|a| a == "--json") { + print!("{}", report.text()); + } + Ok(()) +} + fn run(args: &[String]) -> Result<(), String> { let path = build(true)?; let game = flag(args, "--game") diff --git a/crates/cargo-horizon-mod/src/registry.rs b/crates/cargo-horizon-mod/src/registry.rs new file mode 100644 index 000000000..ac5e77ea4 --- /dev/null +++ b/crates/cargo-horizon-mod/src/registry.rs @@ -0,0 +1,159 @@ +//! `cargo horizon-mod registry build|review|check|list`: the registry repository's CI +//! (`ludovic111/horizon-mods`, docs/api/mod-index.md). Network-free: the +//! workflow downloads the files and publishes what this writes. +use horizon_mods::index::{ + FILE_HOST, + registry::{self, Sources}, +}; +use std::path::Path; + +/// Where the registry's site is published (its icons). +const SITE: &str = "https://ludovic111.github.io/horizon-mods/"; + +const USAGE: &str = "usage: cargo horizon-mod registry build --files --out [--release ] [--site ] [--generated