• Stars
    star
    708
  • Rank 62,396 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python deserialization library for Unity3D Asset format

UnityPack

Build Status

A library to deserialize Unity3D Assets and AssetBundles files (*.unity3d).

Dependencies

How Unity packs assets

Most extractors for Unity3D files (such as Disunity) deal with the format as a "file store", treating it as one would treat a zip. This is not how the format actually works.

Unity files are binary-packed, serialized collections of Unity3D classes. To this end, they are much closer to a json file containing arrays of objects.

Some of those classes have fields which contain raw data, such as Texture2D's image data field or TextAsset's m_Script field. Using this, files can be "extracted" from the asset bundles by using their m_Name and an appropriate extension. But doing so leaves out all the "unextractable" classes which one might want to deal with.

Usage

To open an asset, or asset bundle, with unitypack:

import unitypack

with open("example.unity3d", "rb") as f:
	bundle = unitypack.load(f)

	for asset in bundle.assets:
		print("%s: %s:: %i objects" % (bundle, asset, len(asset.objects)))

The objects field on every Asset is a dictionary of path_id keys to ObjectInfo values. The path_id is a unique 64-bit signed int which represents the object instance. The ObjectInfo class is a lazy lookup for the data on that object.

Thus, if you want to actually extract the data:

for id, object in asset.objects.items():
	# Let's say we only want TextAsset objects
	if object.type == "TextAsset":
		# We avoid reading the data, unless it's a TextAsset
		data = object.read()
		# The resulting `data` is a unitypack.engine.TextAsset instance
		print("Asset name:", data.name)
		print("Contents:", repr(data.script))

Not all base Unity3D classes are implemented. If a class is unimplemented, or a custom class (eg. a non-Unity class) is encountered, the resulting data is a dict of the fields instead. The same dict of fields can be found in the _obj attribute of the instance, otherwise.

Included tools

Included are two scripts which use unitypack for some common operations:

Asset extraction

unityextract can extract common types of data from assets and asset bundles, much like Disunity. By default, it will extract all known extractable types:

  • AudioClip objects will be converted back to their original format. Note that recent Unity3D versions pack these as FSB files, so python-fsb5 is required to convert them back.
  • Texture2D objects will be converted to png files. Not all Texture2D formats are supported. Pillow version >= 3.4 is required for this. decrunch is required for DXT1Crunched / DXT5Crunched.
  • Mesh objects (3D objects) will be pickled. Pull requests implementing a .obj converter are welcome and wanted.
  • TextAsset objects will be extracted as plain text, to .txt files
  • Shader objects work essentially the same way as TextAsset objects, but will be extracted to .cg files.

Filters for individual formats are available. Run unityextract --help for the full list.

YAML conversion

unity2yaml can convert AssetBundles to YAML output. YAML is more appropriate than JSON due to the recursive, pointer-heavy and class-heavy nature of the Unity3D format.

When run with the --strip argument, extractable data will be stripped out. This can make the resulting YAML output far less heavy, as binary data will otherwise be converted to Base64 which can result in extremely large text output.

Here is a stripped example of the movies0.unity3d file from Hearthstone, which contains only two objects (a MovieTexture cinematic and a corresponding AudioClip):

!unitypack:AudioClip
m_BitsPerSample: 16
m_Channels: 0
m_CompressionFormat: 0
m_Frequency: 0
m_IsTrackerFormat: false
m_Legacy3D: false
m_Length: 0.0
m_LoadInBackground: false
m_LoadType: 0
m_Name: Cinematic audio
m_PreloadAudioData: true
m_Resource: !unitypack:StreamedResource {m_Offset: 0, m_Size: 0, m_Source: ''}
m_SubsoundIndex: 0

m_AssetBundleName: ''
m_Container:
- first: final/data/movies/cinematic.unity3d
  second:
    asset: !PPtr [0, -4923783912342650895]
    preloadIndex: 0
    preloadSize: 2
m_Dependencies: []
m_IsStreamedSceneAssetBundle: false
m_MainAsset: {asset: null, preloadIndex: 0, preloadSize: 0}
m_Name: ''
m_PreloadTable:
- !PPtr [0, -6966092991433622133]
- !PPtr [0, -4923783912342650895]
m_RuntimeCompatibility: 1

!unitypack:stripped:MovieTexture
m_AudioClip: !PPtr [0, -6966092991433622133]
m_ColorSpace: 1
m_Loop: false
m_MovieData: <stripped>
m_Name: Cinematic

Stripped classes will be prefixed with unitypack:stripped:.

License

python-unitypack is licensed under the terms of the MIT license. The full license text is available in the LICENSE file.

Community

python-unitypack is a HearthSim project. All development happens on our IRC channel #hearthsim on Freenode.

Contributions are welcome. Make sure to read through the CONTRIBUTING.md first.

More Repositories

1

Hearthstone-Deck-Tracker

A deck tracker and deck manager for Hearthstone on Windows
C#
4,601
star
2

HSTracker

A deck tracker and deck manager for Hearthstone on macOS
Swift
1,145
star
3

UnityHook

Platform to hook into Unity3D assemblies
C#
260
star
4

hsdata

Hearthstone Data
252
star
5

SabberStone

Just another Hearthstone Simulator in C# .Net Core, with some A.I. approaches!
C#
246
star
6

python-hearthstone

Hearthstone Python library (CardDefs, DBF, enums, log parser)
Python
228
star
7

Arcane-Tracker

