Skip to content

Commit

Permalink
✨ Texture2D & Sprite extraction (#38)
Browse files Browse the repository at this point in the history
* ⬆️ Upgrade dependencies

* ⬆️ Upgrade dependencies

* 🏗️ Migrate to rabex

* 📝 Add disclaimer

* ✨ Do puzzles for card and card_big

* 🚨 Fix lint

* ✅ Extract: fix version test
  • Loading branch information
nicks96432 authored Jan 7, 2024
1 parent 6f08b29 commit bf7c4f1
Show file tree
Hide file tree
Showing 71 changed files with 3,058 additions and 7,707 deletions.
1,150 changes: 785 additions & 365 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 17 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
[workspace]
members = ["acb", "cli", "download", "extract", "manifest", "unity", "utils"]
members = [
"acb",
"cli",
"download",
"extract",
"manifest",
"utils",
]
resolver = "2"

[workspace.package]
Expand All @@ -9,31 +16,31 @@ license = "MIT"
repository = "https://github.com/nicks96432/mltd-asset-downloader"

[workspace.dependencies]
ctor = "0.2.3"
linked-hash-map = "0.5.6"
log = "0.4.19"
ctor = "0.2.6"
linked-hash-map = "0.5.6"
log = "0.4.20"
num_cpus = "1.16.0"
rayon = "1.7.0"
serde = "1.0.171"
rayon = "1.8.0"
serde = "1.0.195"

[workspace.dependencies.clap]
default-features = false
features = ["std", "help", "usage"]
version = "4.3.11"
version = "4.4.13"

[workspace.dependencies.env_logger]
default-features = false
features = ["humantime"]
version = "0.10.0"
version = "0.10.1"

[workspace.dependencies.indicatif]
default-features = false
features = ["rayon"]
version = "0.17.5"
version = "0.17.7"

[workspace.dependencies.ureq]
features = ["json", "native-certs"]
version = "2.7.1"
version = "2.9.1"

[profile.release]
codegen-units = 20
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ cargo build --release

The executable will be in the `target/release` directory.

## Disclaimer

None of the repo, the tool, nor the repo owner is affiliated with, or sponsored or authorized by
Bandai Namco Entertainment and Unity Technologies, nor their affiliates or subsidiaries.

## License

Licensed under [MIT](LICENSE).

The copyright of anything that downloaded from this program belongs to Bandai Namco Entertainment.
The copyright of anything that downloaded or extracted from this program belongs to
Bandai Namco Entertainment.
4 changes: 2 additions & 2 deletions acb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ repository.workspace = true
version = "0.1.0"

[dependencies]
cxx = "1.0.100"
cxx = "1.0.115"

[build-dependencies]
cmake = "0.1.50"

[build-dependencies.cxx-build]
features = ["parallel"]
version = "1.0.100"
version = "1.0.115"

[features]
default = []
Expand Down
17 changes: 4 additions & 13 deletions acb/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() {
let dst = cmake::Config::new(libcgss_path)
.pic(true)
.uses_cxx11()
.define("LIBCGSS_BUILD_SHARED_LIB", "OFF")
.define("LIBCGSS_BUILD_SHARED_LIBS", "OFF")
.build();

let mut build = cxx_build::bridge("src/lib.rs");
Expand All @@ -21,17 +21,8 @@ fn main() {

build.compile("acb");

println!(
"cargo:rustc-link-search=native={}",
dst.join("lib").display()
);
println!("cargo:rustc-link-search=native={}", dst.join("lib").display());
println!("cargo:rustc-link-lib=static=cgss");
println!(
"cargo:return-if-changed={}",
Path::new("src").join("acb.cc").display()
);
println!(
"cargo:return-if-changed={}",
Path::new("src").join("acb.h").display()
);
println!("cargo:return-if-changed={}", Path::new("src").join("acb.cc").display());
println!("cargo:return-if-changed={}", Path::new("src").join("acb.h").display());
}
6 changes: 3 additions & 3 deletions acb/src/acb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ decode_stream(cgss::CMemoryStream *stream, const cgss::CHcaDecoderConfig &config
return decoded_data;
}

rust::Vec<Track> to_wav(const rust::Vec<std::uint8_t> &buf) {
std::vector<std::uint8_t> buf_clone = {buf.cbegin(), buf.cend()};
cgss::CMemoryStream stream{buf_clone.data(), static_cast<std::uint64_t>(buf.size()), false};
rust::Vec<Track> to_tracks(rust::Slice<const std::uint8_t> buf) {
std::vector<std::uint8_t> buf_clone = {buf.begin(), buf.end()};
cgss::CMemoryStream stream{buf_clone.data(), static_cast<std::uint64_t>(buf_clone.size()), false};
cgss::CAcbFile acb{&stream, ""};
acb.Initialize();

Expand Down
2 changes: 1 addition & 1 deletion acb/src/acb.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ constexpr uint64_t mltd_hca_key = 765765765765765ULL;
constexpr uint32_t mltd_hca_key1 = mltd_hca_key & 0xffffffff;
constexpr uint32_t mltd_hca_key2 = mltd_hca_key >> 32;

rust::Vec<Track> to_wav(const rust::Vec<std::uint8_t> &buf);
rust::Vec<Track> to_tracks(rust::Slice<const std::uint8_t> buf);

#endif // ACB_ACB_H_
14 changes: 6 additions & 8 deletions acb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,33 @@ mod ffi {
unsafe extern "C++" {
include!("acb/src/acb.h");

pub fn to_wav(buf: &Vec<u8>) -> Result<Vec<Track>>;
pub fn to_tracks(buf: &[u8]) -> Result<Vec<Track>>;
}
}

pub use ffi::Track;

pub fn to_wav(buf: &Vec<u8>) -> Result<Vec<Track>, cxx::Exception> {
ffi::to_wav(buf)
pub fn to_tracks(buf: &[u8]) -> Result<Vec<Track>, cxx::Exception> {
ffi::to_tracks(buf)
}

#[cfg(test)]
mod tests {
use crate::to_wav;
use crate::to_tracks;

use std::fs::File;
use std::io::Read;
use std::path::Path;

#[test]
fn test_to_wav() {
let path = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("test.acb");
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests").join("test.acb");
let mut f = File::open(&path).unwrap();

let mut buf = Vec::new();
f.read_to_end(&mut buf).unwrap();

let tracks = to_wav(&buf).unwrap();
let tracks = to_tracks(&buf).unwrap();
let track = tracks.get(0).unwrap();

let mut expected_file = File::open("tests/test.wav").unwrap();
Expand Down
4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ license.workspace = true
name = "mltd"
readme = "README.md"
repository.workspace = true
version = "2.0.0-beta"
version = "2.0.0-beta.3"

[dependencies]
clap = { workspace = true }
clap-verbosity-flag = "2.0.1"
clap-verbosity-flag = "2.1.1"
env_logger = { workspace = true }
log = { workspace = true }
mltd-utils = { path = "../utils" }
Expand Down
1 change: 1 addition & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum Command {
Extract(ExtractorArgs),

#[cfg(feature = "manifest")]
/// Download manifest from MLTD asset server
Manifest(ManifestArgs),
}

Expand Down
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ vulnerability = "deny"
yanked = "warn"

[licenses]
allow = ["Apache-2.0", "ISC", "MIT", "MPL-2.0"]
allow = ["Apache-2.0", "ISC", "MIT", "MPL-2.0", "Zlib", "BSD-3-Clause"]
allow-osi-fsf-free = "neither"
confidence-threshold = 0.83
copyleft = "deny"
Expand Down
14 changes: 6 additions & 8 deletions download/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ pub fn download_assets(args: &DownloaderArgs) -> Result<(), DownloadError> {
multi_progress.set_move_cursor(true);

log::trace!("create ProgressStyle");
let template =
"{msg:60} {bytes:12} {binary_bytes_per_sec:12} {eta:4} [{wide_bar:.cyan/blue}] {percent:3}%";
let template = "{msg:60} {bytes:12} {binary_bytes_per_sec:12} {eta:4} [{wide_bar:.cyan/blue}] {percent:3}%";
let progress_bar_style = match ProgressStyle::with_template(template) {
Ok(style) => style,
Err(_) => {
Expand Down Expand Up @@ -95,9 +94,8 @@ pub fn download_assets(args: &DownloaderArgs) -> Result<(), DownloadError> {
}

log::debug!("building request agent");
let agent_builder = AgentBuilder::new()
.https_only(true)
.user_agent(args.os_variant.user_agent());
let agent_builder =
AgentBuilder::new().https_only(true).user_agent(args.os_variant.user_agent());
let agent = agent_builder.build();

log::debug!("start downloading assets");
Expand All @@ -108,12 +106,12 @@ pub fn download_assets(args: &DownloaderArgs) -> Result<(), DownloadError> {
let tid = current_thread_index().unwrap_or_default();
let progress_bar = &progress_bars[tid];
progress_bar.reset();
progress_bar.set_length(entry.size);
progress_bar.set_length(entry.2);
progress_bar.set_position(0);
progress_bar.set_style(progress_bar_style.clone());
progress_bar.set_message(filename.clone());

let asset_url = format!("{}/{}", asset_url_base, entry.filename);
let asset_url = format!("{}/{}", asset_url_base, entry.1);
let asset_res = match fetch_asset(&agent, &asset_url) {
Ok(res) => res,
Err(e) => {
Expand Down Expand Up @@ -145,7 +143,7 @@ pub fn download_assets(args: &DownloaderArgs) -> Result<(), DownloadError> {
}

let cur_dounloaded_count = downloaded_count.fetch_add(1, Ordering::AcqRel);
total_progress_bar.inc(entry.size);
total_progress_bar.inc(entry.2);
total_progress_bar.set_message(format!(
"Total ({}/{})",
cur_dounloaded_count,
Expand Down
33 changes: 32 additions & 1 deletion extract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,42 @@ repository.workspace = true
version = "0.1.0"

[dependencies]
# For decoding ACB audio
acb = { path = "../acb" }

# For reading numbers from binary data
byteorder = "1.5.0"

log = { workspace = true }
num-derive = "0.4.1"
num-traits = "0.2.17"
num_cpus = { workspace = true }
unity = { path = "../unity" }

# For unpacking unity assets
rabex = "0.0.3"

# For decoding Texture2D
texture2ddecoder = "0.0.5"

[dependencies.clap]
features = ["derive"]
workspace = true

# For image encoding
[dependencies.image]
features = ["webp-encoder"]
version = "0.24.7"

# For regex matching in texture name
[dependencies.lazy-regex]
default-features = false
features = ["std", "perf"]
version = "3.1.0"

[dev-dependencies]
ctor = { workspace = true }
env_logger = { workspace = true }

[dev-dependencies.mltd-utils]
features = ["log", "rand"]
path = "../utils"
Loading

0 comments on commit bf7c4f1

Please sign in to comment.