unity-asset-cli 0.2.0

Command-line tools for Unity asset parsing and manipulation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
use clap::{Parser, Subcommand};
use std::path::PathBuf;

#[derive(Parser)]
#[command(name = "unity_asset")]
#[command(about = "A Rust-based Unity asset parser")]
#[command(version)]
pub(crate) struct Cli {
    /// Fail-fast TypeTree parsing (no best-effort fallbacks)
    #[arg(long)]
    pub(crate) strict: bool,

    /// Print collected load warnings and TypeTree warnings (when applicable)
    #[arg(long)]
    pub(crate) show_warnings: bool,

    /// External TypeTree registry JSON/TPK (best-effort fallback for stripped assets).
    ///
    /// Can be repeated; earlier registries take precedence (first match wins).
    #[arg(long)]
    pub(crate) typetree_registry: Vec<PathBuf>,

    #[command(subcommand)]
    pub(crate) command: Commands,
}

#[derive(Subcommand)]
pub(crate) enum Commands {
    /// Parse a Unity YAML file
    ParseYaml {
        /// Input YAML file path
        #[arg(short, long)]
        input: PathBuf,

        /// Output format (summary, detailed, json)
        #[arg(short, long, default_value = "debug")]
        format: String,

        /// Preserve original types instead of converting to strings
        #[arg(long)]
        preserve_types: bool,
    },

    /// Extract information from Unity files
    Extract {
        /// Input file or directory path
        #[arg(short, long)]
        input: PathBuf,

        /// Output directory
        #[arg(short, long)]
        output: PathBuf,

        /// Unity class types to extract (GameObject, Transform, etc.)
        #[arg(long)]
        types: Vec<String>,
    },

    /// Export objects from AssetBundles using the bundle `m_Container` (UnityPy-like workflow)
    ExportBundle {
        /// Input file or directory path (bundles will be auto-detected)
        #[arg(short, long)]
        input: PathBuf,

        /// Output directory
        #[arg(short, long)]
        output: PathBuf,

        /// Filter container entries by substring (case-insensitive). Empty means export all.
        #[arg(long, default_value = "")]
        pattern: String,

        /// Limit exported entries (to keep runtime predictable)
        #[arg(long)]
        limit: Option<usize>,

        /// Filter by class id (can be repeated). Only applies to resolvable entries.
        #[arg(long)]
        class_id: Vec<i32>,

        /// Filter by class name substring (case-insensitive). Only applies to resolvable entries.
        #[arg(long, default_value = "")]
        class_name: String,

        /// Only print what would be exported
        #[arg(long)]
        dry_run: bool,

        /// Decode known types (AudioClip -> WAV, Texture2D -> PNG) instead of exporting raw object bytes
        #[arg(long)]
        decode: bool,

        /// Overwrite existing output files (still avoids in-run collisions)
        #[arg(long, conflicts_with = "skip_existing")]
        overwrite: bool,

        /// Skip entries whose output file already exists
        #[arg(long)]
        skip_existing: bool,

        /// Write a JSON manifest of planned/exported entries (for resume and regression checks)
        #[arg(long)]
        manifest: Option<PathBuf>,

        /// Resume from a previous manifest (skips entries that are already exported and still exist)
        #[arg(long, conflicts_with = "overwrite")]
        resume: Option<PathBuf>,

        /// Retry only failed entries from a previous manifest (uses its `asset_path` and `key`)
        #[arg(long, conflicts_with_all = ["resume", "overwrite"])]
        retry_failed_from: Option<PathBuf>,

        /// Continue exporting even if some entries fail; failed entries are recorded in the manifest
        #[arg(long)]
        continue_on_error: bool,

        /// Parallel export jobs (0 = auto, 1 = serial)
        #[arg(long, default_value_t = 0)]
        jobs: usize,
    },

