Skip to content

Commit

Permalink
Extract derialization funcs to static for LEX
Browse files Browse the repository at this point in the history
  • Loading branch information
henbagle committed Sep 19, 2024
1 parent 7d8d457 commit 2a0da2b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
11 changes: 8 additions & 3 deletions ME3Tweaks.Wwiser/Model/Hierarchy/Enums/StreamType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ public void Serialize(Stream stream, Endianness endianness, BinarySerializationC
public void Deserialize(Stream stream, Endianness endianness, BinarySerializationContext serializationContext)
{
var version = serializationContext.FindAncestor<BankSerializationContext>().Version;

Value = DeserializeStatic(stream, version);
}

public static StreamTypeInner DeserializeStatic(Stream stream, uint version)
{
byte value;

if (version <= 89)
{
Span<byte> span = stackalloc byte[4];
Expand All @@ -63,9 +68,9 @@ public void Deserialize(Stream stream, Endianness endianness, BinarySerializatio
}
}

Value = (StreamTypeInner)value;
return (StreamTypeInner)value;
}

public enum StreamTypeInner : byte
{
DataBnk,
Expand Down
2 changes: 1 addition & 1 deletion ME3Tweaks.Wwiser/Model/ParameterNode/AuxParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private AuxFlags GetAuxFlagsFromProperties(uint version)
}

[Flags]
private enum AuxFlags : byte
public enum AuxFlags : byte
{
Unk1 = 1 << 0,
Unk2 = 1 << 1,
Expand Down
16 changes: 12 additions & 4 deletions ME3Tweaks.Wwiser/Model/ParameterNode/PropId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,21 @@ public void Deserialize(Stream stream, Endianness endianness, BinarySerializatio
{
var context = serializationContext.FindAncestor<BankSerializationContext>();
var version = context.Version;
if (context.UseModulator)
(PropValue, ModulatorValue) = DeserializeStatic(stream, context.UseModulator, version);
}

public static (PropId, ModulatorPropId) DeserializeStatic(Stream stream, bool useModulator, uint version)
{
ModulatorPropId modId = 0;
PropId propId = 0;
if (useModulator)
{
var id = (ModulatorPropId)stream.ReadByte();
if (version < 150 && id >= ModulatorPropId.Lfo_Retrigger)
{
id++;
}
ModulatorValue = id;
modId = id;
}
else
{
Expand All @@ -79,8 +86,9 @@ public void Deserialize(Stream stream, Endianness endianness, BinarySerializatio
id = DeserializeVersionLte150(id);
}

PropValue = id;
propId = id;
}
return (propId, modId);
}

private static PropId SerializeVersion113(PropId input, uint version)
Expand Down Expand Up @@ -179,7 +187,7 @@ private static PropId SerializeVersionLte112(PropId input, uint version)
return id;
}

protected virtual PropId DeserializeVersionLte65(PropId input)
private static PropId DeserializeVersionLte65(PropId input)
{
return input switch
{
Expand Down

0 comments on commit 2a0da2b

Please sign in to comment.