Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for v3.16 #66

Merged
merged 3 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions gen/resources/frames.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@
{ "name": "hitlag", "type": "f32",
"version": "3.8" },
{ "name": "animation_index", "type": "u32",
"version": "3.11" }
"version": "3.11" },
{ "name": "last_hit_by_instance", "type": "u16",
"version": "3.16" },
{ "name": "instance_id", "type": "u16",
"version": "3.16" }
],
"Start": [
{ "name": "random_seed", "type": "u32" },
Expand Down Expand Up @@ -104,6 +108,8 @@
{ "name": "misc", "type": "ItemMisc",
"version": "3.2" },
{ "name": "owner", "type": "i8",
"version": "3.6" }
"version": "3.6" },
{ "name": "instance_id", "type": "u16",
"version": "3.16" }
]
}
9 changes: 9 additions & 0 deletions src/frame/immutable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pub struct Item {
pub id: PrimitiveArray<u32>,
pub misc: Option<ItemMisc>,
pub owner: Option<PrimitiveArray<i8>>,
pub instance_id: Option<PrimitiveArray<u16>>,
pub validity: Option<Bitmap>,
}

Expand All @@ -207,6 +208,7 @@ impl Item {
id: self.id.values()[i],
misc: self.misc.as_ref().map(|x| x.transpose_one(i, version)),
owner: self.owner.as_ref().map(|x| x.values()[i]),
instance_id: self.instance_id.as_ref().map(|x| x.values()[i]),
}
}
}
Expand All @@ -224,6 +226,7 @@ impl From<mutable::Item> for Item {
id: x.id.into(),
misc: x.misc.map(|x| x.into()),
owner: x.owner.map(|x| x.into()),
instance_id: x.instance_id.map(|x| x.into()),
validity: x.validity.map(|v| v.into()),
}
}
Expand Down Expand Up @@ -303,6 +306,8 @@ pub struct Post {
pub velocities: Option<Velocities>,
pub hitlag: Option<PrimitiveArray<f32>>,
pub animation_index: Option<PrimitiveArray<u32>>,
pub last_hit_by_instance: Option<PrimitiveArray<u16>>,
pub instance_id: Option<PrimitiveArray<u16>>,
pub validity: Option<Bitmap>,
}

