Guest User

Untitled

a guest
Jun 23rd, 2024
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | Software | 0 0
  1. import os, shutil, UnityPy
  2.  
  3. def copy_and_replace(source_path, destination_path):
  4.     if os.path.exists(destination_path):
  5.         os.remove(destination_path)
  6.     shutil.copy2(source_path, destination_path)
  7.     return
  8.  
  9. def make_mipmaps(source_folder : str, destination_folder : str):
  10.     for root, dirs, files in os.walk(source_folder):
  11.         for file_name in files:
  12.             changed = False
  13.             file_path = os.path.join(root, file_name)
  14.             env = UnityPy.load(file_path)
  15.             for path,obj in env.container.items():
  16.                 if obj.type.name == "Texture2D":
  17.                     data = obj.read()
  18.                     is_sleeve = data.m_Name.startswith("ProtectorIcon")
  19.                     if not is_sleeve: continue
  20.                     data.set_image(data.image, mipmap_count = 1)
  21.                     data.set_image(data.image, mipmap_count = 4)
  22.                     data.save()
  23.                     changed = True
  24.             dest = os.path.join(destination_folder, file_path.removeprefix(source_folder).removeprefix("\\"))
  25.             os.makedirs(os.path.dirname(dest), exist_ok = True)
  26.             with open(dest, "wb") as f:
  27.                 f.write(env.file.save(packer="none"))
  28.             if not changed:
  29.                 copy_and_replace(file_path, dest)
  30.     return
  31.  
  32. def main_func():
  33.     source_folder       = input("Enter source 0000/AssetBundle folder\n")
  34.     destination_folder  = input("Enter destination 0000/AssetBundle folder\n")
  35.     make_mipmaps(source_folder, destination_folder)
  36.     print("Sleeves with mipmaps created in destination folder.")
  37.     print("Optional: It is recommended that you compress the files with UABEA.")
  38.     print("Press Enter to exit.")
  39.     return
  40.  
  41. main_func()
Advertisement
Add Comment
Please, Sign In to add comment