All Projects → K0lb3 → Unitypy

K0lb3 / Unitypy

Licence: mit
UnityPy is python module that makes it possible to extract/unpack and edit Unity assets

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Projects that are alternatives of or similar to Unitypy

Unitypcss
Nvidia's PCSS soft shadow algorithm implemented in Unity
Stars: ✭ 533 (+438.38%)
Mutual labels:  unity, unity-asset
Radialprogressbar
Customizable radial progress bar shader for Unity3D. Allows you to set arc range, minimum and maximum colors, textures, radius, and a few more things. Create HP Bars, Speedometers, rank progress, etc!
Stars: ✭ 714 (+621.21%)
Mutual labels:  unity, unity-asset
Lunar Unity Console
High-performance Unity iOS/Android logger built with native platform UI
Stars: ✭ 628 (+534.34%)
Mutual labels:  unity, unity-asset
Randomation Vehicle Physics
Vehicle physics system for the Unity engine.
Stars: ✭ 487 (+391.92%)
Mutual labels:  unity, unity-asset
Awesome Unity Open Source On Github
A categorized collection of awesome Unity open source on GitHub (800+)
Stars: ✭ 1,124 (+1035.35%)
Mutual labels:  unity, unity-asset
Unity3d Rainbow Folders
This asset allows you to set custom icons for any folder in unity project browser.
Stars: ✭ 519 (+424.24%)
Mutual labels:  unity, unity-asset
Unity Game Hacking
A guide for hacking unity games
Stars: ✭ 710 (+617.17%)
Mutual labels:  unity, unity-asset
Savegamefree
Save Game Free is a free and simple but powerful solution for saving and loading game data in unity.
Stars: ✭ 279 (+181.82%)
Mutual labels:  unity, unity-asset
Unity Assetpipeline Presentation
Unity project for "A Technical Deep-Dive into Unity's Asset Pipeline" presented at Develop: 2018
Stars: ✭ 31 (-68.69%)
Mutual labels:  unity, unity-asset
Savegamepro
A Complete and Powerful Save Game Solution for Unity (Game Engine)
Stars: ✭ 30 (-69.7%)
Mutual labels:  unity, unity-asset
Holoshield
Highly customizable sci-fi shield / force field shader for Unity3D. Allows you to set edge power & color, inner texture scrolling, waviness, scale pulsation and procedural intensity noise. Implements tessellation for low-poly base meshes.
Stars: ✭ 401 (+305.05%)
Mutual labels:  unity, unity-asset
Dlibfacelandmarkdetector
FaceLandmark Detector using Dlib (Unity Asset Plugin)
Stars: ✭ 80 (-19.19%)
Mutual labels:  unity, unity-asset
Opencvforunity
OpenCV for Unity (Untiy Asset Plugin)
Stars: ✭ 359 (+262.63%)
Mutual labels:  unity, unity-asset
Texturepanner
This repository hosts a shader for Unity3D whose main goal is to facilitate the creation of neon-like signs, conveyor belts and basically whatever based on scrolling textures
Stars: ✭ 528 (+433.33%)
Mutual labels:  unity, unity-asset
Unity Script Collection
A maintained collection of useful & free unity scripts / library's / plugins and extensions
Stars: ✭ 3,640 (+3576.77%)
Mutual labels:  unity, unity-asset
Restclient
🦄 Simple HTTP and REST client for Unity based on Promises, also supports Callbacks! 🎮
Stars: ✭ 675 (+581.82%)
Mutual labels:  unity, unity-asset
Unity Editor Toolbox
Tools, custom attributes, drawers, hierarchy overlay, and other extensions for the Unity Editor.
Stars: ✭ 273 (+175.76%)
Mutual labels:  unity, unity-asset
Realtime Csg For Unity
Realtime-CSG, CSG level editor for Unity
Stars: ✭ 281 (+183.84%)
Mutual labels:  unity, unity-asset
Uduino
Simple and easy connection between Arduino and Unity
Stars: ✭ 25 (-74.75%)
Mutual labels:  unity, unity-asset
Fancyscrollview
[Unity] A scrollview component that can implement highly flexible animations.
Stars: ✭ 1,216 (+1128.28%)
Mutual labels:  unity, unity-asset

UnityPy

Discord server invite PyPI supported Python versions Win/Mac/Linux MIT Test and Publish

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
import UnityPy

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 UnityPy.load
            env = UnityPy.load(file_path)

            # iterate over internal objects
            for obj in env.objects:
                # 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)
            
            # alternative way which keeps the original path
            for path,obj in env.container.items():
                if obj.type in ["Texture2D", "Sprite"]:
                    data = obj.read()
                    # create dest based on original path
                    dest = os.path.join(destination_folder, *path.split("/"))
                    # make sure that the dir of that path exists
                    os.makedirs(os.path.dirname(dest), exist_ok = True)
                    # correct extension
                    dest, ext = os.path.splitext(dest)
                    dest = dest + ".png"
                    data.image.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

Environment

Environment 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 .files, which is a dict consisting of asset-name : asset.

The all objects of the loaded assets can be easily accessed via .objects, which itself is a simple recursive iterator.

import io
import UnityPy

# all of the following would work
src = "file_path"
src = b"bytes"
src = io.BytesIO(b"Streamable")

env = UnityPy.load(src)

for obj in env.objects:
    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)

Export

for obj in env.objects:
    if obj.type == "Texture2D":
        data = image.read()
        data.image.save(path)

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)

Export

for obj in env.objects:
    if obj.type == "Sprite":
        data = image.read()
        data.image.save(path)

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.

Export

for obj in env.objects:
    if obj.type == "TextAsset":
        data = image.read()
        with open(path, "wb") as f:
            f.write(bytes(data.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. (example)

  • .name
  • .script
  • .raw_data - data after the basic initialisation

Export

import json

for obj in env.objects:
    if obj.type == "MonoBehaviour":
        data = image.read()
        if data.type_tree:
            with open(path, "wt", encoding="utf8") as f:
                json.dump(data.type_tree.to_dict(), f, ensure_ascii = False, indent=4)            

AudioClip

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

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)

Mesh

  • .export() - mesh exported as .obj (str)

The mesh is converted into an Wavefront .obj file.

mesh : Mesh
with open(f"{mesh.name}.obj", "wt", newline = "") as f:
    # newline = "" is important
    f.write(mesh.export())

Goals

WIP

  • [] documentation

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].