Skip to content

Commit

Permalink
First pass on RandSeqContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
henbagle committed Dec 9, 2023
1 parent ad39dac commit 16eb7ca
Show file tree
Hide file tree
Showing 7 changed files with 408 additions and 8 deletions.
37 changes: 37 additions & 0 deletions ME3Tweaks.Wwiser.Tests/ActionTests/ActionTypeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using ME3Tweaks.Wwiser.Model.Action;

namespace ME3Tweaks.Wwiser.Tests.ActionTests;

public class ActionTypeTests
{
[TestCase(0x01, ActionTypeValue.Stop)]
[TestCase(0x09, ActionTypeValue.SetPitch2)]
[TestCase(0x0A, ActionTypeValue.SetBusVolume1)]
[TestCase(0x0C, ActionTypeValue.SetLFE1)]
[TestCase(0x0E, ActionTypeValue.SetLPF1)]
public void ActionTypeParsesAndReserializes_V56(int hex, ActionTypeValue expected)
{
var (_, result) = TestHelpers.Deserialize<ActionType>((byte)hex, 56);
Assert.That(result.Value, Is.EqualTo(expected));

var reserialized = TestHelpers.Serialize(result, 56);
Assert.That(reserialized[0], Is.EqualTo(hex));
}

[TestCase(0x01, ActionTypeValue.Stop)]
[TestCase(0x09, ActionTypeValue.SetPitch2)]
[TestCase(0x0A, ActionTypeValue.SetNone1)]
[TestCase(0x0B, ActionTypeValue.SetNone2)]
[TestCase(0x0C, ActionTypeValue.SetBusVolume1)]
[TestCase(0x0E, ActionTypeValue.SetLPF1)]
[TestCase(0x19, ActionTypeValue.SetSwitch)]
[TestCase(0x1A, ActionTypeValue.BypassFX1)]
public void ActionTypeParsesAndReserializes_V72(byte hex, ActionTypeValue expected)
{
var (_, result) = TestHelpers.Deserialize<ActionType>(hex, 72);
Assert.That(result.Value, Is.EqualTo(expected));

var reserialized = TestHelpers.Serialize(result, 72);
Assert.That(reserialized[0], Is.EqualTo(hex));
}
}
4 changes: 4 additions & 0 deletions ME3Tweaks.Wwiser/ME3Tweaks.Wwiser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Model\Bus\" />
</ItemGroup>

</Project>
129 changes: 129 additions & 0 deletions ME3Tweaks.Wwiser/Model/Action/ActionType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using BinarySerialization;

namespace ME3Tweaks.Wwiser.Model.Action;

public class ActionType : IBinarySerializable
{
[Ignore]
public ActionTypeValue Value { get; set; }

public void Serialize(Stream stream, Endianness endianness, BinarySerializationContext serializationContext)
{
var version = serializationContext.FindAncestor<BankSerializationContext>().Version;
byte output;
if (version <= 65)
{
output = Value switch
{
ActionTypeValue.Event1 => 0x20,
ActionTypeValue.Event2 => 0x30,
ActionTypeValue.Event3 => 0x40,
ActionTypeValue.Duck => 0x50,
ActionTypeValue.SetSwitch => 0x60,
ActionTypeValue.SetRTPC => 0x61,
ActionTypeValue.BypassFX1 => 0x70,
ActionTypeValue.BypassFX2 => 0x80,
ActionTypeValue.Break => 0x90,
ActionTypeValue.Trigger => 0xA0,
ActionTypeValue.Seek => 0xB0,
>= ActionTypeValue.SetBusVolume1 => (byte)(Value - 2),
_ => (byte)Value
};
}
else
{
output = Value switch
{
>= ActionTypeValue.BypassFX1 => (byte)(Value - 3),
>= ActionTypeValue.SetLPF1 => (byte)(Value - 2),
_ => (byte)Value
};
}
stream.WriteByte(output);
}

public void Deserialize(Stream stream, Endianness endianness, BinarySerializationContext serializationContext)
{
var version = serializationContext.FindAncestor<BankSerializationContext>().Version;
var value = (byte)stream.ReadByte();
if (version <= 65)
{
Value = value switch
{
0x20 => ActionTypeValue.Event1,
0x30 => ActionTypeValue.Event2,
0x40 => ActionTypeValue.Event3,
0x50 => ActionTypeValue.Duck,
0x60 => ActionTypeValue.SetSwitch,
0x61 => ActionTypeValue.SetRTPC,
0x70 => ActionTypeValue.BypassFX1,
0x80 => ActionTypeValue.BypassFX2,
0x90 => ActionTypeValue.Break,
0xA0 => ActionTypeValue.Trigger,
0xB0 => ActionTypeValue.Seek,
>= 0x0A => (ActionTypeValue)(value + 2),
_ => (ActionTypeValue)value
};
}
else
{
Value = value switch
{
>= 0x1A => (ActionTypeValue)(value + 3),
>= 0x0E => (ActionTypeValue)(value + 2),
_ => (ActionTypeValue)value
};
}
}
}

