Skip to content

Commit

Permalink
ParseExport now jumps to serial offset
Browse files Browse the repository at this point in the history
  • Loading branch information
atenfyr committed Dec 10, 2024
1 parent a9dd131 commit e28d709
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
26 changes: 1 addition & 25 deletions UAssetAPI.Benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using UAssetAPI.CustomVersions;
using UAssetAPI.ExportTypes;
using UAssetAPI.IO;
using UAssetAPI.Kismet.Bytecode;
using UAssetAPI.PropertyTypes.Objects;
using UAssetAPI.PropertyTypes.Structs;
using UAssetAPI.UnrealTypes;
using UAssetAPI.Unversioned;

Expand Down Expand Up @@ -363,32 +358,13 @@ public static void Run(string[] args)
new AssetBinaryWriter(testStrm, test).WriteNameBatch(test.HashVersion, (IList<FString>)test.GetNameMapIndexList());
Console.WriteLine(BitConverter.ToString(testStrm.ToArray()));
break;
case "abcd":
{
UAsset myAsset = new UAsset("C:\\my_asset.uasset", EngineVersion.VER_UE4_18);

// all StructExport exports can contain blueprint bytecode, let's pretend Export 1 is a StructExport
StructExport myStructExport = (StructExport)myAsset.Exports[0];

KismetExpression[] bytecode = myStructExport.ScriptBytecode;
if (bytecode != null) // bytecode may fail to parse, in which case it will be null and stored raw in ScriptBytecodeRaw
{
// KismetExpression has many child classes, one child class for each type of instruction
// as with PropertyData, you can access .RawValue for many instruction types, but you'll need to cast for other kinds of instructions to access specific fields
foreach (KismetExpression instruction in bytecode)
{
Console.WriteLine(instruction.Token.ToString() + ": " + instruction.RawValue.ToString());
}
}
}
break;
}
}

public static void Main(string[] args)
{
#if DEBUG || DEBUG_VERBOSE
//Run(new string[] { "mappings" });
Run(new string[] { "abcd" });

while (true)
{
Expand Down
2 changes: 1 addition & 1 deletion UAssetAPI/IO/ZenAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public override void Read(AssetBinaryReader reader, int[] manualSkips = null, in
switch (entry.CommandType)
{
case EExportCommandType.ExportCommandType_Serialize:
ParseExport(reader, (int)entry.LocalExportIndex);
ConvertExportToChildExportAndRead(reader, (int)entry.LocalExportIndex);
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions UAssetAPI/UAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public enum CustomSerializationFlags : int
SkipPreloadDependencyLoading = 4,

/// <summary>
/// Skip parsing exports at read time. Entries in the export map will be read as raw exports. You can manually parse exports with the <see cref="UnrealPackage.ParseExport(AssetBinaryReader, int)"/> method.
/// Skip parsing exports at read time. Entries in the export map will be read as raw exports. You can manually parse exports with the <see cref="UnrealPackage.ConvertExportToChildExportAndRead(AssetBinaryReader, int)"/> method.
/// </summary>
SkipParsingExports = 8
}
Expand Down Expand Up @@ -1108,7 +1108,7 @@ public override void Read(AssetBinaryReader reader, int[] manualSkips = null, in
continue;
}

ParseExport(reader, i);
ConvertExportToChildExportAndRead(reader, i);
}

// catch any stragglers
Expand All @@ -1124,7 +1124,7 @@ public override void Read(AssetBinaryReader reader, int[] manualSkips = null, in
continue;
}

ParseExport(reader, i);
ConvertExportToChildExportAndRead(reader, i);
}
}
}
Expand All @@ -1140,7 +1140,7 @@ public override void Read(AssetBinaryReader reader, int[] manualSkips = null, in
continue;
}

ParseExport(reader, i, false);
ConvertExportToChildExportAndRead(reader, i, false);
}
}

Expand Down
7 changes: 7 additions & 0 deletions UAssetAPI/UnrealPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ internal string InternalAssetPath
}
}


/// <summary>
/// Read an export from disk.
/// </summary>
Expand All @@ -731,6 +732,12 @@ internal string InternalAssetPath
/// <param name="read">Whether or not to serialize the body of the export. If false, simply converts to the respective sub-type.</param>
public void ParseExport(AssetBinaryReader reader, int i, bool read = true)
{
reader.BaseStream.Seek(Exports[i].SerialOffset, SeekOrigin.Begin);
ConvertExportToChildExportAndRead(reader, i, read);
}

public void ConvertExportToChildExportAndRead(AssetBinaryReader reader, int i, bool read = true)
{
#pragma warning disable CS0168 // Variable is declared but never used
try
{
Expand Down

0 comments on commit e28d709

Please sign in to comment.