Skip to content

Commit 06575d0

Browse files
texture.py: Internal restructuring
1 parent b8df13d commit 06575d0

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

lib/sc/texture.py

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from lib.sc.streaming.scPixel import ScPixel
1313
from lib.console import Console
1414

15-
1615
colorama.init()
1716

1817
PACKER_FILTER_TABLE = {
@@ -170,43 +169,43 @@ def load(self, swf, tag, has_external_texture):
170169
self.load_khronos_texture(open(path, "rb").read())
171170

172171
elif ext == "sctx":
173-
print(colorama.Fore.LIGHTMAGENTA_EX + "[INFO] Extracting External Asset Texture:", externalTextureFilepath)
174-
out = path.replace("sctx", "png")
175-
conv = os.path.relpath(os.path.join(os.path.dirname(__file__), "..", "SctxConverter.exe"))
176-
try:
177-
subprocess.run([conv, "decode", path, out, "-t"], check=True)
178-
print(colorama.Fore.LIGHTMAGENTA_EX + "[INFO] SCTX decoded to:", os.path.basename(out))
179-
self._image = Image.open(out)
180-
except FileNotFoundError:
181-
print(colorama.Fore.RED + "[CRITICAL] Missing SctxConverter.exe")
182-
return
183-
except subprocess.CalledProcessError:
184-
print(colorama.Fore.RED + "[ERROR] SctxConverter.exe failed")
185-
return
186-
except Exception as e:
187-
print(colorama.Fore.RED + "[ERROR] Unexpected error:", e)
188-
return
189-
190-
ktx_writer = BinaryWriter()
191-
streaming = SCTX(path, swf.streaming_lowres_id)
192-
ktx_writer.write(b'\xabKTX 11\xbb\r\n\x1a\n')
193-
ktx_writer.write(b'\x01\x02\x03\x04')
194-
ktx_writer.write_uint(0)
195-
ktx_writer.write_uint(1)
196-
ktx_writer.write_uint(0)
197-
ktx_writer.write_uint(ScPixel.glInternalFormat(streaming.texture.pixel_type))
198-
ktx_writer.write_uint(6408)
199-
ktx_writer.write_uint(streaming.texture.width)
200-
ktx_writer.write_uint(streaming.texture.height)
201-
ktx_writer.write_uint(0)
202-
ktx_writer.write_uint(0)
203-
ktx_writer.write_uint(1)
204-
ktx_writer.write_uint(1)
205-
ktx_writer.write_uint(0)
206-
ktx_writer.write_uint(streaming.texture.data_length)
207-
ktx_writer.write(streaming.texture.data)
208-
self.load_khronos_texture(ktx_writer.buffer)
209-
172+
print(colorama.Fore.LIGHTMAGENTA_EX + "[INFO] Extracting External Asset Texture:", externalTextureFilepath)
173+
out = path.replace("sctx", "png")
174+
conv = os.path.relpath(os.path.join(os.path.dirname(__file__), "..", "SctxConverter.exe"))
175+
try:
176+
subprocess.run([conv, "decode", path, out, "-t"], check=True)
177+
print(colorama.Fore.LIGHTMAGENTA_EX + "[INFO] SCTX decoded to:", os.path.basename(out))
178+
self._image = Image.open(out)
179+
180+
ktx_writer = BinaryWriter()
181+
streaming = SCTX(path, swf.streaming_lowres_id)
182+
ktx_writer.write(b'\xabKTX 11\xbb\r\n\x1a\n')
183+
ktx_writer.write(b'\x01\x02\x03\x04')
184+
ktx_writer.write_uint(0)
185+
ktx_writer.write_uint(1)
186+
ktx_writer.write_uint(0)
187+
ktx_writer.write_uint(ScPixel.glInternalFormat(streaming.texture.pixel_type))
188+
ktx_writer.write_uint(6408)
189+
ktx_writer.write_uint(streaming.texture.width)
190+
ktx_writer.write_uint(streaming.texture.height)
191+
ktx_writer.write_uint(0)
192+
ktx_writer.write_uint(0)
193+
ktx_writer.write_uint(1)
194+
ktx_writer.write_uint(1)
195+
ktx_writer.write_uint(0)
196+
ktx_writer.write_uint(streaming.texture.data_length)
197+
ktx_writer.write(streaming.texture.data)
198+
self.load_khronos_texture(ktx_writer.buffer)
199+
200+
except FileNotFoundError:
201+
print(colorama.Fore.RED + "[CRITICAL] Missing SctxConverter.exe")
202+
return
203+
except subprocess.CalledProcessError:
204+
print(colorama.Fore.RED + "[ERROR] SctxConverter.exe failed")
205+
return
206+
except Exception as e:
207+
print(colorama.Fore.RED + "[ERROR] Unexpected error:", e)
208+
return
210209
return
211210

212211
if not has_external_texture:

0 commit comments

Comments
 (0)