Skip to main content

A pythonic port of AssetStudio by Perfare

Project description

UnityPy

Discord server invite PyPI supported Python versions Win/Mac/Linux MIT Build Status

A Unity asset extractor for Python based on AssetStudio.

  1. Installation
  2. Example
  3. Important Classes
  4. Important Object Types
  5. Goals
  6. Motivation
  7. Community

Installation

Python 3.6.0 or higher is required

pip install UnityPy

or download/clone the git and use

python setup.py install

Example

The following is a simple example.

import os
from UnityPy import AssetsManager

def unpack_all_assets(source_folder : str, destination_folder : str):
    # iterate over all files in source folder
    for root, dirs, files in os.walk(source_folder):
        for file_name in files:
            # generate file_path
            file_path = os.path.join(root, file_name)
            # load that file via AssetsManager
            am = AssetsManager(file_path)

            # iterate over all assets and named objects
            for asset in am.assets.values():
                for obj in asset.objects.values():
                    # only process specific object types
                    if obj.type in ["Texture2D", "Sprite"]:
                        # parse the object data
                        data = obj.read()

                        # create destination path
                        dest = os.path.join(destination_folder, data.name)

                        # make sure that the extension is correct
                        # you probably only want to do so with images/textures
                        dest, ext = os.path.splitext(dest)
                        dest = dest + ".png"

                        img = data.image
                        img.save(dest)

You probably have to read Important Classes and Important Object Types to understand how it works.

People who have slightly advanced python skills should take a look at AssetBatchConverter.py for a more advanced example.

Important Classes

AssetsManager

AssetsManager loads and parses the files that are given to it. It can be initialized via:

  • a file path - apk files can be loaded as well
  • a folder path - loads all files in that folder (bad idea for folders with a lot of files)
  • a stream - e.g. io.BytesIO, filestream,...
  • a bytes object - will be loaded into a stream

UnityPy can detect itself if the file is a WebFile, BundleFile, Asset or APK itself.

The unpacked assets will be loaded into .assets, which is a dict consisting of asset-name : asset.

from UnityPy import AssetsManager
am = AssetsManager(src)

for asset_name, asset in am.assets.items():
    pass

Asset

Assets are a container that contains multiple objects. One of these objects can be an AssetBundle, which contains a file path for some of the objects in the same asset.

All objects can be found in the .objects dict - {ID : object}.

The objects which have a file path can be found in the .container dict - {path : object}.

Object

Objects contain the actual files which, e.g. textures, text files, meshes, settings, ...

To acquire the actual data of an object it has to be read first, this happens via the .read() function. This isn't done automatically to save time because only a small part of the objects are of interest.

Important Object Types

All object types can be found in UnityPy/classes.

Texture2D

  • .name
  • .image converts the texture into a PIL.Image
  • .m_Width - texture width (int)
  • .m_Height - texture height (int)

Sprite

Sprites are part of a texture and can have a separate alpha-image as well. Unlike most other extractors (including AssetStudio) UnityPy merges those two images by itself.

  • .name
  • .image - converts the merged texture part into a PIL.Image
  • .m_Width - sprite width (int)
  • .m_Height - sprite height (int)

TextAsset

TextAssets are usually normal text files.

  • .name
  • .script - binary data (bytes)
  • .text - script decoded via UTF8 (str)

Some games save binary data as TextFile, so it's usually better to use .script.

MonoBehaviour

MonoBehaviour assets are usually binary data that has to be decoded. e.g. via msgpack, protobuf

  • .name
  • .script- binary data (bytes)

AudioClip

  • .samples - {sample-name : sample-data} dict

Goals

WIP

  • a documentation
  • the ability to edit assets (like in UABE)

planned

  • support for more object types
  • code optimization
  • speed-ups via C-extensions
  • multiprocessing

Motivation

