Skip to content

Commit

Permalink
add: KSC section extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
ndoa committed Feb 11, 2024
1 parent 9fc8c36 commit fdbfccc
Show file tree
Hide file tree
Showing 6 changed files with 507 additions and 28 deletions.
274 changes: 274 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ edition = "2021"

[dependencies]
anyhow = "1.0.79"
byteorder = "1.5.0"
byteorder = "1.5.0"
clap = { version = "4.5.0", features = ["env", "derive"] }
zstd = "0.13"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Tools for working with the kfc_data/kfc_dir files for Enshrouded modding.
Run the extractor with the following arguments:

```bash
kfc-tools.exe {path to enshrouded.kfc_dir} {path to enshrouded.kfc_data}
kfc-tools.exe extract-kfc {path to enshrouded.kfc_dir} {path to enshrouded.kfc_data}
```

Output notes:
Expand Down
16 changes: 8 additions & 8 deletions src/kfc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ use std::io::{Read, SeekFrom};

#[derive(Debug)]
#[allow(unused)]
pub struct KFCDirHeader {
pub struct KFCDirFileHeader {
pub magic: u32,
pub count: u32,
pub count2: u32,
pub field_0xc: u32,
pub data_file_size: u64,
}

fn read_kfc_dir_header<T>(rdr: &mut T) -> Result<KFCDirHeader>
fn read_kfc_file_header<T>(rdr: &mut T) -> Result<KFCDirFileHeader>
where
T: Read + std::io::Seek,
{
let header = KFCDirHeader {
let header = KFCDirFileHeader {
magic: rdr.read_u32::<LittleEndian>()?,
count: rdr.read_u32::<LittleEndian>()?,
count2: rdr.read_u32::<LittleEndian>()?,
Expand Down Expand Up @@ -52,22 +52,22 @@ where

#[derive(Debug)]
#[allow(unused)]
pub struct KFCDir {
pub struct KFCDirFile {
pub _offset: u64,
pub header: KFCDirHeader,
pub header: KFCDirFileHeader,
pub _data_start: u64,

pub hash_table: Vec<u64>,
pub size_table: Vec<KFCSizeEntry>,
pub offset_table: Vec<u64>,
}

pub fn read_kfc_dir<T>(rdr: &mut T) -> Result<KFCDir>
pub fn read_kfc_dir_file<T>(rdr: &mut T) -> Result<KFCDirFile>
where
T: Read + ReadBytesExt + std::io::Seek,
{
let _offset = rdr.stream_position()?;
let header = read_kfc_dir_header(rdr)?;
let header = read_kfc_file_header(rdr)?;
let _data_start = rdr.stream_position()?;

// I've never seen a case where these are different, but the offset table
Expand Down Expand Up @@ -98,7 +98,7 @@ where
offset_table.push(entry);
}

Ok(KFCDir {
Ok(KFCDirFile {
_offset,
header,
_data_start,
Expand Down
Loading

0 comments on commit fdbfccc

Please sign in to comment.