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.2.tar.gz (62.8 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.2-py3.8.egg (208.5 kB view details)

Uploaded Egg

UnityPy-1.4.2-py3.7.egg (208.0 kB view details)

Uploaded Egg

UnityPy-1.4.2-py3.6.egg (208.4 kB view details)

Uploaded Egg

UnityPy-1.4.2-py3-none-any.whl (86.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: UnityPy-1.4.2.tar.gz
  • Upload date:
  • Size: 62.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for UnityPy-1.4.2.tar.gz
Algorithm Hash digest
SHA256 a0ba2f44827c271b9b063361f53b88ef782b78da506962c1622292bc02c8b25d
MD5 24ab4c88979c6fa9ee1e0792207aa4d4
BLAKE2b-256 37e916c70c09f7f6541cc60b55e5a009cfb65620907dcaf7bd8257ae450abce6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: UnityPy-1.4.2-py3.8.egg
  • Upload date:
  • Size: 208.5 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for UnityPy-1.4.2-py3.8.egg
Algorithm Hash digest
SHA256 f13a46b1df58f1141873f33e820201c823eb0390a958d6bd059f12ee5ac1c823
MD5 fd322c58f28cb26be438e71c75f7a9fc
BLAKE2b-256 ad85bd88bdef49ea5a758c16bffa035c4f0816467698a0fa0d8737f01a24d127

See more details on using hashes here.

File details

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

File metadata

  • Download URL: UnityPy-1.4.2-py3.7.egg
  • Upload date:
  • Size: 208.0 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for UnityPy-1.4.2-py3.7.egg
Algorithm Hash digest
SHA256 ba195b41bcc234fdf6fa7886393888c679672385cbc204b766e1c0f795720f78
MD5 6cbd47f7692046d2b51bdb535bb2a341
BLAKE2b-256 c222a50aa6a0db354945bd2ec84270848b5339361016f29944fd75555ddb7ef1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: UnityPy-1.4.2-py3.6.egg
  • Upload date:
  • Size: 208.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/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.10

File hashes

Hashes for UnityPy-1.4.2-py3.6.egg
Algorithm Hash digest
SHA256 51fc0a5093ec53a0c34699f77b2df0e85586ed8b9b0bc6bec65623b4da493ed2
MD5 a67f09bd79c070e43d16cc5a6642f98c
BLAKE2b-256 c4e32ea54111d7cc0867d26db2e8d5331af4150e1446033fe4ca0ac83441c9ee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: UnityPy-1.4.2-py3-none-any.whl
  • Upload date:
  • Size: 86.3 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/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for UnityPy-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1872c3a10252c439345dc50b9f47ad6dbb4528594afb85f48142cf7a43f71576
MD5 5e308871fb38e918ca4c6f5bf6338ade
BLAKE2b-256 9452a8a43ddb84900e3d355259b69e1a91107ac67058894e58aa2ad363509f5e

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