Skip to content

Sprite-Texture2D merging issue #45

Closed

Description

@szescxz

Code

import UnityPy
env = UnityPy.load("live_note_default")
for path, obj in env.container.items():
    print(path, obj.type)

Error
N/A

Bug
Seems like the Sprite-Texture2D merging is performed in the wrong direction.
Four Sprite in the sample: notes_crtcl, notes_flick, notes_long and notes_normal, all based on the Texture2D notes. (let's ignore the rest of the items here)
I'm expecting all four Sprites in the output, but UnityPy only gives me one Sprite named notes.

Also a tiny bug, too lazy for a separate issue: 1.7.3 breaks str(obj.type), now all items are UnknownType.

To Reproduce

  • a copy of the file that causes the problem
    live_note_default.zip (unzip it and you should get an asset bundle file)
  • following data:
    • Python version 3.7.3
    • UnityPy version 1.7.2

Activity

  1. K0lb3 commented on Apr 17, 2021

    @K0lb3
    Owner

    A lot of sprites in that asset have the identical container path, so extracting the objects only via the container won't do in this case.
    Strictly speaking UnityPy doesn't handle the containers correctly. UnityPy handles them as dict (path -> obj), while they are actually a multi-dict, which can have multiple entries with the same key.

    Also a tiny bug, too lazy for a separate issue: 1.7.3 breaks str(obj.type), now all items are UnknownType.

    Thanks for reporting that issue, I pushed a fix for it just now.

  2. erikchan002 commented on Sep 3, 2022

    @erikchan002

    Are there any plans on completing to TODO of fixing the container dictionary for non-unique container paths?

    While I understand and can workaround the fact that I cannot access all of the objects via the container, the issue also prevents me from knowing the container path for some of the objects even when the objects are accessed by env.objects:

    env = UnityPy.load("live_note_default")
    path_ids = [-8615770281572025746,-8198049756159249405,-3594623656469114911,310693865538495986,4976375391278443517]
    [object.container for object in env.objects if object.path_id in path_ids]
    """
    [None,
     'assets/sekai/assetbundle/resources/startapp/live/note/default/textures/notes.png',
     None,
     None,
     None]
    """

    image


    A simple solution is to just use a dict of list for self.container_ in SerializedFile, self.m_Container in AssetBundle, the type annotation for env, and other places in tools, examples and the readme. e.g. in SerializedFile.py

    from collections import defaultdict

    self.container_ = defaultdict(list)

    # read the asset_bundles to get the containers
    for obj in self.objects.values():
    if obj.type == ClassIDType.AssetBundle:
    data = obj.read()
    for container, assets_info in data.m_Container.items():
    for asset_info in assets_info:
    asset = asset_info.asset
    self.container_[container].append(asset)
    if hasattr(asset, "path_id"):
    self._container[asset.path_id] = container

    etc.

    env = UnityPy.load("live_note_default")
    path_ids = [-8615770281572025746,-8198049756159249405,-3594623656469114911,310693865538495986,4976375391278443517]
    [object.container for object in env.objects if object.path_id in path_ids]
    """
    ['assets/sekai/assetbundle/resources/startapp/live/note/default/textures/notes.png',
     'assets/sekai/assetbundle/resources/startapp/live/note/default/textures/notes.png',
     'assets/sekai/assetbundle/resources/startapp/live/note/default/textures/notes.png',
     'assets/sekai/assetbundle/resources/startapp/live/note/default/textures/notes.png',
     'assets/sekai/assetbundle/resources/startapp/live/note/default/textures/notes.png']
    """

    This however breaks all backwards compatibility for applications currently using containers.

    env.container
    """
    {'assets/sekai/assetbundle/resources/startapp/live/note/default/atlas/noteatlas.spriteatlas': [<PPtr <ObjectReader SpriteAtlas>>],
    ...
    """

    I can create a PR if there is no WIP on fixing this issue but I do not understand UnityPy fully so there may be other affected places I missed. I know it is very bad to have such a huge break in backwards compatibility but I am just trying to keep this discussion open.

  3. K0lb3 commented on Sep 5, 2022

    @K0lb3
    Owner

    I'm planning on fixing the issue with UnityPy version 2,
    as as you've said, it would break all existing scripts that use the container.

    I plan to use either a list of namedtuple or a multidict for the container.

    I guess that it would be possible to add a temporary alternative to container,
    with container falling back to that alternative to avoid breaking compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions