Skip to content

Commit

Permalink
Merge pull request #24 from soulsmods/feat/incremental-dcx-reader
Browse files Browse the repository at this point in the history
Support for incremental DCX reading
  • Loading branch information
garyttierney authored Mar 10, 2024
2 parents ce2d597 + 6387ea9 commit f8de80e
Show file tree
Hide file tree
Showing 19 changed files with 106,730 additions and 310 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
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)]
Expand All @@ -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)?;
Expand Down
4 changes: 3 additions & 1 deletion format/src/bhd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>()?;
Expand Down
10 changes: 5 additions & 5 deletions format/src/dcx/deflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
65 changes: 0 additions & 65 deletions format/src/dcx/kraken.rs

This file was deleted.

Loading

0 comments on commit f8de80e

Please sign in to comment.