Skip to content

Commit

Permalink
Support decompilation of an array of bools; Fixes #59.
Browse files Browse the repository at this point in the history
  • Loading branch information
EliotVU committed Jan 14, 2023
1 parent 889b671 commit e55cfce
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
49 changes: 30 additions & 19 deletions src/Core/Classes/UDefaultProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,38 @@ public string Decompile()
}

var arrayIndex = string.Empty;
if (ArrayIndex > 0 && Type != PropertyType.BoolProperty)
if (ArrayIndex > 0)
{
arrayIndex += $"[{ArrayIndex}]";
}

return $"{Name}{arrayIndex}={value}";
}

private UProperty FindProperty(out UStruct outer)
[CanBeNull]
private T FindProperty<T>(out UStruct outer)
where T : UProperty
{
UProperty property = null;
outer = _Outer ?? _Container.Class as UStruct;
for (var structField = outer; structField != null; structField = structField.Super)
outer = _Outer ?? (UStruct)_Container.Class;
Debug.Assert(outer != null, nameof(outer) + " != null");
foreach (var super in outer.EnumerateSuper(outer))
{
if (structField.Variables == null || !structField.Variables.Any())
foreach (var field in super
.EnumerateFields()
.OfType<UProperty>())
{
continue;
// FIXME: UName
if (field.Table.ObjectName != Name)
{
continue;
}

property = field;
outer = super;
break;
}

property = structField.Variables.Find(i => i.Table.ObjectName == Name);
if (property == null)
{
continue;
Expand All @@ -109,25 +121,20 @@ private UProperty FindProperty(out UStruct outer)
break;

case PropertyType.ArrayProperty:
var arrayField = property as UArrayProperty;
var arrayField = (UArrayProperty)property;
Debug.Assert(arrayField != null, "arrayField != null");
var arrayInnerField = arrayField.InnerProperty;
if (arrayInnerField.Type == PropertyType.StructProperty)
{
_Outer = ((UStructProperty)arrayInnerField).StructObject;
outer = ((UStructProperty)arrayInnerField).StructObject;
}

break;

default:
outer = structField;
break;
}

break;
}

return property;
return (T)property;
}

[Conditional("BINARYMETADATA")]
Expand Down Expand Up @@ -568,14 +575,18 @@ private string DeserializeDefaultPropertyValue(PropertyType type, ref Deserializ
{
case PropertyType.BoolProperty:
{
Debug.Assert(BoolValue != null, nameof(BoolValue) + " != null");
bool value = BoolValue.Value;
if (Size == 1 && _Buffer.Version < (uint)PackageObjectLegacyVersion.UE3)
bool value;
if (Size == 0)
{
Debug.Assert(BoolValue != null, nameof(BoolValue) + " != null");
value = BoolValue.Value;
}
else
{
value = _Buffer.ReadByte() > 0;
Record(nameof(value), value);
}

Record(nameof(value), value);
propertyValue = value ? "true" : "false";
break;
}
Expand Down
12 changes: 10 additions & 2 deletions src/Core/Classes/UField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ public IEnumerable<UStruct> EnumerateSuper()
yield return super;
}
}


public IEnumerable<UStruct> EnumerateSuper(UStruct super)
{
for (; super != null; super = super.Super)
{
yield return super;
}
}

public IEnumerable<UField> EnumerateNext()
{
for (var next = NextField; next != null; next = next.NextField)
Expand Down Expand Up @@ -82,4 +90,4 @@ public string GetSuperGroup()
return group + Name;
}
}
}
}

0 comments on commit e55cfce

Please sign in to comment.