Merge pull request #162 from rdbtCVS/t3code/fix-classic-ui-background
Fix missing background in Classic menus
This commit is contained in:
@@ -17,7 +17,7 @@ pub mod pyjson;
|
||||
mod sounds;
|
||||
mod survival;
|
||||
|
||||
pub use sounds::sounds;
|
||||
pub use sounds::{panorama, sounds};
|
||||
|
||||
use pyjson::Value;
|
||||
use sha2::Digest;
|
||||
@@ -452,7 +452,7 @@ pub fn prepare(options: &Options, log: Log) -> Result<PathBuf, String> {
|
||||
origin,
|
||||
log,
|
||||
};
|
||||
steps(&run, &lock, &oracle)?;
|
||||
steps(&run, &lock, &oracle, options.minecraft_dir.as_deref())?;
|
||||
log(&format!(
|
||||
"Prepared Horizon native-client resources: {}",
|
||||
resources.display()
|
||||
@@ -464,7 +464,12 @@ fn arg(path: &Path) -> String {
|
||||
path.display().to_string()
|
||||
}
|
||||
|
||||
fn steps(run: &Run, lock: &artifacts::Lock, oracle: &Path) -> Result<(), String> {
|
||||
fn steps(
|
||||
run: &Run,
|
||||
lock: &artifacts::Lock,
|
||||
oracle: &Path,
|
||||
minecraft: Option<&Path>,
|
||||
) -> Result<(), String> {
|
||||
let root = &run.resources;
|
||||
let repo = &run.root;
|
||||
let server_cp = run.server_classpath.as_str();
|
||||
@@ -678,6 +683,11 @@ fn steps(run: &Run, lock: &artifacts::Lock, oracle: &Path) -> Result<(), String>
|
||||
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);
|
||||
|
||||
// One file each, exported again when the exporter or the jar it reads changed.
|
||||
let single = |what: &str,
|
||||
file: &str,
|
||||
|
||||
@@ -10,6 +10,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]
|
||||
|
||||
--prepare Import the pinned game files from your own copy first
|
||||
--server-jar PATH The pinned server jar you downloaded yourself
|
||||
@@ -23,6 +24,9 @@ Needs Minecraft played once from the official launcher, and Java (a JDK) of the
|
||||
research-lock.json pins: JAVA_HOME, else javac and java on the PATH.
|
||||
The resources go to <root>/.local/horizon-client/<version>; 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 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
|
||||
game is silent. Nothing is downloaded; it needs the version played once from the official launcher.
|
||||
@@ -52,7 +56,7 @@ fn main() -> ExitCode {
|
||||
};
|
||||
let mut root = None;
|
||||
let mut args = std::env::args_os().skip(1).peekable();
|
||||
let sounds = args.next_if(|a| a == "sounds").is_some();
|
||||
let assets = args.next_if(|a| a == "sounds" || a == "panorama");
|
||||
while let Some(arg) = args.next() {
|
||||
let text = arg.to_string_lossy().into_owned();
|
||||
let (flag, inline) = match text.split_once('=') {
|
||||
@@ -71,8 +75,8 @@ fn main() -> ExitCode {
|
||||
}
|
||||
};
|
||||
let parsed = match flag.as_str() {
|
||||
"--prepare" | "--server-jar" if sounds => {
|
||||
Err(format!("{flag} is for preparing, not for sounds"))
|
||||
"--prepare" | "--server-jar" if assets.is_some() => {
|
||||
Err(format!("{flag} is for preparing, not for asset copying"))
|
||||
}
|
||||
"--prepare" if inline.is_none() => {
|
||||
options.import = true;
|
||||
@@ -108,10 +112,14 @@ fn main() -> ExitCode {
|
||||
let _ = writeln!(out, "{line}");
|
||||
let _ = out.flush();
|
||||
};
|
||||
let result = if sounds {
|
||||
horizon_prepare::sounds(&options.root, options.minecraft_dir.as_deref(), &log)
|
||||
} else {
|
||||
horizon_prepare::prepare(&options, &log)
|
||||
let result = match assets.as_deref().and_then(|a| a.to_str()) {
|
||||
Some("sounds") => {
|
||||
horizon_prepare::sounds(&options.root, options.minecraft_dir.as_deref(), &log)
|
||||
}
|
||||
Some("panorama") => {
|
||||
horizon_prepare::panorama(&options.root, options.minecraft_dir.as_deref(), &log)
|
||||
}
|
||||
_ => horizon_prepare::prepare(&options, &log),
|
||||
};
|
||||
match result {
|
||||
Ok(_) => ExitCode::SUCCESS,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! The pinned version's sounds (sounds.json and the .ogg files) from the player's own official
|
||||
//! The pinned version's sounds and title panorama from the player's own official
|
||||
//! launcher install, each object checked against the asset index's SHA-1, copied into
|
||||
//! `.local/horizon-client/<version>/assets` where the game reads them (tools/fetch_sounds.py and
|
||||
//! the tools/lab.py functions it called). Nothing is downloaded.
|
||||
@@ -76,6 +76,46 @@ fn is_sound(name: &str) -> bool {
|
||||
/// `.local/horizon-client/<version>`; returns that folder. Files already there with the right
|
||||
/// SHA-1 are kept.
|
||||
pub fn sounds(root: &Path, minecraft: Option<&Path>, log: Log) -> Result<PathBuf, String> {
|
||||
copy_assets(root, minecraft, log, is_sound, "Sound", &[])
|
||||
}
|
||||
|
||||
/// Replaces the client JAR's 1x1 title placeholders with the full panorama from the
|
||||
/// launcher's asset store. Also usable on already-prepared resources without Java.
|
||||
pub fn panorama(root: &Path, minecraft: Option<&Path>, log: Log) -> Result<PathBuf, String> {
|
||||
copy_assets(root, minecraft, log, is_panorama, "Panorama", &PANORAMA)
|
||||
}
|
||||
|
||||
/// Full preparation can run from cached JARs without an official launcher install.
|
||||
pub(crate) fn optional_panorama(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"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
const PANORAMA: [&str; 7] = [
|
||||
"minecraft/textures/gui/title/background/panorama_0.png",
|
||||
"minecraft/textures/gui/title/background/panorama_1.png",
|
||||
"minecraft/textures/gui/title/background/panorama_2.png",
|
||||
"minecraft/textures/gui/title/background/panorama_3.png",
|
||||
"minecraft/textures/gui/title/background/panorama_4.png",
|
||||
"minecraft/textures/gui/title/background/panorama_5.png",
|
||||
"minecraft/textures/gui/title/background/panorama_overlay.png",
|
||||
];
|
||||
|
||||
fn is_panorama(name: &str) -> bool {
|
||||
PANORAMA.contains(&name)
|
||||
}
|
||||
|
||||
fn copy_assets(
|
||||
root: &Path,
|
||||
minecraft: Option<&Path>,
|
||||
log: Log,
|
||||
wanted_asset: fn(&str) -> bool,
|
||||
label: &str,
|
||||
required: &[&str],
|
||||
) -> Result<PathBuf, String> {
|
||||
let lock = Lock::read(root)?;
|
||||
let minecraft = artifacts::minecraft_dir(minecraft);
|
||||
let manifest = artifacts::import_manifest(&lock, &minecraft)?;
|
||||
@@ -95,13 +135,19 @@ pub fn sounds(root: &Path, minecraft: Option<&Path>, log: Log) -> Result<PathBuf
|
||||
.ok_or_else(|| format!("{} has no objects", index.display()))?;
|
||||
// A repeated name keeps its first place and its last value, as a Python dict does.
|
||||
let mut wanted: Vec<(&str, &Value)> = Vec::new();
|
||||
for (name, info) in objects.iter().filter(|(name, _)| is_sound(name)) {
|
||||
for (name, info) in objects.iter().filter(|(name, _)| wanted_asset(name)) {
|
||||
match wanted.iter_mut().find(|(n, _)| n == name) {
|
||||
Some(entry) => entry.1 = info,
|
||||
None => wanted.push((name, info)),
|
||||
}
|
||||
}
|
||||
for name in required {
|
||||
if !wanted.iter().any(|(n, _)| n == name) {
|
||||
return Err(format!("{name} is missing from the asset index"));
|
||||
}
|
||||
}
|
||||
let mut total: u64 = 0;
|
||||
let mut copies = Vec::with_capacity(wanted.len());
|
||||
for (name, info) in &wanted {
|
||||
let hash = info
|
||||
.get("hash")
|
||||
@@ -115,17 +161,16 @@ pub fn sounds(root: &Path, minecraft: Option<&Path>, log: Log) -> Result<PathBuf
|
||||
let relative = artifacts::safe_relative(name)
|
||||
.ok_or_else(|| format!("Unsafe asset name {name:?} in the asset index"))?;
|
||||
let source = launcher_object(&store, hash)?;
|
||||
artifacts::import_copy(
|
||||
&source,
|
||||
&target.join("assets").join(relative),
|
||||
hash,
|
||||
"sha1",
|
||||
"",
|
||||
)?;
|
||||
copies.push((source, target.join("assets").join(relative), hash));
|
||||
total += size;
|
||||
}
|
||||
// Check the entire set before replacing any placeholders: a missing late face
|
||||
// must not leave a mixture of real textures and gray faces in either entry point.
|
||||
for (source, destination, hash) in copies {
|
||||
artifacts::import_copy(&source, &destination, hash, "sha1", "")?;
|
||||
}
|
||||
log(&format!(
|
||||
"Sound assets ready: {} files, {:.1} MB",
|
||||
"{label} assets ready: {} files, {:.1} MB",
|
||||
wanted.len(),
|
||||
total as f64 / 1e6
|
||||
));
|
||||
@@ -142,7 +187,7 @@ mod tests {
|
||||
}
|
||||
|
||||
/// A Horizon folder and an official launcher directory holding version `9.9` with
|
||||
/// sounds.json, two sounds and a language file in its asset store.
|
||||
/// sounds, a language file and the full title panorama in its asset store.
|
||||
struct Fixture {
|
||||
dir: PathBuf,
|
||||
root: PathBuf,
|
||||
@@ -152,6 +197,10 @@ mod tests {
|
||||
|
||||
impl Fixture {
|
||||
fn new(name: &str) -> Fixture {
|
||||
Self::with_panorama(name, &PANORAMA)
|
||||
}
|
||||
|
||||
fn with_panorama(name: &str, panorama: &[&'static str]) -> Fixture {
|
||||
let dir = std::env::temp_dir().join(format!(
|
||||
"horizon-prepare-sounds-{name}-{}",
|
||||
std::process::id()
|
||||
@@ -159,12 +208,16 @@ mod tests {
|
||||
let _ = fs::remove_dir_all(&dir);
|
||||
let root = dir.join("horizon");
|
||||
let minecraft = dir.join("minecraft");
|
||||
let objects: Vec<(&'static str, Vec<u8>)> = vec![
|
||||
let mut objects: Vec<(&'static str, Vec<u8>)> = vec![
|
||||
("minecraft/sounds.json", b"{\"a\": {}}".to_vec()),
|
||||
("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()),
|
||||
];
|
||||
for &name in panorama {
|
||||
// Distinct object bytes let the test catch swapped faces too.
|
||||
objects.push((name, name.as_bytes().to_vec()));
|
||||
}
|
||||
let mut index = String::from("{\"objects\": {");
|
||||
for (i, (name, data)) in objects.iter().enumerate() {
|
||||
let hash = sha1_hex(data);
|
||||
@@ -243,6 +296,7 @@ mod tests {
|
||||
assert_eq!(&fs::read(target.join("assets").join(name)).unwrap(), data);
|
||||
}
|
||||
assert!(!target.join("assets/minecraft/lang").exists());
|
||||
assert!(!target.join("assets/minecraft/textures").exists());
|
||||
assert_eq!(
|
||||
fs::read(target.join("asset-index.json")).unwrap(),
|
||||
fs::read(f.minecraft.join("assets/indexes/7.json")).unwrap()
|
||||
@@ -267,6 +321,96 @@ mod tests {
|
||||
assert!(f.run().unwrap_err().starts_with("Missing asset object"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn panorama_replaces_jar_placeholders_and_repairs_repeated_preparations() {
|
||||
let f = Fixture::new("panorama");
|
||||
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..] {
|
||||
let path = target.join("assets").join(name);
|
||||
fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
fs::write(path, b"1x1 gray placeholder").unwrap();
|
||||
}
|
||||
assert_eq!(
|
||||
panorama(&f.root, Some(&f.minecraft), &|_| {}).unwrap(),
|
||||
target
|
||||
);
|
||||
for (name, data) in &f.objects[4..] {
|
||||
assert_eq!(&fs::read(target.join("assets").join(name)).unwrap(), data);
|
||||
}
|
||||
}
|
||||
assert!(!target.join("assets/minecraft/sounds.json").exists());
|
||||
assert!(!target.join("assets/minecraft/lang").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn panorama_objects_are_verified_before_replacing_placeholders() {
|
||||
let f = Fixture::new("panorama-corrupt");
|
||||
fs::write(f.object(4), b"corrupt panorama").unwrap();
|
||||
let path = f
|
||||
.root
|
||||
.join(".local/horizon-client/9.9/assets")
|
||||
.join(f.objects[4].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();
|
||||
assert!(panorama(&f.root, Some(&f.minecraft), &|_| {})
|
||||
.unwrap_err()
|
||||
.starts_with("Missing asset object"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn panorama_requires_every_face_and_the_overlay_in_the_index() {
|
||||
let f = Fixture::with_panorama("panorama-incomplete", &PANORAMA[..6]);
|
||||
let error = panorama(&f.root, Some(&f.minecraft), &|_| {}).unwrap_err();
|
||||
assert_eq!(
|
||||
error,
|
||||
format!("{} is missing from the asset index", PANORAMA[6])
|
||||
);
|
||||
assert!(!f.root.join(".local/horizon-client/9.9/assets").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn full_preparation_keeps_placeholders_when_panorama_is_unavailable() {
|
||||
for missing in ["store", "install", "last-object"] {
|
||||
let f = Fixture::new(&format!("optional-panorama-{missing}"));
|
||||
// The JARs and manifest were imported earlier; the launcher need not remain.
|
||||
artifacts::import_manifest(&Lock::read(&f.root).unwrap(), &f.minecraft).unwrap();
|
||||
let target = f.root.join(".local/horizon-client/9.9/assets");
|
||||
for name in PANORAMA {
|
||||
let path = target.join(name);
|
||||
fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
fs::write(path, b"jar placeholder").unwrap();
|
||||
}
|
||||
match missing {
|
||||
"store" => fs::remove_dir_all(f.minecraft.join("assets")).unwrap(),
|
||||
"install" => fs::remove_dir_all(&f.minecraft).unwrap(),
|
||||
_ => fs::remove_file(f.object(f.objects.len() - 1)).unwrap(),
|
||||
}
|
||||
// The repair subcommand remains strict, even for a missing final object.
|
||||
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| {
|
||||
lines.borrow_mut().push(line.to_string())
|
||||
});
|
||||
assert_eq!(
|
||||
*lines.borrow(),
|
||||
[format!(
|
||||
"Title panorama not imported: {error}; run horizon-prepare panorama later"
|
||||
)]
|
||||
);
|
||||
for name in PANORAMA {
|
||||
assert_eq!(fs::read(target.join(name)).unwrap(), b"jar placeholder");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_index_must_be_the_pinned_one() {
|
||||
let f = Fixture::new("index");
|
||||
|
||||
@@ -23,7 +23,13 @@ verifies it against the pinned checksums, runs vanilla's data generator and smal
|
||||
exporters against those jars, and extracts the jar's assets and data into ignored
|
||||
`.local/horizon-client/26.3/`. Sounds (about 380 MB) are copied from your
|
||||
launcher's asset store by `horizon-prepare sounds`, each file checked against the asset
|
||||
index's SHA-1. Prepared resources are private; never commit them.
|
||||
index's SHA-1. Preparation also tries to replace the JAR's gray 1×1 title panorama
|
||||
placeholders with the full textures from that asset store. If the store is missing or
|
||||
incomplete, preparation logs a warning and keeps the placeholders. To import the panorama
|
||||
later without rerunning the Java exporters, run `horizon-prepare panorama` (or
|
||||
`cargo run --release -p horizon-prepare -- panorama` in a checkout). Pass
|
||||
`--minecraft-dir PATH` when using a different Minecraft installation.
|
||||
Prepared resources are private; never commit them.
|
||||
|
||||
Preparation is `horizon-prepare` (`crates/horizon-prepare`, Rust): it needs no Python, only
|
||||
the JDK, for the small exporters that call Mojang's own code. Release folders ship it beside
|
||||
|
||||
Reference in New Issue
Block a user