Skip to content

Commit

Permalink
implement SoftObjectPathList
Browse files Browse the repository at this point in the history
  • Loading branch information
atenfyr committed Jan 30, 2025
1 parent 84c5799 commit 9e45584
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
37 changes: 22 additions & 15 deletions UAssetAPI/PropertyTypes/Objects/SoftObjectPropertyData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ public FSoftObjectPath(FTopLevelAssetPath assetPath, FString subPathString)
SubPathString = subPathString;
}

public FSoftObjectPath(AssetBinaryReader reader)
public FSoftObjectPath(AssetBinaryReader reader, bool allowIndex = true)
{
// ObjectVersionUE5.DATA_RESOURCES empirical
if (reader.Asset.ObjectVersionUE5 >= ObjectVersionUE5.DATA_RESOURCES && reader.Asset.SoftPackageReferenceList != null && reader.Asset.SoftPackageReferenceList.Count > 0)
if (allowIndex && reader.Asset.SoftObjectPathList != null && reader.Asset.SoftObjectPathList.Count > 0)
{
// serialize as idx
int idx = reader.ReadInt32();
AssetPath = new FTopLevelAssetPath(FName.DefineDummy(reader.Asset, reader.Asset.SoftPackageReferenceList[idx]), null);

FSoftObjectPath target = reader.Asset.SoftObjectPathList[idx];
this.AssetPath = target.AssetPath;
this.SubPathString = target.SubPathString;
}
else
{
Expand All @@ -123,27 +125,22 @@ public FSoftObjectPath(AssetBinaryReader reader)
}
}

public int Write(AssetBinaryWriter writer)
public int Write(AssetBinaryWriter writer, bool allowIndex = true)
{
// ObjectVersionUE5.DATA_RESOURCES empirical
if (writer.Asset.ObjectVersionUE5 >= ObjectVersionUE5.DATA_RESOURCES && writer.Asset.SoftPackageReferenceList != null && writer.Asset.SoftPackageReferenceList.Count > 0)
if (allowIndex && writer.Asset.SoftObjectPathList != null && writer.Asset.SoftObjectPathList.Count > 0)
{
// serialize as idx
// don't automatically add to soft package reference list
FString softName = AssetPath.PackageName?.Value;
if (softName == null) throw new FormatException("Attempt to serialize invalid AssetPath as index");

int idx = -1;
for (int i = 0; i < writer.Asset.SoftPackageReferenceList.Count; i++)
for (int i = 0; i < writer.Asset.SoftObjectPathList.Count; i++)
{
FString testingEntry = writer.Asset.SoftPackageReferenceList[i];
if (testingEntry == softName)
FSoftObjectPath testingEntry = writer.Asset.SoftObjectPathList[i];
if (testingEntry == this)
{
idx = i;
break;
}
}
if (idx < 0) throw new FormatException("Failed to find AssetPath in soft package references list");
if (idx < 0) throw new FormatException("Failed to find AssetPath in SoftObjectPathList");

writer.Write(idx);
return sizeof(int);
Expand All @@ -158,6 +155,16 @@ public int Write(AssetBinaryWriter writer)
writer.Write(SubPathString);
return (int)(writer.BaseStream.Position - offset);
}

public static bool operator ==(FSoftObjectPath lhs, FSoftObjectPath rhs)
{
return lhs.Equals(rhs);
}

public static bool operator !=(FSoftObjectPath lhs, FSoftObjectPath rhs)
{
return !lhs.Equals(rhs);
}
}

/// <summary>
Expand Down
32 changes: 32 additions & 0 deletions UAssetAPI/UAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ public bool HasUnversionedProperties
/// </summary>
internal Dictionary<string, int> nameMapLookup = new Dictionary<string, int>();

/// <summary>
/// List of SoftObjectPath contained in this package.
/// </summary>
public List<FSoftObjectPath> SoftObjectPathList;

/// <summary>
/// Map of the gatherable text data.
/// </summary>
Expand Down Expand Up @@ -1746,6 +1751,17 @@ public virtual void Read(AssetBinaryReader reader, int[] manualSkips = null, int
AddNameReference(nameInMap, true);
}

SoftObjectPathList = null;
if (SoftObjectPathsOffset > 0 && SoftObjectPathsCount > 0)
{
reader.BaseStream.Seek(SoftObjectPathsOffset, SeekOrigin.Begin);
SoftObjectPathList = new List<FSoftObjectPath>();
for (int i = 0; i < SoftObjectPathsCount; i++)
{
SoftObjectPathList.Add(new FSoftObjectPath(reader, false));
}
}

// Gatherable text
if (GatherableTextDataOffset > 0 && GatherableTextDataCount > 0)
{
Expand Down Expand Up @@ -2351,6 +2367,22 @@ public virtual MemoryStream WriteData()
}
}

// soft object paths
if (SoftObjectPathList != null)
{
this.SoftObjectPathsOffset = (int)writer.BaseStream.Position;
this.SoftObjectPathsCount = SoftObjectPathList.Count;

for (int i = 0; i < SoftObjectPathList.Count; i++)
{
SoftObjectPathList[i].Write(writer, false);
}
}
else
{
this.SoftObjectPathsOffset = 0;
}

// Gatherable text
if (!IsFilterEditorOnly && GatherableTextData != null)
{
Expand Down

0 comments on commit 9e45584

Please sign in to comment.