# -*- coding: utf-8 -*- # Vita fix: the engine's libwebp fails to decode LARGE lossless-WebP .stex # textures (needs a big temp RGBA buffer that the memory-starved Vita can't # allocate -> "Failed decoding WebP image" -> scene fails to load). # # Godot already generated an uncompressed RGBA4444 variant alongside each one # (the *.etc.stex). That variant needs NO decode at all, so it loads fine AND # uses less peak runtime memory. This script swaps the plain WebP .stex for the # uncompressed variant, but ONLY for textures whose largest dimension exceeds a # threshold (small WebP textures decode fine and don't need swapping). # # python fix_webp_stex.py [threshold_px] (default 2048; use 0 to do all) # python fix_webp_stex.py --restore (undo: restore .webp_bak backups) import os, sys, struct, glob def _project_root(): d = os.path.dirname(os.path.abspath(__file__)) while d != os.path.dirname(d): if os.path.isdir(os.path.join(d, "SteamVersion", "NewExtractPCK")): return d d = os.path.dirname(d) return os.getcwd() IMPORT_DIR = os.path.join( _project_root(), "SteamVersion", "NewExtractPCK", ".import") VARIANTS = (".etc.stex", ".etc2.stex", ".s3tc.stex", ".pvrtc.stex") def is_variant(name): return any(name.endswith(v) for v in VARIANTS) def read_header(path): with open(path, "rb") as f: head = f.read(20) if len(head) < 20 or head[0:4] != b"GDST": return None w, h, flags, fmt = struct.unpack_from(" %.1fMB)" % (name, w, h, os.path.basename(src), old/1048576.0, new/1048576.0)) print("---") print("Swapped %d texture(s). PCK grows ~%.1f MB on disk " "(runtime memory unchanged or lower)." % (swapped, added_mb)) if __name__ == "__main__": if "--restore" in sys.argv: restore() else: th = int(sys.argv[1]) if len(sys.argv) > 1 and sys.argv[1].isdigit() else 2048 print("Swapping WebP .stex with max dimension > %d px ..." % th) fix(th)