Closed mos9527 closed 1 day ago
Thanks a lot for the very throughout PR and explanation.
I already have another solution in mind, and basically already implemented in a local branch featuring the next bigger update reworking the "files" structure overall.
One of the related changes is moving away from doing any processing in __init__
and instead having from_reader
class methods. This will then also finally allow easily creating instance of the affected classes without hacks.
I was considering if I should just a part of that already to fix the bug, closing your PR in turn, or keeping that off for a complete update PR, and merging your PR. As you did a very good PR I feel more like the later due to your effort.
Is having the decorators there in the first place necessary at all?
The decorators are mainly there for making the classes use __slots__
without having to define the field oneself.
The classes also receive some other goodies due to the decorator, like nice __repr__
and a working __eq__
.
When a bundle file doesn't contain its typetree (i.e.
SerializedFile._enable_type_tree
isFalse
), thenode
attribute inSerializedType
will never be written. Which would crash UnityPy.This behavior is identical with previous versions of UnityPy as the default (
None
) would be used. However, sinceattrs.define
is used whlist having a custom__init__
method on the class - these attributes will be removed unless written otherwise.This crashes the
ObjectReader
as the node attribute is always expected to be present.The patch invokes
__attrs_init__
inSerializedType
's cutsom init function (as per the docs) so that the default values are correctly preserved. Removing the decorator would also fix this issue.BTW it seems like most of the classes have custom init while being decorated by
@define
too in SerializedFile.py. Is having the decorators there in the first place necessary at all?The attached bundle file would reproduce the issue by simply reading all the objects as of commit 6350e2ec327334c8a9b7f494f344a761.
6350e2ec327334c8a9b7f494f344a761.zip