Skip to content

Commit

Permalink
Finish 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
EliotVU committed Dec 6, 2022
2 parents 2df1508 + 6e2fc5b commit 9ffac16
Show file tree
Hide file tree
Showing 25 changed files with 609 additions and 283 deletions.
9 changes: 9 additions & 0 deletions src/Branch/UE3/RSS/Tokens/Bm4ContextToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using UELib.Core;

namespace UELib.Branch.UE3.RSS.Tokens
{
public class Bm4ContextToken : UStruct.UByteCodeDecompiler.ContextToken
{

}
}
12 changes: 12 additions & 0 deletions src/Branch/UE3/RSS/Tokens/NameConstNoNumberToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using UELib.Core;

namespace UELib.Branch.UE3.RSS.Tokens
{
public class NameConstNoNumberToken : UStruct.UByteCodeDecompiler.NameConstToken
{
public override void Deserialize(IUnrealStream stream)
{
Name = ReadNameNoNumber(stream);
}
}
}
66 changes: 59 additions & 7 deletions src/ByteCodeDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
using System.IO;
using System.Runtime.CompilerServices;
using UELib.Annotations;
using UELib.Flags;
using UELib.Tokens;

namespace UELib.Core
{
using System.Linq;
using System.Text;
using UELib.Branch.UE3.RSS.Tokens;

public partial class UStruct
{
Expand Down Expand Up @@ -306,6 +308,18 @@ private void AlignObjectSize()
{ 0x59, (byte)ExprToken.Unused }
};
#endif
#if BATMAN
private static readonly Dictionary<byte, byte> ByteCodeMap_BuildBatman4 = new Dictionary<byte, byte>
{
{ 0x2B, (byte)ExprToken.Unused }, // NameConst but without the Int32 number at the end
// 0x4E, unknown but it has the same pattern as a DynamicCast
{ 0x4F, (byte)ExprToken.DynamicCast },
// 0x4F, unknown but it has the same pattern as a DynamicCast
{ 0x50, (byte)ExprToken.DynamicCast },
// 0x50
{ 0x51, (byte)ExprToken.Unused },
};
#endif
#if APB
private static readonly Dictionary<byte, byte> ByteCodeMap_BuildApb = new Dictionary<byte, byte>
{
Expand Down Expand Up @@ -366,6 +380,13 @@ private void SetupByteCodeMap()
return;
}
#endif
#if BIOSHOCK
if (Package.Build == UnrealPackage.GameBuild.BuildName.Batman4)
{
_ByteCodeMap = ByteCodeMap_BuildBatman4;
return;
}
#endif
#if APB
if (Package.Build == UnrealPackage.GameBuild.BuildName.APB &&
Package.LicenseeVersion >= 32)
Expand Down Expand Up @@ -504,7 +525,12 @@ private void DeserializeDebugToken()

private NativeFunctionToken CreateNativeToken(ushort nativeIndex)
{
var nativeTableItem = _Container.Package.NTLPackage?.FindTableItem(nativeIndex);
var nativeTableItem = _Container.Package.NTLPackage?.FindTableItem(nativeIndex) ?? new NativeTableItem
{
Type = FunctionType.Function,
Name = $"__NFUN_{nativeIndex}__",
ByteToken = nativeIndex
};
return new NativeFunctionToken
{
NativeItem = nativeTableItem
Expand Down Expand Up @@ -1113,8 +1139,26 @@ private Token DeserializeNext(byte tokenCode = byte.MaxValue)
}
}
}
#if BATMAN
// HACK: temporary for the hotfix (:D)
if (token == null && Package.Build == UnrealPackage.GameBuild.BuildName.Batman4)
{
switch (serializedByte)
{
case 0x2B:
token = new NameConstNoNumberToken();
break;

if (token == null) token = new UnresolvedToken();
case 0x50:
token = new Bm4ContextToken();
break;
}
}
#endif
if (token == null)
{
token = new UnresolvedToken();
}
AddToken(token, serializedByte, tokenPosition);
return token;
}
Expand Down Expand Up @@ -1300,11 +1344,11 @@ private Token DeserializeCastToken(byte castToken)
return token;
}

#endregion
#endregion

#if DECOMPILE

#region Decompile
#region Decompile

