Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anarelion committed Oct 27, 2023
0 parents commit 5411e8e
Show file tree
Hide file tree
Showing 21 changed files with 1,299 additions and 0 deletions.
299 changes: 299 additions & 0 deletions Cargo.lock

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

12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "eq_files"
version = "0.1.0"
authors = ["Anarelion <[email protected]>"]
edition = "2021"

[dependencies]
bytes = "1.0"
thiserror = "1.0"
tracing = "0.1"
compress = "0.2"

30 changes: 30 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
mod pfs;
mod utils;
mod wld;

use std::string::FromUtf8Error;

pub use crate::pfs::PackFile;
pub use crate::wld::WldFile;
use bytes::Bytes;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum EQFilesError {
#[error("unknown error")]
UnknownError,
#[error("invalid magic number {0:x}")]
InvalidMagicNumber(u32),
#[error("Invalid WLD version: {0:x}")]
InvalidVersionNumber(u32),
#[error("error decoding string")]
ErrorDecodingString(#[from] FromUtf8Error),
}

pub(crate) trait Decoder {
type Settings;

fn new(input: &mut Bytes, settings: Self::Settings) -> Result<Self, EQFilesError>
where
Self: Sized;
}
26 changes: 26 additions & 0 deletions src/pfs/block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use bytes::{Buf, Bytes};

#[derive(Clone, PartialEq)]
pub struct PackFileBlock {
pub compressed_size: u32,
pub uncompressed_size: u32,
pub data: Bytes,
}

impl crate::Decoder for PackFileBlock {
type Settings = ();

fn new(input: &mut Bytes, _: Self::Settings) -> Result<Self, crate::EQFilesError>
where
Self: Sized,
{
let compressed_size = input.get_u32_le();
let uncompressed_size = input.get_u32_le();
let data = crate::utils::take(input, compressed_size as usize);
Ok(PackFileBlock {
compressed_size,
uncompressed_size,
data,
})
}
}
Loading

0 comments on commit 5411e8e

Please sign in to comment.