You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9232cdd
Browse filesBrowse the repository at this point in the historyBrowse files
@@ -130,6 +128,10 @@ and [Important Object Types](#important-object-types) to understand how it works
130
128
People with slightly advanced python skills should look at [UnityPy/tools/extractor.py](UnityPy/tools/extractor.py) for a more advanced example.
131
129
It can also be used as a general template or as an importable tool.
132
130
131
+
### Setting the decryption key for Unity CN's AssetBundle encryption
132
+
133
+
The chinese version of Unity has its own inbuild option to encrypt AssetBundles/BundleFiles. As it's a feature of Unity itself, and not a game specific protection, it is included in UnityPy as well.
134
+
To enable encryption simply use `UnityPy.set_assetbundle_decrypt_key(key)`, with key being the value that the game that loads the budles passes to `AssetBundle.SetAssetBundleDecryptKey`.
133
135
134
136
## Important Classes
135
137
@@ -138,16 +140,16 @@ It can also be used as a general template or as an importable tool.
138
140
Environment loads and parses the given files.
139
141
It can be initialized via:
140
142
141
-
* a file path - apk files can be loaded as well
142
-
* a folder path - loads all files in that folder (bad idea for folders with a lot of files)
143
-
* a stream - e.g., io.BytesIO, file stream,...
144
-
* a bytes object - will be loaded into a stream
143
+
- a file path - apk files can be loaded as well
144
+
- a folder path - loads all files in that folder (bad idea for folders with a lot of files)
145
+
- a stream - e.g., io.BytesIO, file stream,...
146
+
- a bytes object - will be loaded into a stream
145
147
146
148
UnityPy can detect if the file is a WebFile, BundleFile, Asset, or APK.
147
149
148
-
The unpacked assets will be loaded into ``.files``, a dict consisting of ``asset-name : asset``.
150
+
The unpacked assets will be loaded into `.files`, a dict consisting of `asset-name : asset`.
149
151
150
-
All objects of the loaded assets can be easily accessed via ``.objects``,
152
+
All objects of the loaded assets can be easily accessed via `.objects`,
151
153
which itself is a simple recursive iterator.
152
154
153
155
```python
@@ -177,28 +179,29 @@ with open(dst, "wb") as f:
177
179
Assets are a container that contains multiple objects.
178
180
One of these objects can be an AssetBundle, which contains a file path for some of the objects in the same asset.
179
181
180
-
All objects can be found in the ``.objects`` dict - ``{ID : object}``.
182
+
All objects can be found in the `.objects` dict - `{ID : object}`.
181
183
182
-
The objects with a file path can be found in the ``.container`` dict - ``{path : object}``.
184
+
The objects with a file path can be found in the `.container` dict - `{path : object}`.
183
185
184
186
### [Object](UnityPy/files/ObjectReader.py)
185
187
186
-
Objects contain the *actual* files, e.g., textures, text files, meshes, settings, ...
188
+
Objects contain the _actual_ files, e.g., textures, text files, meshes, settings, ...
187
189
188
-
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.
190
+
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.
189
191
190
192
## Important Object Types
191
193
192
194
All object types can be found in [UnityPy/classes](UnityPy/classes/).
193
195
194
196
### [Texture2D](UnityPy/classes/Texture2D.py)
195
197
196
-
*``.name``
197
-
*``.image`` converts the texture into a ``PIL.Image``
198
-
*``.m_Width`` - texture width (int)
199
-
*``.m_Height`` - texture height (int)
198
+
-`.name`
199
+
-`.image` converts the texture into a `PIL.Image`
200
+
-`.m_Width` - texture width (int)
201
+
-`.m_Height` - texture height (int)
202
+
203
+
**Export**
200
204
201
-
__Export__
202
205
```python
203
206
fromPILimport Image
204
207
for obj in env.objects:
@@ -218,12 +221,13 @@ for obj in env.objects:
218
221
Sprites are part of a texture and can have a separate alpha-image as well.
219
222
Unlike most other extractors (including AssetStudio), UnityPy merges those two images by itself.
220
223
221
-
*``.name``
222
-
*``.image`` - converts the merged texture part into a ``PIL.Image``
223
-
*``.m_Width`` - sprite width (int)
224
-
*``.m_Height`` - sprite height (int)
224
+
-`.name`
225
+
-`.image` - converts the merged texture part into a `PIL.Image`
226
+
-`.m_Width` - sprite width (int)
227
+
-`.m_Height` - sprite height (int)
228
+
229
+
**Export**
225
230
226
-
__Export__
227
231
```python
228
232
for obj in env.objects:
229
233
if obj.type.name =="Sprite":
@@ -235,13 +239,14 @@ for obj in env.objects:
235
239
236
240
TextAssets are usually normal text files.
237
241
238
-
*``.name``
239
-
*``.script`` - binary data (bytes)
240
-
*``.text`` - script decoded via UTF8 (str)
242
+
-`.name`
243
+
-`.script` - binary data (bytes)
244
+
-`.text` - script decoded via UTF8 (str)
245
+
246
+
Some games save binary data as TextFile, so it's usually better to use `.script`.
241
247
242
-
Some games save binary data as TextFile, so it's usually better to use ``.script``.
248
+
**Export**
243
249
244
-
__Export__
245
250
```python
246
251
for obj in env.objects:
247
252
if obj.type.name =="TextAsset":
@@ -263,11 +268,12 @@ If a type tree exists, it can be used to read the whole data,
263
268
but if it doesn't exist, then it is usually necessary to investigate the class that loads the specific MonoBehaviour to extract the data.
*``.raw_data`` - data after the basic initialisation
271
+
-`.name`
272
+
-`.script`
273
+
-`.raw_data` - data after the basic initialisation
274
+
275
+
**Export**
269
276
270
-
__Export__
271
277
```python
272
278
import json
273
279
@@ -300,7 +306,7 @@ for obj in env.objects:
300
306
301
307
### [AudioClip](UnityPy/classes/AudioClip.py)
302
308
303
-
*``.samples`` - ``{sample-name : sample-data}``
309
+
-`.samples` - `{sample-name : sample-data}`
304
310
305
311
The samples are converted into the .wav format.
306
312
The sample data is a .wav file in bytes.
@@ -326,10 +332,9 @@ if obj.type.name == "Font":
326
332
f.write(font.m_FontData)
327
333
```
328
334
329
-
330
335
### [Mesh](UnityPy/classes/Mesh.py)
331
336
332
-
*``.export()`` - mesh exported as .obj (str)
337
+
-`.export()` - mesh exported as .obj (str)
333
338
334
339
The mesh will be converted to the Wavefront .obj file format.
335
340
@@ -341,9 +346,10 @@ with open(f"{mesh.name}.obj", "wt", newline = "") as f:
341
346
```
342
347
343
348
### Renderer, MeshRenderer, SkinnedMeshRenderer
349
+
344
350
ALPHA-VERSION
345
351
346
-
*``.export(export_dir)`` - exports the associated mesh, materials, and textures into the given directory
352
+
-`.export(export_dir)` - exports the associated mesh, materials, and textures into the given directory
347
353
348
354
The mesh and materials will be in the Wavefront formats.
349
355
@@ -366,5 +372,6 @@ thanks a lot to all contributors of UnityPy and all of its users.
366
372
Also,
367
373
many thanks to:
368
374
369
-
-[Perfare](https://github.com/Perfare) for creating and maintaining and every contributor of [AssetStudio](https://github.com/Perfare/AssetStudio)
370
-
-[ds5678](https://github.com/ds5678) for the [TypeTreeDumps](https://github.com/AssetRipper/TypeTreeDumps) and the [custom minimal Tpk format](https://github.com/AssetRipper/Tpk)
375
+
-[Perfare](https://github.com/Perfare) for creating and maintaining and every contributor of [AssetStudio](https://github.com/Perfare/AssetStudio)
376
+
-[ds5678](https://github.com/ds5678) for the [TypeTreeDumps](https://github.com/AssetRipper/TypeTreeDumps) and the [custom minimal Tpk format](https://github.com/AssetRipper/Tpk)
377
+
-[Razmoth](https://github.com/Razmoth) for figuring out and sharing Unity CN's AssetBundle decryption ([src](https://github.com/Razmoth/PGRStudio)).
0 commit comments