diff --git a/README.md b/README.md index 9409663..aeadfd7 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,10 @@ A library to deserialize Unity3D Assets and AssetBundles files (*.unity3d). +## Fork Information + +- This fork is **meant to be used for 07th-mod project** only, I wouldn't use this for other projects. + ## Dependencies * [python-lz4](https://github.com/python-lz4/python-lz4) (For UnityFS-compressed files) diff --git a/unitypack/asset.py b/unitypack/asset.py index 137a6bc..e1b3928 100644 --- a/unitypack/asset.py +++ b/unitypack/asset.py @@ -18,8 +18,9 @@ class Asset: @classmethod - def from_bundle(cls, bundle, buf): + def from_bundle(cls, bundle, buf, legacy_mode): ret = cls() + ret.legacy_mode = legacy_mode ret.bundle = bundle ret.environment = bundle.environment offset = buf.tell() @@ -52,8 +53,9 @@ def from_bundle(cls, bundle, buf): return ret @classmethod - def from_file(cls, file, environment=None): + def from_file(cls, file, legacy_mode, environment=None): ret = cls() + ret.legacy_mode = legacy_mode ret.name = file.name ret._buf_ofs = file.tell() ret._buf = BinaryReader(file) @@ -78,6 +80,7 @@ def get_asset(self, path): return None def __init__(self): + self.legacy_mode = False self._buf_ofs = None self._objects = {} self.adds = [] diff --git a/unitypack/type.py b/unitypack/type.py index 20b50b6..8c472c3 100644 --- a/unitypack/type.py +++ b/unitypack/type.py @@ -151,9 +151,16 @@ def load(self, buf, format=None): tree.load(buf) self.type_trees[class_id] = tree - # 4 unidentified bytes at the end of a type tree in 2019.4 - if format >= 21: - unk1 = buf.read(4) + # I had an issue with only one asset being detected when trying to open a 2019.4.36f1 file + # because this would skip over the 'num_objects' field, resulting in num_objects being set to '1' + # + # I'm not sure how to fix this properly, so I've just added an option to disable it + # (perhaps you could copy how UABE does it? since UABE seems to work fine with the same file) + if not self.asset.legacy_mode: + # The below code change was added in https://github.com/HearthSim/UnityPack/pull/101 + # 4 unidentified bytes at the end of a type tree in 2019.4 + if format >= 21: + unk1 = buf.read(4) else: num_fields = buf.read_int()