Skip to content

Commit

Permalink
Fix for both ReturnToken and the BeginFunctionToken in UE1 v61 packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
EliotVU committed Sep 26, 2022
1 parent 54bc3e3 commit 3653f8e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
5 changes: 5 additions & 0 deletions src/Branch/PackageObjectLegacyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ namespace UELib.Branch
{
public enum PackageObjectLegacyVersion
{
/// <summary>
/// This is one particular update with A LOT of general package changes.
/// </summary>
ReturnExpressionAddedToReturnToken = 62,

/// <summary>
/// FIXME: Unknown version.
/// </summary>
Expand Down
30 changes: 19 additions & 11 deletions src/Core/Tokens/JumpTokens.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using UELib.Annotations;
using UELib.Branch;

namespace UELib.Core
{
Expand All @@ -12,43 +13,50 @@ public class ReturnToken : Token
{
public override void Deserialize(IUnrealStream stream)
{
if (Decompiler._Buffer.Version < (uint)PackageObjectLegacyVersion.ReturnExpressionAddedToReturnToken)
{
return;
}

// Expression
DeserializeNext();
}

public override string Decompile()
{
#region CaseToken Support

// HACK: for case's that end with a return instead of a break.
if (Decompiler.IsInNest(NestManager.Nest.NestType.Default) != null)
{
Decompiler._Nester.TryAddNestEnd(NestManager.Nest.NestType.Switch, Position + Size);
}

#endregion
Decompiler.MarkSemicolon();
if (Decompiler._Buffer.Version < (uint)PackageObjectLegacyVersion.ReturnExpressionAddedToReturnToken)
{
// FIXME: Transport the emitted "ReturnValue = Expression" over here.
return "return";
}

string returnValue = DecompileNext();
Decompiler._CanAddSemicolon = true;
return "return" + (returnValue.Length != 0 ? " " + returnValue : string.Empty);
return "return" + (returnValue.Length != 0
? " " + returnValue
: string.Empty);
}
}

public class ReturnNothingToken : EatReturnValueToken
{
public override string Decompile()
{
#region CaseToken Support

// HACK: for case's that end with a return instead of a break.
if (Decompiler.IsInNest(NestManager.Nest.NestType.Default) != null)
{
Decompiler._Nester.TryAddNestEnd(NestManager.Nest.NestType.Switch, Position + Size);
}

#endregion

return ReturnValueProperty != null ? ReturnValueProperty.Name : string.Empty;
return ReturnValueProperty != null
? ReturnValueProperty.Name
: string.Empty;
}
}

Expand All @@ -62,7 +70,7 @@ public override void Deserialize(IUnrealStream stream)

public override string Decompile()
{
Decompiler._CanAddSemicolon = true;
Decompiler.MarkSemicolon();
return $"goto {DecompileNext()}";
}
}
Expand Down
21 changes: 6 additions & 15 deletions src/Core/Tokens/OtherTokens.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public override void Deserialize(IUnrealStream stream)
// -- definitely not in the older UE3 builds v186
if (stream.Version < 200) return;

ReturnValueProperty = stream.ReadObject() as UProperty;
ReturnValueProperty = stream.ReadObject<UProperty>();
Decompiler.AlignObjectSize();
}
}
Expand All @@ -187,27 +187,18 @@ public class BeginFunctionToken : Token
{
public override void Deserialize(IUnrealStream stream)
{
var structContainer = Decompiler._Container;
for (var field = structContainer.Children; field != null; field = field.NextField)
for (;;)
{
var property = field as UProperty;
if (property == null)
byte elementSize = stream.ReadByte();
Decompiler.AlignSize(sizeof(byte));
if (elementSize == 0x00)
{
continue;
break;
}

if (!property.HasPropertyFlag(Flags.PropertyFlagsLO.Parm | Flags.PropertyFlagsLO.ReturnParm))
continue;

stream.ReadByte(); // Size
Decompiler.AlignSize(sizeof(byte));

stream.ReadByte(); // bOutParam
Decompiler.AlignSize(sizeof(byte));
}

stream.ReadByte(); // End
Decompiler.AlignSize(sizeof(byte));
}
}

Expand Down

0 comments on commit 3653f8e

Please sign in to comment.