Skip to content

Commit

Permalink
Implement data deserialization of UPolys and FPoly for UE1, UE2, and …
Browse files Browse the repository at this point in the history
…UE3.
  • Loading branch information
EliotVU committed Nov 2, 2022
1 parent 5bc918b commit ab290b6
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 8 deletions.
42 changes: 35 additions & 7 deletions src/Branch/PackageObjectLegacyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public enum PackageObjectLegacyVersion
/// This is one particular update with A LOT of general package changes.
/// </summary>
ReturnExpressionAddedToReturnToken = 62,

SphereExtendsPlane = 62,
LazyArrayAdded = 63,

Expand All @@ -19,28 +19,56 @@ public enum PackageObjectLegacyVersion
/// </summary>
CastStringSizeTokenDeprecated = 70,

PanUVRemovedFromPoly = 78,

/// <summary>
/// FIXME: Version, set 95 (Deus Ex: IW)
/// </summary>
PrimitiveCastTokenAdded = 95,



LightMapScaleAddedToPoly = 106,

KerningAddedToUFont = 119,
FontPagesDisplaced = 122,

UE3 = 184,
RangeConstTokenDeprecated = UE3,

// The estimated version changes that came after the latest known UE2 build.
TextureDeprecatedFromPoly = 170,
MaterialAddedToPoly = 170,

/// <summary>
/// Present in all released UE3 games (starting with RoboBlitz).
///
/// FIXME: Unknown version.
/// </summary>
IsLocalAddedToDelegateFunctionToken = 181,

UE3 = 184,
RangeConstTokenDeprecated = UE3,

// 227 according to the GoW client
FixedVerticesToArrayFromPoly = 227,

// FIXME: Not attested in the GoW client, must have been before v321
LightMapScaleRemovedFromPoly = 300,

// FIXME: Not attested in the GoW client, must have been before v321
ShadowMapScaleAddedToPoly = 300,

// 321 according to the GoW client
ElementOwnerAddedToUPolys = 321,

// 417 according to the GoW client
LightingChannelsAddedToPoly = 417,

VerticalOffsetAddedToUFont = 506,
CleanupFonts = 511,


LightmassAdded = 600,
UProcBuildingReferenceAddedToPoly = 606,
LightmassShadowIndirectOnlyOptionAdded = 652,
LightmassExplicitEmissiveLightRadiusAdded = 636,
PolyRulesetVariationTypeChangedToName = 670,

ProbeMaskReducedAndIgnoreMaskRemoved = 692,
ForceScriptOrderAddedToUClass = 749,
SuperReferenceMovedToUStruct = 756,
Expand Down
5 changes: 5 additions & 0 deletions src/Eliot.UELib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@
<Compile Include="Core\Types\UScale.cs" />
<Compile Include="Core\Types\USphere.cs" />
<Compile Include="Engine\Classes\UMultiFont.cs" />
<Compile Include="Engine\Classes\UProcBuildingRuleset.cs" />
<Compile Include="Engine\Types\LightingChannelContainer.cs" />
<Compile Include="Engine\Types\LightmassPrimitiveSettings.cs" />
<Compile Include="ObjectModel\Annotations\OutputAttribute.cs" />
<Compile Include="Core\Types\UColor.cs" />
<Compile Include="Core\Types\UMap.cs" />
Expand All @@ -194,6 +197,7 @@
<Compile Include="Engine\Classes\AActor.cs" />
<Compile Include="Engine\Classes\UBitmapMaterial.cs" />
<Compile Include="Engine\Classes\ABrush.cs" />
<Compile Include="Engine\Classes\UPolys.cs" />
<Compile Include="Engine\Classes\UPalette.cs" />
<Compile Include="Decoding\IBufferDecoder.cs" />
<Compile Include="Branch\UE2\AA2\EngineBranch.AA2.cs" />
Expand All @@ -204,6 +208,7 @@
<Compile Include="Engine\Classes\UModel.cs" />
<Compile Include="Engine\Classes\UTexture.cs" />
<Compile Include="Engine\Classes\USound.cs" />
<Compile Include="Engine\Types\Poly.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Branch\UE2\DNF\Tokens\IntConstWordToken.cs" />
<Compile Include="Properties\Annotations.cs" />
Expand Down
14 changes: 13 additions & 1 deletion src/Engine/Classes/UModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
using UELib.Engine;
using UELib.ObjectModel.Annotations;

namespace UELib.Core
{
/// <summary>
/// Implements UModel/Engine.Model
/// Implements UModel/Engine.Model
/// </summary>
[Output("Brush")]
[UnrealRegisterClass]
public class UModel : UObject
{
[Output]
public UPolys Polys;

public UModel()
{
ShouldDeserializeOnDemand = true;
}

protected override void Deserialize()
{
base.Deserialize();
}
}
}
62 changes: 62 additions & 0 deletions src/Engine/Classes/UPolys.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using UELib.Annotations;
using UELib.Branch;
using UELib.Core;
using UELib.Flags;
using UELib.ObjectModel.Annotations;

