Skip to content
32 changes: 32 additions & 0 deletions UnityDataTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public static async Task<int> Main(string[] args)

var rootCommand = new RootCommand();

var typeTreeDataOpt = new Option<FileInfo>(
aliases: new[] { "--typetree-data", "-d" },
description: "Path to an external TypeTree data file to load before processing bundles");
typeTreeDataOpt.ExistingOnly();
rootCommand.AddGlobalOption(typeTreeDataOpt);

{
var pathArg = new Argument<DirectoryInfo>("path", "The path to the directory containing the files to analyze").ExistingOnly();
var oOpt = new Option<string>(aliases: new[] { "--output-file", "-o" }, description: "Filename of the output database", getDefaultValue: () => "database.db");
Expand Down Expand Up @@ -187,6 +193,32 @@ public static async Task<int> Main(string[] args)
rootCommand.AddCommand(serializedFileCommand);
}

// Load external TypeTree data file before any command executes.
for (int i = 0; i < args.Length - 1; i++)
{
if (args[i] == "--typetree-data" || args[i] == "-d")
{
var typeTreeFile = args[i + 1];
if (!File.Exists(typeTreeFile))
{
Console.Error.WriteLine($"TypeTree data file not found: {typeTreeFile}");
UnityFileSystem.Cleanup();
return 1;
}
try
{
UnityFileSystem.AddTypeTreeSourceFromFile(typeTreeFile);
}
catch (EntryPointNotFoundException)
{
Console.Error.WriteLine("Error: The loaded UnityFileSystemApi does not support external TypeTree data files. Please update to Unity 6.5 or newer.");
UnityFileSystem.Cleanup();
return 1;
}
break;
}
}
Comment thread
paulb-unity marked this conversation as resolved.
Outdated

var r = await rootCommand.InvokeAsync(args);

UnityFileSystem.Cleanup();
Expand Down
5 changes: 5 additions & 0 deletions UnityFileSystem/DllWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ public static extern ReturnCode ReadFile(UnityFileHandle handle, long size,
public static extern ReturnCode GetRefTypeTypeTree(SerializedFileHandle handle, [MarshalAs(UnmanagedType.LPStr)] string className,
[MarshalAs(UnmanagedType.LPStr)] string namespaceName, [MarshalAs(UnmanagedType.LPStr)] string assemblyName, out TypeTreeHandle typeTree);

[DllImport("UnityFileSystemApi",
CallingConvention = CallingConvention.Cdecl,
EntryPoint = "UFS_AddTypeTreeSourceFromFile")]
public static extern ReturnCode AddTypeTreeSourceFromFile([MarshalAs(UnmanagedType.LPStr)] string path, out long handle);

[DllImport("UnityFileSystemApi",
CallingConvention = CallingConvention.Cdecl,
EntryPoint = "UFS_GetTypeTreeNodeInfo")]
Expand Down
7 changes: 7 additions & 0 deletions UnityFileSystem/UnityFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public static UnityFile OpenFile(string path)
return new UnityFile() { m_Handle = handle };
}

public static long AddTypeTreeSourceFromFile(string path)
{
var r = DllWrapper.AddTypeTreeSourceFromFile(path, out var handle);
HandleErrors(r, path);
return handle;
}

public static SerializedFile OpenSerializedFile(string path)
{
var r = DllWrapper.OpenSerializedFile(path, out var handle);
Expand Down