public class NestManager
{
Expand Down Expand Up @@ -1571,6 +1615,10 @@ public string Decompile()
#endif
}
}
catch (EndOfStreamException)
{
break;
}
catch (Exception e)
{
output.Append($"// ({e.GetType().Name})");
Expand All @@ -1591,6 +1639,10 @@ public string Decompile()
}
}
}
catch (EndOfStreamException)
{
break;
}
catch (Exception e)
{
output.AppendLine("\r\n"
Expand Down Expand Up @@ -1921,17 +1973,17 @@ private string DecompileNests(bool outputAllRemainingNests = false)
return output;
}

#endregion
#endregion

#region Disassemble
#region Disassemble

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public string Disassemble()
{
return string.Empty;
}

#endregion
#endregion

#endif
}
Expand Down
22 changes: 14 additions & 8 deletions src/Core/Classes/Props/UProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,24 @@ protected override void Deserialize()
}
#endif
int info = _Buffer.ReadInt32();
Record("ArrayDim&ElementSize", info);
ArrayDim = (ushort)(info & 0x0000FFFFU);
Record("ArrayDim", ArrayDim);
Debug.Assert(ArrayDim <= 2048, "Bad array dim");
ElementSize = (ushort)(info >> 16);
Record("ElementSize", ElementSize);
skipInfo:

PropertyFlags = Package.Version >= 220
? _Buffer.ReadUInt64()
: _Buffer.ReadUInt32();
Record("PropertyFlags", PropertyFlags);

