Skip to content

Commit

Permalink
Rewrite functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SunsetMkt committed Jan 12, 2023
1 parent 7e45627 commit 47c85b8
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 69 deletions.
77 changes: 43 additions & 34 deletions py/getModelsGlobal.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import os
from io import BytesIO

import requests
import unitypack
from PIL import ImageOps
import UnityPy

# conf
option = {
Expand Down Expand Up @@ -119,45 +117,56 @@ def downloadFile(url, fname):


def extractTextAsset(object, dest):
# parse the object data
data = object.read()
if (type(data.script) == bytes):
with open(f"{dest}/{data.name}", "wb") as f:
f.write(data.script)
elif (type(data.script) == str):
with open(f"{dest}/{data.name}", "wb") as f:
f.write(bytes(str(data.script), 'utf-8'))
else:
raise Exception("Not handled")

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

# touch folder
os.makedirs(os.path.dirname(dest), exist_ok=True)

# just save
with open(dest, "wb") as f:
f.write(data.script)


def extractTexture2D(object, dest):
# parse the object data
data = object.read()
img = ImageOps.flip(data.image)
output = BytesIO()
img.save(output, format="png")
with open(f"{dest}/{data.name}.png", "wb") as f:
f.write(output.getvalue())

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

# touch folder
os.makedirs(os.path.dirname(dest), exist_ok=True)

# 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)


def extractCharacter(src, dest):
with open(src, "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():
# print(id, object)
# extract skel & atlas
if object.type == "TextAsset":
data = object.read()
if ".atlas" in data.name or ".skel" in data.name:
print(data.name)
extractTextAsset(object, dest)
# extract texture
elif object.type == "Texture2D":
data = object.read()

print(data.name + ".png")
extractTexture2D(object, dest)
# load the bundle
bundle = UnityPy.load(src)

for obj in bundle.objects:
# extract skel & atlas
if obj.type.name == "TextAsset":
data = obj.read()
if ".atlas" in data.name or ".skel" in data.name:
print(data.name)
extractTextAsset(obj, dest)
# extract texture
elif obj.type.name == "Texture2D":
data = obj.read()

print(data.name + ".png")
extractTexture2D(obj, dest)


if __name__ == "__main__":
Expand Down
77 changes: 43 additions & 34 deletions py/getModelsJapan.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import os
from io import BytesIO

import requests
import unitypack
from PIL import ImageOps
import UnityPy

# conf
option = {
Expand Down Expand Up @@ -59,45 +57,56 @@ def downloadFile(url, fname):


def extractTextAsset(object, dest):
# parse the object data
data = object.read()
if (type(data.script) == bytes):
with open(f"{dest}/{data.name}", "wb") as f:
f.write(data.script)
elif (type(data.script) == str):
with open(f"{dest}/{data.name}", "wb") as f:
f.write(bytes(str(data.script), 'utf-8'))
else:
raise Exception("Not handled")

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

# touch folder
os.makedirs(os.path.dirname(dest), exist_ok=True)

# just save
with open(dest, "wb") as f:
f.write(data.script)


def extractTexture2D(object, dest):
# parse the object data
data = object.read()
img = ImageOps.flip(data.image)
output = BytesIO()
img.save(output, format="png")
with open(f"{dest}/{data.name}.png", "wb") as f:
f.write(output.getvalue())

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

# touch folder
os.makedirs(os.path.dirname(dest), exist_ok=True)

# 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)


def extractCharacter(src, dest):
with open(src, "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():
# print(id, object)
# extract skel & atlas
if object.type == "TextAsset":
data = object.read()
if ".atlas" in data.name or ".skel" in data.name:
print(data.name)
extractTextAsset(object, dest)
# extract texture
elif object.type == "Texture2D":
data = object.read()

print(data.name + ".png")
extractTexture2D(object, dest)
# load the bundle
bundle = UnityPy.load(src)

for obj in bundle.objects:
# extract skel & atlas
if obj.type.name == "TextAsset":
data = obj.read()
if ".atlas" in data.name or ".skel" in data.name:
print(data.name)
extractTextAsset(obj, dest)
# extract texture
elif obj.type.name == "Texture2D":
data = obj.read()

print(data.name + ".png")
extractTexture2D(obj, dest)


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
Pillow==9.4.0
requests==2.28.1
UnityPy==1.9.24

0 comments on commit 47c85b8

Please sign in to comment.