Skip to content

Commit

Permalink
Handle the new data type in the EOS update
Browse files Browse the repository at this point in the history
  • Loading branch information
kythyria committed Jun 11, 2023
1 parent ef82533 commit edfc0d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 61 deletions.
57 changes: 2 additions & 55 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ steam = { path = "./steam" }
scriptdata = { path = "./scriptdata" }
gc = { version = "0.4.1", features = ["derive"] }
itertools = "0.10.5"
chumsky = "0.9.2"
proc-macro2 = { version = "1.0.60", features = ["span-locations"] }
syn = "2.0.18"
# miette = "5.9.0"

[workspace]
members = [ "xmlparser", "blender/fdm_python", "macros", "bundlefs", "steam", "scriptdata" ]
Expand Down
18 changes: 14 additions & 4 deletions src/formats/player_save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pub enum DataItem {
Byte(u8),
Short(u16),
Bool(bool),
Dictionary(HashMap<DataItem, DataItem>)
Dictionary(HashMap<DataItem, DataItem>),
Unknown9([u8; 12])
}
impl PartialEq for DataItem {
fn eq(&self, other: &Self) -> bool {
Expand All @@ -37,6 +38,7 @@ impl PartialEq for DataItem {
(Self::Short(l0), Self::Short(r0)) => l0 == r0,
(Self::Bool(l0), Self::Bool(r0)) => l0 == r0,
(Self::Dictionary(l0), Self::Dictionary(r0)) => l0 == r0,
(Self::Unknown9(l0), Self::Unknown9(r0)) => l0 == r0,
_ => core::mem::discriminant(self) == core::mem::discriminant(other),
}
}
Expand Down Expand Up @@ -67,6 +69,7 @@ impl std::hash::Hash for DataItem {
v.hash(state);
}
},
DataItem::Unknown9(b) => b.hash(state)
}
}
}
Expand Down Expand Up @@ -112,12 +115,13 @@ fn read_datablock(bytes: &mut &[u8]) -> Result<Vec<u8>> {
ensure!(block_version == 10, "Unknown datablock version");
let body_size = block_size - 16 - 4; // 16 bytes of checksum at the end, 4 bytes of size, length doesn't count
let (body, rest) = bytes.split_at(body_size as usize);
let (checksum, rest) = rest.split_at(16);
let (_checksum, rest) = rest.split_at(16);
*bytes = rest;
Ok(body.to_owned())
}

fn read_item(bytes: &mut &[u8]) -> Result<DataItem> {
let item_addr = bytes.as_ptr();
let tag: u8 = bytes.read_item().context("Failed to read tag")?;
let res = match tag {
1 => read_string(bytes).context("Failed to read string")?,
Expand All @@ -126,8 +130,9 @@ fn read_item(bytes: &mut &[u8]) -> Result<DataItem> {
4 => DataItem::Byte(bytes.read_item::<u8>().context("Failed to read byte")?),
5 => DataItem::Short(bytes.read_item::<u16>().context("Failed to read short")?),
6 => DataItem::Bool(bytes.read_item::<bool>().context("Failed to read bool")?),
7 => DataItem::Dictionary(read_dictionary(bytes).context("Failed to read dictionary")?),
_ => bail!("Invalid tag ({})", tag)
7 => DataItem::Dictionary(read_dictionary(bytes).context(format!("Failed to read dictionary @ {:p}", item_addr))?),
9 => DataItem::Unknown9(bytes.read_item().context(format!("Failed to read Unknown9 @ {:p}", item_addr))?),
_ => bail!("Invalid tag {} @ {:p}", tag, item_addr)
};
Ok(res)
}
Expand Down Expand Up @@ -222,6 +227,11 @@ impl From<&DataItem> for crate::notation_rs::Item {
}
Item::Compound(c)
},
DataItem::Unknown9(b) => {
let mut c = Compound::new_parenthesized().with_tag("Unknown9");
c.push_indexed(Item::new_binary(&*b));
Item::Compound(c)
}
}
}
}

0 comments on commit edfc0d8

Please sign in to comment.