public enum ActionTypeValue : byte
{
Unknown,
Stop,
Pause,
Resume,
Play,
PlayAndContinue,
Mute1,
Mute2,
SetPitch1,
SetPitch2,
SetNone1,
SetNone2,
SetBusVolume1,
SetBusVolume2,
SetLFE1,
SetLFE2,
SetLPF1,
SetLPF2,
UseState1,
UseState2,
SetState,
SetGameParameter1,
SetGameParameter2,
Event1,
Event2,
Event3,
Duck,
SetSwitch,
SetRTPC,
BypassFX1,
BypassFX2,
Break,
Trigger,
Seek,
Release,
SetHPF1,
PlayEvent,
ResetPlaylist,
PlayEventUnknown,
SetHPF2,
SetFX1,
SetFX2,
BypassFX3,
BypassFX4,
BypassFX5,
BypassFX6,
BypassFX7
}
8 changes: 2 additions & 6 deletions ME3Tweaks.Wwiser/Model/Hierarchy/ActorMixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ public class ActorMixer : HircItem
{
[FieldOrder(0)]
public NodeBaseParameters NodeBaseParameters { get; set; } = new();

[FieldOrder(1)]
public uint ChildrenCount { get; set; }

[FieldOrder(2)]
[FieldCount(nameof(ChildrenCount))]
public List<uint> Children { get; set; } = new();
[FieldOrder(1)]
public Children Children { get; set; } = new();
}
30 changes: 30 additions & 0 deletions ME3Tweaks.Wwiser/Model/Hierarchy/Children.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections;
using BinarySerialization;

namespace ME3Tweaks.Wwiser.Model.Hierarchy;

public class Children : IEnumerable<uint>
{
[FieldOrder(1)]
public uint ChildrenCount { get; set; }

[FieldOrder(2)]
[FieldCount(nameof(ChildrenCount))]
public List<uint> ChildrenValues { get; set; } = new();

public uint this[int i]
{
get => ChildrenValues[i];
set => ChildrenValues[i] = value;
}

public IEnumerator<uint> GetEnumerator()
{
return ChildrenValues.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
8 changes: 6 additions & 2 deletions ME3Tweaks.Wwiser/Model/Hierarchy/HircTypeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ public class HircTypeFactory : ISubtypeFactory
private static readonly Dictionary<Type, HircType> TypeToEnum = new()
{
{ typeof(Event), HircType.Event },
{typeof(Attenuation), HircType.Attenuation },
{ typeof(Attenuation), HircType.Attenuation },
{ typeof(FxShareSet), HircType.FxShareSet },
{ typeof(FxCustom), HircType.FxCustom}
{ typeof(FxCustom), HircType.FxCustom },
{ typeof(Sound), HircType.Sound },
{ typeof(ActorMixer), HircType.ActorMixer },
};

public bool TryGetKey(Type valueType, [UnscopedRef] out object key)
Expand Down Expand Up @@ -40,6 +42,8 @@ public bool TryGetType(object key, [UnscopedRef] out Type type)
HircType.Attenuation => typeof(Attenuation),
HircType.FxShareSet => typeof(FxShareSet),
HircType.FxCustom => typeof(FxCustom),
HircType.Sound => typeof(Sound),
HircType.ActorMixer => typeof(ActorMixer),
_ => typeof(HircItem)
};
return true;
Expand Down
Loading

0 comments on commit 16eb7ca

Please sign in to comment.