-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
408 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.