Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
henbagle committed Sep 8, 2024
2 parents a84e732 + 2d0b56b commit 2d0b096
Show file tree
Hide file tree
Showing 26 changed files with 380 additions and 46 deletions.
2 changes: 1 addition & 1 deletion BinarySerializer
18 changes: 14 additions & 4 deletions ME3Tweaks.Wwiser.Tests/ChunkTests/BankHeaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace ME3Tweaks.Wwiser.Tests.ChunkTests;
public class BankHeaderTests
{
[Test]
public void V134_Parses()
public void BKHD_V134_Parses()
{
var data = TestData.GetTestDataBytes(@"BankHeader",@"v134.bin");
var (_, result) = TestHelpers.Deserialize<ChunkContainer>(data, 134);
Expand All @@ -25,7 +25,7 @@ public void V134_Parses()
}

[Test]
public void V56_Parses()
public void BKHD_V56_Parses()
{
var data = TestData.GetTestDataBytes(@"BankHeader",@"v56.bin");
var (_, result) = TestHelpers.Deserialize<ChunkContainer>(data, 56);
Expand All @@ -48,12 +48,22 @@ public void V56_Parses()
}

[Test]
public void V134_Reserializes()
public void BKHD_V134_Reserializes()
{
var data = TestData.GetTestDataBytes(@"BankHeader",@"v134.bin");
var (_, result) = TestHelpers.Deserialize<ChunkContainer>(data, 134);

var reserialized = TestHelpers.Serialize(result, 134);
Assert.That(reserialized, Is.EqualTo(data));
Assert.That(reserialized, Is.EquivalentTo(data));
}

[Test]
public void BKHD_V56_Reserializes()
{
var data = TestData.GetTestDataBytes(@"BankHeader",@"v56.bin");
var (_, result) = TestHelpers.Deserialize<ChunkContainer>(data, 56);

var reserialized = TestHelpers.Serialize(result, 56);
Assert.That(reserialized, Is.EquivalentTo(data));
}
}
6 changes: 3 additions & 3 deletions ME3Tweaks.Wwiser.Tests/ChunkTests/MediaIndexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class MediaIndexTests
{
[Test]
public void V134_Parses()
public void DIDX_V134_Parses()
{
var data = TestData.GetTestDataBytes(@"MediaIndex",@"DIDXv134.bin");
var (_, result) = TestHelpers.Deserialize<ChunkContainer>(data, 134);
Expand All @@ -29,12 +29,12 @@ public void V134_Parses()
}

[Test]
public void V134_Reserializes()
public void DIDX_V134_Reserializes()
{
var data = TestData.GetTestDataBytes(@"MediaIndex",@"DIDXv134.bin");
var (_, result) = TestHelpers.Deserialize<ChunkContainer>(data, 134);

var reserialized = TestHelpers.Serialize(result, 134);
Assert.That(reserialized, Is.EqualTo(data));
Assert.That(reserialized, Is.EquivalentTo(data));
}
}
6 changes: 3 additions & 3 deletions ME3Tweaks.Wwiser.Tests/ChunkTests/StringMappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class StringMappingTests
{
[Test]
public void V56_Parses()
public void STID_V56_Parses()
{
var data = TestData.GetTestDataBytes(@"StringMapping",@"STIDv56.bin");
var (_, result) = TestHelpers.Deserialize<ChunkContainer>(data, 56);
Expand All @@ -29,12 +29,12 @@ public void V56_Parses()
}

[Test]
public void V56_Reserializes()
public void STID_V56_Reserializes()
{
var data = TestData.GetTestDataBytes(@"StringMapping",@"STIDv56.bin");
var (_, result) = TestHelpers.Deserialize<ChunkContainer>(data, 56);

var reserialized = TestHelpers.Serialize(result, 56);
Assert.That(reserialized, Is.EqualTo(data));
Assert.That(reserialized, Is.EquivalentTo(data));
}
}
4 changes: 2 additions & 2 deletions ME3Tweaks.Wwiser.Tests/ConvertTests/ActionConvertTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ME3Tweaks.Wwiser.Tests.ConvertTests;
public class ActionTests
{
[Test]
public void Convert56to134_Works()
public void ConvertActionItem_56to134_Works()
{
var from = new BankSerializationContext(56);
var to = new BankSerializationContext(134);
Expand All @@ -18,7 +18,7 @@ public void Convert56to134_Works()
}

[Test]
public void Convert134to56_Works()
public void ConvertActionItem_134to56_Works()
{
var from = new BankSerializationContext(134);
var to = new BankSerializationContext(56);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ME3Tweaks.Wwiser.Tests.ConvertTests;
public class ActorMixerConvertTests
{
[Test]
public void Convert56to134_Works()
public void ConvertActorMixer_56to134_Works()
{
var from = new BankSerializationContext(56);
var to = new BankSerializationContext(134);
Expand Down
6 changes: 3 additions & 3 deletions ME3Tweaks.Wwiser.Tests/ConvertTests/HircChunkConvertTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ME3Tweaks.Wwiser.Tests.ConvertTests;
public class HircChunkConvertTests
{
[Test]
public void Convert56to134_Works()
public void ConvertHircChunk_56to134_ReturnsCorrectDataLength()
{
var from = new BankSerializationContext(56);
var to = new BankSerializationContext(134);
Expand All @@ -22,8 +22,8 @@ public void Convert56to134_Works()
var data134 = TestData.GetTestDataBytes(@"Convert", @"HIRC", @"134.bin");
Assert.That(newData.Length, Is.EqualTo(data134.Length));

var outfile = TestData.GetTestDataFilePath("Convert", "HIRC", "Out134");
/*var outfile = TestData.GetTestDataFilePath("Convert", "HIRC", "Out134");
File.WriteAllText(outfile, string.Empty); // Wipe out file
TestHelpers.WriteStreamToFile(new MemoryStream(newData), outfile);
TestHelpers.WriteStreamToFile(new MemoryStream(newData), outfile);*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ME3Tweaks.Wwiser.Tests.ConvertTests;
public class ParameterNodeConvertTests
{
[Test]
public void Convert56to134_Works()
public void ConvertParameterNode_56to134_Works()
{
var from = new BankSerializationContext(56);
var to = new BankSerializationContext(134);
Expand All @@ -23,7 +23,7 @@ public void Convert56to134_Works()
}

[Test]
public void Convert134to56_Works()
public void ConvertParameterNode_134to56_Works()
{
var from = new BankSerializationContext(134);
var to = new BankSerializationContext(56);
Expand Down
39 changes: 39 additions & 0 deletions ME3Tweaks.Wwiser.Tests/FormatTests/BankHeaderPaddingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace ME3Tweaks.Wwiser.Tests.FormatTests;

public class BankHeaderPaddingTests
{
[TestCase(8)]
[TestCase(24)]
[TestCase(0x158)]
public void DataProperlyAligned_PaddingIsZero(long dataOffset)
{
var padding = new BankHeaderPadding();
padding.SetPadding(dataOffset);

Assert.That(padding.Padding.Length, Is.EqualTo(0));
}

[TestCase(0, 8)]
[TestCase(4, 4)]
[TestCase(33, 7)]
public void DataNotAligned_PaddingAlignsProperly(long dataOffset, long expectedPadding)
{
var padding = new BankHeaderPadding();
padding.SetPadding(dataOffset);

Assert.That(padding.Padding.Length, Is.LessThanOrEqualTo(8));
Assert.That(padding.Padding.Length, Is.EqualTo(expectedPadding));
}

[TestCase(15, 9)]
[TestCase(12, 12)]
[TestCase(0x15E, 10)]
public void DataNotAligned_PaddingProperlyOffsetBy8(long dataOffset, long expectedPadding)
{
var padding = new BankHeaderPadding();
padding.SetPadding(dataOffset);

Assert.That(padding.Padding.Length, Is.GreaterThan(8));
Assert.That(padding.Padding.Length, Is.EqualTo(expectedPadding));
}
}
2 changes: 1 addition & 1 deletion ME3Tweaks.Wwiser.Tests/FormatTests/UniTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class UniTests
[TestCase(new byte[] {0x0, 0x0, 0xC0, 0xC0 })]
[TestCase(new byte[] {0x0, 0x0, 0x40, 0xC1 })]
[TestCase(new byte[] {0xBF, 0x65, 0xD7, 0x17 })]
public void UniReserializes(byte[] data)
public void Uni_ReserializesSameBytes(byte[] data)
{
var (_, result) = TestHelpers.Deserialize<Uni>(data, 113);
var reserialized = TestHelpers.Serialize(result, 113);
Expand Down
20 changes: 16 additions & 4 deletions ME3Tweaks.Wwiser.Tests/HierarchyTests/HierarchyChunkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ namespace ME3Tweaks.Wwiser.Tests.HierarchyTests;

public class HierarchyChunkTests
{
[TestCase("HIRCv44.bin", 44)]
[TestCase("HIRCv56.bin", 56)]
[TestCase("HIRCv134.bin", 134)]
public void SimpleHircChunk_Reserializes(string fileName, int version)
{
var data = TestData.GetTestDataBytes(@"Hierarchy", @"SmallFullChunks", fileName);
var (serializer, result) = TestHelpers.Deserialize<ChunkContainer>(data, version);

var reserialized = TestHelpers.Serialize(result, version);
Assert.That(reserialized, Is.EquivalentTo(data));
}

[Test]
public void SimpleChunk_v44_Parses()
public void SimpleHircChunk_v44_Parses()
{
var data = TestData.GetTestDataBytes(@"Hierarchy", @"SmallFullChunks", @"HIRCv44.bin");
var (serializer, result) = TestHelpers.Deserialize<ChunkContainer>(data, 44);
Expand All @@ -32,7 +44,7 @@ public void SimpleChunk_v44_Parses()
}

[Test]
public void SimpleChunk_v56_Parses()
public void SimpleHircChunk_v56_Parses()
{
var data = TestData.GetTestDataBytes(@"Hierarchy", @"SmallFullChunks", @"HIRCv56.bin");
var (serializer, result) = TestHelpers.Deserialize<ChunkContainer>(data, 56);
Expand All @@ -58,7 +70,7 @@ public void SimpleChunk_v56_Parses()
}

[Test]
public void SimpleChunk_v134_Parses()
public void SimpleHircChunk_v134_Parses()
{
var data = TestData.GetTestDataBytes(@"Hierarchy", @"SmallFullChunks", @"HIRCv134.bin");
var (serializer, result) = TestHelpers.Deserialize<ChunkContainer>(data, 134);
Expand All @@ -84,7 +96,7 @@ public void SimpleChunk_v134_Parses()
}

[Test]
public void BigChunkTest()
public void BigHircChunk_Reserializes()
{
var data = TestData.GetTestDataBytes(@"Hierarchy", @"LargeFullChunks", @"HIRC_V56.bin");
var (serializer, result) = TestHelpers.Deserialize<ChunkContainer>(data, 56);
Expand Down
2 changes: 1 addition & 1 deletion ME3Tweaks.Wwiser.Tests/HierarchyTests/StateChunkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class StateChunkTests
{
[TestCase(new byte[] {00, 00}, 134)]
[TestCase(new byte[] {00, 00, 00, 00}, 120)]
public void Empty_MultipleVersions_Parses(byte[] data, int version)
public void EmptyStateChunk_MultipleVersions_Parses(byte[] data, int version)
{
var (_, result) = TestHelpers.Deserialize<StateChunk>(data, version);

Expand Down
16 changes: 16 additions & 0 deletions ME3Tweaks.Wwiser.Tests/HierarchyTests/SwitchContainerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ME3Tweaks.Wwiser.Model.Hierarchy;

namespace ME3Tweaks.Wwiser.Tests.HierarchyTests;

public class SwitchContainerTests
{
[TestCase("SwitchContainer_V56.bin", 56)]
public void SwitchContainer_Reserializes(string filename, int version)
{
var data = TestData.GetTestDataBytes(@"Hierarchy",@"SwitchContainer", filename);
var (_, result) = TestHelpers.Deserialize<SwitchContainer>(data, version);

var reserialized = TestHelpers.Serialize(result, version);
Assert.That(reserialized, Is.EquivalentTo(data));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class AdvSettingsTests
{
[TestCase("Empty_V134.bin", 134)]
[TestCase("Empty_V44.bin", 44)]
public void Empty_MultipleVersions_Reserializes(string file, int version)
public void EmptyAdvSettings_MultipleVersions_Reserializes(string file, int version)
{
var data = TestData.GetTestDataBytes(@"ParameterNode",@"AdvSettings", file);
var (_, result) = TestHelpers.Deserialize<AdvSettingsParams>(data, version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class FullParameterNode
{
[TestCase("A_V134.bin", 134)]
[TestCase("A_V56.bin", 56)]
public void Full_MultipleVersions_Reserializes(string file, int version)
public void FullParameterNode_MultipleVersions_Reserializes(string file, int version)
{
var data = TestData.GetTestDataBytes(@"ParameterNode", file);
var (_, result) = TestHelpers.Deserialize<NodeBaseParameters>(data, version);
Expand Down
Binary file not shown.
25 changes: 19 additions & 6 deletions ME3Tweaks.Wwiser.Tests/WwiseBankParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,42 @@ public void OnInstantiation_WithFullBank_ParsesVersionCorrectly(string bankFileN
Assert.That(parser.Version, Is.EqualTo(correctVersion));
}

[Test]
public void FullBank_Reserializes_Synchronous()
{
var parser = new WwiseBankParser(TestData.GetTestDataFilePath("WholeBanks", "ME3_v56_1.bnk"));
parser.Deserialize();

var stream = new MemoryStream();
parser.SerializeTo(stream);
//TestHelpers.WriteStreamToFile(stream, TestData.GetTestDataFilePath("WholeBanks", "Out1.bnk"));
var data = TestData.GetTestDataBytes("WholeBanks", "ME3_v56_1.bnk");
Assert.That(stream.ToArray(), Is.EquivalentTo(data));
}

[TestCase("ME3_v56_1.bnk")]
[TestCase("ME3_v56_2.bnk")]
[TestCase("ME3_v56_3.bnk")]
public async Task FullBank_V56_Reserializes(string filename)
public async Task FullBank_V56_Reserializes_Async(string filename)
{
var parser = new WwiseBankParser(TestData.GetTestDataFilePath("WholeBanks", filename));
await parser.Deserialize();
await parser.DeserializeAsync();

var stream = new MemoryStream();
await parser.Serialize(stream);
await parser.SerializeToAsync(stream);
//TestHelpers.WriteStreamToFile(stream, TestData.GetTestDataFilePath("WholeBanks", "Out1.bnk"));
var data = TestData.GetTestDataBytes("WholeBanks", filename);
Assert.That(stream.ToArray(), Is.EquivalentTo(data));
}

[TestCase("LE3_v134_1.bnk")] // TODO: What is at the end of this file?
public async Task FullBank_V134_Reserializes(string filename)
public async Task FullBank_V134_Reserializes_Async(string filename)
{
var parser = new WwiseBankParser(TestData.GetTestDataFilePath("WholeBanks", filename));
await parser.Deserialize();
await parser.DeserializeAsync();

var stream = new MemoryStream();
await parser.Serialize(stream);
await parser.SerializeToAsync(stream);
//TestHelpers.WriteStreamToFile(stream, TestData.GetTestDataFilePath("WholeBanks", "Out1.bnk"));
var data = TestData.GetTestDataBytes("WholeBanks", filename);
var outData = stream.ToArray();
Expand Down
12 changes: 8 additions & 4 deletions ME3Tweaks.Wwiser/BankConversion/AttenuationConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ public class AttenuationConverter(BankSerializationContext from, BankSerializati
{
public void Convert(Attenuation item)
{
item.Curves.Insert(2, item.Curves[1].Clone());
item.CurveToUse.CurveMap[2] = 2;
for(var i = 3; i < item.CurveToUse.CurveMap.Length; i++)
if (item.Curves.Count >= 2)
{
if (item.CurveToUse.CurveMap[i] > -1) item.CurveToUse.CurveMap[i]++;
item.Curves.Insert(2, item.Curves[1].Clone());
item.CurveToUse.CurveMap[2] = 2;
for(var i = 3; i < item.CurveToUse.CurveMap.Length; i++)
{
if (item.CurveToUse.CurveMap[i] > -1) item.CurveToUse.CurveMap[i]++;
}
}

foreach (var c in item.Curves)
{
// Could be mass effect le only
RtpcConverter.ConvertRtpcFloatLt0(c);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ME3Tweaks.Wwiser/Model/Action/Specific/SetGameParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ME3Tweaks.Wwiser.Model.Action.Specific;

public class SetGameParameter
public class SetGameParameter : ISpecificParams
{
[FieldOrder(0)]
[SerializeWhenVersion(89, ComparisonOperator.GreaterThan)]
Expand Down
Loading

0 comments on commit 2d0b096

Please sign in to comment.