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
Copy file name to clipboardExpand all lines: README.md
+38-19Lines changed: 38 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,39 +138,58 @@ It can also be used as a general template or as an importable tool.
138
138
### Environment
139
139
140
140
[Environment](UnityPy/environment.py) loads and parses the given files.
141
-
It can be initialized via:
142
141
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
142
+
#### Initialization
147
143
148
-
UnityPy can detect if the file is a WebFile, BundleFile, Asset, or APK.
144
+
An Environment object can be created by providing:
149
145
150
-
The unpacked assets will be loaded into `.files`, a dict consisting of `asset-name : asset`.
146
+
- a file path - loads a single file (typically an asset bundle file, apk file or zip file).
147
+
- a folder path - loads all files in the given folder (bad idea for large folders).
148
+
- a streamable object - loads the data from the given stream (it can be `io.BytesIO`, file stream returned by `open()` and any other object that extends `io.IOBase`).
149
+
- a bytes object - loads the data from memory.
150
+
151
+
UnityPy can detect if the file is a WebFile, BundleFile, Asset, or APK.
151
152
152
-
All objects of the loaded assets can be easily accessed via `.objects`,
153
-
which itself is a simple recursive iterator.
153
+
The following code shows the different ways to create an Environment object.
154
154
155
155
```python
156
156
import io
157
157
import UnityPy
158
158
159
-
# all of the following would work
160
-
src ="file_path"
161
-
src =b"bytes"
162
-
src = io.BytesIO(b"Streamable")
159
+
# load from file path or folder path
160
+
env = UnityPy.load("path/to/your/file")
161
+
162
+
# note that the best way to pass a file to UnityPy is
163
+
# using with-statement to ensure the file can be properly closed
164
+
withopen("path/to/your/file", "rb") as f:
165
+
env = UnityPy.load(f)
166
+
167
+
# load from bytes io stream
168
+
data = io.BytesIO(b"streamable-data")
169
+
env = UnityPy.load(data)
170
+
171
+
# load from bytes object
172
+
data =b"some-bytes-data"
173
+
env = UnityPy.load(data)
174
+
```
175
+
176
+
#### Attributes
177
+
178
+
The unpacked assets will be loaded into `.files`, a dict consisting of `asset-name : asset`.
163
179
164
-
env = UnityPy.load(src)
180
+
All objects of the loaded assets can be easily accessed via `.objects`, which itself is a simple recursive iterator.
181
+
If you want, you can modify the objects and save the edited file later.
182
+
See [Object](#object) section to learn how to apply modifications to the objects.
0 commit comments