    /// Export objects from SerializedFiles (e.g. `.asset`, `.assets`) by scanning objects directly
    #[command(name = "export-serialized")]
    ExportSerialized {
        /// Input file or directory path (serialized files will be auto-detected)
        #[arg(short, long)]
        input: PathBuf,

        /// Output directory
        #[arg(short, long)]
        output: PathBuf,

        /// Restrict exporting to a specific loaded serialized source path
        #[arg(long)]
        source: Option<PathBuf>,

        /// Filter by Unity class id (can be repeated). Empty means export all.
        #[arg(long)]
        class_id: Vec<i32>,

        /// Filter by Unity class name substring (case-insensitive).
        #[arg(long, default_value = "")]
        class_name: String,

        /// Filter by object `m_Name`/`name` substring (case-insensitive) via a TypeTree prefix fast path.
        ///
        /// Note: this requires TypeTree to be present and to include a name field; otherwise the object is treated as non-matching.
        #[arg(long, default_value = "")]
        name: String,

        /// Limit exported objects
        #[arg(long)]
        limit: Option<usize>,

        /// Only print what would be exported
        #[arg(long)]
        dry_run: bool,

        /// Decode known types (AudioClip -> WAV/encoded, Texture2D -> PNG, Sprite -> PNG, TextAsset -> TXT) instead of exporting raw bytes
        #[arg(long)]
        decode: bool,

        /// Overwrite existing output files
        #[arg(long, conflicts_with = "skip_existing")]
        overwrite: bool,

        /// Skip objects whose output file already exists
        #[arg(long)]
        skip_existing: bool,

        /// Write a JSON manifest of planned/exported objects (for resume and regression checks)
        #[arg(long)]
        manifest: Option<PathBuf>,

        /// Resume from a previous manifest (skips objects that are already exported and still exist)
        #[arg(long, conflicts_with = "overwrite")]
        resume: Option<PathBuf>,

        /// Retry only failed objects from a previous manifest
        #[arg(long, conflicts_with_all = ["resume", "overwrite"])]
        retry_failed_from: Option<PathBuf>,

        /// Continue exporting even if some objects fail (failures are recorded in the manifest)
        #[arg(long)]
        continue_on_error: bool,

        /// Parallel export jobs (0 = auto, 1 = serial)
        #[arg(long, default_value_t = 0)]
        jobs: usize,
    },

    /// List AssetBundle nodes (files) for debugging and inspection
    ListBundle {
        /// Input AssetBundle path
        #[arg(short, long)]
        input: PathBuf,

        /// Filter node names by substring (case-insensitive). Empty means show all.
        #[arg(long, default_value = "")]
        filter: String,

        /// Print offsets and sizes
        #[arg(long)]
        verbose: bool,
    },

    /// List binary objects (path_id/class_id/peek_name) from SerializedFiles or bundles
    #[command(name = "list-objects")]
    ListObjects {
        /// Input file or directory path (assets/bundles will be auto-detected)
        #[arg(short, long)]
        input: PathBuf,

        /// Source kind: `all`, `bundle`, or `serialized`
        #[arg(long, default_value = "serialized")]
        kind: String,

        /// Restrict listing to a specific loaded source path
        #[arg(long)]
        source: Option<PathBuf>,

        /// Restrict listing to a specific bundle asset index (only applies when --kind bundle or all)
        #[arg(long)]
        asset_index: Option<usize>,

        /// Filter by Unity class ID (repeatable). Example: `--class-id 28` (Texture2D).
        #[arg(long)]
        class_id: Vec<i32>,

        /// Filter by Unity class name substring (case-insensitive). Example: `--class-name Texture`.
        #[arg(long, default_value = "")]
        class_name: String,

        /// Filter by object `m_Name`/`name` substring (case-insensitive) via a TypeTree prefix fast path.
        ///
        /// Note: this requires TypeTree to be present and to include a name field; otherwise the object is treated as non-matching.
        #[arg(long, default_value = "")]
        name: String,

        /// Limit printed objects
        #[arg(long)]
        limit: Option<usize>,

        /// Print one JSON object per line
        #[arg(long)]
        json: bool,
    },

    /// Find objects by AssetBundle `m_Container` asset path pattern (UnityPy-like discovery)
    FindObject {
        /// Input file or directory path (bundles will be auto-detected)
        #[arg(short, long)]
        input: PathBuf,

        /// Filter container entries by substring (case-insensitive). Empty means show all.
        #[arg(long, default_value = "")]
        pattern: String,

        /// Filter by object `m_Name`/`name` substring (case-insensitive) via a TypeTree prefix fast path.
        ///
        /// Note: this requires TypeTree to be present and to include a name field; otherwise the object is treated as non-matching.
        #[arg(long, default_value = "")]
        name: String,

        /// Filter by Unity class ID (repeatable). Example: `--class-id 83` (AudioClip).
        #[arg(long)]
        class_id: Vec<i32>,

        /// Filter by Unity class name substring (case-insensitive). Example: `--class-name Texture`.
        #[arg(long, default_value = "")]
        class_name: String,

        /// Limit matched entries
        #[arg(long)]
        limit: Option<usize>,

        /// Include entries that could not be resolved to a `BinaryObjectKey`
        #[arg(long)]
        include_unresolved: bool,

        /// Print extra object info (type_id, byte_size) when resolvable
        #[arg(long)]
        verbose: bool,
    },