namespace UELib.Engine
{
/// <summary>
/// Implements UPolys/Engine.Polys
/// </summary>
[Output("PolyList")]
[UnrealRegisterClass]
public class UPolys : UObject
{
[CanBeNull] public UObject ElementOwner;

[Output]
public UArray<Poly> Element;

public UPolys()
{
ShouldDeserializeOnDemand = true;
}

protected override void Deserialize()
{
base.Deserialize();

// Faster serialization for cooked packages, no don't have to check for the package's version here.
if (Package.Summary.PackageFlags.HasFlag(PackageFlags.Cooked))
{
ElementOwner = _Buffer.ReadObject();
Record(nameof(ElementOwner), ElementOwner);

_Buffer.ReadArray(out Element);
Record(nameof(Element), Element);
return;
}

int num, max;

num = _Buffer.ReadInt32();
Record(nameof(num), num);
max = _Buffer.ReadInt32();
Record(nameof(max), max);

if (_Buffer.Version >= (uint)PackageObjectLegacyVersion.ElementOwnerAddedToUPolys)
{
ElementOwner = _Buffer.ReadObject();
Record(nameof(ElementOwner), ElementOwner);
}

Element = new UArray<Poly>(num);
if (num > 0)
{
_Buffer.ReadArray(out Element, num);
Record(nameof(Element), Element);
}
}
}
}
13 changes: 13 additions & 0 deletions src/Engine/Classes/UProcBuildingRuleset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using UELib.Core;

namespace UELib.Engine
{
/// <summary>
/// Implements UProcBuildingRuleset/Engine.ProcBuildingRuleset
/// </summary>
[UnrealRegisterClass]
[BuildGeneration(BuildGeneration.UE3)]
public class UProcBuildingRuleset : UObject
{
}
}
16 changes: 16 additions & 0 deletions src/Engine/Types/LightingChannelContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Runtime.InteropServices;

namespace UELib.Engine
{
/// <summary>
/// See LightingChannelContainer in Engine/Classes/LightComponent.uc
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 4)]
public struct LightingChannelContainer : IUnrealAtomicStruct
{
[MarshalAs(UnmanagedType.I1)] public bool Initialized;
[MarshalAs(UnmanagedType.I1)] public bool BSP;
[MarshalAs(UnmanagedType.I1)] public bool Static;
[MarshalAs(UnmanagedType.I1)] public bool Dynamic;
}
}
75 changes: 75 additions & 0 deletions src/Engine/Types/LightmassPrimitiveSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System.ComponentModel;
using System.Runtime.InteropServices;
using UELib.Branch;

namespace UELib.Engine
{
/// <summary>
/// Implements FLightmassPrimitiveSettings
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct LightmassPrimitiveSettings : IUnrealSerializableClass
{
[MarshalAs(UnmanagedType.I1)] public bool UseTwoSidedLighting;
[MarshalAs(UnmanagedType.I1)] public bool ShadowIndirectOnly;
[MarshalAs(UnmanagedType.I1)] public bool UseEmissiveForStaticLighting;

public float EmissiveLightFalloffExponent;
public float EmissiveLightExplicitInfluenceRadius;
public float EmissiveBoost;
public float DiffuseBoost;
public float SpecularBoost;

[DefaultValue(1.0f)] public float FullyOccludedSamplesFraction;

public void Deserialize(IUnrealStream stream)
{
if (stream.Version >= (uint)PackageObjectLegacyVersion.LightmassShadowIndirectOnlyOptionAdded)
{
stream.Read(out UseTwoSidedLighting);
stream.Read(out ShadowIndirectOnly);
stream.Read(out FullyOccludedSamplesFraction);
}

if (stream.Version >= (uint)PackageObjectLegacyVersion.LightmassAdded)
{
stream.Read(out UseEmissiveForStaticLighting);
stream.Read(out EmissiveLightFalloffExponent);
}

if (stream.Version >= (uint)PackageObjectLegacyVersion.LightmassExplicitEmissiveLightRadiusAdded)
{
stream.Read(out EmissiveLightExplicitInfluenceRadius);
}

stream.Read(out EmissiveBoost);
stream.Read(out DiffuseBoost);
stream.Read(out SpecularBoost);
}

public void Serialize(IUnrealStream stream)
{
if (stream.Version >= (uint)PackageObjectLegacyVersion.LightmassShadowIndirectOnlyOptionAdded)
{
stream.Write(UseTwoSidedLighting);
stream.Write(ShadowIndirectOnly);
stream.Write(FullyOccludedSamplesFraction);
}

if (stream.Version >= (uint)PackageObjectLegacyVersion.LightmassAdded)
{
stream.Write(UseEmissiveForStaticLighting);
stream.Write(EmissiveLightFalloffExponent);
}

if (stream.Version >= (uint)PackageObjectLegacyVersion.LightmassExplicitEmissiveLightRadiusAdded)
{
stream.Write(EmissiveLightExplicitInfluenceRadius);
}

stream.Write(EmissiveBoost);
stream.Write(DiffuseBoost);
stream.Write(SpecularBoost);
}
}
}
Loading

0 comments on commit ab290b6

Please sign in to comment.