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 used to save the class instances with their values. If a type tree exists it can be used to read the whole data, but if it doesn't, then it is usually necessary to investigate the class that loads the specific MonoBehaviour to extract the data.

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

AudioClip

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

The samples are converted into the .wav format. The sample-data is a .wav file in bytes.

clip : AudioClip
for name, data in clip.samples.items():
    with open(name, "wb") as f:
        f.write(data)

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.3.1.tar.gz (8.9 MB 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.3.1-py3.8.egg (9.1 MB view details)

Uploaded Egg

UnityPy-1.5.3.1-py3.7.egg (9.1 MB view details)

Uploaded Egg

UnityPy-1.5.3.1-py3.6.egg (9.1 MB view details)

Uploaded Egg

UnityPy-1.5.3.1-py3-none-any.whl (8.9 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: UnityPy-1.5.3.1.tar.gz
  • Upload date:
  • Size: 8.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.6

File hashes

Hashes for UnityPy-1.5.3.1.tar.gz
Algorithm Hash digest
SHA256 e75dfd2a6c759e2760c28d63e913a4b970eea6d74fbf72c609f7ba0015eeed19
MD5 81e99d0b1282ebc069fd8b93f0e58d4a
BLAKE2b-256 bedaf9ed9c1091959eca61d496f2398b00f545d7f15beaff8f57b088464a806e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: UnityPy-1.5.3.1-py3.8.egg
  • Upload date:
  • Size: 9.1 MB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.6

File hashes

Hashes for UnityPy-1.5.3.1-py3.8.egg
Algorithm Hash digest
SHA256 1965071dc03de4cbc22625958c07ea0bbb5450efb0759b22ed106f4a361c2ee0
MD5 640a4117488cb1b1675d452a8efdb322
BLAKE2b-256 428780374f85e19db3dfa98cbdf319ffd18afd2eb1963b07106961de44f3671b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: UnityPy-1.5.3.1-py3.7.egg
  • Upload date:
  • Size: 9.1 MB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.9

File hashes

Hashes for UnityPy-1.5.3.1-py3.7.egg
Algorithm Hash digest
SHA256 fd8dbfb95ee4ce622bb60648d3df0ee47eb0b5ab8b2628e41e712e4f8731d08e
MD5 afd17b258351e1b31188124fd70ab90c
BLAKE2b-256 8b1266e55fc9ab9e582c3ca476edf9a2f37a3abf9dc0e310069a70d089c8f3e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: UnityPy-1.5.3.1-py3.6.egg
  • Upload date:
  • Size: 9.1 MB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.6.8

File hashes

Hashes for UnityPy-1.5.3.1-py3.6.egg
Algorithm Hash digest
SHA256 74d30577b7d2f2de3ec3c4dc345b0913403b73aa8883dad45fa6de3fd13c8517
MD5 97f2bf2637da6f9d66632b7870728b47
BLAKE2b-256 a88577cb5010a0d15bbf93e1bd161e70d91f6bc1678ff20e3350601f617ffba1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: UnityPy-1.5.3.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.6

File hashes

Hashes for UnityPy-1.5.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7dd92b985198624bd01d9db4c5060781b849657a72dfadb1aaca564219d11f35
MD5 a53f17e3c2ce0dbdeeb2900b709d6c84
BLAKE2b-256 52c95867248efb9c395d351ef87787a25047ce08c6f5528716cbf5b2130bb7c1

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