Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #196

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 38 additions & 20 deletions README.md
Expand Up @@ -81,11 +81,17 @@ The following is a simple example.
```python
import os
import UnityPy
import logging
from pathlib import Path

def unpack_all_assets(source_folder : str, destination_folder : str):
logger = logging.getLogger("depackage")

def unpack_all_assets(source_folder: str, destination_folder: str):
# iterate over all files in source folder
for root, dirs, files in os.walk(source_folder):
print(root, dirs, files)
for file_name in files:
print(file_name)
# generate file_path
file_path = os.path.join(root, file_name)
# load that file via UnityPy.load
Expand All @@ -98,29 +104,41 @@ def unpack_all_assets(source_folder : str, destination_folder : str):
# parse the object data
data = obj.read()

# create destination path
dest = os.path.join(destination_folder, data.name)

# make sure that the extension is correct
# you probably only want to do so with images/textures
dest, ext = os.path.splitext(dest)
dest = dest + ".png"

img = data.image
img.save(dest)
try:
# create destination path
tmp_dir, _ = os.path.splitext(Path(file_path).name)
dest = os.path.join(destination_folder, tmp_dir, data.name)

# make sure that the extension is correct
# you probably only want to do so with images/textures
dest, ext = os.path.splitext(dest)
dest = dest + ".png"
img = data.image
img.save(dest)
logger.info(f"Successfully save image to {dest}")
except:
logger.warning(f"Could not save image to {dest}")
continue

# alternative way which keeps the original path
for path,obj in env.container.items():
for path, obj in env.container.items():
if obj.type.name in ["Texture2D", "Sprite"]:
data = obj.read()
# create dest based on original path
dest = os.path.join(destination_folder, *path.split("/"))
# make sure that the dir of that path exists
os.makedirs(os.path.dirname(dest), exist_ok = True)
# correct extension
dest, ext = os.path.splitext(dest)
dest = dest + ".png"
data.image.save(dest)
try:
# create dest based on original path
tmp_dir, _ = os.path.splitext(Path(file_path).name)
dest = os.path.join(destination_folder, tmp_dir, *path.split("/"))
# make sure that the dir of that path exists
os.makedirs(os.path.dirname(dest), exist_ok=True)
# correct extension
dest, ext = os.path.splitext(dest)
dest = dest + ".png"
data.image.save(dest)
logger.info(f"Successfully save image to {dest}")
except:
logger.warning(f"Could not save image to {dest}")
continue

```

You probably have to read [Important Classes](#important-classes)
Expand Down