HearthSim / UnityPack

Python deserialization library for Unity3D Asset format
https://hearthsim.info/
MIT License
720 stars 153 forks source link

KeyError when extracting spells0.unity3d #10

Closed boingy closed 7 years ago

boingy commented 8 years ago

For example if I try to run bin/unityextract with spells0.unity3d:

Traceback (most recent call last):
  File "unityextract", line 146, in <module>
    main()
  File "unityextract", line 143, in main
    exit(app.run())
  File "unityextract", line 56, in run
    self.handle_asset(asset)
  File "unityextract", line 82, in handle_asset
    if obj.type not in self.handle_formats:
  File "<snip>/unitypack/object.py", line 35, in type
    typename = self.asset.tree.type_trees[-150].type
KeyError: -150
robert-nix commented 8 years ago

Probably not the right fix, but my hack for it

diff --git a/unitypack/object.py b/unitypack/object.py
index edef4c8..8c7db82 100644
--- a/unitypack/object.py
+++ b/unitypack/object.py
@@ -32,7 +32,7 @@ class ObjectInfo:
                                except NotImplementedError:
                                        typename = script.type.type[5:-1]  # Capture type name in PPtr<...>
                        else:
-                               typename = self.asset.tree.type_trees[-150].type
+                               typename = self.asset.tree.type_trees[self.type_id].type
                        self.asset.typenames[self.type_id] = typename
                return self.asset.typenames[self.type_id]
jleclanche commented 7 years ago

@Mischanix How is this not the right fix?