Skip to content

Commit

Permalink
rvff rename
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWillard committed May 4, 2024
1 parent eaeccc8 commit 3930aea
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 98 deletions.
20 changes: 10 additions & 10 deletions src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum PaaError {
PaaLzoErr(#[from] lzokay_native::Error),

#[error("LZSS Error")]
RvffLzssError(#[from] RvffLzssError),
LzssError(#[from] LzssError),

#[error("Invalid state")]
InvalidState,
Expand All @@ -27,7 +27,7 @@ pub enum PaaError {
}

#[derive(Debug, Error)]

Check warning on line 29 in src/errors/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/errors/mod.rs#L29

Added line #L29 was not covered by tests
pub enum RvffLzssError {
pub enum LzssError {
#[error("IO failed")]
IOError(#[from] io::Error),

Expand All @@ -39,7 +39,7 @@ pub enum RvffLzssError {
}

#[derive(Debug, PartialEq, Eq, Clone, Copy, Error)]
pub enum RvffOdolError {
pub enum OdolError {
#[error("Signature Missing")]
SignatureMissing,

Expand All @@ -51,21 +51,21 @@ pub enum RvffOdolError {
}

#[derive(Debug, Error)]
pub enum RvffError {
pub enum AffError {
#[error("IO failed {0}")]
RvffIOError(#[from] io::Error),
IOError(#[from] io::Error),

#[error("FromUTF8 failed {0}")]
RvffUTFError(#[from] FromUtf8Error),
UTFError(#[from] FromUtf8Error),

#[error("Binrw failed {0}")]
RvffBinrwError(#[from] binrw::Error),
BinrwError(#[from] binrw::Error),

#[error("LZSS Error")]
RvffLzssError(#[from] RvffLzssError),
LzssError(#[from] LzssError),

#[error("ODOL Error")]
RvffOdolError(#[from] RvffOdolError),
OdolError(#[from] OdolError),

#[error("Invalid file")]
InvalidFileError,
Expand All @@ -77,5 +77,5 @@ pub enum RvffError {
Unknown,

#[error("Parsing failed: {0}")]
RvffParseError(String),
ParseError(String),
}
31 changes: 15 additions & 16 deletions src/real_virtuality/core/lzss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use std::{

use byteorder::{LittleEndian, ReadBytesExt};

use crate::errors::{RvffError, RvffLzssError};
use crate::errors::{AffError, LzssError};

pub fn decompress_lzss<R>(
reader: &mut R,
expected_size: usize,
use_signed_checksum: bool,
) -> Result<(u64, Vec<u8>), RvffLzssError>
) -> Result<(u64, Vec<u8>), LzssError>
where
R: Read + Seek,
{
Expand All @@ -38,19 +38,19 @@ where
while remaining_size > 0 {
num5 >>= 1;
if (num5 & 256) == 0 {
let val = reader.read_u8().unwrap();
let val = reader.read_u8()?;
num5 = i32::from(val) | 65280;
}
if (num5 & 1) == 0 {
let mut i = i32::from(reader.read_u8().unwrap());
let mut val = i32::from(reader.read_u8().unwrap());
let mut i = i32::from(reader.read_u8()?);
let mut val = i32::from(reader.read_u8()?);
i |= (val & 240) << 4;
val &= 15;
val += 2;
let mut j = num4 - i;
let num8 = val + j;
if (val + 1) as usize > remaining_size {
return Err(RvffLzssError::Overflow);
return Err(LzssError::Overflow);

Check warning on line 53 in src/real_virtuality/core/lzss.rs

View check run for this annotation

Codecov / codecov/patch

src/real_virtuality/core/lzss.rs#L53

Added line #L53 was not covered by tests
}
while j <= num8 {
let num6 = array[(j & 4095) as usize];
Expand All @@ -68,7 +68,7 @@ where
j += 1;
}
} else {
let val = reader.read_u8().unwrap();
let val = reader.read_u8()?;
if use_signed_checksum {
calculated_hash += i32::from(val as i8);
} else {
Expand All @@ -83,15 +83,15 @@ where
}
}

let hash = reader.read_i32::<LittleEndian>().unwrap();
let hash = reader.read_i32::<LittleEndian>()?;
if hash != calculated_hash {
return Err(RvffLzssError::ChecksumMissmatch);
return Err(LzssError::ChecksumMissmatch);

Check warning on line 88 in src/real_virtuality/core/lzss.rs

View check run for this annotation

Codecov / codecov/patch

src/real_virtuality/core/lzss.rs#L88

Added line #L88 was not covered by tests
}
let size = reader.stream_position().unwrap() - pos;
let size = reader.stream_position()? - pos;
Ok((size, dst))
}

pub fn decompress_lzss_unk_size<R>(reader: &mut R) -> Result<Vec<u8>, RvffError>
pub fn decompress_lzss_unk_size<R>(reader: &mut R) -> Result<Vec<u8>, AffError>
where
R: Read + Seek,
{
Expand All @@ -105,8 +105,7 @@ where
let threshold: i32 = 2;

let mut text_buffer = vec![0_u8; (sliding_winding_size + best_match - 1) as usize];
let mut out = Vec::new();
out.reserve(in_size as usize * 4);
let mut out = Vec::with_capacity(in_size as usize * 4);

let mut check_sum = 0_i32;
let mut flags = 0_i32;
Expand Down Expand Up @@ -161,14 +160,14 @@ where
out.truncate(size);
Ok(out)
} else {
Err(RvffError::Unknown)
Err(AffError::Unknown)

Check warning on line 163 in src/real_virtuality/core/lzss.rs

View check run for this annotation

Codecov / codecov/patch

src/real_virtuality/core/lzss.rs#L163

Added line #L163 was not covered by tests
}
}

pub fn check_for_magic_and_decompress_lzss<R>(
reader: &mut R,
magic: &[u8],
) -> Result<Option<Vec<u8>>, RvffError>
) -> Result<Option<Vec<u8>>, AffError>
where
R: Read + Seek,
{
Expand All @@ -194,7 +193,7 @@ where
pub fn check_for_magic_and_decompress_lzss_file<P: AsRef<Path>>(
path: P,
magic: &[u8],
) -> Result<bool, RvffError> {
) -> Result<bool, AffError> {

Check warning on line 196 in src/real_virtuality/core/lzss.rs

View check run for this annotation

Codecov / codecov/patch

src/real_virtuality/core/lzss.rs#L196

Added line #L196 was not covered by tests
let mut file = File::open(&path)?;
let uncomp_data = check_for_magic_and_decompress_lzss(&mut file, magic)?;

Expand Down
20 changes: 8 additions & 12 deletions src/real_virtuality/p3d/odol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
};

use crate::real_virtuality::core::decompress_lzss_unk_size;
use crate::{errors::RvffError, real_virtuality::p3d::model_info::ModelInfo};
use crate::{errors::AffError, real_virtuality::p3d::model_info::ModelInfo};
use derivative::Derivative;

use super::animations::Animations;
Expand Down Expand Up @@ -207,27 +207,27 @@ impl ODOL {
Self::default()
}

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, RvffError> {
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, AffError> {
let file = File::open(path)?;
let mut buf_reader = BufReader::new(file);
Self::from_stream(&mut buf_reader)
}

pub(crate) fn from_stream_lazy<R>(reader: &mut R) -> Result<Self, RvffError>
pub(crate) fn from_stream_lazy<R>(reader: &mut R) -> Result<Self, AffError>

Check warning on line 216 in src/real_virtuality/p3d/odol.rs

View check run for this annotation

Codecov / codecov/patch

src/real_virtuality/p3d/odol.rs#L216

Added line #L216 was not covered by tests
where
R: Read + Seek,
{
Self::read(reader, true)
}

pub fn from_stream<R>(reader: &mut R) -> Result<Self, RvffError>
pub fn from_stream<R>(reader: &mut R) -> Result<Self, AffError>
where
R: Read + Seek,
{
Self::read(reader, false)
}

fn read<R>(reader: &mut R, skip_lods: bool) -> Result<Self, RvffError>
fn read<R>(reader: &mut R, skip_lods: bool) -> Result<Self, AffError>
where
R: Read + Seek,
{
Expand All @@ -249,11 +249,7 @@ impl ODOL {
Ok(Self::read_le_args(reader, (opt,))?)
}

pub fn read_lod<RS>(
&self,
reader: &mut RS,
resolution: ResolutionEnum,
) -> Result<Lod, RvffError>
pub fn read_lod<RS>(&self, reader: &mut RS, resolution: ResolutionEnum) -> Result<Lod, AffError>

Check warning on line 252 in src/real_virtuality/p3d/odol.rs

View check run for this annotation

Codecov / codecov/patch

src/real_virtuality/p3d/odol.rs#L252

Added line #L252 was not covered by tests
where
RS: Read + Seek,
{
Expand Down Expand Up @@ -286,7 +282,7 @@ impl<R> OdolLazyReader<R>
where
R: Read + Seek,
{
pub fn from_reader(mut reader: R) -> Result<Self, RvffError> {
pub fn from_reader(mut reader: R) -> Result<Self, AffError> {

Check warning on line 285 in src/real_virtuality/p3d/odol.rs

View check run for this annotation

Codecov / codecov/patch

src/real_virtuality/p3d/odol.rs#L285

Added line #L285 was not covered by tests
let odol = ODOL::from_stream_lazy(&mut reader)?;
Ok(Self {
lods: HashMap::new(),
Expand All @@ -295,7 +291,7 @@ where
})
}

pub fn read_lod(&mut self, resolution: ResolutionEnum) -> Result<Lod, RvffError> {
pub fn read_lod(&mut self, resolution: ResolutionEnum) -> Result<Lod, AffError> {

Check warning on line 294 in src/real_virtuality/p3d/odol.rs

View check run for this annotation

Codecov / codecov/patch

src/real_virtuality/p3d/odol.rs#L294

Added line #L294 was not covered by tests
if let Some(lod_index) = self
.odol
.resolutions
Expand Down
18 changes: 9 additions & 9 deletions src/real_virtuality/pbo/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rsa::BigUint;
use sha1::digest::Output;
use sha1::{Digest, Sha1};

use crate::errors::RvffError;
use crate::errors::AffError;
use crate::real_virtuality::core::read::ReadExtTrait;
use crate::real_virtuality::sign::{PrivateKey, PublicKey, SignVersion, Signature, KEY_LENGTH};

Expand Down Expand Up @@ -37,13 +37,13 @@ impl Pbo {
Self::default()
}

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, RvffError> {
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, AffError> {
let file = File::open(path)?;
let mut buf_reader = BufReader::new(file);
Self::from_stream(&mut buf_reader)
}

pub fn from_stream<R>(reader: &mut R) -> Result<Self, RvffError>
pub fn from_stream<R>(reader: &mut R) -> Result<Self, AffError>
where
R: BufRead + Seek,
{
Expand Down Expand Up @@ -78,15 +78,15 @@ impl Pbo {
self.entries.contains_key(&self.handle_prefix(entry_path))
}

pub(crate) fn read<R>(&mut self, reader: &mut R, skip_data: bool) -> Result<(), RvffError>
pub(crate) fn read<R>(&mut self, reader: &mut R, skip_data: bool) -> Result<(), AffError>
where
R: BufRead + Seek,
{
if reader.read_u8()? != 0
|| reader.read_string(4)? != PBO_MAGIC
|| reader.read_bytes(16)?.into_iter().all(|x| x != 0)
{
return Err(RvffError::InvalidFileError);
return Err(AffError::InvalidFileError);

Check warning on line 89 in src/real_virtuality/pbo/archive.rs

View check run for this annotation

Codecov / codecov/patch

src/real_virtuality/pbo/archive.rs#L89

Added line #L89 was not covered by tests
}

while reader.peek_u8()? != 0 {
Expand Down Expand Up @@ -125,7 +125,7 @@ impl Pbo {

reader.seek(SeekFrom::Start(data_pos))?;
if reader.read_u8()? != 0 {
return Err(RvffError::InvalidFileError);
return Err(AffError::InvalidFileError);

Check warning on line 128 in src/real_virtuality/pbo/archive.rs

View check run for this annotation

Codecov / codecov/patch

src/real_virtuality/pbo/archive.rs#L128

Added line #L128 was not covered by tests
}

self.hash = reader.read_bytes(20)?;
Expand All @@ -137,7 +137,7 @@ impl Pbo {
&mut self,
entry_path: &str,
reader: &mut R,
) -> Result<Option<Entry>, RvffError>
) -> Result<Option<Entry>, AffError>
where
R: BufRead + Seek,
{
Expand All @@ -159,7 +159,7 @@ impl Pbo {
out_path: &str,
full_path: bool,
reader: &mut R,
) -> Result<(), RvffError>
) -> Result<(), AffError>
where
R: BufRead + Seek,
{
Expand Down Expand Up @@ -187,7 +187,7 @@ impl Pbo {

Ok(())
} else {
Err(RvffError::PboEntryNotFound(entry_path.clone()))
Err(AffError::PboEntryNotFound(entry_path.clone()))

Check warning on line 190 in src/real_virtuality/pbo/archive.rs

View check run for this annotation

Codecov / codecov/patch

src/real_virtuality/pbo/archive.rs#L190

Added line #L190 was not covered by tests
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/real_virtuality/pbo/archive_reader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io::{BufRead, Seek};

use crate::errors::RvffError;
use crate::errors::AffError;

use super::{Entry, Pbo};

Expand All @@ -17,7 +17,7 @@ impl<R> PboReader<R>
where
R: BufRead + Seek,
{
pub fn from_stream(reader: R) -> Result<Self, RvffError> {
pub fn from_stream(reader: R) -> Result<Self, AffError> {
let mut pbo_reader = Self {
reader,
pbo: Pbo::new(),
Expand All @@ -26,7 +26,7 @@ where
Ok(pbo_reader)
}

pub fn get_entry(&mut self, entry_path: &str) -> Result<Option<Entry>, RvffError> {
pub fn get_entry(&mut self, entry_path: &str) -> Result<Option<Entry>, AffError> {
self.pbo.get_entry(entry_path, &mut self.reader)
}

Expand All @@ -39,7 +39,7 @@ where
entry_path: &str,
out_path: &str,
full_path: bool,
) -> Result<(), RvffError> {
) -> Result<(), AffError> {
self.pbo
.extract_single_file(entry_path, out_path, full_path, &mut self.reader)
}
Expand Down
8 changes: 4 additions & 4 deletions src/real_virtuality/pbo/entry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io::{BufRead, Seek, SeekFrom, Write};

use crate::errors::RvffError;
use crate::errors::AffError;
use crate::real_virtuality::core::read::ReadExtTrait;
use crate::real_virtuality::core::write::WriteExtTrait;
#[derive(Debug, Default, PartialEq, Eq, Clone)]
Expand All @@ -23,7 +23,7 @@ impl Entry {
Self::default()
}

pub fn read<R>(&mut self, reader: &mut R) -> Result<(), RvffError>
pub fn read<R>(&mut self, reader: &mut R) -> Result<(), AffError>
where
R: BufRead + Seek,
{
Expand All @@ -36,7 +36,7 @@ impl Entry {

Ok(())
}
pub fn read_data<R>(&mut self, reader: &mut R) -> Result<(), RvffError>
pub fn read_data<R>(&mut self, reader: &mut R) -> Result<(), AffError>
where
R: BufRead + Seek,
{
Expand All @@ -45,7 +45,7 @@ impl Entry {
Ok(())
}

pub fn write<R>(&mut self, writer: &mut R) -> Result<(), RvffError>
pub fn write<R>(&mut self, writer: &mut R) -> Result<(), AffError>

Check warning on line 48 in src/real_virtuality/pbo/entry.rs

View check run for this annotation

Codecov / codecov/patch

src/real_virtuality/pbo/entry.rs#L48

Added line #L48 was not covered by tests
where
R: Write + Seek,
{
Expand Down
Loading

0 comments on commit 3930aea

Please sign in to comment.