An automatic Hearthstone tracker for Android
Kotlin
146
star
8

python-fsb5

Library and tool to extract audio from FSB5 (FMOD Sample Bank) files
Python
130
star
9

Joust

๐Ÿฟ Hearthstone replays in your browser.
TypeScript
114
star
10

Sunwell

Canvas-based high quality Hearthstone card renderer - no longer maintained
TypeScript
95
star
11

dj-paypal

Paypal integration for Django - Inspired by dj-Stripe
Python
86
star
12

proto-extractor

Program to extract protobufs compiled for C#
C#
79
star
13

HearthDb

HearthDb is a .NET Hearthstone database.
C#
68
star
14

hs-bugs

Unofficial Hearthstone issue tracker
65
star
15

docker-pgredshift

Redshift docker image based on postgres
Dockerfile
61
star
16

HDT-Releases

56
star
17

python-hslog

Python module to parse Hearthstone Power.log files
Python
56
star
18

python-hsreplay

Python library for creating and parsing HSReplay XML files
Python
50
star
19

LotusTracker

Deck Tracker for Magic Arena [DEPRECATED]
C++
50
star
20

hearthstone-deckstrings

๐Ÿ”— Decode and encode Hearthstone Deckstrings.
JavaScript
50
star
21

hs-icons

Hearthstone vector icons
39
star
22

twitch-hdt-frontend

๐Ÿ“บ The official Twitch Extension for Hearthstone Deck Tracker.
TypeScript
39
star
23

hsreplaynet-localstack

HSReplay.net local Docker dev stack
Python
32
star
24

hsproto

Hearthstone Protobuf files
32
star
25

HDT-Localization

Localization for Hearthstone Deck Tracker
XML
23
star
26

Brazier

Hearthstone Simulator in Java
Java
21
star
27

dynity

Load an assembly in Unity at runtime
C++
20
star
28

keg

A client for Blizzard's NGDP protocol
Python
20
star
29

django-reflinks

Referral links implementation for Django
Python
15
star
30

twitch-hdt-ebs

๐Ÿ“ข Twitch Extension Backend Service for Hearthstone Deck Tracker.
Python
15
star
31

decrunch

Python wrapper around Crunch DXTc decompressor
C++
13
star
32

articles

Analysis of Hearthstone replays
Jupyter Notebook
11
star
33

hs-card-tiles

Hearthstone Card Tiles
C#
9
star
34

UnityPack-Swift

Swift port of UnityPack
C
8
star
35

python-hearthstone-data

CardDefs.xml and Strings.txt for Hearthstone, conveniently packaged in Python
Python
7
star
36

unity-examples

ASP
7
star
37

HearthBot

Hearthstone bot for Discord
Python
7
star
38

HSTracker-Beta

6
star
39

pyreplib

Starcraft Replay File parser [archived]
C++
6
star
40

hearthsim.info

The HearthSim community website
SCSS
6
star
41

hearthstonejson-client

๐Ÿ“– HearthstoneJSON client for browsers and Node.
TypeScript
6
star
42

hearthforge

JavaScript
5
star
43

hsreplay-xml

๐Ÿ“ผ Replay format for Hearthstone
5
star
44

hsreplaynet-i18n

๐ŸŒŽ Translations for HSReplay.net.
Gettext Catalog
5
star
45

deck-code-bot

A bot for decoding Hearthstone deck codes on Reddit
Python
4
star
46

legal

HearthSim legal documents (Privacy Policy, Terms of Services, etc)
Markdown
3
star
47

hsreplaynet-embed

Embeddable library for HSReplay.net features on other sites
TypeScript
3
star
48

FSBReader

FSB Reader code for FSBExtractor
Pascal
3
star
49

scenfiles

Hearthstone .scen files and conversion utility
Python
2
star
50

HearthstoneJSON.com

The HearthstoneJSON.com frontend jekyll website
CSS
2
star
51

hsreplay-test-data

Log data for HSReplay and hslog tests
XML
2
star
52

node-canvas-lambda

Builds node-canvas for lambda
Shell
2
star
53

kettle-design

Repo for Kettle design collaboration
C#
2
star
54

CardBot-lua

An IRC card search bot for #hearthsim [archived]
Lua
2
star
55

django-intenumfield

An IntEnumField for Django
Python
2
star
56

deckwarper

๐Ÿ”ง A tiny web-based tool to create and edit Hearthstone decks.
JavaScript
2
star
57

hsreplaynet-api-docs

1
star
58

SabberStoneSynchronizer

Synchronizer between a running Hearthstone client and SabberStone.
C#
1
star
59

hearthsim-instrumentation

Legacy HSReplay.net runtime tooling
Python
1
star
60

HDT-Releases-HSReplay

1
star
61

MtgLotusValley.com

www.mtglotusvalley.com
Vue
1
star
62

hsreplaynet-lambdas

Python
1
star
63

branding

๐ŸŽจ Logos, Colors and Guidelines for the HearthSim brands.
1
star
64

eslint-config-typescript

HearthSim's common ESLint configuration
JavaScript
1
star
65

Firestarter

Rust
1
star
66

mpqlib

Bob Jenkins' MPQLib (Public Domain)
C
1
star
67

hs-proto-go

Autogenerated Golang code for hs-proto
Shell
1
star
68

react-hs-components

๐Ÿ—„๏ธ Common React components used across HearthSim products.
TypeScript
1
star
69

django-hearthstone

Hearthstone DBF models for Django
Python
1
star