Skip to content

Commit

Permalink
Add rose-vfs-dump which can extract VFS formats which have no filenames.
Browse files Browse the repository at this point in the history
e.g. titanrose, aruarose, iroseph
  • Loading branch information
exjam committed Mar 6, 2024
1 parent 7668b59 commit 15e09f8
Show file tree
Hide file tree
Showing 8 changed files with 642 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"rose-network-irose",
"rose-offline-server",
"rose-offline-tools/rose-conv",
"rose-offline-tools/rose-vfs-dump",
]

[workspace.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion rose-file-readers/src/aruavfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl From<&str> for FileNameHash {
.chars()
.map(|c| Wrapping(c.to_ascii_uppercase() as u32))
{
seed1 = Wrapping(HASH_TABLE[ch.0 as usize]) ^ (seed1 + seed2);
seed1 = Wrapping(HASH_TABLE[(ch.0 & 0xff) as usize]) ^ (seed1 + seed2);
seed2 = ch + seed1 + seed2 + (seed2 << 5) + Wrapping(3);
}

Expand Down
2 changes: 1 addition & 1 deletion rose-file-readers/src/irosephvfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl From<&str> for FileNameHash {
{
seed1 += seed2;
seed2 *= Wrapping(0x21);
seed1 ^= HASH_TABLE[ch.0 as usize];
seed1 ^= HASH_TABLE[(ch.0 & 0xFF) as usize];
seed2 = seed2 + seed1 + ch + Wrapping(3);
}

Expand Down
17 changes: 16 additions & 1 deletion rose-file-readers/src/lit.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use anyhow::anyhow;

use crate::{reader::RoseFileReader, RoseFile};

#[derive(Debug)]
Expand Down Expand Up @@ -25,11 +27,24 @@ impl RoseFile for LitFile {

fn read(mut reader: RoseFileReader, _: &Self::ReadOptions) -> Result<Self, anyhow::Error> {
let object_count = reader.read_u32()? as usize;
if object_count > 10000 {
return Err(anyhow!(
"Corrupt .LIT file, invalid object_count {}",
object_count
));
}

let mut objects = Vec::with_capacity(object_count);
for _ in 0..object_count {
let part_count = reader.read_u32()? as usize;
let object_id = reader.read_u32()?;
if part_count > 10000 {
return Err(anyhow!(
"Corrupt .LIT file, invalid part_count {}",
part_count
));
}

let object_id = reader.read_u32()?;
let mut parts = Vec::with_capacity(part_count);
for _ in 0..part_count {
let name_len = reader.read_u8()?;
Expand Down
2 changes: 1 addition & 1 deletion rose-file-readers/src/titanvfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl From<&str> for FileNameHash {
{
seed1 += seed2;
seed2 *= Wrapping(0x21);
seed1 ^= HASH_TABLE[ch.0 as usize];
seed1 ^= HASH_TABLE[(ch.0 & 0xff) as usize];
seed2 = seed2 + seed1 + ch + Wrapping(3);
}

Expand Down
11 changes: 10 additions & 1 deletion rose-file-readers/src/virtual_filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a> From<&'a VfsFile<'a>> for RoseFileReader<'a> {
}
}

#[derive(Default, Debug, Hash, Clone)]
#[derive(Default, Debug, Hash, Clone, PartialEq, Eq)]
pub struct VfsPathBuf {
path: PathBuf,
}
Expand All @@ -45,6 +45,14 @@ impl VfsPathBuf {
}
}

impl<'a> From<&VfsPath<'a>> for VfsPathBuf {
fn from(path: &VfsPath<'a>) -> Self {
VfsPathBuf {
path: path.path.to_path_buf(),
}
}
}

#[derive(Debug, Hash, Clone)]
pub struct VfsPath<'a> {
path: Cow<'a, Path>,
Expand All @@ -58,6 +66,7 @@ impl<'a> VfsPath<'a> {

pub fn normalise_path(path: &str) -> PathBuf {
path.replace('\\', "/")
.replace("//", "/")
.to_uppercase()
.trim_start()
.trim_end()
Expand Down
11 changes: 11 additions & 0 deletions rose-offline-tools/rose-vfs-dump/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "rose-vfs-dump"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }

[dependencies]
rose-file-readers = { path = "../../rose-file-readers" }
clap = { workspace = true }
serde = { workspace = true }
log = { workspace = true }
Loading

0 comments on commit 15e09f8

Please sign in to comment.