Skip to content

Instantly share code, notes, and snippets.

@bluecookies
Last active November 1, 2017 04:53
Show Gist options
  • Save bluecookies/ed201c1bcb110145a5530fb2739668fb to your computer and use it in GitHub Desktop.
Save bluecookies/ed201c1bcb110145a5530fb2739668fb to your computer and use it in GitHub Desktop.
temp unpacker
@echo off
setlocal enabledelayedexpansion
for %%f in (Album/pri_l_*.unity3d) do @(
set id=%%~nf
unpack.py Album/%%f Processed/!id:~6!_large.png
)
for %%f in (Album/pri_s_*.unity3d) do @(
set id=%%~nf
unpack.py Album/%%f Processed/!id:~6!_small.png
)
for %%f in (Album/pri_ll_*.unity3d) do @(
set id=%%~nf
unpack.py Album/%%f Processed/!id:~7!_llarge.png
)
import sys
import unitypack
from unitypack.engine.texture import TextureFormat
from pprint import pprint
from io import BytesIO
from PIL import ImageOps
from PIL import Image
if len(sys.argv) < 2:
sys.exit("Usage: unpack.py <input_file>")
with open(sys.argv[1], "rb") as f:
bundle = unitypack.load(f)
for asset in bundle.assets:
print("%s: %s:: %i objects" % (bundle, asset, len(asset.objects)))
for id, object in asset.objects.items():
if object.type == "TextAsset":
data = object.read()
# The resulting `data` is a unitypack.engine.TextAsset instance
print("Asset name:", data.name)
print("Contents:", repr(data.script))
elif object.type == "Texture2D":
data = object.read()
print("Asset name: %s, Dimensions: %i %i" % (data.name, data.width, data.height))
print("Format: %s" % (data.format))
#pprint(dir(data))
#pprint(data.color_space)
# Texture2D objects are flipped
img = ImageOps.flip(data.image)
# Endian different, reverse bands
if (data.format == TextureFormat.RGBA4444):
img = Image.merge('RGBA', img.split()[::-1])
output = BytesIO()
img.save(output, format="png")
if len(sys.argv) > 2:
path = sys.argv[2]
else:
path = sys.argv[1] + ".png"
with open(path, "wb") as f:
written = f.write(output.getvalue())
print("Written %i bytes to %r" % (written, path))
else:
print(object)
#elif object.type == "AssetBundle":
# pprint(vars(object))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment