Skip to content

Commit

Permalink
Fix: when inlining a subobject, don't insert the class=classref par…
Browse files Browse the repository at this point in the history
…ameter if the object has an archetype reference, meaning the subobject is an override.
  • Loading branch information
EliotVU committed Apr 25, 2024
1 parent b613696 commit 61fa3ae
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
9 changes: 7 additions & 2 deletions src/Branch/PackageObjectLegacyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace UELib.Branch
public enum PackageObjectLegacyVersion
{
Undefined = 0,

/// <summary>
/// This is one particular update with A LOT of general package changes.
/// </summary>
Expand Down Expand Up @@ -73,9 +73,14 @@ public enum PackageObjectLegacyVersion
// FIXME: Version
EnumTagNameAddedToBytePropertyTag = UE3,

ObjectFlagsSizeChangedToULong = 195,
ArchetypeAddedToExports = 220,

// 227 according to the GoW client
FixedVerticesToArrayFromPoly = 227,

SerialSizeConditionRemoved = 249,

// Thanks to @https://www.gildor.org/ for reverse-engineering the lazy-loader version changes.
LazyLoaderFlagsAddedToLazyArray = 251,
StorageSizeAddedToLazyArray = 254,
Expand All @@ -86,7 +91,7 @@ public enum PackageObjectLegacyVersion
// -- albeit the exact nature is not clear
// -- whether if this indicates the addition of such an ObjectFlag or just the conditional test.
ClassDefaultCheckAddedToTemplateName = 267,

ComponentGuidDeprecated = 273,

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Core/Classes/UObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public partial class UObject : object, IAcceptable, IContainsTable, IBinaryData,
[CanBeNull]
public UObject Outer => Package.GetIndexObject(Table.OuterIndex);

[CanBeNull]
public UObject Archetype => ExportTable != null
? Package.GetIndexObject(ExportTable.ArchetypeIndex)
: null;

/// <summary>
/// The object's index represented as a table index.
/// </summary>
Expand Down
27 changes: 20 additions & 7 deletions src/Core/Classes/UObjectDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,28 @@ public virtual string Decompile()
BeginDeserializing();
}

string output = $"// Reference: {GetReferencePath()}\r\n";

if (ImportTable != null)
{
return $"// Cannot decompile import {Name}";
return output + $"\r\n{UDecompilingState.Tabs}// Cannot decompile an imported object";
}

output += UDecompilingState.Tabs;
output += $"begin object name={Name}";
// If null then we have a new sub-object (not an override)
if (Archetype == null)
{
Debug.Assert(Class != null);
output += $" class={Class.GetReferencePath()}";
}
else
{
// Commented out, too noisy but useful.
//output += $" /*archetype={Archetype.GetReferencePath()}*/";
}
output += "\r\n";

Debug.Assert(Class != null);
string output = $"begin object name={Name} class={Class.Name}" +
"\r\n";
UDecompilingState.AddTabs(1);
try
{
Expand All @@ -32,9 +46,8 @@ public virtual string Decompile()
UDecompilingState.RemoveTabs(1);
}

return $"{output}{UDecompilingState.Tabs}end object" +
$"\r\n{UDecompilingState.Tabs}" +
$"// Reference: {Class.Name}'{GetOuterGroup()}'";
return $"{output}" +
$"{UDecompilingState.Tabs}end object";
}

public virtual string FormatHeader()
Expand Down
16 changes: 7 additions & 9 deletions src/Core/Tables/UExportTableItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ namespace UELib
/// </summary>
public sealed class UExportTableItem : UObjectTableItem, IUnrealSerializableClass
{
private const int VArchetype = 220;
[Obsolete]
public const int VObjectFlagsToULONG = 195;

private const int VSerialSizeConditionless = 249;

#region Serialized Members

private int _ClassIndex;
Expand Down Expand Up @@ -121,15 +119,15 @@ public void Serialize(IUnrealStream stream)
stream.Write(_SuperIndex);
stream.Write(OuterIndex);
stream.Write(ObjectName);
if (stream.Version >= VArchetype)
if (stream.Version >= (uint)PackageObjectLegacyVersion.ArchetypeAddedToExports)
{
_ArchetypeIndex = stream.ReadInt32();
}
stream.Write(stream.Version >= VObjectFlagsToULONG
stream.Write(stream.Version >= (uint)PackageObjectLegacyVersion.ObjectFlagsSizeChangedToULong
? ObjectFlags
: (uint)ObjectFlags);
stream.WriteIndex(SerialSize); // Assumes SerialSize has been updated to @Object's buffer size.
if (SerialSize > 0 || stream.Version >= VSerialSizeConditionless)
if (SerialSize > 0 || stream.Version >= (uint)PackageObjectLegacyVersion.SerialSizeConditionRemoved)
{
// SerialOffset has to be set and written after this object has been serialized.
stream.WriteIndex(SerialOffset); // Assumes the same as @SerialSize comment.
Expand All @@ -155,7 +153,7 @@ public void Deserialize(IUnrealStream stream)
}
#endif
ObjectName = stream.ReadNameReference();
if (stream.Version >= VArchetype)
if (stream.Version >= (uint)PackageObjectLegacyVersion.ArchetypeAddedToExports)
{
_ArchetypeIndex = stream.ReadInt32();
}
Expand All @@ -176,14 +174,14 @@ public void Deserialize(IUnrealStream stream)
}
#endif
ObjectFlags = stream.ReadUInt32();
if (stream.Version >= VObjectFlagsToULONG)
if (stream.Version >= (uint)PackageObjectLegacyVersion.ObjectFlagsSizeChangedToULong)
{
ObjectFlags = (ObjectFlags << 32) | stream.ReadUInt32();
}

streamSerialSize:
SerialSize = stream.ReadIndex();
if (SerialSize > 0 || stream.Version >= VSerialSizeConditionless)
if (SerialSize > 0 || stream.Version >= (uint)PackageObjectLegacyVersion.SerialSizeConditionRemoved)
{
#if ROCKETLEAGUE
// FIXME: Can't change SerialOffset to 64bit due UE Explorer.
Expand Down

0 comments on commit 61fa3ae

Please sign in to comment.