#if BATMAN
if (Package.Build == BuildGeneration.RSS &&
Package.LicenseeVersion >= 101)
{
PropertyFlags = (PropertyFlags & 0xFFFF0000) >> 24;
Record("PropertyFlags", (PropertyFlagsLO)PropertyFlags);
}
#endif
#if XCOM2
if (Package.Build == UnrealPackage.GameBuild.BuildName.XCOM2WotC)
{
Expand All @@ -108,7 +114,7 @@ protected override void Deserialize()
}
#endif
#if THIEF_DS || DEUSEX_IW
if (Package.Build.Generation == BuildGeneration.Thief)
if (Package.Build == BuildGeneration.Thief)
{
// Property flags like CustomEditor, CustomViewer, ThiefProp, DeusExProp, NoTextExport, NoTravel
uint deusFlags = _Buffer.ReadUInt32();
Expand All @@ -128,7 +134,7 @@ protected override void Deserialize()
else
{
#if THIEF_DS || DEUSEX_IW
if (Package.Build.Generation == BuildGeneration.Thief)
if (Package.Build == BuildGeneration.Thief)
{
short deusInheritedOrRuntimeInstiantiated = _Buffer.ReadInt16();
Record(nameof(deusInheritedOrRuntimeInstiantiated), deusInheritedOrRuntimeInstiantiated);
Expand All @@ -145,7 +151,7 @@ protected override void Deserialize()
Record("RepOffset", RepOffset);
}
#if VENGEANCE
if (Package.Build.Generation == BuildGeneration.Vengeance)
if (Package.Build == BuildGeneration.Vengeance)
{
var vengeanceEditComboType = _Buffer.ReadNameReference();
Record(nameof(vengeanceEditComboType), vengeanceEditComboType);
Expand All @@ -155,9 +161,9 @@ protected override void Deserialize()
#endif
// Appears to be a UE2X feature, it is not present in UE2 builds with no custom LicenseeVersion
// Albeit DeusEx indicates otherwise?
if ((HasPropertyFlag(PropertyFlagsLO.EditorData) && (Package.Build.Generation == BuildGeneration.UE2_5 || Package.Build.Generation == BuildGeneration.Thief))
if ((HasPropertyFlag(PropertyFlagsLO.EditorData) && (Package.Build == BuildGeneration.UE2_5 || Package.Build == BuildGeneration.Thief))
// No property flag
|| Package.Build.Generation == BuildGeneration.Vengeance)
|| Package.Build == BuildGeneration.Vengeance)
{
// May represent a tooltip/comment in some games.
EditorDataText = _Buffer.ReadText();
Expand Down
80 changes: 51 additions & 29 deletions src/Core/Classes/UClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected override void Deserialize()
#endif
base.Deserialize();
#if VENGEANCE
if (Package.Build.Generation == BuildGeneration.Vengeance &&
if (Package.Build == BuildGeneration.Vengeance &&
Package.LicenseeVersion >= 36)
{
var header = (2, 0);
Expand Down Expand Up @@ -171,7 +171,7 @@ protected override void Deserialize()
PackageImports = DeserializeGroup(nameof(PackageImports));
}

skipTo61Stuff:
skipTo61Stuff:
if (Package.Version >= 62)
{
// Class Name Extends Super.Name Within _WithinIndex
Expand Down Expand Up @@ -203,6 +203,7 @@ protected override void Deserialize()
)
DeserializeHideCategories();

// Seems to have been removed in transformer packages
DeserializeComponentsMap();

// RoboBlitz(369)
Expand Down Expand Up @@ -240,10 +241,32 @@ protected override void Deserialize()
|| Package.Version <= vHideCategoriesOldOrder || Package.Version >= 576)
AutoExpandCategories = DeserializeGroup("AutoExpandCategories");

#if TRANSFORMERS
if (Package.Build == UnrealPackage.GameBuild.BuildName.Transformers)
{
var constructorsCount = _Buffer.ReadInt32();
Record("Constructors.Count", constructorsCount);
if (constructorsCount >= 0)
{
int numBytes = constructorsCount * 4;
AssertEOS(numBytes, "Constructors");
_Buffer.Skip(numBytes);
}
}
#endif

if (Package.Version > 670)
{
AutoCollapseCategories = DeserializeGroup("AutoCollapseCategories");

#if BATMAN
// Only attested in bm4 with no version check.
if (_Buffer.Package.Build == BuildGeneration.RSS &&
_Buffer.Package.Build == UnrealPackage.GameBuild.BuildName.Batman4)
{
IList<int> bm4_v198;
bm4_v198 = DeserializeGroup(nameof(bm4_v198));
}
#endif
if (Package.Version >= 749
#if SPECIALFORCE2
&& Package.Build != UnrealPackage.GameBuild.BuildName.SpecialForce2
Expand All @@ -258,32 +281,35 @@ protected override void Deserialize()
{
var unknownName = _Buffer.ReadNameReference();
Record("Unknown:Dishonored", unknownName);

NativeClassName = _Buffer.ReadText();
Record(nameof(NativeClassName), NativeClassName);
goto skipEditorContent;
}
#endif
if (Package.Version >= UnrealPackage.VCLASSGROUP)
#if BATMAN
if (_Buffer.Package.Build == BuildGeneration.RSS &&
_Buffer.Package.LicenseeVersion >= 95)
{
#if DISHONORED
if (Package.Build == UnrealPackage.GameBuild.BuildName.Dishonored)
{
NativeClassName = _Buffer.ReadText();
Record(nameof(NativeClassName), NativeClassName);
goto skipClassGroups;
}
uint bm4_v174 = _Buffer.ReadUInt32();
Record(nameof(bm4_v174), bm4_v174);
}
#endif
if (Package.Version >= UnrealPackage.VCLASSGROUP)
{
ClassGroups = DeserializeGroup("ClassGroups");
if (Package.Version >= 813)
{
NativeClassName = _Buffer.ReadText();
Record(nameof(NativeClassName), NativeClassName);
}
}
#if DISHONORED
skipClassGroups: ;
#endif

// No version check in batman???
if (Package.Version >= 813)
{
NativeClassName = _Buffer.ReadText();
Record(nameof(NativeClassName), NativeClassName);
}
}
}

// FIXME: Found first in(V:655), Definitely not in APB and GoW 2
// FIXME: Found first in(V:655, DLLBind?), Definitely not in APB and GoW 2
// TODO: Corrigate Version
if (Package.Version > 575 && Package.Version < 673
#if TERA
Expand All @@ -299,12 +325,8 @@ protected override void Deserialize()
}
}
}
#if BATMAN
if (_Buffer.Package.Build == UnrealPackage.GameBuild.BuildName.BatmanUDK)
{
_Buffer.Skip(sizeof(int));
}
#endif

skipEditorContent:
if (Package.Version >= UnrealPackage.VDLLBIND)
{
if (!Package.Build.Flags.HasFlag(BuildFlags.NoDLLBind))
Expand Down Expand Up @@ -334,13 +356,13 @@ protected override void Deserialize()
}
}
#if THIEF_DS || DeusEx_IW
if (Package.Build.Generation == BuildGeneration.Thief)
if (Package.Build == BuildGeneration.Thief)
{
string thiefClassVisibleName = _Buffer.ReadText();
Record(nameof(thiefClassVisibleName), thiefClassVisibleName);

// Restore the human-readable name if possible
if (!string.IsNullOrEmpty(thiefClassVisibleName)
if (!string.IsNullOrEmpty(thiefClassVisibleName)
&& Package.Build == UnrealPackage.GameBuild.BuildName.Thief_DS)
{
var nameEntry = new UNameTableItem()
Expand All @@ -352,7 +374,7 @@ protected override void Deserialize()
}
#endif
#if VENGEANCE
if (Package.Build.Generation == BuildGeneration.Vengeance)
if (Package.Build == BuildGeneration.Vengeance)
{
if (Package.LicenseeVersion >= 2)
{
Expand Down
Loading

0 comments on commit 9ffac16

Please sign in to comment.