Skip to content

Commit

Permalink
Add option to use legacy behavior for TypeMetadata loading
Browse files Browse the repository at this point in the history
 - When option is enabled, reverts HearthSim#101
  • Loading branch information
drojf committed Jan 25, 2024
1 parent 2e3e77d commit 5bf2958
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions unitypack/asset.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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 = []
Expand Down
13 changes: 10 additions & 3 deletions unitypack/type.py
Expand Up @@ -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()
Expand Down

0 comments on commit 5bf2958

Please sign in to comment.