I'm an active data-miner and noticed that unitypack has problems with new unity assets. The problem in unitypack isn't that easy to fix and the undocumented code is a bit hard to understand. That's why I tried other tools like UABE and AssetStudio. Sadly none of these tools can be used like unitypack. That's why I started this project.

Community

Discord

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

UnityPy-1.4.6.1.tar.gz (64.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

UnityPy-1.4.6.1-py3.8.egg (203.2 kB view details)

Uploaded Egg

UnityPy-1.4.6.1-py3.7.egg (202.4 kB view details)

Uploaded Egg

UnityPy-1.4.6.1-py3.6.egg (203.6 kB view details)

Uploaded Egg

UnityPy-1.4.6.1-py3-none-any.whl (84.8 kB view details)

Uploaded Python 3

File details

Details for the file UnityPy-1.4.6.1.tar.gz.

File metadata

  • Download URL: UnityPy-1.4.6.1.tar.gz
  • Upload date:
  • Size: 64.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for UnityPy-1.4.6.1.tar.gz
Algorithm Hash digest
SHA256 13a1fddf8d055aa58001ba721b32eca50f4e8f045d26129a8f7cad704a29b7c0
MD5 2553ef236fbfd6ab2abae793344dc213
BLAKE2b-256 a93dd9992c38aa564d9b7a69253a74091967b9db07bbedee9678c18303ff8879

See more details on using hashes here.

File details

Details for the file UnityPy-1.4.6.1-py3.8.egg.

File metadata

  • Download URL: UnityPy-1.4.6.1-py3.8.egg
  • Upload date:
  • Size: 203.2 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for UnityPy-1.4.6.1-py3.8.egg
Algorithm Hash digest
SHA256 abb7cc0819d4677c43b6106bb479cec61cff34bbcdc087d9cf4f22fe3499bff2
MD5 3d2951705314da4af8ec9783588b1be9
BLAKE2b-256 e804613da6e03749130ad61ff872f551ac83b4ea9e8ea482a9364c357b1e3546

See more details on using hashes here.

File details

Details for the file UnityPy-1.4.6.1-py3.7.egg.

File metadata

  • Download URL: UnityPy-1.4.6.1-py3.7.egg
  • Upload date:
  • Size: 202.4 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

File hashes

Hashes for UnityPy-1.4.6.1-py3.7.egg
Algorithm Hash digest
SHA256 86e91360f916d78af960642318a282a554cba92359da57bc31ee5db5bff4a93b
MD5 b199eae7f5e81dbb62ed69a60371aa30
BLAKE2b-256 4f3c0129c973c3632584cf60374c253dd62b5592b5de2d3ebf7992af1df03462

See more details on using hashes here.

File details

Details for the file UnityPy-1.4.6.1-py3.6.egg.

File metadata

  • Download URL: UnityPy-1.4.6.1-py3.6.egg
  • Upload date:
  • Size: 203.6 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.12

File hashes

Hashes for UnityPy-1.4.6.1-py3.6.egg
Algorithm Hash digest
SHA256 ea6fbebad827c037c1eb5e2b69b4d91121cd8bccf1dcd09829f5631db806e40a
MD5 0d06b9c60d8d26fc50dd061e91c7aefc
BLAKE2b-256 7a573ee6b701a861d0729121db629756619b27d84a1f91ecf02a12009041460b

See more details on using hashes here.

File details

Details for the file UnityPy-1.4.6.1-py3-none-any.whl.

File metadata

  • Download URL: UnityPy-1.4.6.1-py3-none-any.whl
  • Upload date:
  • Size: 84.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for UnityPy-1.4.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 55dbaafd71ac071ebcd63f3e952dbbc94ad5be14616db81af71cb89e672301a7
MD5 18d65fb9ea13279ba02bc73f72f5237d
BLAKE2b-256 8f8799f20a2e19b342cd85a3bc5a1b5bf9a3a90b2b7bb0a00a5be5bd4a83d0f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page