Skip to content

Commit

Permalink
First pass on ActionTypePlay parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
henbagle committed Dec 9, 2023
1 parent c134b30 commit 734363a
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ME3Tweaks.Wwiser/Model/Action/ActionParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ME3Tweaks.Wwiser.Model.Action;

public class ActionParams
{

}
36 changes: 36 additions & 0 deletions ME3Tweaks.Wwiser/Model/Action/ActionParamsFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Diagnostics.CodeAnalysis;
using BinarySerialization;
using ME3Tweaks.Wwiser.Model.Hierarchy;

namespace ME3Tweaks.Wwiser.Model.Action;

public class ActionParamsFactory : ISubtypeFactory
{
private static readonly Dictionary<Type, ActionTypeValue> TypeToEnum = new()
{
{ typeof(Play), ActionTypeValue.Play},
};

public bool TryGetKey(Type valueType, [UnscopedRef] out object key)
{
if (TypeToEnum.TryGetValue(valueType, out var value))
{
key = value;
return true;
}

// fallback
key = ActionTypeValue.Play;
return false;
}

public bool TryGetType(object key, [UnscopedRef] out Type type)
{
type = (ActionTypeValue)key switch
{
ActionTypeValue.Play => typeof(Play),
_ => typeof(Play)
};
return true;
}
}
5 changes: 3 additions & 2 deletions ME3Tweaks.Wwiser/Model/Action/ActionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Serialize(Stream stream, Endianness endianness, BinarySerializationC
_ => (byte)Value
};
var shifted = (uint)(output << 12);
var value = shifted | Data;
var value = shifted | (Data & 0xFFF);
stream.Write(BitConverter.GetBytes(value));
}
else
Expand All @@ -44,7 +44,8 @@ public void Serialize(Stream stream, Endianness endianness, BinarySerializationC
>= ActionTypeValue.SetLPF1 => (byte)(Value - 2),
_ => (byte)Value
};
var value = (ushort)((ushort)(output << 8) | Data);
var shifted = (ushort)(output << 8);
var value = (ushort)(shifted | (Data & 0xFF));
stream.Write(BitConverter.GetBytes(value));
}

Expand Down
23 changes: 23 additions & 0 deletions ME3Tweaks.Wwiser/Model/Action/ExceptParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using BinarySerialization;
using ME3Tweaks.Wwiser.Attributes;
using ME3Tweaks.Wwiser.Formats;

namespace ME3Tweaks.Wwiser.Model.Action;

public class ExceptParams
{
[FieldOrder(0)]
public VarCount ExceptionCount { get; set; }

[FieldOrder(1)]
[FieldCount($"{nameof(ExceptionCount)}.{nameof(ExceptionCount.Value)}")]
public List<ElementException> Exceptions { get; set; } = new();
}

public class ElementException : AkIdentifiable
{
[FieldOrder(0)]
[SerializeAs(SerializedType.UInt1)]
[SerializeWhenVersion(65, ComparisonOperator.GreaterThan)]
public bool IsBus { get; set; }
}
40 changes: 40 additions & 0 deletions ME3Tweaks.Wwiser/Model/Action/Play.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using BinarySerialization;
using ME3Tweaks.Wwiser.Attributes;
using ME3Tweaks.Wwiser.Model.RTPC;

namespace ME3Tweaks.Wwiser.Model.Action;

public class Play : ActionParams
{
[FieldOrder(0)]
[SerializeWhenVersion(56, ComparisonOperator.LessThanOrEqual)]
public int Time { get; set; }

[FieldOrder(1)]
[SerializeWhenVersion(56, ComparisonOperator.LessThanOrEqual)]
public int TimeMin { get; set; }

[FieldOrder(2)]
[SerializeWhenVersion(56, ComparisonOperator.LessThanOrEqual)]
public int TimeMax { get; set; }

[FieldOrder(3)]
[SerializeAs(SerializedType.UInt1)]
public CurveInterpolation CurveInterpolation { get; set; }

[FieldOrder(4)]
[SerializeWhenVersion(56, ComparisonOperator.LessThanOrEqual)]
public SpecificParams SpecificParams { get; set; }

[FieldOrder(5)]
[SerializeWhenVersion(56, ComparisonOperator.LessThanOrEqual)]
public ExceptParams ExceptParams { get; set; }

[FieldOrder(6)]
[SerializeWhenVersion(26, ComparisonOperator.GreaterThan)]
public uint BankId { get; set; }

[FieldOrder(7)]
[SerializeWhenVersion(144, ComparisonOperator.GreaterThanOrEqual)]
public uint BankType { get; set; }
}
12 changes: 12 additions & 0 deletions ME3Tweaks.Wwiser/Model/Action/SpecificParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BinarySerialization;
using ME3Tweaks.Wwiser.Attributes;

namespace ME3Tweaks.Wwiser.Model.Action;

public class SpecificParams
{
[FieldOrder(0)]
[FieldLength(0x10)]
[SerializeWhenVersion(56, ComparisonOperator.LessThanOrEqual)]
public byte[] Data { get; set; }
}
45 changes: 45 additions & 0 deletions ME3Tweaks.Wwiser/Model/Hierarchy/Action.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using BinarySerialization;
using ME3Tweaks.Wwiser.Attributes;
using ME3Tweaks.Wwiser.Model.Action;
using ME3Tweaks.Wwiser.Model.ParameterNode;

namespace ME3Tweaks.Wwiser.Model.Hierarchy;

public class Action : HircItem
{
[FieldOrder(0)]
public ActionType Type { get; set; } = new();

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

[FieldOrder(2)]
[SerializeWhenVersion(56, ComparisonOperator.LessThanOrEqual)]
public int Delay { get; set; }

[FieldOrder(3)]
[SerializeWhenVersion(56, ComparisonOperator.LessThanOrEqual)]
public int DelayMin { get; set; }

[FieldOrder(4)]
[SerializeWhenVersion(56, ComparisonOperator.LessThanOrEqual)]
public int DelayMax { get; set; }

[FieldOrder(5)]
[SerializeWhenVersion(56, ComparisonOperator.LessThanOrEqual)]
public uint SubSectionSize { get; set; } // TODO: this needs to go away

[FieldOrder(6)]
[SerializeWhenVersion(65, ComparisonOperator.GreaterThan)]
[SerializeAs(SerializedType.UInt1)]
public bool IsBus { get; set; }

[FieldOrder(7)]
[SerializeWhenVersion(56, ComparisonOperator.GreaterThan)]
public InitialParamsV62 PropBundle { get; set; } = new();

[FieldOrder(8)]
[FieldLength(nameof(SubSectionSize))]
[SubtypeFactory($"{nameof(Type)}.{nameof(Type.Value)}", typeof(ActionParamsFactory))]
public ActionParams ActionParams { get; set; } = new();
}

0 comments on commit 734363a

Please sign in to comment.