Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for incremental DCX reading #24

Merged
merged 18 commits into from
Mar 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -35,5 +35,8 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- run: ls /opt/test-data
- run: ls -R /opt/test-data/elden-ring
- run: cargo test --workspace --all-features
env:
ER_PATH: /opt/test-data/elden-ring/Game
ER_KEYS_PATH: /opt/test-data/elden-ring
96 changes: 96 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
[package]
name = "fstools"
edition = "2021"

[dependencies]
format = { path = "format" }
souls_vfs = { path = "vfs" }

[dev-dependencies]
insta = "1"
libtest-mimic = "0.7"

[[test]]
name = "dcx"
path = "tests/dcx.rs"
harness = false

[workspace]
resolver = "2"
default-members = ["cli", "viewer"]
20 changes: 7 additions & 13 deletions cli/src/bin/dcx-extract.rs → cli/src/bin/bnd-extract.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::io::{Read, Write};
use std::{
error::Error,
io::{Read, Write},
};

use clap::Parser;
use format::{bnd4::BND4, dcx::Dcx};
use memmap2::MmapOptions;
use format::{bnd4::BND4, dcx::DcxHeader};

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
@@ -11,20 +13,12 @@ struct Args {
file: String,
}

fn main() -> Result<(), std::io::Error> {
fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();
let path = std::path::PathBuf::from(args.file);

let dcx_file = std::fs::File::open(&path)?;
let data = unsafe {
MmapOptions::new()
.populate()
.map_copy_read_only(&dcx_file)?
};

let dcx = Dcx::parse(&data).unwrap();

let mut decoder = dcx.create_decoder().expect("Could not create decoder");
let (_, mut decoder) = DcxHeader::read(dcx_file)?;

let mut decompressed = Vec::with_capacity(decoder.hint_size());
decoder.read_to_end(&mut decompressed)?;
4 changes: 3 additions & 1 deletion format/src/bhd.rs
Original file line number Diff line number Diff line change
@@ -111,7 +111,9 @@ pub fn read_header_data<R: Read, O: ByteOrder>(
mut reader: R,
is_big_endian: bool,
) -> Result<BhdHeader, std::io::Error> {
reader.read_padding(7)?;
let _ = reader.read_u8()?;
reader.read_padding(2)?;
let _ = reader.read_u32::<O>()?;

let file_size = reader.read_u32::<O>()?;
let toc_buckets = reader.read_i32::<O>()?;
10 changes: 5 additions & 5 deletions format/src/dcx/deflate.rs
Original file line number Diff line number Diff line change
@@ -2,15 +2,15 @@ use std::io::{self, Read};

use flate2::read::ZlibDecoder;

pub struct DcxDecoderDeflate<'a>(ZlibDecoder<&'a [u8]>);
pub struct DcxDecoderDeflate<R: Read>(ZlibDecoder<R>);

impl<'a> DcxDecoderDeflate<'a> {
pub fn from_buffer(buf: &'a [u8]) -> Self {
Self(ZlibDecoder::new(buf))
impl<R: Read> DcxDecoderDeflate<R> {
pub fn new(reader: R) -> Self {
Self(ZlibDecoder::new(reader))
}
}

impl<'a> Read for DcxDecoderDeflate<'a> {
impl<R: Read> Read for DcxDecoderDeflate<R> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.0.read(buf)
}
65 changes: 0 additions & 65 deletions format/src/dcx/kraken.rs

This file was deleted.

Loading