Skip to content

Commit

Permalink
Little cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
EliotVU committed May 24, 2022
1 parent 4f88007 commit b0ed0bf
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/ByteCodeDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ private Token DeserializeNext(byte tokenCode = byte.MaxValue)
if (Buffer.Package.Build == UnrealPackage.GameBuild.BuildName.Unreal2 ||
Buffer.Package.Build == UnrealPackage.GameBuild.BuildName.Unreal2XMP)
{
token = new SkipToken();
token = new LineNumberToken();
break;
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Classes/Props/UProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected override void Deserialize()
int info = _Buffer.ReadInt32();
ArrayDim = (ushort)(info & 0x0000FFFFU);
Record("ArrayDim", ArrayDim);
Debug.Assert(ArrayDim <= 2048);
Debug.Assert(ArrayDim <= 2048, "Bad array dim");
ElementSize = (ushort)(info >> 16);
Record("ElementSize", ElementSize);
skipInfo:
Expand All @@ -110,7 +110,7 @@ protected override void Deserialize()
#if THIEF_DS || DEUSEX_IW
if (Package.Build.Generation == BuildGeneration.Thief)
{
// Property flags like CustomEditor, CustomViewer, ThiefProp, DeusExProp
// Property flags like CustomEditor, CustomViewer, ThiefProp, DeusExProp, NoTextExport, NoTravel
uint deusFlags = _Buffer.ReadUInt32();
Record(nameof(deusFlags), deusFlags);
}
Expand Down
23 changes: 15 additions & 8 deletions src/Core/Classes/UClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ public void Deserialize(IUnrealStream stream)
// TODO: Clean this mess up...
protected override void Deserialize()
{
#if UNREAL2
if (Package.Build == UnrealPackage.GameBuild.BuildName.Unreal2)
{
_Buffer.ReadArray(out UArray<UObject> u2NetProperties);
Record(nameof(u2NetProperties), u2NetProperties);
}
#endif
base.Deserialize();
#if VENGEANCE
if (Package.Build.Generation == BuildGeneration.Vengeance &&
Expand Down Expand Up @@ -182,7 +189,7 @@ protected override void Deserialize()
;

// +HideCategories
if (Package.Version > 98)
if (Package.Version >= 99)
{
// TODO: Corrigate Version
if (Package.Version >= 220)
Expand Down Expand Up @@ -271,7 +278,7 @@ protected override void Deserialize()
}
}
#if DISHONORED
skipClassGroups:;
skipClassGroups: ;
#endif
}
}
Expand Down Expand Up @@ -324,16 +331,16 @@ protected override void Deserialize()
#if THIEF_DS || DeusEx_IW
if (Package.Build.Generation == BuildGeneration.Thief)
{
string thiefFriendlyNameText = _Buffer.ReadText();
Record(nameof(thiefFriendlyNameText), thiefFriendlyNameText);
string thiefClassVisibleName = _Buffer.ReadText();
Record(nameof(thiefClassVisibleName), thiefClassVisibleName);

// Restore the human-readable name if possible
if (!string.IsNullOrEmpty(thiefFriendlyNameText)
if (!string.IsNullOrEmpty(thiefClassVisibleName)
&& Package.Build == UnrealPackage.GameBuild.BuildName.Thief_DS)
{
var nameEntry = new UNameTableItem()
{
Name = thiefFriendlyNameText
Name = thiefClassVisibleName
};
NameTable.Name = nameEntry;
}
Expand All @@ -359,7 +366,7 @@ protected override void Deserialize()
string vengeanceDefaultPropertiesText = _Buffer.ReadText();
Record(nameof(vengeanceDefaultPropertiesText), vengeanceDefaultPropertiesText);
}

if (Package.LicenseeVersion >= 6)
{
string vengeanceClassFilePath = _Buffer.ReadText();
Expand All @@ -378,7 +385,7 @@ protected override void Deserialize()
_Buffer.ReadArray(out Vengeance_Implements);
Record(nameof(Vengeance_Implements), Vengeance_Implements);
}

if (Package.LicenseeVersion >= 20)
{
UArray<UObject> unk;
Expand Down
14 changes: 3 additions & 11 deletions src/Core/Classes/UObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ protected virtual void Deserialize()
)
{
int netIndex = _Buffer.ReadInt32();
Record("netIndex", netIndex);
Record(nameof(netIndex), netIndex);
}

// TODO: Serialize component data here
//if( _Buffer.Version > 400
// && HasObjectFlag( Flags.ObjectFlagsHO.PropertiesObject )
Expand All @@ -263,7 +263,6 @@ protected virtual void Deserialize()
// var componentClass = _Buffer.ReadObjectIndex();
// var componentName = _Buffer.ReadNameIndex();
//}

#if THIEF_DS || DEUSEX_IW
// FIXME: Not present in all objects, even some classes?
if (Package.Build.Generation == BuildGeneration.Thief && GetType() != typeof(UnknownObject))
Expand All @@ -288,14 +287,6 @@ protected virtual void Deserialize()
{
DeserializeProperties();
}
#if UNREAL2
else if (Package.Build == UnrealPackage.GameBuild.BuildName.Unreal2)
{
UArray<UObject> objs;
_Buffer.ReadArray(out objs);
Record("Unknown:Unreal2", objs);
}
#endif
}

