喜欢这游戏的风格,但是cocos开发的 as解不了
以前自用的py脚本
import os
from PIL import Image
import texture2ddecoder
def decrypt_astc(file_path):
with open(file_path, 'rb') as f:
jy = f.read()
if jy[:4] == b'\x13\xAB\xA1\x5C':
aa = int.from_bytes(jy[4:5], byteorder='little', signed=False)
ab = int.from_bytes(jy[5:6], byteorder='little', signed=False)
ac = int.from_bytes(jy[7:9], byteorder='little', signed=False)
ad = int.from_bytes(jy[10:12], byteorder='little', signed=False)
jy = texture2ddecoder.decode_astc(jy[16:], ac, ad, aa, ab)
return jy, ac, ad, aa, ab
return None, None, None, None, None
def process_astc_files(directory, output_format='png'):
if not os.path.exists(directory):
print(f"目录 {directory} 不存在。")
return
for root, _, files in os.walk(directory):
relative_path = os.path.relpath(root, directory)
output_directory = os.path.join(directory, 'decrypted_images', relative_path)
os.makedirs(output_directory, exist_ok=True)
for file_name in files:
if file_name.endswith('.astc'):
file_path = os.path.join(root, file_name)
try:
jy, ac, ad, aa, ab = decrypt_astc(file_path)
if jy is not None:
output_file_name = os.path.splitext(file_name)[0] + f'.{output_format}'
output_file_path = os.path.join(output_directory, output_file_name)
if output_format.lower() == 'jpg':
tp = Image.frombytes("RGBA", (ac, ad), jy, 'raw', ("BGRA")).convert("RGB")
tp.save(output_file_path, format="JPEG", quality=90)
else:
tp = Image.frombytes("RGBA", (ac, ad), jy, 'raw', ("BGRA"))
tp.save(output_file_path, format='PNG')
print(f"保存解密后的图片到 {output_file_path}")
else:
print(f"解密失败: {file_path}")
except Exception as e:
print(f"处理文件 {file_path} 时出错: {e}")
input_directory = '/home/rikka/Downloads/UnpackGames/assets'
process_astc_files(input_directory, output_format='png')
您简直是神