    /// Inspect a single object by source location (useful for TypeTree debugging)
    InspectObject {
        /// Input file or directory path (assets/bundles will be auto-detected)
        #[arg(short, long)]
        input: PathBuf,

        /// Copy/paste key emitted by `find-object --verbose` (overrides --source/--kind/--asset-index/--path-id)
        #[arg(long)]
        key: Option<String>,

        /// Source file path that contains the object (an AssetBundle or a standalone SerializedFile).
        ///
        /// When `--input` is a single file, this defaults to `--input`.
        #[arg(long)]
        source: Option<PathBuf>,

        /// Source kind: `bundle` or `serialized`
        #[arg(long, default_value = "bundle")]
        kind: String,

        /// Asset index inside the bundle (required when `--kind bundle`)
        #[arg(long)]
        asset_index: Option<usize>,

        /// Object PathID inside the serialized file
        #[arg(long)]
        path_id: Option<i64>,

        /// Limit printed recursion depth
        #[arg(long, default_value_t = 6)]
        max_depth: usize,

        /// Limit total printed nodes (prevents huge dumps)
        #[arg(long, default_value_t = 500)]
        max_items: usize,

        /// Limit printed array items per array node
        #[arg(long, default_value_t = 16)]
        max_array: usize,

        /// Only print paths containing this substring (case-insensitive)
        #[arg(long, default_value = "")]
        filter: String,
    },

    /// Dump a JSON TypeTree registry from loaded files (for stripped-asset fallback parsing)
    #[command(name = "dump-typetree-registry")]
    DumpTypeTreeRegistry {
        /// Input file or directory path (assets/bundles will be auto-detected)
        #[arg(short, long)]
        input: PathBuf,

        /// Output JSON path
        #[arg(short, long)]
        output: PathBuf,

        /// Filter by Unity class ID (repeatable). Empty means dump all.
        #[arg(long)]
        class_id: Vec<i32>,

        /// Emit Unity version as a major.minor prefix (e.g. `2020.3.*`) instead of exact version.
        #[arg(long)]
        version_prefix: bool,

        /// Overwrite existing output file
        #[arg(long)]
        overwrite: bool,
    },

    /// Scan PPtr references (`fileID`, `pathID`) from TypeTree without fully parsing objects
    #[command(name = "scan-pptr")]
    ScanPPtr {
        /// Input file or directory path (assets/bundles will be auto-detected)
        #[arg(short, long)]
        input: PathBuf,

        /// Source kind: `all`, `bundle`, or `serialized`
        #[arg(long, default_value = "all")]
        kind: String,

        /// Restrict scanning to a specific loaded source path
        #[arg(long)]
        source: Option<PathBuf>,

        /// Restrict scanning to a specific bundle asset index (only applies when --kind bundle or all)
        #[arg(long)]
        asset_index: Option<usize>,

        /// Filter by Unity class ID (repeatable). Example: `--class-id 1` (GameObject).
        #[arg(long)]
        class_id: Vec<i32>,

        /// Filter by object `m_Name`/`name` substring (case-insensitive) via a TypeTree prefix fast path.
        #[arg(long, default_value = "")]
        name: String,

        /// Limit printed objects
        #[arg(long)]
        limit: Option<usize>,

        /// Include objects where TypeTree is unavailable (printed with empty refs)
        #[arg(long)]
        include_no_typetree: bool,

        /// Print one JSON object per line
        #[arg(long)]
        json: bool,
    },

    /// Build a best-effort dependency graph using TypeTree PPtr scanning
    ///
    /// This is intentionally optimized for large assets: it prefers the zero-allocation PPtr scan
    /// path (no full object parsing).
    #[command(name = "deps")]
    Deps {
        /// Input file or directory path (assets/bundles will be auto-detected)
        #[arg(short, long)]
        input: PathBuf,

        /// Source kind: `bundle` or `serialized`
        #[arg(long, default_value = "bundle")]
        kind: String,

        /// Source file path that contains the objects (an AssetBundle or a standalone SerializedFile)
        #[arg(long)]
        source: Option<PathBuf>,

        /// Asset index inside the bundle (required when `--kind bundle`)
        #[arg(long)]
        asset_index: Option<usize>,

        /// Output format: `summary`, `edges`, `dot`, or `json`
        #[arg(long, default_value = "summary")]
        format: String,

        /// Include best-effort object names in `edges` output (uses TypeTree prefix peek)
        #[arg(long)]
        names: bool,

        /// Maximum edges to print for `edges`/`dot` output (prevents huge dumps)
        #[arg(long, default_value_t = 2000)]
        max_edges: usize,
    },
}