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. Serialized objects can be set with raw data using .set_raw_data(data) or modified with .save() function if supported.

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, kaitaistruct etc)

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

AudioClip

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

Goals

WIP

  • A documentation
  • The ability to edit assets (like in UABE)

TODO

  • 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.5.1.tar.gz (65.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.5.1-py3.8.egg (209.0 kB view details)

Uploaded Egg

UnityPy-1.5.1-py3.7.egg (208.3 kB view details)

Uploaded Egg

UnityPy-1.5.1-py3.6.egg (209.3 kB view details)

Uploaded Egg

UnityPy-1.5.1-py3-none-any.whl (86.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: UnityPy-1.5.1.tar.gz
  • Upload date:
  • Size: 65.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for UnityPy-1.5.1.tar.gz
Algorithm Hash digest
SHA256 fc578d60bb876dd2c934b4e50e2010482a3d2798bc68c92f821402bd4330a251
MD5 4ba4fa881a231024bcac9450b7acd2c2
BLAKE2b-256 37d2e3f7302c1f9f6663b3daa4d5114dee10dfa0bd7c35d96fff1b58384ecdff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: UnityPy-1.5.1-py3.8.egg
  • Upload date:
  • Size: 209.0 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for UnityPy-1.5.1-py3.8.egg
Algorithm Hash digest
SHA256 4b6003988d9ac5fbc837cce86f4c65d1df68a790f43964e6e120f7bb7180f017
MD5 470e0d3dfc6214164716194bd9ccad88
BLAKE2b-256 51099678706f28be1394503ca7973bb72971d2fff03b742923e1dded19ecb528

See more details on using hashes here.

File details

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

File metadata

  • Download URL: UnityPy-1.5.1-py3.7.egg
  • Upload date:
  • Size: 208.3 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9

File hashes

Hashes for UnityPy-1.5.1-py3.7.egg
Algorithm Hash digest
SHA256 ff3e71f304f02644c0838b301bdc805e362e0bd8e025104a989f753a77121193
MD5 b5ec05f9c8a87a4e93fdb70931daff74
BLAKE2b-256 5def4893f6be004242482c2d6de53488c26ce9eeeda98c16531dba70118a6455

See more details on using hashes here.

File details

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

File metadata

  • Download URL: UnityPy-1.5.1-py3.6.egg
  • Upload date:
  • Size: 209.3 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.12

File hashes

Hashes for UnityPy-1.5.1-py3.6.egg
Algorithm Hash digest
SHA256 e472ae14d48b70f0704e17bec51cbb968495034275d7c49c6aa1680453afc83d
MD5 761a1ae6c02555e511a7d78936d25ee0
BLAKE2b-256 bff6d570a31065ae1ec552325f57e7b184326be7a26b60fae1a56c359d323fa3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: UnityPy-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 86.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9

File hashes

Hashes for UnityPy-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9af7b7813226e2d7887d2820022b9f1dd647c2342c1f1fc1c83a2e916e7ca222
MD5 0bef442049f8af7dc5734bfad553ea7b
BLAKE2b-256 60f6d5c37a85f1a10859e2b966506d290e4f5c2ceb765e274a240eb18ca4a3d8

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