diff --git a/ME3Tweaks.Wwiser.Tests/HierarchyTests/BankSourceDataTests.cs b/ME3Tweaks.Wwiser.Tests/HierarchyTests/BankSourceDataTests.cs index bdde557..e8e093d 100644 --- a/ME3Tweaks.Wwiser.Tests/HierarchyTests/BankSourceDataTests.cs +++ b/ME3Tweaks.Wwiser.Tests/HierarchyTests/BankSourceDataTests.cs @@ -7,6 +7,7 @@ public class BankSourceDataTests [TestCase("BSDV134.bin", 134)] [TestCase("BSDV56.bin", 56)] [TestCase("BSDV56_2.bin", 56)] + [TestCase("BSDV56_3.bin", 56)] [TestCase("BSDV44.bin", 44)] public void BankSourceData_Reserializes(string filename, int version) { @@ -14,6 +15,6 @@ public void BankSourceData_Reserializes(string filename, int version) var (_, result) = TestHelpers.Deserialize(data, version); var reserialized = TestHelpers.Serialize(result, version); - Assert.That(reserialized, Is.EqualTo(data.Take(reserialized.Length).ToArray())); + Assert.That(reserialized, Is.EqualTo(data)); } } \ No newline at end of file diff --git a/ME3Tweaks.Wwiser.Tests/HierarchyTests/HierarchyChunkTests.cs b/ME3Tweaks.Wwiser.Tests/HierarchyTests/HierarchyChunkTests.cs index e33cf52..70aecd4 100644 --- a/ME3Tweaks.Wwiser.Tests/HierarchyTests/HierarchyChunkTests.cs +++ b/ME3Tweaks.Wwiser.Tests/HierarchyTests/HierarchyChunkTests.cs @@ -82,4 +82,15 @@ public void SimpleChunk_v134_Parses() }); } } + + [Test] + public void BigChunkTest() + { + var data = TestData.GetTestDataBytes(@"Hierarchy", @"LargeFullChunks", @"HIRC_V56.bin"); + var (serializer, result) = TestHelpers.Deserialize(data, 56); + + var reserialized = TestHelpers.Serialize(result, 56); + TestHelpers.WriteStreamToFile(new MemoryStream(reserialized), TestData.GetTestDataFilePath(@"Hierarchy", @"LargeFullChunks", @"Out56.bin")); + Assert.That(reserialized, Is.EqualTo(data)); + } } \ No newline at end of file diff --git a/ME3Tweaks.Wwiser.Tests/HierarchyTests/RandSeqContainerTests.cs b/ME3Tweaks.Wwiser.Tests/HierarchyTests/RandSeqContainerTests.cs new file mode 100644 index 0000000..fe8bafa --- /dev/null +++ b/ME3Tweaks.Wwiser.Tests/HierarchyTests/RandSeqContainerTests.cs @@ -0,0 +1,18 @@ +using ME3Tweaks.Wwiser.Model.Hierarchy; +using ME3Tweaks.Wwiser.Model.Hierarchy.Enums; + +namespace ME3Tweaks.Wwiser.Tests.HierarchyTests; + +public class RandSeqContainerTests +{ + + [TestCase("RandSeqContainer_V56.bin", 56)] + public void RandSeqContainer_Reserializes(string filename, int version) + { + var data = TestData.GetTestDataBytes(@"Hierarchy",@"RandSeqContainer", filename); + var (_, result) = TestHelpers.Deserialize(data, version); + + var reserialized = TestHelpers.Serialize(result, version); + Assert.That(reserialized, Is.EqualTo(data)); + } +} \ No newline at end of file diff --git a/ME3Tweaks.Wwiser.Tests/TestData/Hierarchy/BankSourceData/BSDV56_3.bin b/ME3Tweaks.Wwiser.Tests/TestData/Hierarchy/BankSourceData/BSDV56_3.bin new file mode 100644 index 0000000..c7a13e2 Binary files /dev/null and b/ME3Tweaks.Wwiser.Tests/TestData/Hierarchy/BankSourceData/BSDV56_3.bin differ diff --git a/ME3Tweaks.Wwiser.Tests/TestData/Hierarchy/LargeFullChunks/HIRC_V56.bin b/ME3Tweaks.Wwiser.Tests/TestData/Hierarchy/LargeFullChunks/HIRC_V56.bin new file mode 100644 index 0000000..344a344 Binary files /dev/null and b/ME3Tweaks.Wwiser.Tests/TestData/Hierarchy/LargeFullChunks/HIRC_V56.bin differ diff --git a/ME3Tweaks.Wwiser.Tests/TestData/Hierarchy/RandSeqContainer/RandSeqContainer_V56.bin b/ME3Tweaks.Wwiser.Tests/TestData/Hierarchy/RandSeqContainer/RandSeqContainer_V56.bin new file mode 100644 index 0000000..7545c35 Binary files /dev/null and b/ME3Tweaks.Wwiser.Tests/TestData/Hierarchy/RandSeqContainer/RandSeqContainer_V56.bin differ diff --git a/ME3Tweaks.Wwiser.Tests/TestHelpers.cs b/ME3Tweaks.Wwiser.Tests/TestHelpers.cs index 60d2446..d2b07a1 100644 --- a/ME3Tweaks.Wwiser.Tests/TestHelpers.cs +++ b/ME3Tweaks.Wwiser.Tests/TestHelpers.cs @@ -43,7 +43,7 @@ public static byte[] Serialize(object data, int version, bool useModulator = fa return Serialize(data, (uint)version, useModulator); } - private static void WriteStreamToFile(Stream stream, string filepath) + public static void WriteStreamToFile(Stream stream, string filepath) { stream.Seek(0, SeekOrigin.Begin); diff --git a/ME3Tweaks.Wwiser.Tests/WwiseBankParserTests.cs b/ME3Tweaks.Wwiser.Tests/WwiseBankParserTests.cs index 7514975..bdf9e73 100644 --- a/ME3Tweaks.Wwiser.Tests/WwiseBankParserTests.cs +++ b/ME3Tweaks.Wwiser.Tests/WwiseBankParserTests.cs @@ -10,15 +10,18 @@ public void OnInstantiation_WithFullBank_ParsesVersionCorrectly(string bankFileN Assert.That(parser.Version, Is.EqualTo(correctVersion)); } - [Test] - public async Task FullBank_V56_Reserializes() + [TestCase("ME3_v56_1.bnk")] + [TestCase("ME3_v56_2.bnk")] + [TestCase("ME3_v56_3.bnk")] + public async Task FullBank_V56_Reserializes(string filename) { - var parser = new WwiseBankParser(TestData.GetTestDataFilePath("WholeBanks", "ME3_v56_2.bnk")); + var parser = new WwiseBankParser(TestData.GetTestDataFilePath("WholeBanks", filename)); await parser.Deserialize(); var stream = new MemoryStream(); await parser.Serialize(stream); - var data = TestData.GetTestDataBytes("WholeBanks", "ME3_v56_2.bnk"); + //TestHelpers.WriteStreamToFile(stream, TestData.GetTestDataFilePath("WholeBanks", "Out1.bnk")); + var data = TestData.GetTestDataBytes("WholeBanks", filename); Assert.That(stream.ToArray(), Is.EquivalentTo(data)); } } \ No newline at end of file diff --git a/ME3Tweaks.Wwiser/Model/Hierarchy/BankSourceData.cs b/ME3Tweaks.Wwiser/Model/Hierarchy/BankSourceData.cs index eaf9ce0..de47609 100644 --- a/ME3Tweaks.Wwiser/Model/Hierarchy/BankSourceData.cs +++ b/ME3Tweaks.Wwiser/Model/Hierarchy/BankSourceData.cs @@ -21,10 +21,10 @@ public class BankSourceData [FieldOrder(3)] public MediaInformation MediaInformation { get; set; } = new(); - /*[FieldOrder(4)] + [FieldOrder(4)] [SerializeWhen(nameof(Plugin), true, ConverterType = typeof(HasPluginParamConverter))] - public PluginParameters PluginParameters { get; set; } = new();*/ + public PluginParameters PluginParameters { get; set; } = new(); } public class AudioFormat diff --git a/ME3Tweaks.Wwiser/Model/Hierarchy/EmptyHircItem.cs b/ME3Tweaks.Wwiser/Model/Hierarchy/EmptyHircItem.cs new file mode 100644 index 0000000..521af40 --- /dev/null +++ b/ME3Tweaks.Wwiser/Model/Hierarchy/EmptyHircItem.cs @@ -0,0 +1,11 @@ +using BinarySerialization; + +namespace ME3Tweaks.Wwiser.Model.Hierarchy; + +public class EmptyHircItem : HircItem +{ + [FieldOrder(0)] + [FieldLength(nameof(HircItemContainer.Size), AncestorType = typeof(HircItemContainer), + RelativeSourceMode = RelativeSourceMode.FindAncestor)] + public byte[] Data { get; set; } = Array.Empty(); +} \ No newline at end of file diff --git a/ME3Tweaks.Wwiser/Model/Hierarchy/HircTypeFactory.cs b/ME3Tweaks.Wwiser/Model/Hierarchy/HircTypeFactory.cs index 2ab0fb3..34bd2e8 100644 --- a/ME3Tweaks.Wwiser/Model/Hierarchy/HircTypeFactory.cs +++ b/ME3Tweaks.Wwiser/Model/Hierarchy/HircTypeFactory.cs @@ -1,5 +1,6 @@ using System.Diagnostics.CodeAnalysis; using BinarySerialization; +using ME3Tweaks.Wwiser.Model.Action; using ME3Tweaks.Wwiser.Model.Hierarchy.Enums; namespace ME3Tweaks.Wwiser.Model.Hierarchy; @@ -65,7 +66,7 @@ public bool TryGetType(object key, [UnscopedRef] out Type type) //HircType.Envelope => //HircType.AudioDevice => //HircType.TimeMod => - _ => typeof(HircItem) + _ => typeof(EmptyHircItem) }; return true; } diff --git a/ME3Tweaks.Wwiser/Model/Hierarchy/RandSeqContainer.cs b/ME3Tweaks.Wwiser/Model/Hierarchy/RandSeqContainer.cs index 3dd4a5d..c27ca34 100644 --- a/ME3Tweaks.Wwiser/Model/Hierarchy/RandSeqContainer.cs +++ b/ME3Tweaks.Wwiser/Model/Hierarchy/RandSeqContainer.cs @@ -47,6 +47,9 @@ public class RandSeqContainer : HircItem [FieldOrder(11)] public Children Children { get; set; } = new(); + + [FieldOrder(12)] + public Playlist Playlist { get; set; } = new(); } public class RanSeqFlags : IBinarySerializable @@ -157,14 +160,18 @@ public void Serialize(Stream stream, Endianness endianness, BinarySerializationC public void Deserialize(Stream stream, Endianness endianness, BinarySerializationContext serializationContext) { var version = serializationContext.FindAncestor().Version; + Span span = stackalloc byte[4]; + var read = stream.Read(span); + if (read != 4) throw new Exception(); + Id = BitConverter.ToUInt32(span); + if (version <= 56) { Weight = stream.ReadByte(); } else { - Span span = stackalloc byte[4]; - var read = stream.Read(span); + read = stream.Read(span); if (read != 4) throw new Exception(); Weight = BitConverter.ToInt32(span); }