Skip to content

Commit

Permalink
Pull Request EliotVU#85: Improvements for Duke Nukem Forever (2011)
Browse files Browse the repository at this point in the history
  • Loading branch information
EliotVU committed Jul 6, 2024
2 parents 205aece + 4bf5447 commit 5d3c0cd
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 15 deletions.
8 changes: 8 additions & 0 deletions src/Core/Classes/Props/UDelegateProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ 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
20 changes: 20 additions & 0 deletions src/Core/Classes/Props/UPointerProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ namespace UELib.Core
[UnrealRegisterClass]
public class UPointerProperty : UProperty
{
#if DNF
public UName PointerType;
#endif

/// <summary>
/// Creates a new instance of the UELib.Core.UPointerProperty class.
/// </summary>
Expand All @@ -18,9 +22,25 @@ public UPointerProperty()
Type = PropertyType.PointerProperty;
}

/// <inheritdoc/>
protected override void Deserialize()
{
base.Deserialize();
#if DNF
if (Package.Build == UnrealPackage.GameBuild.BuildName.DNF)
{
PointerType = _Buffer.ReadNameReference();
}
#endif
}

/// <inheritdoc/>
public override string GetFriendlyType()
{
#if DNF
if (Package.Build == UnrealPackage.GameBuild.BuildName.DNF)
return "pointer(" + PointerType.Name + ")";
#endif
return "pointer";
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Core/Classes/Props/UProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ public bool IsParm()
return HasPropertyFlag(PropertyFlagsLO.Parm);
}

public virtual bool IsCompilerGenerated()
{
return false;
}

public virtual string GetFriendlyInnerType()
{
return string.Empty;
Expand Down
26 changes: 24 additions & 2 deletions src/Core/Classes/Props/UPropertyDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ private string DecompileEditorData()

string[] options = EditorDataText.TrimEnd('\n').Split('\n');
string decodedOptions = string.Join(" ", options.Select(PropertyDisplay.FormatLiteral));
#if DNF
if (Package.Build == UnrealPackage.GameBuild.BuildName.DNF)
return " ?(" + decodedOptions + ")";
#endif
return " " + decodedOptions;
}

