Skip to content

Commit 32925ab

Browse files
committed
Added support for specifying an extracted type tree data file
1 parent 0f5f050 commit 32925ab

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

UnityDataTool/Program.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public static async Task<int> Main(string[] args)
2323

2424
var rootCommand = new RootCommand();
2525

26+
var typeTreeDataOpt = new Option<FileInfo>(
27+
aliases: new[] { "--typetree-data", "-d" },
28+
description: "Path to an external TypeTree data file to load before processing bundles");
29+
typeTreeDataOpt.ExistingOnly();
30+
rootCommand.AddGlobalOption(typeTreeDataOpt);
31+
2632
{
2733
var pathArg = new Argument<DirectoryInfo>("path", "The path to the directory containing the files to analyze").ExistingOnly();
2834
var oOpt = new Option<string>(aliases: new[] { "--output-file", "-o" }, description: "Filename of the output database", getDefaultValue: () => "database.db");
@@ -187,6 +193,32 @@ public static async Task<int> Main(string[] args)
187193
rootCommand.AddCommand(serializedFileCommand);
188194
}
189195

196+
// Load external TypeTree data file before any command executes.
197+
for (int i = 0; i < args.Length - 1; i++)
198+
{
199+
if (args[i] == "--typetree-data" || args[i] == "-d")
200+
{
201+
var typeTreeFile = args[i + 1];
202+
if (!File.Exists(typeTreeFile))
203+
{
204+
Console.Error.WriteLine($"TypeTree data file not found: {typeTreeFile}");
205+
UnityFileSystem.Cleanup();
206+
return 1;
207+
}
208+
try
209+
{
210+
UnityFileSystem.AddTypeTreeSourceFromFile(typeTreeFile);
211+
}
212+
catch (EntryPointNotFoundException)
213+
{
214+
Console.Error.WriteLine("Error: The loaded UnityFileSystemApi does not support external TypeTree data files. Please update to Unity 6.5 or newer.");
215+
UnityFileSystem.Cleanup();
216+
return 1;
217+
}
218+
break;
219+
}
220+
}
221+
190222
var r = await rootCommand.InvokeAsync(args);
191223

192224
UnityFileSystem.Cleanup();

UnityFileSystem/DllWrapper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ public static extern ReturnCode ReadFile(UnityFileHandle handle, long size,
251251
public static extern ReturnCode GetRefTypeTypeTree(SerializedFileHandle handle, [MarshalAs(UnmanagedType.LPStr)] string className,
252252
[MarshalAs(UnmanagedType.LPStr)] string namespaceName, [MarshalAs(UnmanagedType.LPStr)] string assemblyName, out TypeTreeHandle typeTree);
253253

254+
[DllImport("UnityFileSystemApi",
255+
CallingConvention = CallingConvention.Cdecl,
256+
EntryPoint = "UFS_AddTypeTreeSourceFromFile")]
257+
public static extern ReturnCode AddTypeTreeSourceFromFile([MarshalAs(UnmanagedType.LPStr)] string path, out long handle);
258+
254259
[DllImport("UnityFileSystemApi",
255260
CallingConvention = CallingConvention.Cdecl,
256261
EntryPoint = "UFS_GetTypeTreeNodeInfo")]

UnityFileSystem/UnityFileSystem.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public static UnityFile OpenFile(string path)
4444
return new UnityFile() { m_Handle = handle };
4545
}
4646

47+
public static long AddTypeTreeSourceFromFile(string path)
48+
{
49+
var r = DllWrapper.AddTypeTreeSourceFromFile(path, out var handle);
50+
HandleErrors(r, path);
51+
return handle;
52+
}
53+
4754
public static SerializedFile OpenSerializedFile(string path)
4855
{
4956
var r = DllWrapper.OpenSerializedFile(path, out var handle);

0 commit comments

Comments
 (0)