diff --git a/crates/horizon-prepare/src/lib.rs b/crates/horizon-prepare/src/lib.rs index 6e6ce2e11..66ff671f9 100644 --- a/crates/horizon-prepare/src/lib.rs +++ b/crates/horizon-prepare/src/lib.rs @@ -17,7 +17,7 @@ pub mod pyjson; mod sounds; mod survival; -pub use sounds::{panorama, sounds}; +pub use sounds::{fonts, panorama, sounds}; use pyjson::Value; use sha2::Digest; @@ -684,10 +684,11 @@ fn steps( count += 1; } - // The JAR holds only gray 1x1 panorama placeholders. Import the indexed - // textures afterwards, including on reruns that just extracted the JAR again. - // Cosmetic assets are optional when preparing from already-imported JARs. - sounds::optional_panorama(repo, minecraft, run.log); + // The JAR holds only gray 1x1 panorama placeholders and an empty Unifont + // include. Import the indexed ones afterwards, including on reruns that just + // extracted the JAR again. They are optional when preparing from + // already-imported JARs. + sounds::optional_assets(repo, minecraft, run.log); // One file each, exported again when the exporter or the jar it reads changed. let single = |what: &str, diff --git a/crates/horizon-prepare/src/main.rs b/crates/horizon-prepare/src/main.rs index 4be86f525..0e8adc927 100644 --- a/crates/horizon-prepare/src/main.rs +++ b/crates/horizon-prepare/src/main.rs @@ -11,6 +11,7 @@ horizon-prepare: prepare Horizon's resources from your own Minecraft Java Editio Usage: horizon-prepare [--prepare] [--server-jar PATH] [--minecraft-dir PATH] [--root PATH] horizon-prepare sounds [--minecraft-dir PATH] [--root PATH] horizon-prepare panorama [--minecraft-dir PATH] [--root PATH] + horizon-prepare fonts [--minecraft-dir PATH] [--root PATH] --prepare Import the pinned game files from your own copy first --server-jar PATH The pinned server jar you downloaded yourself @@ -25,7 +26,8 @@ research-lock.json pins: JAVA_HOME, else javac and java on the PATH. The resources go to /.local/horizon-client/; pass that to horizon-client --resources. horizon-prepare panorama repairs the classic menu background in existing resources without Java. -Full preparation also imports these textures after extracting the client JAR's placeholders. +horizon-prepare fonts adds the GNU Unifont glyphs (characters the bitmap fonts lack) the same way. +Full preparation also imports both after extracting the client JAR's placeholders. horizon-prepare sounds copies the pinned version's sounds (about 380 MB) from the official launcher's asset store into the same folder, checking every file. It is optional: without it the @@ -56,7 +58,7 @@ fn main() -> ExitCode { }; let mut root = None; let mut args = std::env::args_os().skip(1).peekable(); - let assets = args.next_if(|a| a == "sounds" || a == "panorama"); + let assets = args.next_if(|a| a == "sounds" || a == "panorama" || a == "fonts"); while let Some(arg) = args.next() { let text = arg.to_string_lossy().into_owned(); let (flag, inline) = match text.split_once('=') { @@ -119,6 +121,9 @@ fn main() -> ExitCode { Some("panorama") => { horizon_prepare::panorama(&options.root, options.minecraft_dir.as_deref(), &log) } + Some("fonts") => { + horizon_prepare::fonts(&options.root, options.minecraft_dir.as_deref(), &log) + } _ => horizon_prepare::prepare(&options, &log), }; match result { diff --git a/crates/horizon-prepare/src/sounds.rs b/crates/horizon-prepare/src/sounds.rs index 313100ff4..fd9e18210 100644 --- a/crates/horizon-prepare/src/sounds.rs +++ b/crates/horizon-prepare/src/sounds.rs @@ -105,13 +105,25 @@ pub fn panorama(root: &Path, minecraft: Option<&Path>, log: Log) -> Result, log: Log) -> Result { + copy_assets(root, minecraft, log, is_font, "Font", &UNIFONT) +} + /// Full preparation can run from cached JARs without an official launcher install. -pub(crate) fn optional_panorama(root: &Path, minecraft: Option<&Path>, log: Log) { +pub(crate) fn optional_assets(root: &Path, minecraft: Option<&Path>, log: Log) { if let Err(error) = panorama(root, minecraft, log) { log(&format!( "Title panorama not imported: {error}; run horizon-prepare panorama later" )); } + if let Err(error) = fonts(root, minecraft, log) { + log(&format!( + "Unifont glyphs not imported: {error}; run horizon-prepare fonts later" + )); + } } const PANORAMA: [&str; 7] = [ @@ -128,6 +140,16 @@ fn is_panorama(name: &str) -> bool { PANORAMA.contains(&name) } +const UNIFONT: [&str; 2] = [ + "minecraft/font/include/unifont.json", + "minecraft/font/unifont.zip", +]; + +/// The fonts only the asset index holds (the JAR has the bitmap fonts). +fn is_font(name: &str) -> bool { + name.starts_with("minecraft/font/") +} + fn copy_assets( root: &Path, minecraft: Option<&Path>, @@ -206,6 +228,9 @@ mod tests { crate::hex(&sha1::Sha1::digest(data)) } + /// Where the fixture's panorama objects start. + const FIRST_FACE: usize = 6; + /// A Horizon folder and an official launcher directory holding version `9.9` with /// sounds, a language file and the full title panorama in its asset store. struct Fixture { @@ -233,6 +258,11 @@ mod tests { ("minecraft/sounds/ambient/cave1.ogg", b"OggS cave".to_vec()), ("minecraft/sounds/dig/stone1.ogg", b"OggS stone".to_vec()), ("minecraft/lang/fr_fr.json", b"{}".to_vec()), + ( + UNIFONT[0], + b"{\"providers\": [{\"type\": \"unihex\"}]}".to_vec(), + ), + (UNIFONT[1], b"PK unifont".to_vec()), ]; for &name in panorama { // Distinct object bytes let the test catch swapped faces too. @@ -392,7 +422,7 @@ mod tests { let target = f.root.join(".local/horizon-client/9.9"); for _ in 0..2 { // Full preparation extracts the JAR before importing the asset store. - for (name, _) in &f.objects[4..] { + for (name, _) in &f.objects[FIRST_FACE..] { let path = target.join("assets").join(name); fs::create_dir_all(path.parent().unwrap()).unwrap(); fs::write(path, b"1x1 gray placeholder").unwrap(); @@ -401,7 +431,7 @@ mod tests { panorama(&f.root, Some(&f.minecraft), &|_| {}).unwrap(), target ); - for (name, data) in &f.objects[4..] { + for (name, data) in &f.objects[FIRST_FACE..] { assert_eq!(&fs::read(target.join("assets").join(name)).unwrap(), data); } } @@ -412,18 +442,18 @@ mod tests { #[test] fn panorama_objects_are_verified_before_replacing_placeholders() { let f = Fixture::new("panorama-corrupt"); - fs::write(f.object(4), b"corrupt panorama").unwrap(); + fs::write(f.object(FIRST_FACE), b"corrupt panorama").unwrap(); let path = f .root .join(".local/horizon-client/9.9/assets") - .join(f.objects[4].0); + .join(f.objects[FIRST_FACE].0); fs::create_dir_all(path.parent().unwrap()).unwrap(); fs::write(&path, b"placeholder").unwrap(); assert!(panorama(&f.root, Some(&f.minecraft), &|_| {}) .unwrap_err() .starts_with("Corrupt asset object")); assert_eq!(fs::read(path).unwrap(), b"placeholder"); - fs::remove_file(f.object(4)).unwrap(); + fs::remove_file(f.object(FIRST_FACE)).unwrap(); assert!(panorama(&f.root, Some(&f.minecraft), &|_| {}) .unwrap_err() .starts_with("Missing asset object")); @@ -461,21 +491,51 @@ mod tests { let error = panorama(&f.root, Some(&f.minecraft), &|_| {}).unwrap_err(); let lines = std::cell::RefCell::new(Vec::new()); // This is the optional import step used by full preparation after extraction. - optional_panorama(&f.root, Some(&f.minecraft), &|line| { + optional_assets(&f.root, Some(&f.minecraft), &|line| { lines.borrow_mut().push(line.to_string()) }); + let lines = lines.into_inner(); assert_eq!( - *lines.borrow(), - [format!( - "Title panorama not imported: {error}; run horizon-prepare panorama later" - )] + lines[0], + format!("Title panorama not imported: {error}; run horizon-prepare panorama later") ); + // The fonts come on their own when only a panorama face is missing. + match missing { + "last-object" => assert_eq!(lines[1], "Font assets ready: 2 files, 0.0 MB"), + _ => assert!( + lines[1].starts_with("Unifont glyphs not imported: "), + "{lines:?}" + ), + } + assert_eq!(lines.len(), 2); for name in PANORAMA { assert_eq!(fs::read(target.join(name)).unwrap(), b"jar placeholder"); } } } + /// #1076: the JAR's `font/include/unifont.json` is empty; the asset index has the real + /// one and the glyph archives it names. + #[test] + fn fonts_replace_the_jar_include_and_add_unifont() { + let f = Fixture::new("fonts"); + let target = f.root.join(".local/horizon-client/9.9"); + let include = target.join("assets").join(UNIFONT[0]); + fs::create_dir_all(include.parent().unwrap()).unwrap(); + fs::write(&include, b"{\"providers\": []}").unwrap(); + let lines = std::cell::RefCell::new(Vec::new()); + let done = fonts(&f.root, Some(&f.minecraft), &|l| { + lines.borrow_mut().push(l.to_string()) + }); + assert_eq!(done.unwrap(), target); + for (name, data) in &f.objects[4..FIRST_FACE] { + assert_eq!(&fs::read(target.join("assets").join(name)).unwrap(), data); + } + assert_eq!(*lines.borrow(), ["Font assets ready: 2 files, 0.0 MB"]); + assert!(!target.join("assets/minecraft/sounds.json").exists()); + assert!(!target.join("assets/minecraft/textures").exists()); + } + #[test] fn the_index_must_hold_the_sounds() { let f = Fixture::new("index");