From b0ed0bfcd679b94f4c95ba9e934abe978e854c20 Mon Sep 17 00:00:00 2001 From: Eliot Date: Tue, 24 May 2022 19:50:11 +0200 Subject: [PATCH] Little cleanup. --- src/ByteCodeDecompiler.cs | 2 +- src/Core/Classes/Props/UProperty.cs | 4 ++-- src/Core/Classes/UClass.cs | 23 +++++++++++++++-------- src/Core/Classes/UObject.cs | 14 +++----------- src/Core/Classes/UTextBuffer.cs | 15 ++++++++++----- src/Core/Tokens/FunctionTokens.cs | 9 +++------ src/Core/Tokens/OtherTokens.cs | 25 +++++++++++++++++++++++-- src/UnrealTokens.cs | 7 ++++--- 8 files changed, 61 insertions(+), 38 deletions(-) diff --git a/src/ByteCodeDecompiler.cs b/src/ByteCodeDecompiler.cs index 7351f1d8..7ad1634c 100644 --- a/src/ByteCodeDecompiler.cs +++ b/src/ByteCodeDecompiler.cs @@ -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 diff --git a/src/Core/Classes/Props/UProperty.cs b/src/Core/Classes/Props/UProperty.cs index 4e434d3d..56ecb667 100644 --- a/src/Core/Classes/Props/UProperty.cs +++ b/src/Core/Classes/Props/UProperty.cs @@ -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: @@ -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); } diff --git a/src/Core/Classes/UClass.cs b/src/Core/Classes/UClass.cs index 47999a5c..6fa13217 100644 --- a/src/Core/Classes/UClass.cs +++ b/src/Core/Classes/UClass.cs @@ -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 u2NetProperties); + Record(nameof(u2NetProperties), u2NetProperties); + } +#endif base.Deserialize(); #if VENGEANCE if (Package.Build.Generation == BuildGeneration.Vengeance && @@ -182,7 +189,7 @@ protected override void Deserialize() ; // +HideCategories - if (Package.Version > 98) + if (Package.Version >= 99) { // TODO: Corrigate Version if (Package.Version >= 220) @@ -271,7 +278,7 @@ protected override void Deserialize() } } #if DISHONORED - skipClassGroups:; + skipClassGroups: ; #endif } } @@ -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; } @@ -359,7 +366,7 @@ protected override void Deserialize() string vengeanceDefaultPropertiesText = _Buffer.ReadText(); Record(nameof(vengeanceDefaultPropertiesText), vengeanceDefaultPropertiesText); } - + if (Package.LicenseeVersion >= 6) { string vengeanceClassFilePath = _Buffer.ReadText(); @@ -378,7 +385,7 @@ protected override void Deserialize() _Buffer.ReadArray(out Vengeance_Implements); Record(nameof(Vengeance_Implements), Vengeance_Implements); } - + if (Package.LicenseeVersion >= 20) { UArray unk; diff --git a/src/Core/Classes/UObject.cs b/src/Core/Classes/UObject.cs index 66639e12..fba90b2c 100644 --- a/src/Core/Classes/UObject.cs +++ b/src/Core/Classes/UObject.cs @@ -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 ) @@ -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)) @@ -288,14 +287,6 @@ protected virtual void Deserialize() { DeserializeProperties(); } -#if UNREAL2 - else if (Package.Build == UnrealPackage.GameBuild.BuildName.Unreal2) - { - UArray objs; - _Buffer.ReadArray(out objs); - Record("Unknown:Unreal2", objs); - } -#endif } /// @@ -312,6 +303,7 @@ protected void DeserializeProperties() { break; } + Properties.Add(tag); } } diff --git a/src/Core/Classes/UTextBuffer.cs b/src/Core/Classes/UTextBuffer.cs index ff84b076..ec0c469c 100644 --- a/src/Core/Classes/UTextBuffer.cs +++ b/src/Core/Classes/UTextBuffer.cs @@ -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 @@ -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 diff --git a/src/Core/Tokens/FunctionTokens.cs b/src/Core/Tokens/FunctionTokens.cs index 9d255452..11bd6987 100644 --- a/src/Core/Tokens/FunctionTokens.cs +++ b/src/Core/Tokens/FunctionTokens.cs @@ -10,10 +10,6 @@ public partial class UByteCodeDecompiler { public class EndFunctionParmsToken : Token { - public override string Decompile() - { - return ")"; - } } public abstract class FunctionToken : Token @@ -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; } @@ -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 diff --git a/src/Core/Tokens/OtherTokens.cs b/src/Core/Tokens/OtherTokens.cs index 0c1b66ea..aff28101 100644 --- a/src/Core/Tokens/OtherTokens.cs +++ b/src/Core/Tokens/OtherTokens.cs @@ -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) @@ -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)); } @@ -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(); @@ -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 { diff --git a/src/UnrealTokens.cs b/src/UnrealTokens.cs index 574b61c1..18964050 100644 --- a/src/UnrealTokens.cs +++ b/src/UnrealTokens.cs @@ -40,13 +40,14 @@ public enum ExprToken : ushort /// BeginFunction = 0x14, LetBool = 0x14, - + /// /// UE1: ??? - /// UE2: Skip-like (early UE2)? + /// UE2: LineNumber (early UE2)? /// UE2X: Deprecated (Bad Expr Token) - /// UE3: As described + /// UE3: EndParmValue /// + LineNumber = 0x15, EndParmValue = 0x15, EndFunctionParms = 0x16, // ) Self = 0x17, // Self