Skip to content

Commit

Permalink
feat: package version 525 support
Browse files Browse the repository at this point in the history
  • Loading branch information
localcc committed Jun 29, 2024
1 parent ba49752 commit fcffd61
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
Binary file added resources/test/package_version_525.sav
Binary file not shown.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl GvasHeader {
}

let package_file_version = cursor.read_u32::<LittleEndian>()?;
if !package_file_version.between(0x205, 0x20C) {
if !package_file_version.between(0x205, 0x20D) {
Err(DeserializeError::InvalidHeader(
format!("Package file version {package_file_version} not supported")
.into_boxed_str(),
Expand Down
1 change: 1 addition & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub const ENUM_ARRAY_PATH: &str = "resources/test/enum_array.sav";
pub const FEATURES_01_PATH: &str = "resources/test/features_01.bin";
pub const OPTIONS_PATH: &str = "resources/test/Options.sav";
pub const PACKAGE_VERSION_524_PATH: &str = "resources/test/package_version_524.sav";
pub const PACKAGE_VERSION_525_PATH: &str = "resources/test/package_version_525.sav";
pub const PALWORLD_ZLIB_PATH: &str = "resources/test/palworld_zlib.sav";
pub const PALWORLD_ZLIB_TWICE_PATH: &str = "resources/test/palworld_zlib_twice.sav";
pub const PROFILE_0_PATH: &str = "resources/test/Profile_0.sav";
Expand Down
1 change: 1 addition & 0 deletions tests/gvas_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ mod test_cursor;
mod test_file;
mod test_guid;
mod test_property;
mod package_version_525;
38 changes: 38 additions & 0 deletions tests/gvas_tests/package_version_525.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use std::fs::File;
use std::io::{Cursor, Read};
use std::path::Path;
use gvas::game_version::GameVersion;
use gvas::GvasFile;
use crate::common::PACKAGE_VERSION_525_PATH;

#[test]
fn package_version_525() {
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join(PACKAGE_VERSION_525_PATH);
let mut file = File::open(path).expect("Failed to open test asset");

// Read the file in to a Vec<u8>
let mut data = Vec::new();
file.read_to_end(&mut data)
.expect("Failed to read test asset");

// Convert the Vec<u8> to a GvasFile
let mut cursor = Cursor::new(data);
let file =
GvasFile::read(&mut cursor, GameVersion::Default).expect("Failed to parse gvas file");

// Convert the GvasFile back to a Vec<u8>
let mut writer = Cursor::new(Vec::new());
file.write(&mut writer)
.expect("Failed to serialize gvas file");

// Compare the two Vec<u8>s
assert_eq!(cursor.get_ref(), writer.get_ref());

// Read the file back in again
let mut reader = Cursor::new(writer.get_ref().to_owned());
let read_back = GvasFile::read(&mut reader, GameVersion::Default)
.expect("Failed to parse serialized save file");

// Compare the two GvasFiles
assert_eq!(file, read_back);
}

0 comments on commit fcffd61

Please sign in to comment.