├── requirements.txt ├── README.md ├── ktx.py └── dumpsc.py /requirements.txt: -------------------------------------------------------------------------------- 1 | Pillow 2 | pylzham 3 | zstandard 4 | pyliblzfse 5 | texture2ddecoder 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dumpsc 2 | **Dumpsc** is an adapted version of [cr-sc-dump](https://github.com/123456abcdef/cr-sc-dump). This version aim to support all kind of **_tex.sc** files from different Supercell games. 3 | 4 | 5 | 6 | ## Usage 7 | 8 | If your file is compressed run the following command: 9 | 10 | > python dumpsc.py -d 11 | 12 | else simply use: 13 | 14 | > python dumpsc.py 15 | 16 | 17 | 18 | ## Dependencies 19 | 20 | To install **Dumpsc** dependencies run the following command: 21 | 22 | > python -m pip install -r requirements.txt 23 | -------------------------------------------------------------------------------- /ktx.py: -------------------------------------------------------------------------------- 1 | import struct 2 | import liblzfse 3 | 4 | from PIL import Image 5 | from texture2ddecoder import decode_astc 6 | 7 | 8 | def load_ktx(data): 9 | header = data[:64] 10 | ktx_data = data[64:] 11 | 12 | if header[12:16] == bytes.fromhex('01020304'): 13 | endianness = '<' 14 | 15 | else: 16 | endianness = '>' 17 | 18 | if header[0:7] != b'\xabKTX 11': 19 | raise TypeError('Unsupported or unknown KTX version: {}'.format(header[0:7])) 20 | 21 | glInternalFormat, = struct.unpack(endianness + 'I', header[28:32]) 22 | pixelWidth, pixelHeight = struct.unpack(endianness + '2I', header[36:44]) 23 | bytesOfKeyValueData, = struct.unpack(endianness + 'I', header[60:64]) 24 | 25 | if glInternalFormat not in (0x93B0, 0x93B4, 0x93B7): 26 | raise TypeError('Unsupported texture format: {}'.format(hex(glInternalFormat))) 27 | 28 | if glInternalFormat == 0x93B0: 29 | block_width, block_height = 4, 4 30 | 31 | elif glInternalFormat == 0x93B4: 32 | block_width, block_height = 6, 6 33 | 34 | else: 35 | block_width, block_height = 8, 8 36 | 37 | key_value_data = ktx_data[:bytesOfKeyValueData] 38 | ktx_data = ktx_data[bytesOfKeyValueData:] 39 | 40 | if b'Compression_APPLE' in key_value_data: 41 | if ktx_data[12:15] == b'bvx': 42 | image_data = liblzfse.decompress(ktx_data[12:]) 43 | 44 | else: 45 | raise ValueError('Unsupported compression type: {}'.format( 46 | ktx_data[12:15]) 47 | ) 48 | 49 | else: 50 | image_data = ktx_data[4:] 51 | 52 | decoded_data = decode_astc(image_data, pixelWidth, pixelHeight, block_width, block_height) 53 | return Image.frombytes('RGBA', (pixelWidth, pixelHeight), decoded_data, 'raw', ('BGRA')) 54 | -------------------------------------------------------------------------------- /dumpsc.py: -------------------------------------------------------------------------------- 1 | import os 2 | import lzma 3 | import lzham 4 | import struct 5 | import argparse 6 | import zstandard 7 | 8 | from PIL import Image 9 | from texture2ddecoder import decode_astc 10 | 11 | from ktx import load_ktx 12 | 13 | 14 | def convert_pixel(pixel, type): 15 | if type == 0 or type == 1: 16 | # RGB8888 17 | return struct.unpack('4B', pixel) 18 | elif type == 2: 19 | # RGB4444 20 | pixel, = struct.unpack('> 12) & 0xF) << 4, ((pixel >> 8) & 0xF) << 4, 22 | ((pixel >> 4) & 0xF) << 4, ((pixel >> 0) & 0xF) << 4) 23 | elif type == 3: 24 | # RBGA5551 25 | pixel, = struct.unpack('> 11) & 0x1F) << 3, ((pixel >> 6) & 0x1F) << 3, 27 | ((pixel >> 1) & 0x1F) << 3, ((pixel) & 0xFF) << 7) 28 | elif type == 4: 29 | # RGB565 30 | pixel, = struct.unpack("> 11) & 0x1F) << 3, ((pixel >> 5) & 0x3F) << 2, (pixel & 0x1F) << 3) 32 | elif type == 6: 33 | # LA88 = Luminance Alpha 88 34 | pixel, = struct.unpack("> 8), (pixel >> 8), (pixel >> 8), (pixel & 0xFF) 36 | elif type == 10: 37 | # L8 = Luminance8 38 | pixel, = struct.unpack(" 5: 149 | fileType, = struct.unpack('