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
Visual C++ Redistributable is required for the brotli dependency.
71
72
In case a new(ish) Python version is used, it can happen that the C-dependencies of UnityPy might not be precompiled for this version.
72
73
In such cases the user either has to report this as issue or follow the steps of [this issue](https://github.com/K0lb3/UnityPy/issues/223) to compile it oneself.
73
-
Another option for the user is downgrading Python to the latest version supported by UnityPy. For this see the python version badge at the top of the README.
74
-
75
-
### Crash without warning/error
74
+
Another option for the user is downgrading Python to the latest version supported by UnityPy. For this see the Python version badge at the top of the README.
76
75
77
-
The C-implementation of the typetree reader can directly crash python.
78
-
In case this happens, the usage of the C-typetree reader can be disabled by adding these two lines to your main file.
76
+
#### Crash without warning/error
79
77
80
-
```python
81
-
from UnityPy.helpers import TypeTreeHelper
82
-
TypeTreeHelper.read_typetree_boost =False
83
-
```
78
+
The C-implementation of the typetree reader can directly crash Python.
79
+
In case this happens, the usage of the C-typetree reader can be disabled. Read [this section](#disable-typetree-c-implementation) for more details.
84
80
85
81
## Example
86
82
@@ -90,7 +86,7 @@ The following is a simple example.
You probably have to read [Important Classes](#important-classes)
135
131
and [Important Object Types](#important-object-types) to understand how it works.
136
132
137
-
People with slightly advanced python skills should look at [UnityPy/tools/extractor.py](UnityPy/tools/extractor.py) for a more advanced example.
133
+
Users with slightly advanced Python skills should look at [UnityPy/tools/extractor.py](UnityPy/tools/extractor.py) for a more advanced example.
138
134
It can also be used as a general template or as an importable tool.
139
135
140
-
### Setting the decryption key for Unity CN's AssetBundle encryption
141
-
142
-
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.
143
-
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`.
144
-
145
136
## Important Classes
146
137
147
-
### [Environment](UnityPy/environment.py)
138
+
### Environment
148
139
149
-
Environment loads and parses the given files.
140
+
[Environment](UnityPy/environment.py) loads and parses the given files.
150
141
It can be initialized via:
151
142
152
143
- a file path - apk files can be loaded as well
153
144
- a folder path - loads all files in that folder (bad idea for folders with a lot of files)
154
-
- a stream - e.g., io.BytesIO, file stream,...
145
+
- a stream - e.g., `io.BytesIO`, file stream,...
155
146
- a bytes object - will be loaded into a stream
156
147
157
148
UnityPy can detect if the file is a WebFile, BundleFile, Asset, or APK.
@@ -183,26 +174,26 @@ with open(dst, "wb") as f:
183
174
f.write(env.file.save())
184
175
```
185
176
186
-
### [Asset](UnityPy/files/SerializedFile.py)
177
+
### Asset
187
178
188
-
Assets are a container that contains multiple objects.
179
+
Assets \([SerializedFile class](UnityPy/files/SerializedFile.py)\)are a container that contains multiple objects.
189
180
One of these objects can be an AssetBundle, which contains a file path for some of the objects in the same asset.
190
181
191
182
All objects can be found in the `.objects` dict - `{ID : object}`.
192
183
193
184
The objects with a file path can be found in the `.container` dict - `{path : object}`.
194
185
195
-
### [Object](UnityPy/files/ObjectReader.py)
186
+
### Object
196
187
197
-
Objects contain the _actual_ files, e.g., textures, text files, meshes, settings, ...
188
+
Objects \([ObjectReader class](UnityPy/files/ObjectReader.py)\)contain the _actual_ files, e.g., textures, text files, meshes, settings, ...
198
189
199
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.
200
191
201
192
## Important Object Types
202
193
203
-
All object types can be found in [UnityPy/classes](UnityPy/classes/).
194
+
Now UnityPy uses [auto generated classes](UnityPy/classes/generated.py) with some useful extension methods and properties defined in [legacy_patch](UnityPy/classes/legacy_patch/). You can search for a specific classes in the module `UnityPy.classes` with your IDE's autocompletion.
204
195
205
-
### [Texture2D](UnityPy/classes/Texture2D.py)
196
+
### Texture2D
206
197
207
198
-`.m_Name`
208
199
-`.image` converts the texture into a `PIL.Image`
@@ -226,7 +217,7 @@ for obj in env.objects:
226
217
data.save()
227
218
```
228
219
229
-
### [Sprite](UnityPy/classes/Sprite.py)
220
+
### Sprite
230
221
231
222
Sprites are part of a texture and can have a separate alpha-image as well.
232
223
Unlike most other extractors (including AssetStudio), UnityPy merges those two images by itself.
@@ -246,14 +237,15 @@ for obj in env.objects:
246
237
data.image.save(path)
247
238
```
248
239
249
-
### [TextAsset](UnityPy/classes/TextAsset.py)
240
+
### TextAsset
250
241
251
242
TextAssets are usually normal text files.
252
243
253
244
-`.m_Name`
254
245
-`.m_Script` - str
255
246
256
-
Some games save binary data as TextFile, so to convert the ``str`` back to bytes correctly ``m_Script.encode("utf-8", "surrogateescape")`` has to be used.
247
+
Some games save binary data as TextAssets. As ``m_Script`` gets handled as str by default,
248
+
use ``m_Script.encode("utf-8", "surrogateescape")`` to retrieve the original binary data.
MonoBehaviour assets are usually used to save the class instances with their values.
278
270
The structure/typetree for these classes might not be contained in the asset files.
@@ -312,7 +304,7 @@ for obj in env.objects:
312
304
UnityPy can generate the typetrees of MonoBehaviours from the game assemblies using an optional package, ``TypeTreeGeneratorAPI``, which has to be installed via pip.
313
305
UnityPy will automatically try to generate the typetree of MonoBehaviours if the typetree is missing in the assets and ``env.typetree_generator`` is set.
314
306
315
-
```py
307
+
```python
316
308
import UnityPy
317
309
from UnityPy.helpers.TypeTreeGenerator import TypeTreeGenerator
318
310
@@ -340,25 +332,27 @@ for obj in objects:
340
332
```
341
333
342
334
343
-
### [AudioClip](UnityPy/classes/AudioClip.py)
335
+
### AudioClip
344
336
345
337
-`.samples` - `{sample-name : sample-data}`
346
338
347
339
The samples are converted into the .wav format.
348
340
The sample data is a .wav file in bytes.
349
341
350
342
```python
351
-
clip: AudioClip
343
+
clip: AudioClip
352
344
for name, data in clip.samples.items():
353
345
withopen(name, "wb") as f:
354
346
f.write(data)
355
347
```
356
348
357
-
### [Font](UnityPy/classes/Font.py)
349
+
### Font
350
+
351
+
**Export**
358
352
359
353
```python
360
354
if obj.type.name =="Font":
361
-
font: Font = obj.read()
355
+
font: Font = obj.read()
362
356
if font.m_FontData:
363
357
extension =".ttf"
364
358
if font.m_FontData[0:4] ==b"OTTO":
@@ -368,14 +362,14 @@ if obj.type.name == "Font":
368
362
f.write(font.m_FontData)
369
363
```
370
364
371
-
### [Mesh](UnityPy/classes/Mesh.py)
365
+
### Mesh
372
366
373
367
-`.export()` - mesh exported as .obj (str)
374
368
375
369
The mesh will be converted to the Wavefront .obj file format.
376
370
377
371
```python
378
-
mesh: Mesh
372
+
mesh: Mesh
379
373
withopen(f"{mesh.m_Name}.obj", "wt", newline="") as f:
380
374
# newline = "" is important
381
375
f.write(mesh.export())
@@ -390,7 +384,7 @@ ALPHA-VERSION
390
384
The mesh and materials will be in the Wavefront formats.
391
385
392
386
```python
393
-
mesh_renderer: Renderer
387
+
mesh_renderer: Renderer
394
388
export_dir: str
395
389
396
390
if mesh_renderer.m_GameObject:
@@ -400,7 +394,7 @@ if mesh_renderer.m_GameObject:
There're several configurations and interfaces that provide the customizability to UnityPy.
423
+
424
+
### Unity CN Decryption
425
+
426
+
The Chinese version of Unity has its own builtin 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.
427
+
To enable encryption simply use the code as follow, with `key` being the value that the game that loads the bundles passes to `AssetBundle.SetAssetBundleDecryptKey`.
428
+
429
+
```python
430
+
import UnityPy
431
+
UnityPy.set_assetbundle_decrypt_key(key)
432
+
```
433
+
434
+
### Unity Fallback Version
435
+
436
+
In case UnityPy failed to detect the Unity version of the game assets, you can set a fallback version. e.g.
437
+
438
+
```python
439
+
import UnityPy.config
440
+
UnityPy.config.FALLBACK_UNITY_VERSION="2.5.0f5"
441
+
```
442
+
443
+
### Disable Typetree C-Implementation
444
+
445
+
The [C-implementation](UnityPyBoost/) of typetree reader can boost the parsing of typetree by a lot. If you want to disable it and use pure Python reader, you can put the following 2 lines in your main file.
446
+
447
+
```python
448
+
from UnityPy.helpers import TypeTreeHelper
449
+
TypeTreeHelper.read_typetree_boost =False
450
+
```
451
+
452
+
### Custom Block (De)compression
453
+
454
+
Some game assets have non-standard compression/decompression algorithm applied on the block data. If you wants to customize the compression/decompression function, you can modify the corresponding function mapping. e.g.
455
+
456
+
```python
457
+
from UnityPy.enums.BundleFile import CompressionFlags
UnityPy uses [fsspec](https://github.com/fsspec/filesystem_spec) under the hood to manage all filesystem interactions.
429
471
This allows using various different types of filesystems without having to change UnityPy's code.
430
472
It also means that you can use your own custom filesystem to e.g. handle indirection via catalog files, load assets on demand from a server, or decrypt files.
431
473
432
474
Following methods of the filesystem have to be implemented for using it in UnityPy.
433
475
434
-
- sep (not a function, just the seperator as character)
thanks a lot to all contributors of UnityPy and all of its users.
446
488
447
-
Also,
448
-
many thanks to:
489
+
Also, many thanks to:
449
490
450
491
-[Perfare](https://github.com/Perfare) for creating and maintaining and every contributor of [AssetStudio](https://github.com/Perfare/AssetStudio)
451
492
-[ds5678](https://github.com/ds5678) for the [TypeTreeDumps](https://github.com/AssetRipper/TypeTreeDumps) and the [custom minimal Tpk format](https://github.com/AssetRipper/Tpk)
452
493
-[Razmoth](https://github.com/Razmoth) for figuring out and sharing Unity CN's AssetBundle decryption ([src](https://github.com/Razmoth/PGRStudio)).
453
494
-[nesrak1](https://github.com/nesrak1) for figuring out the [Switch texture swizzling](https://github.com/nesrak1/UABEA/blob/master/TexturePlugin/Texture2DSwitchDeswizzler.cs)
454
-
- xiop_13690 (discord) for figuring out unsolved issues of the ManagedReferencesRegistry
495
+
- xiop_13690 (discord) for figuring out unsolved issues of the ManagedReferencesRegistry
0 commit comments