Expand Down Expand Up @@ -336,6 +341,8 @@ impl Post {
.map(|x| x.transpose_one(i, version)),
hitlag: self.hitlag.as_ref().map(|x| x.values()[i]),
animation_index: self.animation_index.as_ref().map(|x| x.values()[i]),
last_hit_by_instance: self.last_hit_by_instance.as_ref().map(|x| x.values()[i]),
instance_id: self.instance_id.as_ref().map(|x| x.values()[i]),
}
}
}
Expand Down Expand Up @@ -364,6 +371,8 @@ impl From<mutable::Post> for Post {
velocities: x.velocities.map(|x| x.into()),
hitlag: x.hitlag.map(|x| x.into()),
animation_index: x.animation_index.map(|x| x.into()),
last_hit_by_instance: x.last_hit_by_instance.map(|x| x.into()),
instance_id: x.instance_id.map(|x| x.into()),
validity: x.validity.map(|v| v.into()),
}
}
Expand Down
48 changes: 44 additions & 4 deletions src/frame/immutable/peppi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ impl Item {
if version.gte(3, 2) {
fields.push(Field::new("misc", ItemMisc::data_type(version), false));
if version.gte(3, 6) {
fields.push(Field::new("owner", DataType::Int8, false))
fields.push(Field::new("owner", DataType::Int8, false));
if version.gte(3, 16) {
fields.push(Field::new("instance_id", DataType::UInt16, false))
}
}
}
};
Expand All @@ -328,7 +331,10 @@ impl Item {
if version.gte(3, 2) {
values.push(self.misc.unwrap().into_struct_array(version).boxed());
if version.gte(3, 6) {
values.push(self.owner.unwrap().boxed())
values.push(self.owner.unwrap().boxed());
if version.gte(3, 16) {
values.push(self.instance_id.unwrap().boxed())
}
}
};
StructArray::new(Self::data_type(version), values, self.validity)
Expand Down Expand Up @@ -395,6 +401,12 @@ impl Item {
.unwrap()
.clone()
}),
instance_id: values.get(10).map(|x| {
x.as_any()
.downcast_ref::<PrimitiveArray<u16>>()
.unwrap()
.clone()
}),
validity: validity,
}
}
Expand Down Expand Up @@ -531,7 +543,19 @@ impl Post {
"animation_index",
DataType::UInt32,
false,
))
));
if version.gte(3, 16) {
fields.push(Field::new(
"last_hit_by_instance",
DataType::UInt16,
false,
));
fields.push(Field::new(
"instance_id",
DataType::UInt16,
false,
))
}
}
}
}
Expand Down Expand Up @@ -570,7 +594,11 @@ impl Post {
if version.gte(3, 8) {
values.push(self.hitlag.unwrap().boxed());
if version.gte(3, 11) {
values.push(self.animation_index.unwrap().boxed())
values.push(self.animation_index.unwrap().boxed());
if version.gte(3, 16) {
values.push(self.last_hit_by_instance.unwrap().boxed());
values.push(self.instance_id.unwrap().boxed())
}
}
}
}
Expand Down Expand Up @@ -702,6 +730,18 @@ impl Post {
.unwrap()
.clone()
}),
last_hit_by_instance: values.get(21).map(|x| {
x.as_any()
.downcast_ref::<PrimitiveArray<u16>>()
.unwrap()
.clone()
}),
instance_id: values.get(22).map(|x| {
x.as_any()
.downcast_ref::<PrimitiveArray<u16>>()
.unwrap()
.clone()
}),
validity: validity,
}
}
Expand Down
24 changes: 20 additions & 4 deletions src/frame/immutable/slippi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ impl Item {
if version.gte(3, 2) {
self.misc.as_ref().unwrap().write(w, version, i)?;
if version.gte(3, 6) {
w.write_i8(self.owner.as_ref().unwrap().value(i))?
w.write_i8(self.owner.as_ref().unwrap().value(i))?;
if version.gte(3, 16) {
w.write_u16::<BE>(self.instance_id.as_ref().unwrap().value(i))?
}
}
};
Ok(())
Expand All @@ -220,7 +223,10 @@ impl Item {
if version.gte(3, 2) {
size += ItemMisc::size(version);
if version.gte(3, 6) {
size += size_of::<i8>()
size += size_of::<i8>();
if version.gte(3, 16) {
size += size_of::<u16>()
}
}
};
size
Expand Down Expand Up @@ -295,7 +301,13 @@ impl Post {
if version.gte(3, 8) {
w.write_f32::<BE>(self.hitlag.as_ref().unwrap().value(i))?;
if version.gte(3, 11) {
w.write_u32::<BE>(self.animation_index.as_ref().unwrap().value(i))?
w.write_u32::<BE>(self.animation_index.as_ref().unwrap().value(i))?;
if version.gte(3, 16) {
w.write_u16::<BE>(
self.last_hit_by_instance.as_ref().unwrap().value(i),
)?;
w.write_u16::<BE>(self.instance_id.as_ref().unwrap().value(i))?
}
}
}
}
Expand Down Expand Up @@ -333,7 +345,11 @@ impl Post {
if version.gte(3, 8) {
size += size_of::<f32>();
if version.gte(3, 11) {
size += size_of::<u32>()
size += size_of::<u32>();
if version.gte(3, 16) {
size += size_of::<u16>();
size += size_of::<u16>()
}
}
}
}
Expand Down
44 changes: 39 additions & 5 deletions src/frame/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ pub struct Item {
pub id: MutablePrimitiveArray<u32>,
pub misc: Option<ItemMisc>,
pub owner: Option<MutablePrimitiveArray<i8>>,
pub instance_id: Option<MutablePrimitiveArray<u16>>,
pub validity: Option<MutableBitmap>,
}

Expand All @@ -226,6 +227,9 @@ impl Item {
owner: version
.gte(3, 6)
.then(|| MutablePrimitiveArray::<i8>::with_capacity(capacity)),
instance_id: version
.gte(3, 16)
.then(|| MutablePrimitiveArray::<u16>::with_capacity(capacity)),
validity: None,
}
}
Expand All @@ -250,7 +254,10 @@ impl Item {
if version.gte(3, 2) {
self.misc.as_mut().unwrap().push_null(version);
if version.gte(3, 6) {
self.owner.as_mut().unwrap().push_null()
self.owner.as_mut().unwrap().push_null();
if version.gte(3, 16) {
self.instance_id.as_mut().unwrap().push_null()
}
}
}
}
Expand All @@ -268,7 +275,11 @@ impl Item {
self.misc.as_mut().unwrap().read_push(r, version)?;
if version.gte(3, 6) {
r.read_i8()
.map(|x| self.owner.as_mut().unwrap().push(Some(x)))?
.map(|x| self.owner.as_mut().unwrap().push(Some(x)))?;
if version.gte(3, 16) {
r.read_u16::<BE>()
.map(|x| self.instance_id.as_mut().unwrap().push(Some(x)))?
}
}
};
self.validity.as_mut().map(|v| v.push(true));
Expand All @@ -287,6 +298,7 @@ impl Item {
id: self.id.values()[i],
misc: self.misc.as_ref().map(|x| x.transpose_one(i, version)),
owner: self.owner.as_ref().map(|x| x.values()[i]),
instance_id: self.instance_id.as_ref().map(|x| x.values()[i]),
}
}
}
Expand Down Expand Up @@ -402,6 +414,8 @@ pub struct Post {
pub velocities: Option<Velocities>,
pub hitlag: Option<MutablePrimitiveArray<f32>>,
pub animation_index: Option<MutablePrimitiveArray<u32>>,
pub last_hit_by_instance: Option<MutablePrimitiveArray<u16>>,
pub instance_id: Option<MutablePrimitiveArray<u16>>,
pub validity: Option<MutableBitmap>,
}

