mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 10:54:38 +00:00
Add support for wuthering waves custom format
This commit is contained in:
parent
cd349a95f5
commit
44d90fad11
4 changed files with 84 additions and 13 deletions
|
@ -15,6 +15,7 @@ oodle_loader = ["dep:oodle_loader"]
|
|||
oodle_explicit = ["oodle"]
|
||||
oodle_implicit_dynamic = ["dep:oodle_loader", "oodle"]
|
||||
encryption = ["dep:aes"]
|
||||
wuthering-waves = []
|
||||
|
||||
[dependencies]
|
||||
byteorder = "1.5"
|
||||
|
|
|
@ -309,7 +309,21 @@ impl Entry {
|
|||
reader: &mut R,
|
||||
version: super::Version,
|
||||
) -> Result<Self, super::Error> {
|
||||
let bits = reader.read_u32::<LE>()?;
|
||||
|
||||
let bits = {
|
||||
let tmp = reader.read_u32::<LE>()?;
|
||||
#[cfg(not(feature = "wuthering-waves"))]
|
||||
{ tmp }
|
||||
#[cfg(feature = "wuthering-waves")]
|
||||
if version == Version::V12 {
|
||||
reader.read_u8()?;
|
||||
(tmp >> 16) & 0x3f | (tmp & 0xFFFF) << 6 | (tmp & (1 << 28)) >> 6 |
|
||||
(tmp & 0x0FC00000) << 1 | tmp & 0xE0000000
|
||||
} else {
|
||||
tmp
|
||||
}
|
||||
};
|
||||
|
||||
let compression = match (bits >> 23) & 0x3f {
|
||||
0 => None,
|
||||
n => Some(n - 1),
|
||||
|
@ -333,8 +347,19 @@ impl Entry {
|
|||
})
|
||||
};
|
||||
|
||||
let (offset, uncompressed) = {
|
||||
let offset = var_int(31)?;
|
||||
let uncompressed = var_int(30)?;
|
||||
#[cfg(not(feature = "wuthering-waves"))]
|
||||
{ (offset, uncompressed) }
|
||||
#[cfg(feature = "wuthering-waves")]
|
||||
if version == Version::V12 {
|
||||
(uncompressed, offset)
|
||||
} else {
|
||||
(offset, uncompressed)
|
||||
}
|
||||
};
|
||||
|
||||
let compressed = match compression {
|
||||
None => uncompressed,
|
||||
_ => var_int(29)?,
|
||||
|
@ -382,7 +407,7 @@ impl Entry {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn write_encoded<W: io::Write>(&self, writer: &mut W) -> Result<(), super::Error> {
|
||||
pub fn write_encoded<W: io::Write>(&self, writer: &mut W, version: Version) -> Result<(), super::Error> {
|
||||
let mut compression_block_size = (self.compression_block_size >> 11) & 0x3f;
|
||||
if (compression_block_size << 11) != self.compression_block_size {
|
||||
compression_block_size = 0x3f;
|
||||
|
@ -404,12 +429,24 @@ impl Entry {
|
|||
| ((is_uncompressed_size_32_bit_safe as u32) << 30)
|
||||
| ((is_offset_32_bit_safe as u32) << 31);
|
||||
|
||||
#[cfg(not(feature = "wuthering-waves"))]
|
||||
writer.write_u32::<LE>(flags)?;
|
||||
#[cfg(feature = "wuthering-waves")]
|
||||
if version == Version::V12 {
|
||||
let tmp = ((flags & 0x3f) << 16) | ((flags >> 6) & 0xFFFF) |
|
||||
((flags << 6) & (1 << 28)) | ((flags >> 1) & 0x0FC00000) | flags & 0xE0000000;
|
||||
writer.write_u32::<LE>(tmp)?;
|
||||
writer.write_u8(0)?;
|
||||
} else {
|
||||
writer.write_u32::<LE>(flags)?;
|
||||
}
|
||||
|
||||
if compression_block_size == 0x3f {
|
||||
writer.write_u32::<LE>(self.compression_block_size)?;
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wuthering-waves"))]
|
||||
{
|
||||
if is_offset_32_bit_safe {
|
||||
writer.write_u32::<LE>(self.offset as u32)?;
|
||||
} else {
|
||||
|
@ -421,6 +458,33 @@ impl Entry {
|
|||
} else {
|
||||
writer.write_u64::<LE>(self.uncompressed)?
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "wuthering-waves")]
|
||||
if version == Version::V12 {
|
||||
if is_uncompressed_size_32_bit_safe {
|
||||
writer.write_u32::<LE>(self.uncompressed as u32)?
|
||||
} else {
|
||||
writer.write_u64::<LE>(self.uncompressed)?
|
||||
}
|
||||
|
||||
if is_offset_32_bit_safe {
|
||||
writer.write_u32::<LE>(self.offset as u32)?;
|
||||
} else {
|
||||
writer.write_u64::<LE>(self.offset)?;
|
||||
}
|
||||
} else {
|
||||
if is_offset_32_bit_safe {
|
||||
writer.write_u32::<LE>(self.offset as u32)?;
|
||||
} else {
|
||||
writer.write_u64::<LE>(self.offset)?;
|
||||
}
|
||||
|
||||
if is_uncompressed_size_32_bit_safe {
|
||||
writer.write_u32::<LE>(self.uncompressed as u32)?
|
||||
} else {
|
||||
writer.write_u64::<LE>(self.uncompressed)?
|
||||
}
|
||||
}
|
||||
|
||||
if self.compression_slot.is_some() {
|
||||
if is_size_32_bit_safe {
|
||||
|
|
|
@ -45,6 +45,8 @@ pub enum Version {
|
|||
V9,
|
||||
V10,
|
||||
V11,
|
||||
#[cfg(feature = "wuthering-waves")]
|
||||
V12,
|
||||
}
|
||||
|
||||
#[repr(u32)]
|
||||
|
@ -65,6 +67,8 @@ pub enum VersionMajor {
|
|||
FrozenIndex, // v9 frozen index byte included
|
||||
PathHashIndex, // v10
|
||||
Fnv64BugFix, // v11
|
||||
#[cfg(feature = "wuthering-waves")]
|
||||
WuwaCustom, // v12
|
||||
}
|
||||
|
||||
// strum shouldn't need to be installed by users
|
||||
|
@ -115,6 +119,8 @@ impl Version {
|
|||
Version::V9 => VersionMajor::FrozenIndex,
|
||||
Version::V10 => VersionMajor::PathHashIndex,
|
||||
Version::V11 => VersionMajor::Fnv64BugFix,
|
||||
#[cfg(feature = "wuthering-waves")]
|
||||
Version::V12 => VersionMajor::WuwaCustom,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -479,7 +479,7 @@ impl Pak {
|
|||
let mut encoded_entries = io::Cursor::new(vec![]);
|
||||
for entry in self.index.entries.values() {
|
||||
offsets.push(encoded_entries.get_ref().len() as u32);
|
||||
entry.write_encoded(&mut encoded_entries)?;
|
||||
entry.write_encoded(&mut encoded_entries, self.version)?;
|
||||
}
|
||||
(encoded_entries.into_inner(), offsets)
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue