Expand description
UnityPy’s pure-Python writer (helpers/TypeTreeHelper.py:161-179,
:381-458). Dispatch is on the type name first (FUNCTION_WRITE_MAP), then
pair, ReferencedObject, an Array first child, and a class. Under
super::WriteRules::UnityPy each array element aligns after itself when
its node is flagged, then the vector or Array flag aligns once; a class
writes value[child.m_Name] for every child, a missing key failing and an
extra key ignored; ReferencedObject data needs a non-empty ref_types
(:99-100) and a ref type with a tree: an empty class, or a matched ref
type with no tree, fails (KeyError: 'data' when the reader left data
out, else an AttributeError on the None node); integers are
range-checked as struct.pack checks them.
Duck typing (W2). The writer takes any value Python’s operations
accept, not only the variant the reader makes for the node, which a
duplicate-name object exercises (its dict holds one child’s value under
the other’s node). Probed on UnityPy 1.25.2: a bool node takes any value
(its truthiness; an empty Str, Bytes, List, Tuple or Dict is
false); an integer node takes Bool and Int/UInt in range; a float
or double node takes Bool, integers and floats; a string node only
Str; TypelessData only Bytes; a pair node anything with items 0
and 1 (List, Tuple, Prims or Bytes of length 2 or more, a Str
of 2 or more characters written through the children’s kinds); an array
any sized iterable (List, Tuple, Prims, Bytes as integers, Str
as one-character strings, a Dict as its keys), each element written by
the element node under the same rules; a class with no children any value
(its non-dict branch iterates no children and writes nothing); a class
with children a Dict (value[child.m_Name]) or any other value that has
each child’s cleaned name as a Python attribute (getattr(value, child._clean_name), TypeTreeHelper.py:447-455: an int value satisfies a child named
real, a list one named count, whose bound method a bool node
writes as true). An Array node with three or more children writes its
elements through m_Children[1] (:434), as the pure-Python reader
reads them.
The mirror. Under super::WriteRules::MirrorReader the writer
takes the rules of the reader that built the value (Parsed::read_by):
its kinds (Writer::kind), its runs (run.rs), its empty strings and its
ReferencedObject data. Review round 11: it took UnityPyBoost’s for every
value, so it refused the pure-Python reader’s value of a zero-byte object
read through a type name holding a NUL, which UnityPy writes.
Owner: package B.
Re-exports§
pub use pyobj::cleans_to;
Functions§
- cleans_
to - Whether UnityPyBoost’s
clean_nameofnameistarget([clean_name]), the key UnityPy’s object mode gives a field (parse_class). Atargetlonger than [CLEAN_MAX] bytes is never one. - write
- Writes
parsedthroughtree(the object’s own tree, or anodes=override: keys are then matched by name), appending toout, a buffer on the object’s input’s meter that charges before it grows (a value read with a negative length can name the same bytes many times, so the output can be far larger than the value; plan section 3.15). Its work is the open’s ofout’s meter, counted as it goes whatever the outcome (OpenWork):VALUE_WORKfor each value it writes or child it skips, but a primitive, which counts the bytes it writes, as a read counts a primitive run’s; and each step of finding a child’s entry that builds no value (super::STEP_WORK, and the bytes of a name it compares or hashes). A write is refused before it starts once the open’s work has passed its allowance, and fails once its own work takes the open past it (the module docs ofsuper, “Work”). - write_
at - Append an object while aligning relative to a caller’s stream origin.
UnityPy’s supplied writer aligns its complete stream, including any prefix
(
streams/EndianBinaryWriter.py:88-97). An origin past the current output refuses before writing. [write] retains object-relative alignment. - write_
at_ with_ lengths - Append a Python writer snapshot whose protocol lengths may differ from storage sizes. Overrides affect only length prefixes; all retained bytes and yielded elements still count toward work and output limits.