Expand Down Expand Up @@ -451,6 +465,12 @@ impl Post {
animation_index: version
.gte(3, 11)
.then(|| MutablePrimitiveArray::<u32>::with_capacity(capacity)),
last_hit_by_instance: version
.gte(3, 16)
.then(|| MutablePrimitiveArray::<u16>::with_capacity(capacity)),
instance_id: version
.gte(3, 16)
.then(|| MutablePrimitiveArray::<u16>::with_capacity(capacity)),
validity: None,
}
}
Expand Down Expand Up @@ -490,7 +510,11 @@ impl Post {
if version.gte(3, 8) {
self.hitlag.as_mut().unwrap().push_null();
if version.gte(3, 11) {
self.animation_index.as_mut().unwrap().push_null()
self.animation_index.as_mut().unwrap().push_null();
if version.gte(3, 16) {
self.last_hit_by_instance.as_mut().unwrap().push_null();
self.instance_id.as_mut().unwrap().push_null()
}
}
}
}
Expand Down Expand Up @@ -534,8 +558,16 @@ impl Post {
r.read_f32::<BE>()
.map(|x| self.hitlag.as_mut().unwrap().push(Some(x)))?;
if version.gte(3, 11) {
r.read_u32::<BE>()
.map(|x| self.animation_index.as_mut().unwrap().push(Some(x)))?
r.read_u32::<BE>().map(|x| {
self.animation_index.as_mut().unwrap().push(Some(x))
})?;
if version.gte(3, 16) {
r.read_u16::<BE>().map(|x| {
self.last_hit_by_instance.as_mut().unwrap().push(Some(x))
})?;
r.read_u16::<BE>()
.map(|x| self.instance_id.as_mut().unwrap().push(Some(x)))?
}
}
}
}
Expand Down Expand Up @@ -575,6 +607,8 @@ impl Post {
.map(|x| x.transpose_one(i, version)),
hitlag: self.hitlag.as_ref().map(|x| x.values()[i]),
animation_index: self.animation_index.as_ref().map(|x| x.values()[i]),
last_hit_by_instance: self.last_hit_by_instance.as_ref().map(|x| x.values()[i]),
instance_id: self.instance_id.as_ref().map(|x| x.values()[i]),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/frame/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct Item {
pub id: u32,
pub misc: Option<ItemMisc>,
pub owner: Option<i8>,
pub instance_id: Option<u16>,
}

#[derive(PartialEq, Clone, Copy, Debug, Default)]
Expand Down Expand Up @@ -75,6 +76,8 @@ pub struct Post {
pub velocities: Option<Velocities>,
pub hitlag: Option<f32>,
pub animation_index: Option<u32>,
pub last_hit_by_instance: Option<u16>,
pub instance_id: Option<u16>,
}

#[derive(PartialEq, Clone, Copy, Debug, Default)]
Expand Down
2 changes: 1 addition & 1 deletion src/io/slippi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use ser::write;
/// We can read replays with higher versions than this, but that discards information.
/// We don't support writing these replays as a result, though this restriction may be
/// relaxed in the future.
pub const MAX_SUPPORTED_VERSION: Version = Version(3, 15, 0);
pub const MAX_SUPPORTED_VERSION: Version = Version(3, 16, 0);

/// Every .slp file will start with a UBJSON opening brace, `raw` key & type: "{U\x03raw[$U#l"
pub const FILE_SIGNATURE: [u8; 11] = [
Expand Down
Binary file added tests/data/v3.16.slp
Binary file not shown.
Loading
Loading