Skip to content

Commit

Permalink
Re-factor "IsCompilerGenerated"
Browse files Browse the repository at this point in the history
  • Loading branch information
EliotVU committed Jul 20, 2024
1 parent 41d57d6 commit 7de145f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
8 changes: 0 additions & 8 deletions src/Core/Classes/Props/UDelegateProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ protected override void Deserialize()
}
}

#if DNF
public override bool IsCompilerGenerated()
{
// delegate properties are compiler generated in DNF, not part of the source.
return Package.Build == UnrealPackage.GameBuild.BuildName.DNF;
}
#endif

/// <inheritdoc/>
public override string GetFriendlyType()
{
Expand Down
5 changes: 0 additions & 5 deletions src/Core/Classes/Props/UProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,6 @@ public bool IsParm()
return HasPropertyFlag(PropertyFlagsLO.Parm);
}

public virtual bool IsCompilerGenerated()
{
return false;
}

public virtual string GetFriendlyInnerType()
{
return string.Empty;
Expand Down
25 changes: 17 additions & 8 deletions src/Core/Classes/UStructDecompiler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if DECOMPILE
using System;
using System.Linq;
using UELib.Decompiler;

namespace UELib.Core
{
Expand Down Expand Up @@ -203,24 +204,32 @@ protected string FormatProperties()
// Don't use foreach, screws up order.
foreach (var property in Variables)
{
if (property.IsCompilerGenerated())
continue;
bool isCompilerGenerated = IsCompilerAutoGeneratedHelper.Visit((dynamic)property);

// Fix for properties within structs
output += "\r\n" +
property.PreDecompile() +
$"{UDecompilingState.Tabs}var";
output += "\r\n";
// MetaData like comments.
string preOutput = property.PreDecompile();
output += preOutput;
output += UDecompilingState.Tabs;
if (isCompilerGenerated)
{
output += "//";
}

output += "var";
if (property.CategoryName != null && !property.CategoryName.IsNone())
{
output += property.CategoryName == Name
? "()"
: $"({property.CategoryName})";
}
output += $" {property.Decompile()};";
string s = property.PostDecompile();
if (!string.IsNullOrEmpty(s))

string postOutput = property.PostDecompile();
if (!string.IsNullOrEmpty(postOutput))
{
output += s;
output += postOutput;
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/Decompiler/IsCompilerAutoGeneratedHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using UELib.Core;

namespace UELib.Decompiler
{
// Static non-interface visitor class because we don't require any polymorphism here.
public static class IsCompilerAutoGeneratedHelper
{
public static bool Visit(UDelegateProperty obj)
{
return obj.Name.StartsWith("__", StringComparison.OrdinalIgnoreCase) &&
obj.Name.EndsWith("__Delegate", StringComparison.OrdinalIgnoreCase);
}

public static bool Visit(UField obj)
{
return false;
}

public static bool Visit(UObject obj)
{
return obj.Name.StartsWith("Default__", StringComparison.OrdinalIgnoreCase);
}
}
}

0 comments on commit 7de145f

Please sign in to comment.