Expand Down Expand Up @@ -378,7 +382,12 @@ public string FormatFlags()
}
else // Not Automated
{
if ((PropertyFlags & (ulong)Flags.PropertyFlagsLO.NoExport) != 0)
if ((PropertyFlags & (ulong)Flags.PropertyFlagsLO.NoExport) != 0
#if DNF
// 0x00800000 is CPF_Comment in DNF
&& Package.Build != UnrealPackage.GameBuild.BuildName.DNF
#endif
)
{
output += "noexport ";
copyFlags &= ~(ulong)Flags.PropertyFlagsLO.NoExport;
Expand Down Expand Up @@ -422,14 +431,21 @@ public string FormatFlags()
if ((PropertyFlags & (ulong)Flags.PropertyFlagsLO.EdFindable) != 0
#if AHIT
&& Package.Build != UnrealPackage.GameBuild.BuildName.AHIT
#endif
#if DNF
&& Package.Build != UnrealPackage.GameBuild.BuildName.DNF
#endif
)
{
copyFlags &= ~(ulong)Flags.PropertyFlagsLO.EdFindable;
output += "edfindable ";
}

if ((PropertyFlags & (ulong)Flags.PropertyFlagsLO.Deprecated) != 0)
if ((PropertyFlags & (ulong)Flags.PropertyFlagsLO.Deprecated) != 0
#if DNF
&& Package.Build != UnrealPackage.GameBuild.BuildName.DNF
#endif
)
{
output += "deprecated ";
copyFlags &= ~(ulong)Flags.PropertyFlagsLO.Deprecated;
Expand Down Expand Up @@ -495,6 +511,12 @@ public string FormatFlags()
#if DNF
if (Package.Build == UnrealPackage.GameBuild.BuildName.DNF)
{
if (HasPropertyFlag(0x20000000))
{
output += "edfindable ";
copyFlags &= ~(uint)0x20000000;
}

if (HasPropertyFlag(0x1000000))
{
output += "nontrans ";
Expand Down
65 changes: 56 additions & 9 deletions src/Core/Classes/UClassDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,29 @@ private string FormatFlags()
}
}

if ((ClassFlags & (uint)Flags.ClassFlags.EditInlineNew) != 0)
#if DNF
if (Package.Build == UnrealPackage.GameBuild.BuildName.DNF)
{
output += "\r\n\teditinlinenew";
if (HasClassFlag(0x00001000U))
{
output += "\r\n\tobsolete";
}
}
else
#endif
{
// Only do if parent had EditInlineNew
var parentClass = (UClass)Super;
if (parentClass != null && (parentClass.ClassFlags & (uint)Flags.ClassFlags.EditInlineNew) != 0)
if ((ClassFlags & (uint)Flags.ClassFlags.EditInlineNew) != 0)
{
output += "\r\n\teditinlinenew";
}
else
{
output += "\r\n\tnoteditinlinenew";
// Only do if parent had EditInlineNew
var parentClass = (UClass)Super;
if (parentClass != null && (parentClass.ClassFlags & (uint)Flags.ClassFlags.EditInlineNew) != 0)
{
output += "\r\n\tnoteditinlinenew";
}
}
}

Expand All @@ -268,6 +280,25 @@ private string FormatFlags()
output += "\r\n\tcollapsecategories";
}

#if DNF
if (Package.Build == UnrealPackage.GameBuild.BuildName.DNF)
{
if (HasClassFlag(0x00004000))
{
output += "\r\n\teditinlinenew";
}
else
{
// Only do if parent had EditInlineNew
var parentClass = (UClass)Super;
if (parentClass != null && (parentClass.ClassFlags & 0x00004000) != 0)
{
output += "\r\n\tnoteditinlinenew";
}
}
}
else
#endif
// TODO: Might indicate "Interface" in later versions
if (HasClassFlag(Flags.ClassFlags.ExportStructs) && Package.Version < 300)
{
Expand All @@ -281,13 +312,29 @@ private string FormatFlags()

if (Extends("Actor"))
{
if ((ClassFlags & (uint)Flags.ClassFlags.Placeable) != 0)
#if DNF
if (Package.Build == UnrealPackage.GameBuild.BuildName.DNF)
{
output += Package.Version >= PlaceableVersion ? "\r\n\tplaceable" : "\r\n\tusercreate";
if (HasClassFlag(0x02000))
{
output += "\r\n\tplaceable";
}
else
{
output += $"\r\n\tnotplaceable";
}
}
else
#endif
{
output += Package.Version >= PlaceableVersion ? "\r\n\tnotplaceable" : "\r\n\tnousercreate";
if ((ClassFlags & (uint)Flags.ClassFlags.Placeable) != 0)
{
output += Package.Version >= PlaceableVersion ? "\r\n\tplaceable" : "\r\n\tusercreate";
}
else
{
output += Package.Version >= PlaceableVersion ? "\r\n\tnotplaceable" : "\r\n\tnousercreate";
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/Core/Classes/UFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ public bool IsPre()
return IsOperator() && HasFunctionFlag(Flags.FunctionFlags.PreOperator);
}

public bool IsDelegate()
{
#if DNF
if (Package.Build == UnrealPackage.GameBuild.BuildName.DNF)
return HasFunctionFlag(0x400000);
#endif
return HasFunctionFlag(Flags.FunctionFlags.Delegate);
}

public bool HasOptionalParamData()
{
// FIXME: Deprecate version check, and re-map the function flags using the EngineBranch class approach.
Expand Down
9 changes: 6 additions & 3 deletions src/Core/Classes/UFunctionDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ private string FormatFlags()
#if DNF
if (Package.Build == UnrealPackage.GameBuild.BuildName.DNF)
{
// 0x20000200 unknown specifier

if (HasFunctionFlag(0x20000000))
{
output += "devexec ";
}

if (HasFunctionFlag(0x4000000))
{
output += "animevent ";
Expand Down Expand Up @@ -207,7 +210,7 @@ private string FormatFlags()
isNormalFunction = false;
}

if (HasFunctionFlag(Flags.FunctionFlags.Delegate))
if (IsDelegate())
{
output += "delegate ";
isNormalFunction = false;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Classes/UFunctionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override string GetImageName()
{
name = "Event";
}
else if (HasFunctionFlag(Flags.FunctionFlags.Delegate))
else if (IsDelegate())
{
name = "Delegate";
}
Expand Down
3 changes: 3 additions & 0 deletions src/Core/Classes/UStructDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ protected string FormatProperties()
// Don't use foreach, screws up order.
foreach (var property in Variables)
{
if (property.IsCompilerGenerated())
continue;

// Fix for properties within structs
output += "\r\n" +
property.PreDecompile() +
Expand Down

0 comments on commit 5d3c0cd

Please sign in to comment.