Skip to content

Commit

Permalink
Implement ExprToken RangeConst (UE2).
Browse files Browse the repository at this point in the history
  • Loading branch information
EliotVU committed May 25, 2022
1 parent b0ed0bf commit 9a8a6a0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/ByteCodeDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void AlignObjectSize()
{ 0x44, (byte)ExprToken.PrimitiveCast },
{ 0x45, (byte)ExprToken.GlobalFunction },
{ 0x46, (byte)ExprToken.VectorConst },
{ 0x47, (byte)ExprToken.RotatorConst },
{ 0x47, (byte)ExprToken.RotationConst },
{ 0x48, (byte)ExprToken.Unused },
{ 0x49, (byte)ExprToken.Unused },
{ 0x4A, (byte)ExprToken.Unused },
Expand Down Expand Up @@ -252,7 +252,7 @@ private void AlignObjectSize()
{ 0x23, (byte)ExprToken.IntZero },
{ 0x24, (byte)ExprToken.ObjectConst },
{ 0x25, (byte)ExprToken.ByteConst },
{ 0x26, (byte)ExprToken.RotatorConst },
{ 0x26, (byte)ExprToken.RotationConst },
{ 0x27, (byte)ExprToken.False },
{ 0x28, (byte)ExprToken.True },
{ 0x29, (byte)ExprToken.NoObject },
Expand Down Expand Up @@ -416,7 +416,7 @@ private byte FixToken(byte tokenCode)
if (Package.Version >= 184
&&
(
tokenCode >= (byte)ExprToken.Unused35 && tokenCode < (byte)ExprToken.ReturnNothing
tokenCode >= (byte)ExprToken.RangeConst && tokenCode < (byte)ExprToken.ReturnNothing
||
tokenCode > (byte)ExprToken.NoDelegate && tokenCode < (byte)ExprToken.ExtendedNative)
) ++tokenCode;
Expand Down Expand Up @@ -983,14 +983,18 @@ private Token DeserializeNext(byte tokenCode = byte.MaxValue)
token = new UniStringConstToken();
break;

case (byte)ExprToken.RotatorConst:
token = new RotatorConstToken();
case (byte)ExprToken.RotationConst:
token = new RotationConstToken();
break;

case (byte)ExprToken.VectorConst:
token = new VectorConstToken();
break;

case (byte)ExprToken.RangeConst:
token = new RangeConstToken();
break;

#endregion

#region Functions
Expand Down
21 changes: 20 additions & 1 deletion src/Core/Tokens/ConstTokens.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public override string Decompile()
}
}

public class RotatorConstToken : Token
public class RotationConstToken : Token
{
public struct Rotator
{
Expand Down Expand Up @@ -276,6 +276,25 @@ public override string Decompile()
$"vect({PropertyDisplay.FormatLiteral(X)}, {PropertyDisplay.FormatLiteral(Y)}, {PropertyDisplay.FormatLiteral(Z)})";
}
}

public class RangeConstToken : Token
{
public float A, B;

public override void Deserialize(IUnrealStream stream)
{
A = stream.UR.ReadSingle();
Decompiler.AlignSize(sizeof(float));
B = stream.UR.ReadSingle();
Decompiler.AlignSize(sizeof(float));
}

public override string Decompile()
{
return
$"rng({PropertyDisplay.FormatLiteral(A)}, {PropertyDisplay.FormatLiteral(B)})";
}
}
}
}
}
8 changes: 4 additions & 4 deletions src/UnrealTokens.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public enum ExprToken : ushort
StringConst = 0x1F, // "String"
ObjectConst = 0x20,
NameConst = 0x21, // 'Name'
// RotationConst
RotatorConst = 0x22,
RotationConst = 0x22,
VectorConst = 0x23,
ByteConst = 0x24,
IntZero = 0x25,
Expand Down Expand Up @@ -91,9 +90,10 @@ public enum ExprToken : ushort
#region FixedByteCodes
/// <summary>
/// UE1: ???
/// UE2: Deprecated (Bad Expr Token)
/// UE2: RangeConst or Deprecated (Bad Expr Token)
/// UE3: ???
/// </summary>
Unused35 = 0x35,
RangeConst = 0x35,
StructMember = 0x36, // Struct.Property
DynArrayLength = 0x37, // ARRAY.Length
GlobalFunction = 0x38, // Global.
Expand Down

0 comments on commit 9a8a6a0

Please sign in to comment.