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
+
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
75
76
### Crash without warning/error
76
77
77
-
The C-implementation of the typetree reader can directly crash python.
78
+
The C-implementation of the typetree reader can directly crash Python.
78
79
In case this happens, the usage of the C-typetree reader can be disabled by adding these two lines to your main file.
79
80
80
81
```python
@@ -90,7 +91,7 @@ The following is a simple example.
You probably have to read [Important Classes](#important-classes)
135
136
and [Important Object Types](#important-object-types) to understand how it works.
136
137
137
-
People with slightly advanced python skills should look at [UnityPy/tools/extractor.py](UnityPy/tools/extractor.py) for a more advanced example.
138
+
People with slightly advanced Python skills should look at [UnityPy/tools/extractor.py](UnityPy/tools/extractor.py) for a more advanced example.
138
139
It can also be used as a general template or as an importable tool.
139
140
140
141
### Setting the decryption key for Unity CN's AssetBundle encryption
141
142
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`.
143
+
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.
144
+
To enable encryption simply use `UnityPy.set_assetbundle_decrypt_key(key)`, with key being the value that the game that loads the bundles passes to `AssetBundle.SetAssetBundleDecryptKey`.
144
145
145
146
## Important Classes
146
147
147
-
### [Environment](UnityPy/environment.py)
148
+
### Environment
148
149
149
-
Environment loads and parses the given files.
150
+
[Environment](UnityPy/environment.py) loads and parses the given files.
150
151
It can be initialized via:
151
152
152
153
- a file path - apk files can be loaded as well
153
154
- 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,...
155
+
- a stream - e.g., `io.BytesIO`, file stream,...
155
156
- a bytes object - will be loaded into a stream
156
157
157
158
UnityPy can detect if the file is a WebFile, BundleFile, Asset, or APK.
@@ -183,26 +184,26 @@ with open(dst, "wb") as f:
183
184
f.write(env.file.save())
184
185
```
185
186
186
-
### [Asset](UnityPy/files/SerializedFile.py)
187
+
### Asset
187
188
188
-
Assets are a container that contains multiple objects.
189
+
Assets \([SerializedFile class](UnityPy/files/SerializedFile.py)\)are a container that contains multiple objects.
189
190
One of these objects can be an AssetBundle, which contains a file path for some of the objects in the same asset.
190
191
191
192
All objects can be found in the `.objects` dict - `{ID : object}`.
192
193
193
194
The objects with a file path can be found in the `.container` dict - `{path : object}`.
194
195
195
-
### [Object](UnityPy/files/ObjectReader.py)
196
+
### Object
196
197
197
-
Objects contain the _actual_ files, e.g., textures, text files, meshes, settings, ...
198
+
Objects \([ObjectReader class](UnityPy/files/ObjectReader.py)\)contain the _actual_ files, e.g., textures, text files, meshes, settings, ...
198
199
199
200
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
201
201
202
## Important Object Types
202
203
203
-
All object types can be found in [UnityPy/classes](UnityPy/classes/).
204
+
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
205
205
-
### [Texture2D](UnityPy/classes/Texture2D.py)
206
+
### Texture2D
206
207
207
208
-`.m_Name`
208
209
-`.image` converts the texture into a `PIL.Image`
@@ -226,7 +227,7 @@ for obj in env.objects:
226
227
data.save()
227
228
```
228
229
229
-
### [Sprite](UnityPy/classes/Sprite.py)
230
+
### Sprite
230
231
231
232
Sprites are part of a texture and can have a separate alpha-image as well.
232
233
Unlike most other extractors (including AssetStudio), UnityPy merges those two images by itself.
@@ -246,14 +247,15 @@ for obj in env.objects:
246
247
data.image.save(path)
247
248
```
248
249
249
-
### [TextAsset](UnityPy/classes/TextAsset.py)
250
+
### TextAsset
250
251
251
252
TextAssets are usually normal text files.
252
253
253
254
-`.m_Name`
254
255
-`.m_Script` - str
255
256
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.
257
+
Some games save binary data as TextAssets. As ``m_Script`` gets handled as str by default,
258
+
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
280
The structure/typetree for these classes might not be contained in the asset files.
@@ -312,7 +314,7 @@ for obj in env.objects:
312
314
UnityPy can generate the typetrees of MonoBehaviours from the game assemblies using an optional package, ``TypeTreeGeneratorAPI``, which has to be installed via pip.
313
315
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
316
315
-
```py
317
+
```python
316
318
import UnityPy
317
319
from UnityPy.helpers.TypeTreeGenerator import TypeTreeGenerator
318
320
@@ -340,7 +342,7 @@ for obj in objects:
340
342
```
341
343
342
344
343
-
### [AudioClip](UnityPy/classes/AudioClip.py)
345
+
### AudioClip
344
346
345
347
-`.samples` - `{sample-name : sample-data}`
346
348
@@ -354,7 +356,9 @@ for name, data in clip.samples.items():
354
356
f.write(data)
355
357
```
356
358
357
-
### [Font](UnityPy/classes/Font.py)
359
+
### Font
360
+
361
+
**Export**
358
362
359
363
```python
360
364
if obj.type.name =="Font":
@@ -368,14 +372,14 @@ if obj.type.name == "Font":
368
372
f.write(font.m_FontData)
369
373
```
370
374
371
-
### [Mesh](UnityPy/classes/Mesh.py)
375
+
### Mesh
372
376
373
377
-`.export()` - mesh exported as .obj (str)
374
378
375
379
The mesh will be converted to the Wavefront .obj file format.
376
380
377
381
```python
378
-
mesh: Mesh
382
+
mesh: Mesh
379
383
withopen(f"{mesh.m_Name}.obj", "wt", newline="") as f:
380
384
# newline = "" is important
381
385
f.write(mesh.export())
@@ -390,7 +394,7 @@ ALPHA-VERSION
390
394
The mesh and materials will be in the Wavefront formats.
391
395
392
396
```python
393
-
mesh_renderer: Renderer
397
+
mesh_renderer: Renderer
394
398
export_dir: str
395
399
396
400
if mesh_renderer.m_GameObject:
@@ -400,7 +404,7 @@ if mesh_renderer.m_GameObject:
UnityPy uses [fsspec](https://github.com/fsspec/filesystem_spec) under the hood to manage all filesystem interactions.
429
433
This allows using various different types of filesystems without having to change UnityPy's code.
430
434
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
435
432
436
Following methods of the filesystem have to be implemented for using it in UnityPy.
433
437
434
-
- sep (not a function, just the seperator as character)
438
+
- sep (not a function, just the separator as character)
435
439
- isfile(self, path: str) -> bool
436
440
- isdir(self, path: str) -> bool
437
441
- exists(self, path: str, \*\*kwargs) -> bool
@@ -444,11 +448,10 @@ Following methods of the filesystem have to be implemented for using it in Unity
444
448
First of all,
445
449
thanks a lot to all contributors of UnityPy and all of its users.
446
450
447
-
Also,
448
-
many thanks to:
451
+
Also, many thanks to:
449
452
450
453
-[Perfare](https://github.com/Perfare) for creating and maintaining and every contributor of [AssetStudio](https://github.com/Perfare/AssetStudio)
451
454
-[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
455
-[Razmoth](https://github.com/Razmoth) for figuring out and sharing Unity CN's AssetBundle decryption ([src](https://github.com/Razmoth/PGRStudio)).
453
456
-[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
457
+
- xiop_13690 (discord) for figuring out unsolved issues of the ManagedReferencesRegistry
0 commit comments