Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compatibility of FTextProperty parser #13

Merged
merged 1 commit into from
Aug 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions UnrealEngine.Gvas/FProperties/FTextProperty.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,58 @@
using System.Xml.Linq;
namespace UnrealEngine.Gvas.FProperties;

[OptionalGuid]
public class FTextProperty : FProperty
{
public string? Owner { get; set; }
public string? Identifier { get; set; }
public string? Value { get; set; }
public int Unknown1 { get; set; }
public byte Unknown2 { get; set; }
public byte[]? Unknown3 { get; set; }
public byte Flags { get; set; }

internal override void Read(BinaryReader reader, string? propertyName, long fieldLength, bool bodyOnly = false)
{
long startPos = reader.BaseStream.Position;
Unknown1 = reader.ReadInt32();
Unknown2 = reader.ReadByte();
if (Unknown1 != 0)
Flags = reader.ReadByte();
if (fieldLength == 5)
{
reader.ReadInt32();
if (Flags != 255)
{
throw new NotImplementedException();
}
return;
}
Owner = reader.ReadFString();
if (Flags == 255)
{
// no extra fields
}
else if (Flags == 11)
{
Identifier = reader.ReadFString();
}
else if (Flags == 0)
{
Identifier = reader.ReadFString();
Value = reader.ReadFString();
int bytesLeft = (int) (fieldLength - (reader.BaseStream.Position - startPos));
Unknown3 = reader.ReadBytes(bytesLeft);
}
else
{
throw new NotImplementedException();
}
}

protected override IEnumerable<object> SerializeContent()
{
throw new NotImplementedException();
yield return Value ?? string.Empty;
}

protected override void ModifyXmlNode(XElement element)
{
if (Owner is {Length: > 0})
element.SetAttributeValue("Owner", Owner);
if (Identifier is {Length: > 0})
element.SetAttributeValue("Identifier", Identifier);
}
}