Skip to content

Commit

Permalink
Update support for the class UTexture (and its related classes).
Browse files Browse the repository at this point in the history
  • Loading branch information
EliotVU committed Nov 2, 2022
1 parent a6328e9 commit e37b8a1
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/Branch/PackageObjectLegacyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public enum PackageObjectLegacyVersion
CastStringSizeTokenDeprecated = 70,

PanUVRemovedFromPoly = 78,

CompMipsDeprecated = 84,

/// <summary>
/// FIXME: Version, set 95 (Deus Ex: IW)
Expand Down
4 changes: 4 additions & 0 deletions src/Eliot.UELib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
<Compile Include="Branch\UE3\MOH\EngineBranch.MOH.cs" />
<Compile Include="Branch\UE3\RSS\EngineBranch.RSS.cs" />
<Compile Include="Branch\UE3\RSS\Tokens\NameConstNoNumberToken.cs" />
<Compile Include="Engine\Classes\UMaterial.cs" />
<Compile Include="Engine\Classes\UMaterialInterface.cs" />
<Compile Include="Core\Tokens\TokenFactory.cs" />
<Compile Include="Core\Tokens\TokenMap.cs" />
<Compile Include="Branch\UE3\DD2\EngineBranch.DD2.cs" />
Expand Down Expand Up @@ -184,6 +186,8 @@
<Compile Include="Core\Types\USphere.cs" />
<Compile Include="Engine\Classes\UMultiFont.cs" />
<Compile Include="Engine\Classes\UProcBuildingRuleset.cs" />
<Compile Include="Engine\Classes\URenderedMaterial.cs" />
<Compile Include="Engine\Classes\USurface.cs" />
<Compile Include="Engine\Types\LightingChannelContainer.cs" />
<Compile Include="Engine\Types\LightmassPrimitiveSettings.cs" />
<Compile Include="ObjectModel\Annotations\OutputAttribute.cs" />
Expand Down
25 changes: 21 additions & 4 deletions src/Engine/Classes/UBitmapMaterial.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using UELib.Annotations;
using UELib.Branch;
using UELib.Core;

namespace UELib.Engine
Expand All @@ -7,7 +8,8 @@ namespace UELib.Engine
/// Implements UBitmapMaterial/Engine.BitmapMaterial
/// </summary>
[UnrealRegisterClass]
public class UBitmapMaterial : UObject
[BuildGenerationRange(BuildGeneration.UE1, BuildGeneration.UE2_5)]
public class UBitmapMaterial : URenderedMaterial
{
// UE2 implementation
public enum TextureFormat
Expand All @@ -27,20 +29,35 @@ public enum TextureFormat
};

public TextureFormat Format;
[CanBeNull] public UPalette Palette;

public UBitmapMaterial()
{
ShouldDeserializeOnDemand = true;
}

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

// HACK: This will do until we have a proper property linking setup.

var formatProperty = Properties.Find("Format");
if (formatProperty != null)
{
Enum.TryParse(formatProperty.Value, out Format);
_Buffer.StartPeek(formatProperty._PropertyValuePosition);
_Buffer.Read(out byte index);
_Buffer.EndPeek();

Format = (TextureFormat)index;
}

