Upload files to "/"

Added support for files with more than 1 texture
This commit is contained in:
katboi01 2025-02-15 15:42:32 +08:00
parent bf86ede0d2
commit 9b437b610b
1 changed files with 36 additions and 25 deletions

View File

@ -4,11 +4,20 @@ import UnityPy
from PIL import Image from PIL import Image
#made by Katboi01 #made by Katboi01
def convert(in_path, out_path): def convert(in_path, out_path, file_name):
env = UnityPy.load(in_path) env = UnityPy.load(os.path.join(in_path, file_name))
textures = []
for obj in env.objects: for obj in env.objects:
if obj.type.name == "Texture2D": if obj.type.name == "Texture2D":
textures.append(obj)
if len(textures) > 1:
out_path = os.path.join(out_path, file_name)
os.makedirs(out_path, exist_ok=True)
for idx, obj in enumerate(textures):
try:
data = obj.read() data = obj.read()
im : Image = data.image im : Image = data.image
width, height = im.size width, height = im.size
@ -39,7 +48,9 @@ def convert(in_path, out_path):
result = Image.fromarray(new_image) result = Image.fromarray(new_image)
result.save(out_path, format="PNG") result.save(os.path.join(out_path, data.m_Name + ".png"), format="PNG")
except Exception as e:
print(f"Failed to extract ({idx}/{len(textures)}) from {file_name}", e)
def main(): def main():
in_path = "decoder_in" in_path = "decoder_in"
@ -54,6 +65,6 @@ def main():
for _, _, files in os.walk(in_path): for _, _, files in os.walk(in_path):
for name in files: for name in files:
print(name) print(name)
convert(os.path.join(in_path, name), os.path.join(out_path, name)) convert(in_path, out_path, name)
main() main()