From 1aa5ed30edbdc67e76103f0543b37b83b771826a Mon Sep 17 00:00:00 2001 From: Nick Condron Date: Fri, 9 Feb 2024 15:32:56 -0500 Subject: [PATCH] Add support for v3.16 --- gen/resources/frames.json | 6 +++++- src/frame/immutable/mod.rs | 6 ++++++ src/frame/immutable/peppi.rs | 32 ++++++++++++++++++++++++++++++-- src/frame/immutable/slippi.rs | 14 ++++++++++++-- src/frame/mutable.rs | 28 +++++++++++++++++++++++++--- src/frame/transpose.rs | 2 ++ src/io/slippi/mod.rs | 2 +- 7 files changed, 81 insertions(+), 9 deletions(-) diff --git a/gen/resources/frames.json b/gen/resources/frames.json index b58f27a..3fdba75 100644 --- a/gen/resources/frames.json +++ b/gen/resources/frames.json @@ -75,7 +75,11 @@ { "name": "hitlag", "type": "f32", "version": "3.8" }, { "name": "animation_index", "type": "u32", - "version": "3.11" } + "version": "3.11" }, + { "name": "instance_hit_by", "type": "u16", + "version": "3.16" }, + { "name": "instance_id", "type": "u16", + "version": "3.16" } ], "Start": [ { "name": "random_seed", "type": "u32" }, diff --git a/src/frame/immutable/mod.rs b/src/frame/immutable/mod.rs index 9fdf9db..95ab619 100644 --- a/src/frame/immutable/mod.rs +++ b/src/frame/immutable/mod.rs @@ -303,6 +303,8 @@ pub struct Post { pub velocities: Option, pub hitlag: Option>, pub animation_index: Option>, + pub instance_hit_by: Option>, + pub instance_id: Option>, pub validity: Option, } @@ -336,6 +338,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]), + instance_hit_by: self.instance_hit_by.as_ref().map(|x| x.values()[i]), + instance_id: self.instance_id.as_ref().map(|x| x.values()[i]), } } } @@ -364,6 +368,8 @@ impl From 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()), + instance_hit_by: x.instance_hit_by.map(|x| x.into()), + instance_id: x.instance_id.map(|x| x.into()), validity: x.validity.map(|v| v.into()), } } diff --git a/src/frame/immutable/peppi.rs b/src/frame/immutable/peppi.rs index f91ae56..569a74e 100644 --- a/src/frame/immutable/peppi.rs +++ b/src/frame/immutable/peppi.rs @@ -531,7 +531,19 @@ impl Post { "animation_index", DataType::UInt32, false, - )) + )); + if version.gte(3, 16) { + fields.push(Field::new( + "instance_hit_by", + DataType::UInt16, + false, + )); + fields.push(Field::new( + "instance_id", + DataType::UInt16, + false, + )) + } } } } @@ -570,7 +582,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.instance_hit_by.unwrap().boxed()); + values.push(self.instance_id.unwrap().boxed()) + } } } } @@ -702,6 +718,18 @@ impl Post { .unwrap() .clone() }), + instance_hit_by: values.get(21).map(|x| { + x.as_any() + .downcast_ref::>() + .unwrap() + .clone() + }), + instance_id: values.get(22).map(|x| { + x.as_any() + .downcast_ref::>() + .unwrap() + .clone() + }), validity: validity, } } diff --git a/src/frame/immutable/slippi.rs b/src/frame/immutable/slippi.rs index c13e8b9..a4c6108 100644 --- a/src/frame/immutable/slippi.rs +++ b/src/frame/immutable/slippi.rs @@ -295,7 +295,13 @@ impl Post { if version.gte(3, 8) { w.write_f32::(self.hitlag.as_ref().unwrap().value(i))?; if version.gte(3, 11) { - w.write_u32::(self.animation_index.as_ref().unwrap().value(i))? + w.write_u32::(self.animation_index.as_ref().unwrap().value(i))?; + if version.gte(3, 16) { + w.write_u16::( + self.instance_hit_by.as_ref().unwrap().value(i), + )?; + w.write_u16::(self.instance_id.as_ref().unwrap().value(i))? + } } } } @@ -333,7 +339,11 @@ impl Post { if version.gte(3, 8) { size += size_of::(); if version.gte(3, 11) { - size += size_of::() + size += size_of::(); + if version.gte(3, 16) { + size += size_of::(); + size += size_of::() + } } } } diff --git a/src/frame/mutable.rs b/src/frame/mutable.rs index fb7c0c6..6b93b95 100644 --- a/src/frame/mutable.rs +++ b/src/frame/mutable.rs @@ -402,6 +402,8 @@ pub struct Post { pub velocities: Option, pub hitlag: Option>, pub animation_index: Option>, + pub instance_hit_by: Option>, + pub instance_id: Option>, pub validity: Option, } @@ -451,6 +453,12 @@ impl Post { animation_index: version .gte(3, 11) .then(|| MutablePrimitiveArray::::with_capacity(capacity)), + instance_hit_by: version + .gte(3, 16) + .then(|| MutablePrimitiveArray::::with_capacity(capacity)), + instance_id: version + .gte(3, 16) + .then(|| MutablePrimitiveArray::::with_capacity(capacity)), validity: None, } } @@ -490,7 +498,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.instance_hit_by.as_mut().unwrap().push_null(); + self.instance_id.as_mut().unwrap().push_null() + } } } } @@ -534,8 +546,16 @@ impl Post { r.read_f32::() .map(|x| self.hitlag.as_mut().unwrap().push(Some(x)))?; if version.gte(3, 11) { - r.read_u32::() - .map(|x| self.animation_index.as_mut().unwrap().push(Some(x)))? + r.read_u32::().map(|x| { + self.animation_index.as_mut().unwrap().push(Some(x)) + })?; + if version.gte(3, 16) { + r.read_u16::().map(|x| { + self.instance_hit_by.as_mut().unwrap().push(Some(x)) + })?; + r.read_u16::() + .map(|x| self.instance_id.as_mut().unwrap().push(Some(x)))? + } } } } @@ -575,6 +595,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]), + instance_hit_by: self.instance_hit_by.as_ref().map(|x| x.values()[i]), + instance_id: self.instance_id.as_ref().map(|x| x.values()[i]), } } } diff --git a/src/frame/transpose.rs b/src/frame/transpose.rs index cc4857e..39bd473 100644 --- a/src/frame/transpose.rs +++ b/src/frame/transpose.rs @@ -75,6 +75,8 @@ pub struct Post { pub velocities: Option, pub hitlag: Option, pub animation_index: Option, + pub instance_hit_by: Option, + pub instance_id: Option, } #[derive(PartialEq, Clone, Copy, Debug, Default)] diff --git a/src/io/slippi/mod.rs b/src/io/slippi/mod.rs index ba780ac..0dcce05 100644 --- a/src/io/slippi/mod.rs +++ b/src/io/slippi/mod.rs @@ -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] = [