var paletteProperty = Properties.Find("Palette");
if (paletteProperty != null)
{
_Buffer.StartPeek(paletteProperty._PropertyValuePosition);
_Buffer.Read(out Palette);
_Buffer.EndPeek();
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/Engine/Classes/UFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
namespace UELib.Engine
{
/// <summary>
/// Implements UFont:Engine.Font
/// Implements UFont/Engine.Font
/// </summary>
[UnrealRegisterClass]
public class UFont : UObject, IUnrealViewable
public class UFont : UObject
{
public UArray<FontCharacter> Characters;
public UArray<UObject> Textures;
Expand Down Expand Up @@ -82,8 +82,7 @@ protected override void Deserialize()
_Buffer.Read(out IsRemapped);
Record(nameof(IsRemapped), IsRemapped);

//if (_Buffer.Package.Build == UnrealPackage.GameBuild.BuildName.Unreal2XMP &&
// _Buffer.LicenseeVersion > 0)
//if (_Buffer.Package.Build == UnrealPackage.GameBuild.BuildName.Unreal2)
//{
// _Buffer.Read(out int xPad);
// _Buffer.Read(out int yPad);
Expand Down
21 changes: 21 additions & 0 deletions src/Engine/Classes/UMaterial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace UELib.Engine
{
/// <summary>
/// Implements UMaterial/Engine.Material
/// </summary>
[UnrealRegisterClass]
public class UMaterial : UMaterialInterface
{
protected override void Deserialize()
{
base.Deserialize();
#if UNREAL2
if (Package.Build == UnrealPackage.GameBuild.BuildName.Unreal2)
{
_Buffer.Read(out byte textureType);
Record(nameof(textureType), textureType);
}
#endif
}
}
}
13 changes: 13 additions & 0 deletions src/Engine/Classes/UMaterialInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using UELib.Branch;

namespace UELib.Engine
{
/// <summary>
/// Implements UMaterialInterface/Engine.MaterialInterface
/// </summary>
[UnrealRegisterClass]
[BuildGeneration(BuildGeneration.UE3)]
public class UMaterialInterface : USurface
{
}
}
2 changes: 1 addition & 1 deletion src/Engine/Classes/UMultiFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace UELib.Engine
{
/// <summary>
/// Represents the UMultiFont:Engine.MultiFont
/// Implements UMultiFont/Engine.MultiFont
/// </summary>
[UnrealRegisterClass]
[BuildGeneration(BuildGeneration.UE3)]
Expand Down
5 changes: 3 additions & 2 deletions src/Engine/Classes/UPalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace UELib.Engine
{
/// <summary>
/// Implements UPalette/Engine.Palette
/// Implements UPalette/Engine.Palette
/// </summary>
[UnrealRegisterClass]
public class UPalette : UObject, IUnrealViewable
Expand All @@ -30,7 +30,8 @@ protected override void Deserialize()
// This could be a lot faster with a fixed array, but it's not a significant class of interest.
int count = _Buffer.ReadIndex();
Debug.Assert(count == 256);
_Buffer.ReadMarshalArray(out Colors, count);
_Buffer.ReadArray(out Colors, count);
Record(nameof(Colors), Colors);
#if UNDYING
if (Package.Build == UnrealPackage.GameBuild.BuildName.Undying &&
_Buffer.Version >= 75)
Expand Down
13 changes: 13 additions & 0 deletions src/Engine/Classes/URenderedMaterial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using UELib.Branch;

namespace UELib.Engine
{
/// <summary>
/// Implements URenderedMaterial/Engine.RenderedMaterial
/// </summary>
[UnrealRegisterClass]
[BuildGenerationRange(BuildGeneration.UE1, BuildGeneration.UE2_5)]
public class URenderedMaterial : UMaterial
{
}
}
14 changes: 14 additions & 0 deletions src/Engine/Classes/USurface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using UELib.Branch;
using UELib.Core;

namespace UELib.Engine
{
/// <summary>
/// Implements USurface/Engine.Surface
/// </summary>
[UnrealRegisterClass]
[BuildGeneration(BuildGeneration.UE3)]
public class USurface : UObject, IUnrealViewable
{
}
}
39 changes: 24 additions & 15 deletions src/Engine/Classes/UTexture.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using System.Diagnostics.CodeAnalysis;
using UELib.Branch;
using UELib.Engine;

namespace UELib.Core
{
/// <summary>
/// Implements UTexture/Engine.Texture
/// Implements UTexture/Engine.Texture
/// </summary>
[UnrealRegisterClass]
public class UTexture : UBitmapMaterial, IUnrealViewable
public class UTexture : UBitmapMaterial
{
public UArray<MipMap> Mips;
public bool HasComp;
Expand All @@ -22,18 +23,22 @@ protected override void Deserialize()
throw new NotSupportedException("UTexture is not supported for this build");
}

_Buffer.ReadArray(out Mips);
Record(nameof(Mips), Mips);

var bHasCompProperty = Properties.Find("bHasComp");
if (bHasCompProperty != null)
if (_Buffer.Version < (uint)PackageObjectLegacyVersion.CompMipsDeprecated)
{
HasComp = bool.Parse(bHasCompProperty.Value);
if (HasComp)
var bHasCompProperty = Properties.Find("bHasComp");
if (bHasCompProperty != null)
{
throw new NotSupportedException("UTexture of this kind is not supported");
HasComp = bool.Parse(bHasCompProperty.Value);
if (HasComp)
{
_Buffer.ReadArray(out UArray<MipMap> oldMips);
Record(nameof(oldMips), oldMips);
}
}
}

_Buffer.ReadArray(out Mips);
Record(nameof(Mips), Mips);
}

[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
Expand All @@ -48,15 +53,19 @@ public struct MipMap : IUnrealSerializableClass
public void Deserialize(IUnrealStream stream)
{
stream.ReadLazyArray(out Data);
USize = stream.ReadInt32();
VSize = stream.ReadInt32();
UBits = stream.ReadByte();
VBits = stream.ReadByte();
stream.Read(out USize);
stream.Read(out VSize);
stream.Read(out UBits);
stream.Read(out VBits);
}

public void Serialize(IUnrealStream stream)
{
throw new NotImplementedException();
stream.WriteLazyArray(ref Data);
stream.Write(USize);
stream.Write(VSize);
stream.Write(UBits);
stream.Write(VBits);
}
}
}
Expand Down

0 comments on commit e37b8a1

Please sign in to comment.