/// <summary>
Expand All @@ -312,6 +303,7 @@ protected void DeserializeProperties()
{
break;
}

Properties.Add(tag);
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/Core/Classes/UTextBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ public partial class UTextBuffer : UObject
{
#region Serialized Members

protected uint _Top;
protected uint _Pos;
public string ScriptText = string.Empty;
public uint Top;
public uint Pos;

public string ScriptText;

#endregion

Expand All @@ -21,9 +22,13 @@ public UTextBuffer()
protected override void Deserialize()
{
base.Deserialize();
_Top = _Buffer.ReadUInt32();
_Pos = _Buffer.ReadUInt32();

Top = _Buffer.ReadUInt32();
Record(nameof(Top), Top);
Pos = _Buffer.ReadUInt32();
Record(nameof(Pos), Pos);
ScriptText = _Buffer.ReadText();
Record(nameof(ScriptText), "...");
}

#endregion
Expand Down
9 changes: 3 additions & 6 deletions src/Core/Tokens/FunctionTokens.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ public partial class UByteCodeDecompiler
{
public class EndFunctionParmsToken : Token
{
public override string Decompile()
{
return ")";
}
}

public abstract class FunctionToken : Token
Expand Down Expand Up @@ -102,7 +98,8 @@ protected string DecompileCall(string functionName)
Decompiler._IsWithinClassContext = false;
}

var output = $"{functionName}({DecompileParms()}";
string arguments = DecompileParms();
var output = $"{functionName}({arguments})";
return output;
}

Expand Down Expand Up @@ -132,7 +129,7 @@ private string DecompileParms()

// End ")"
case EndFunctionParmsToken _:
output = new StringBuilder(output.ToString().TrimEnd(',') + v);
output = new StringBuilder(output.ToString().TrimEnd(','));
break;

// Any passed values
Expand Down
25 changes: 23 additions & 2 deletions src/Core/Tokens/OtherTokens.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ public class EndOfScriptToken : Token

public class AssertToken : Token
{
public ushort Line;
public bool DebugMode;

public override void Deserialize(IUnrealStream stream)
{
stream.ReadUInt16(); // Line
Line = stream.ReadUInt16();
Decompiler.AlignSize(sizeof(short));

// TODO: Corrigate version, at least known since Mirrors Edge(536)
Expand Down Expand Up @@ -178,9 +179,11 @@ public override void Deserialize(IUnrealStream stream)

public class CastStringSizeToken : Token
{
public byte Size;

public override void Deserialize(IUnrealStream stream)
{
stream.ReadByte(); // Size
Size = stream.ReadByte();
Decompiler.AlignSize(sizeof(byte));
}

Expand Down Expand Up @@ -323,6 +326,7 @@ public override void Deserialize(IUnrealStream stream)
Decompiler.AlignSize(4);
#if UNREAL2
// FIXME: Is this a legacy feature or U2 specific?
// Also in RSRS
if (stream.Package.Build == UnrealPackage.GameBuild.BuildName.Unreal2XMP)
{
OpCodeText = stream.ReadASCIIString();
Expand All @@ -349,6 +353,23 @@ public override string Decompile()
}
#endif
}

public class LineNumberToken : Token
{
public ushort Line;

public override void Deserialize(IUnrealStream stream)
{
Line = stream.ReadUInt16();
Decompiler.AlignSize(sizeof(ushort));
DeserializeNext();
}

public override string Decompile()
{
return DecompileNext();
}
}
#if BIOSHOCK
public class LogFunctionToken : FunctionToken
{
Expand Down
7 changes: 4 additions & 3 deletions src/UnrealTokens.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ public enum ExprToken : ushort
/// </summary>
BeginFunction = 0x14,
LetBool = 0x14,

/// <summary>
/// UE1: ???
/// UE2: Skip-like (early UE2)?
/// UE2: LineNumber (early UE2)?
/// UE2X: Deprecated (Bad Expr Token)
/// UE3: As described
/// UE3: EndParmValue
/// </summary>
LineNumber = 0x15,
EndParmValue = 0x15,
EndFunctionParms = 0x16, // )
Self = 0x17, // Self
Expand Down

0 comments on commit b0ed0bf

Please sign in to comment.