Skip to content

Commit

Permalink
Re-evaluate extra data in ActionType
Browse files Browse the repository at this point in the history
  • Loading branch information
henbagle committed Dec 15, 2023
1 parent 8028bbd commit 8e80518
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 10 deletions.
21 changes: 21 additions & 0 deletions ME3Tweaks.Wwiser.Tests/ConvertTests/ActionConvertTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using ME3Tweaks.Wwiser.BankConversion;
using ME3Tweaks.Wwiser.Model.ParameterNode;
using Action = ME3Tweaks.Wwiser.Model.Hierarchy.Action;

namespace ME3Tweaks.Wwiser.Tests.ConvertTests;

public class ActionTests
{
[Test]
public void Convert56to134_Works()
{
var from = new BankSerializationContext(56);
var to = new BankSerializationContext(134);

var data = TestData.GetTestDataBytes(@"Convert", @"Action", @"SetPitch_V56.bin");
var (_, result) = TestHelpers.Deserialize<Action>(data, 56);

var newData = TestHelpers.Serialize(result, 134);
Assert.That(newData, Is.EquivalentTo(TestData.GetTestDataBytes(@"Convert", @"Action", @"SetPitch_V134.bin")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public void Convert56to134_Works()
[Test]
public void Convert134to56_Works()
{
var from = new BankSerializationContext(134);
var to = new BankSerializationContext(56);

var data = TestData.GetTestDataBytes(@"Convert", @"ParameterNode", @"134.bin");
var (_, result) = TestHelpers.Deserialize<NodeBaseParameters>(data, 134);

var c = new InitialParamsConverter(result);
var from = new BankSerializationContext(134);
var to = new BankSerializationContext(56);
Assert.That(c.ShouldConvert(from, to), Is.True);
c.Convert(from, to);

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
33 changes: 27 additions & 6 deletions ME3Tweaks.Wwiser/Model/Action/ActionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ActionType : IBinarySerializable
public ActionTypeValue Value { get; set; }

[Ignore]
public uint Data { get; set; }
public ActionFlagsUnk Data { get; set; }

public void Serialize(Stream stream, Endianness endianness, BinarySerializationContext serializationContext)
{
Expand All @@ -33,7 +33,8 @@ public void Serialize(Stream stream, Endianness endianness, BinarySerializationC
_ => (byte)Value
};
var shifted = (uint)(output << 12);
var value = shifted | (Data & 0xFFF);

var value = shifted | ((uint)Data & 0xFFF);
stream.Write(BitConverter.GetBytes(value));
}
else
Expand All @@ -45,7 +46,14 @@ public void Serialize(Stream stream, Endianness endianness, BinarySerializationC
_ => (byte)Value
};
var shifted = (ushort)(output << 8);
var value = (ushort)(shifted | (Data & 0xFF));

var flags = Data;
if (flags.HasFlag(ActionFlagsUnk.Unk4))
{
flags &= ~ActionFlagsUnk.Unk4;
flags |= ActionFlagsUnk.Unk1;
}
var value = (ushort)(shifted | ((ushort)flags & 0xFF));
stream.Write(BitConverter.GetBytes(value));
}

Expand All @@ -55,7 +63,6 @@ public void Deserialize(Stream stream, Endianness endianness, BinarySerializatio
{
var version = serializationContext.FindAncestor<BankSerializationContext>().Version;

//var value = (byte)stream.ReadByte();
if (version <= 56)
{
Span<byte> span = stackalloc byte[4];
Expand All @@ -64,7 +71,7 @@ public void Deserialize(Stream stream, Endianness endianness, BinarySerializatio
uint value = BitConverter.ToUInt32(span);

var enumValue = value >> 12;
Data = value & 0xFFF;
Data = (ActionFlagsUnk)(byte)(value & 0xFFF);

Value = enumValue switch
{
Expand All @@ -91,7 +98,12 @@ public void Deserialize(Stream stream, Endianness endianness, BinarySerializatio
ushort value = BitConverter.ToUInt16(span);

var enumValue = value >> 8;
Data = (uint)value & 0xFF;
Data = (ActionFlagsUnk)(byte)(value & 0xFF);
if (Data.HasFlag(ActionFlagsUnk.Unk1))
{
Data &= ~ActionFlagsUnk.Unk1;
Data |= ActionFlagsUnk.Unk4;
}

Value = enumValue switch
{
Expand Down Expand Up @@ -152,4 +164,13 @@ public enum ActionTypeValue : byte
BypassFX5,
BypassFX6,
BypassFX7
}

// TODO: Are these really flags?
[Flags]
public enum ActionFlagsUnk : byte
{
Unk0 = 1 << 0,
Unk1 = 1 << 1,
Unk4 = 1 << 4 // Means the same thing as Unk1 on 56 and below?
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ private void Write3DParams(Stream stream, uint version)
// HoldListener and HoldEmitter are one flag lower on version 132 and lower
if (mode.HasFlag(SpatializationMode.HoldEmitterPosAndOrient))
{
mode &= SpatializationMode.EnableAttenuation;
mode |= SpatializationMode.EnableAttenuation;
mode &= ~SpatializationMode.HoldEmitterPosAndOrient;
}

if (mode.HasFlag(SpatializationMode.HoldListenerOrient))
{
mode &= SpatializationMode.HoldEmitterPosAndOrient;
mode |= SpatializationMode.HoldEmitterPosAndOrient;
mode &= ~SpatializationMode.HoldListenerOrient;
}

Expand Down

0 comments on commit 8e80518

Please sign in to comment.