K0lb3 / UnityPy-rewrite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UnityPy (rewrite / dev)

The rewrite is still very much work in progress, with breaking changes bound to take place.

Currently there is still no top level environment handler, so assets have to be parsed in following way atm:

from UnityPy.streams.EndianBinaryReader import EndianBinaryReaderStream
from UnityPy.files import parse_file
from UnityPy.object_handlers.Mesh import MeshHandler

fp = "tests/resources/prefab"
file = parse_file(
    EndianBinaryReaderStream(open(fp, "rb")),
    os.path.basename(fp),
    fp,
)
assert file is not None
for obj in file.get_objects():
    # filter by obj class type
    # obj.m_ClassID is a pure int now, that gets resolved via the tpk,
    # so the property .classname has to be able to get the object class without parsing
    # - bound to change, propably by exporting a map from the tpk, or generating a corresponding enum
    if obj.class_name != "Mesh":
        continue
    try:
        print(obj.m_PathID)
        # parse the object content as dict, comparable to .read_typetree()
        obj_dict = obj.parse_as_dict()
        # parse the object as object class, comparable to .read(),
        # but now it also uses the typetrees and doesn't do any post processing automatically anymore
        obj_inst = obj.parse_as_object()
        # the exporters are now handlers, to allow reimporting later on
        # any previous automatic post processing of the asset data will be done here instead
        handler = MeshHandler(obj_inst)
        handler.process()
        pass
    except Exception as e:
        print(obj.m_PathID, e)
        exit()

Similar Projects

TODO

Credits

About


Languages

Language:Python 100.0%