diff --git a/Cargo.lock b/Cargo.lock index a6139137..9e621dbd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -840,6 +840,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" dependencies = [ "crc32fast", + "libz-rs-sys", "miniz_oxide", ] @@ -1625,7 +1626,6 @@ dependencies = [ "wgpu", "winit", "xml-rs", - "yazi", ] [[package]] @@ -1734,6 +1734,15 @@ dependencies = [ "redox_syscall 0.5.8", ] +[[package]] +name = "libz-rs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a90e19106f1b2c93f1fa6cdeec2e56facbf2e403559c1e1c0ddcc6d46e979cdf" +dependencies = [ + "zlib-rs", +] + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -4755,12 +4764,6 @@ version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea8b391c9a790b496184c29f7f93b9ed5b16abb306c05415b68bcc16e4d06432" -[[package]] -name = "yazi" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7773623574268945095a9008f1583f7feac95bf1c4c406de5c98d02e0c0eb98" - [[package]] name = "yoke" version = "0.7.5" @@ -4855,6 +4858,12 @@ dependencies = [ "syn", ] +[[package]] +name = "zlib-rs" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aada01553a9312bad4b9569035a1f12b05e5ec9770a1a4b323757356928944f8" + [[package]] name = "zune-core" version = "0.4.12" diff --git a/Cargo.toml b/Cargo.toml index 4e508c33..f19d1fb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ cpal = "0.15" derive-new = "0.7" etherparse = "0.16" fast-srgb8 = "1" -flate2 = "1" +flate2 = { version = "1", default-features = false } glidesort = "0.1" hashbrown = "0.15" image = { version = "0.25", default-features = false } @@ -50,7 +50,6 @@ walkdir = "2.5" wgpu = "23.0" winit = "0.30" xml-rs = "0.8" -yazi = "0.2" [profile.dev.build-override] opt-level = 3 diff --git a/korangar/Cargo.toml b/korangar/Cargo.toml index b7a18666..525fdd2e 100644 --- a/korangar/Cargo.toml +++ b/korangar/Cargo.toml @@ -11,7 +11,7 @@ cgmath = { workspace = true, features = ["mint", "serde"] } chrono = { workspace = true } cosmic-text = { workspace = true, features = ["std", "fontconfig"] } derive-new = { workspace = true } -flate2 = { workspace = true } +flate2 = { workspace = true, features = ["zlib-rs"] } hashbrown = { workspace = true } glidesort = { workspace = true } image = { workspace = true, features = ["bmp", "jpeg", "png", "tga", "rayon"] } @@ -39,7 +39,6 @@ walkdir = { workspace = true } wgpu = { workspace = true } winit = { workspace = true } xml-rs = { workspace = true } -yazi = { workspace = true } [features] debug = ["korangar_debug", "korangar_audio/debug", "ragnarok_packets/debug", "random_color"] diff --git a/korangar/src/loaders/archive/native/builder.rs b/korangar/src/loaders/archive/native/builder.rs index d85aebca..cfcdac70 100644 --- a/korangar/src/loaders/archive/native/builder.rs +++ b/korangar/src/loaders/archive/native/builder.rs @@ -1,12 +1,15 @@ -//! Implements an writable instance of a GRF File +//! Implements a writable instance of a GRF File //! This way, we can provide a temporal storage to files before the final write -//! occurs while keeping it outside of the +//! occurs while keeping it outside the //! [`NativeArchive`](super::NativeArchive) implementation + +use std::io::Read; use std::path::{Path, PathBuf}; +use flate2::bufread::ZlibEncoder; +use flate2::Compression; use ragnarok_bytes::ToBytes; use ragnarok_formats::archive::{AssetTable, FileTableRow, Header}; -use yazi::{compress, CompressionLevel, Format}; use super::FileTable; use crate::loaders::archive::Writable; @@ -29,7 +32,9 @@ impl NativeArchiveBuilder { impl Writable for NativeArchiveBuilder { fn add_file(&mut self, path: &str, asset: Vec) { - let compressed = compress(&asset, Format::Zlib, CompressionLevel::Default).unwrap(); + let mut encoder = ZlibEncoder::new(asset.as_slice(), Compression::default()); + let mut compressed = Vec::default(); + encoder.read_to_end(&mut compressed).expect("can't compress asset"); let compressed_size = compressed.len() as u32; let compressed_size_aligned = compressed_size; @@ -66,14 +71,17 @@ impl Writable for NativeArchiveBuilder { file_table_data.extend(file_information.to_bytes().unwrap()); } - let compressed_file_information_data = compress(&file_table_data, Format::Zlib, CompressionLevel::Default).unwrap(); + let mut encoder = ZlibEncoder::new(file_table_data.as_slice(), Compression::default()); + let mut compressed = Vec::default(); + encoder.read_to_end(&mut compressed).expect("can't compress file information"); + let file_table = AssetTable { - compressed_size: compressed_file_information_data.len() as u32, + compressed_size: compressed.len() as u32, uncompressed_size: file_table_data.len() as u32, }; bytes.extend(file_table.to_bytes().unwrap()); - bytes.extend(compressed_file_information_data); + bytes.extend(compressed); std::fs::write(&self.os_file_path, bytes).expect("unable to write file"); } diff --git a/korangar/src/loaders/archive/native/mod.rs b/korangar/src/loaders/archive/native/mod.rs index 22947f69..aa2d2236 100644 --- a/korangar/src/loaders/archive/native/mod.rs +++ b/korangar/src/loaders/archive/native/mod.rs @@ -8,11 +8,11 @@ use std::io::{Read, Seek, SeekFrom}; use std::path::Path; use std::sync::Mutex; +use flate2::bufread::ZlibDecoder; #[cfg(feature = "debug")] use korangar_debug::logging::{Colorize, Timer}; use ragnarok_bytes::{ByteReader, FixedByteSize, FromBytes}; use ragnarok_formats::archive::{AssetTable, FileTableRow, Header}; -use yazi::{decompress, Format}; pub use self::builder::NativeArchiveBuilder; use crate::loaders::archive::native::mixcrypt::decrypt_file; @@ -44,11 +44,14 @@ impl Archive for NativeArchive { let mut file_table_buffer = vec![0; AssetTable::size_in_bytes()]; file.read_exact(&mut file_table_buffer).unwrap(); - let file_table = AssetTable::from_bytes(&mut ByteReader::without_metadata(&file_table_buffer)).unwrap(); + let file_table = AssetTable::from_bytes(&mut ByteReader::without_metadata(&file_table_buffer)).expect("can't read file table"); let mut compressed_file_table_buffer = vec![0u8; file_table.compressed_size as usize]; file.read_exact(&mut compressed_file_table_buffer).unwrap(); - let (decompressed, _checksum) = decompress(&compressed_file_table_buffer, Format::Zlib).unwrap(); + + let mut decoder = ZlibDecoder::new(compressed_file_table_buffer.as_slice()); + let mut decompressed = Vec::with_capacity(file_table.uncompressed_size as usize); + decoder.read_to_end(&mut decompressed).expect("can't decompress file table"); let file_count = file_header.get_file_count(); @@ -66,7 +69,7 @@ impl Archive for NativeArchive { timer.stop(); // TODO: only take 64..? bytes so that loaded game archives can be extended - // aswell + // as well. Self { file_table: assets, file_handle: Mutex::new(file), @@ -86,15 +89,16 @@ impl Archive for NativeArchive { file_handle.seek(SeekFrom::Start(position)).unwrap(); file_handle .read_exact(&mut compressed_file_buffer) - .expect("Can't read archive content"); + .expect("can't read archive content"); } decrypt_file(file_information, &mut compressed_file_buffer); - let (uncompressed_file_buffer, _checksum) = - decompress(&compressed_file_buffer, Format::Zlib).expect("Can't decompress archive content"); + let mut decoder = ZlibDecoder::new(compressed_file_buffer.as_slice()); + let mut decompressed = Vec::with_capacity(file_information.uncompressed_size as usize); + decoder.read_to_end(&mut decompressed).expect("can't decompress archive content"); - uncompressed_file_buffer + decompressed }) }