Skip to content

SerializedFile metadata command (Unity version, platform and typetree info)#59

Merged
SkowronskiAndrew merged 18 commits intomainfrom
next
Mar 6, 2026
Merged

SerializedFile metadata command (Unity version, platform and typetree info)#59
SkowronskiAndrew merged 18 commits intomainfrom
next

Conversation

@SkowronskiAndrew
Copy link
Collaborator

@SkowronskiAndrew SkowronskiAndrew commented Mar 5, 2026

Summary

This branch adds a new serialized-file metadata command and expands the depth of metadata parsing in the
UnityDataTool.

New serialized-file metadata Command

A new subcommand that exposes the full metadata section of a Unity serialized file, including:

  • File format version and target platform
  • Whether the file uses type trees
  • Type tree data — the full type tree table with type hashes, script type information, and per-type node structure
  • Object list — parsed directly from the metadata section, fixing an existing bug where object listing failed on files
    without type trees
  • External file references — the list of external files referenced by the serialized file
  • Script types table — the final piece of the metadata section, now fully parsed

Note: i keep this information separate from "header". One reason is to match how it is actually structured inside SerializedFiles. Another reason is to keep the header command very light weight because we use to check each file before trying to open it. The meta-data command will potentially pull a lot more data.

Note: In this case the Json and text output for the command diverge. I hope this isn't confusing. But it seemed reasonable to keep the text version short and to the point rather than try to express complex arrays in text formats. The json format is more appropriate for the detailed structured representation of the metadata.

Refactoring & Code Quality

  • File utility helpers (ArchiveDetector, GuidHelper, BinaryFileHelper) moved from the Analyzer project into a new
    dedicated UnityBinaryFormat assembly, making them cleaner to reuse across tools
  • Better error reporting with more descriptive messages (e.g. when passing the wrong file, or files without typetrees to the dump, archive, analyze or serialized-file commands)
  • Guards use to avoid attempting to parse files from future/unknown format versions.

Test Coverage

  • New test cases for the new information in the metadata command
  • Additional reference binary files added (including Addressable build variants) to broaden test coverage, including the recent changes to the file format for typetree extraction support.
  • I also did a fair bit of manual testing of the reference files and other projects to check if the output and errorhandling worked well.

Documentation

New subcommand is documented, which also helps explain some of the concepts in these data structures.

Initial implementation exposes the first few fields (version / platform / EnableTypeTree)
Add 3 variations of a very specific Addressable build
This will be used for testing how well UnityDataTool exposes type information
@SkowronskiAndrew SkowronskiAndrew requested a review from Copilot March 5, 2026 13:11
@SkowronskiAndrew SkowronskiAndrew changed the title SerializedFile metadata command: TypeTree section parsing SerializedFile metadata command (Unity version, platform and typetree info) Mar 5, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds richer SerializedFile metadata parsing (including TypeTree entry headers for v19–v23) and exposes it via a new serialized-file metadata / sf metadata CLI subcommand, along with test fixtures and NUnit coverage for common TypeTree configurations (inline, extracted, disabled, SerializeReference types).

Changes:

  • Introduces BinaryFileHelper / UnityHash128 and extends SerializedFileDetector.TryParseMetadata to parse TypeTree section counts and per-entry metadata for regular and SerializeReference type lists.
  • Adds sf metadata command with text + JSON output (including TypeTree arrays in JSON).
  • Adds/updates test data and NUnit tests for metadata parsing and new CLI behavior.

Reviewed changes

Copilot reviewed 8 out of 24 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
UnityDataTool/SerializedFileCommands.cs Adds HandleMetadata plus text/JSON output helpers for new metadata command.
UnityDataTool/Program.cs Registers new serialized-file metadata subcommand (alias sf metadata).
UnityDataTool.Tests/SerializedFileCommandTests.cs Adds initial CLI test coverage for metadata command error path (legacy version).
Analyzer/Util/SerializedFileDetector.cs Adds SerializedFileMetadata / TypeTreeInfo models and implements TypeTree metadata parsing in TryParseMetadata.
Analyzer/Util/BinaryFileHelper.cs Adds shared endian-aware binary helpers and UnityHash128.
Analyzer.Tests/FileDetectionTests.cs Adds NUnit tests validating metadata parsing across representative files; adjusts one archive test path.
Documentation/command-serialized-file.md Documents new metadata subcommand under serialized-file.
TestCommon/Data/LegacyFormats/v22_strippedVersion Adds stripped-version serialized file fixture for metadata parsing scenarios.
TestCommon/Data/AssetBundleTypeTreeVariations/README.md Documents the new typetree-variation fixtures and how to inspect them.
TestCommon/Data/AssetBundleTypeTreeVariations/v23_extracted/prefab_with_serializedreference.serializedfile Fixture: v23 extracted typetree prefab serializedfile.
TestCommon/Data/AssetBundleTypeTreeVariations/v23_extracted/packedassets_assets_all.bundle Fixture: v23 extracted typetree main bundle.
TestCommon/Data/AssetBundleTypeTreeVariations/v23_extracted/monoscriptbundle.serializedfile Fixture: v23 extracted typetree monoscript bundle serializedfile.
TestCommon/Data/AssetBundleTypeTreeVariations/v23_extracted/MonoScript_monoscripts_dde848dc9848681e340a8b4fa9bd7578.bundle Fixture: v23 extracted typetree autoscript bundle.
TestCommon/Data/AssetBundleTypeTreeVariations/v23_extracted/AssetBundle.typetreedata Fixture: extracted typetree store archive used by v23 extracted builds.
TestCommon/Data/AssetBundleTypeTreeVariations/v23_Inline/prefab_with_serializedreference.serializedfile Fixture: v23 inline typetree prefab serializedfile.
TestCommon/Data/AssetBundleTypeTreeVariations/v23_Inline/packedassets_assets_all.bundle Fixture: v23 inline typetree main bundle.
TestCommon/Data/AssetBundleTypeTreeVariations/v23_Inline/monoscriptbundle.serializedfile Fixture: v23 inline typetree monoscript bundle serializedfile.
TestCommon/Data/AssetBundleTypeTreeVariations/v23_Inline/MonoScript_monoscripts_dde848dc9848681e340a8b4fa9bd7578.bundle Fixture: v23 inline typetree autoscript bundle.
TestCommon/Data/AssetBundleTypeTreeVariations/v22/prefab_with_serializedreference.serializedfile Fixture: v22 typetree prefab serializedfile (SerializeReference).
TestCommon/Data/AssetBundleTypeTreeVariations/v22/packedassets_assets_all.bundle Fixture: v22 typetree main bundle.
TestCommon/Data/AssetBundleTypeTreeVariations/v22/monoscriptbundle.serializedfile Fixture: v22 typetree monoscript bundle serializedfile.
TestCommon/Data/AssetBundleTypeTreeVariations/v22/MonoScript_monoscripts_dde848dc9848681e340a8b4fa9bd7578.bundle Fixture: v22 typetree autoscript bundle.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

SkowronskiAndrew and others added 12 commits March 5, 2026 10:11
And other comment/doc improvements.
This fixes ObjectList for files without TypeTrees
Final step of fully parsing the metadata section of serialized files
Also update comment based on research into exactly what this is.
This code gets to graduate to its own assembly, it didn't belong in the Analyzer anymore.
This makes it cleaner to use from TextDumper and upcoming UnityFileSystem usage
Show extra message when there is no type trees
And avoid large unhelpful callstack when printing out errors if it is general Unknown error
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@SkowronskiAndrew SkowronskiAndrew merged commit 287b8f3 into main Mar 6, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants