Skip to main content

Module read

Module read 

Source
Expand description

The cutter’s reads (docs/BATCH_SPEC.md 4.4 steps 1 and 2, section 5): a MonoBehaviour’s head, a peeked name, a texture’s fields, an atlas’s material name, each as the shape the cutter reads or a Class.

The head (the second carried question). UnityPy reads a MonoBehaviour’s head with its TPK’s MonoBehaviour tree for the file’s version, check_read off, whatever typetree the object stores (parse_monobehaviour_head). Version 1 configures no typetree provider (docs/plans/batch.md A8), so the cutter reads it with fixed rows of its own instead, nothing in them taken from a TPK (docs/plans/core.md Q2). UnityPy 1.25.2’s MIT class definitions name the four fields (classes/generated.py: MonoBehaviour‘s m_GameObject, a PPtr[GameObject] it has from Component, m_Enabled, m_Script, a PPtr[MonoScript], and m_Name, a str), but type m_Enabled only as an int. Its width and alignment, the rows’ type names and their order are format facts from Perfare/AssetStudio’s release v0.16.47 (MIT; no AssetStudio code is ported or kept here): Component reads m_GameObject (AssetStudio/Classes/Component.cs; EditorExtension before it reads only in an editor file), Behaviour one byte, m_Enabled, then aligns (Classes/Behaviour.cs), and MonoBehaviour m_Script, then the aligned string m_Name (Classes/MonoBehaviour.cs); AssetStudioUtility/SerializedTypeHelper.cs’s AddMonoBehaviour names the rows PPtr<GameObject> m_GameObject, UInt8 m_Enabled (aligned), PPtr<MonoScript> m_Script, string m_Name (its Array aligned). Each pointer is an int m_FileID and an m_PathID that is an SInt64 from SerializedFile format 14 on and an int before it, as UnityPy reads an identifier in a file (files/SerializedFile.py’s LocalSerializedObjectIdentifier) and AssetStudio a pointer (Classes/PPtr.cs). Of each row’s meta flags only the align bit is set, the one the reader acts on ([head_rows]). Two tests pin the rows: one reads them back from a file whose stored typetree is written from those facts, at formats 9 and 22, and the reference’s reads of the testkit’s atlases (format 22 files), which UnityPy makes with its TPK’s tree at run time, are recorded (tools/fixtures/ngui.py) and replayed against these rows (X5); no scene has a file before format 14. No UnityPy sample holds a MonoBehaviour to measure them against. A head read that fails is the m_Script read’s failure. UnityPy chooses the head’s tree by the file’s Unity version through its bundled typetree package, so the two can differ for a file whose version string disagrees with its format: a divergence (PARITY.md 19.3, docs/BATCH_SPEC.md 4.4 step 1), which no scene records.

Fields. UnityPy reads only the Texture2D as an object, whose attributes are its children’s cleaned names (attr, the core’s Parsed::attr); the atlas, its elements, the Material, the MonoScript, a pointer and a peeked name are typetree dicts, keyed by the children’s raw names, a repeated one keeping its last value (field, the core’s Parsed::field; review round 2’s C2). Integers are kept wide (integer).

Structs§

Blob
m_PlatformBlob, any list (4.4 step 2): what is_switch_swizzled reads of it, its length and its elements 8 to 12 as bytes, and no copy.
Head
A MonoBehaviour’s head: m_Script and m_Name.
Reader
The cutter’s reader: the head trees, and the peek tree of each type of X’s own files, built once, in a hash table by the type’s tree, charged to M_X (one entry per type a name is read of: as many as the input has objects, so a sorted table’s inserts would be quadratic, B3’s review round 1). A dependency’s tree is never kept: its peek tree is built, read with and dropped in the read (docs/plans/batch.md 2.6 step 7; review round 2’s S3).
Stream
Shared streamed texture spans and Python slicing. m_StreamData, retaining signed and wide integers until read.
Texture
A Texture2D’s fields, as the cutter reads them: the integers wide, as read, narrowed only where section 3’s answers use them (answer).

Enums§

Span
Shared streamed texture spans and Python slicing. The core range, or a Python slice of the whole resource.

Constants§

BLOB_ELEMENT
Section 3’s rule for a Switch blob element among bytes 8 to 12 that is not a byte: UnityPy’s int.from_bytes(platform_blob[8:12], "little") raises, so the texture’s answer is decode_error, detail read.

Functions§

answer
Section 3’s answers 1 to 3 for t on platform, exporting the formats of allowed (the spec’s, docs/BATCH_SPEC.md 1.5): its format, or the skip. A format outside i32 is unsupported_format(<decimal>); a Switch blob is read as bytes (Blob, BLOB_ELEMENT).
attr
An object’s attribute, as UnityPy’s object mode keys it: the last child whose cleaned name is name (Parsed::attr). The Texture2D’s only.
field
A dict’s field by its raw name, as parse_as_dict keys it: of children of one name, the last one’s value.
integer
Any integer, signed or not (not a bool, which UnityPy’s dict keeps apart), as read.
parent_bundle
The bundle a SerializedFile or bundle’s parent link names, while alive.
pptr
A pointer struct: an integer m_FileID and m_PathID.
python_slice
Shared streamed texture spans and Python slicing. Python’s data[start:stop], including negative indices and clamping.
shape
A value of another shape than the cutter reads: a ParseError’s Read (4.4 step 2’s rule).
texture
A texture’s object read (4.4 step 2): the checked read, then the class UnityPy builds (a Texture2D lacking a field of no default, or with a field it cannot be given, is an UnknownObject; one that shadows set_object_reader fails its read), then the shape.
top_bundle
The top-level bundle that holds file, held while a read uses it (docs/plans/batch.md 2.6 step 7).