Skip to content

Commit 062c2fc

Browse files
committed
Update fingerprints and dumpsc
1 parent 2622f8b commit 062c2fc

File tree

8 files changed

+89
-57
lines changed

8 files changed

+89
-57
lines changed

.github/workflows/build-and-publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Build and Publish
22

33
env:
4-
FINGERPRINT: b8cb4e1c4ee7485bafc34123e4cb2b5b869b4f93
4+
FINGERPRINT: c4e8c2976dcf42530d68dcb1fdfb61d071085abf
55
GAME_ASSET_URL: https://game-assets.clashofclans.com
66
GCP_BUCKET_NAME: game-assets-clashofclans.appspot.com
77

.github/workflows/build-and-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
env:
88
GCP_BUCKET_NAME: game-assets-clashofclans.appspot.com
9-
FINGERPRINT: b8cb4e1c4ee7485bafc34123e4cb2b5b869b4f93
9+
FINGERPRINT: c4e8c2976dcf42530d68dcb1fdfb61d071085abf
1010
GAME_ASSET_URL: https://game-assets.clashofclans.com
1111
SC_FILE_NAME: ui_cc.sc
1212
SC_TEX_FILE_NAME: ui_cc_tex.sc

Main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ def extract_images():
4242
with open(f"{input_folder}/{file}", "rb") as f:
4343
print('')
4444
Console.info(f"Processing {file}")
45+
texturePath = os.path.dirname(file)
4546
# extracting texture
46-
images = process_sc(f"{sc_file_name}_tex", f.read(), f"{sc_output_dir}/texture/", True)
47+
images = process_sc(texturePath, f"{sc_file_name}_tex", f.read(), f"{sc_output_dir}/texture/", True)
4748

4849
if sc_file not in files:
4950
Console.warn(f"{sc_file} not found! Will skip cutting images")

System/Dumpsc.py

+26-52
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,7 @@
1111
import astc_decomp
1212
import liblzfse
1313

14-
def load_ktx(data):
15-
header = data[:64]
16-
ktx_data = data[64:]
17-
18-
if header[12:16] == bytes.fromhex('01020304'):
19-
endianness = '<'
20-
21-
else:
22-
endianness = '>'
23-
24-
if header[0:7] != b'\xabKTX 11':
25-
raise TypeError('Unsupported or unknown KTX version: {}'.format(header[0:7]))
26-
27-
glInternalFormat, = struct.unpack(endianness + 'I', header[28:32])
28-
pixelWidth, pixelHeight = struct.unpack(endianness + '2I', header[36:44])
29-
bytesOfKeyValueData, = struct.unpack(endianness + 'I', header[60:64])
30-
31-
if glInternalFormat not in (0x93B0, 0x93B4, 0x93B7):
32-
raise TypeError('Unsupported texture format: {}'.format(hex(glInternalFormat)))
33-
34-
if glInternalFormat == 0x93B0:
35-
block_width, block_height = 4, 4
36-
37-
elif glInternalFormat == 0x93B4:
38-
block_width, block_height = 6, 6
39-
40-
else:
41-
block_width, block_height = 8, 8
42-
43-
key_value_data = ktx_data[:bytesOfKeyValueData]
44-
ktx_data = ktx_data[bytesOfKeyValueData:]
45-
46-
if b'Compression_APPLE' in key_value_data:
47-
if ktx_data[12:15] == b'bvx':
48-
image_data = liblzfse.decompress(ktx_data[12:])
49-
50-
else:
51-
raise ValueError('Unsupported compression type: {}'.format(
52-
ktx_data[12:15])
53-
)
54-
55-
else:
56-
image_data = ktx_data[4:]
57-
58-
return Image.frombytes('RGBA', (pixelWidth, pixelHeight), image_data, 'astc', (block_width, block_height, False))
59-
14+
from System.Ktx import load_ktx
6015

6116
def convert_pixel(pixel, type):
6217
if type in (0, 1):
@@ -141,7 +96,7 @@ def decompress_data(data, baseName="Unknown"):
14196
return decompressed
14297

14398

144-
def process_sc(baseName, data, path, decompress):
99+
def process_sc(texturePath, baseName, data, path, decompress):
145100
if decompress:
146101
decompressed = decompress_data(data, baseName)
147102

@@ -160,12 +115,21 @@ def process_sc(baseName, data, path, decompress):
160115
i += 4 # Ignore this uint32, it's basically the fileSize + the size of subType + width + height (9 bytes)
161116

162117
fileSize, = struct.unpack('<I', decompressed[i + 1:i + 5])
163-
subType, = struct.unpack('<b', bytes([decompressed[i + 5]]))
164-
width, = struct.unpack('<H', decompressed[i + 6:i + 8])
165-
height, = struct.unpack('<H', decompressed[i + 8:i + 10])
166-
i += 10
118+
i += 5
119+
120+
if fileType == 0x2F:
121+
zktx_path = decompressed[i + 1: i + 1 + decompressed[i]].decode('utf-8')
122+
i += decompressed[i] + 1
167123

168-
if fileType != 0x2D:
124+
subType, = struct.unpack('<b', bytes([decompressed[i]]))
125+
width, = struct.unpack('<H', decompressed[i + 1:i + 3])
126+
height, = struct.unpack('<H', decompressed[i + 3:i + 5])
127+
i += 5
128+
129+
print('fileType: {}, fileSize: {}, subType: {}, width: {}, '
130+
'height: {}'.format(fileType, fileSize, subType, width, height))
131+
132+
if fileType != 0x2D and fileType != 0x2F:
169133
if subType in (0, 1):
170134
pixelSize = 4
171135
elif subType in (2, 3, 4, 6):
@@ -219,6 +183,16 @@ def process_sc(baseName, data, path, decompress):
219183
imgl[h + (width - (width % 32)), j + (height - (height % 32))] = pixels[iSrcPix]
220184
iSrcPix += 1
221185

186+
elif fileType == 0x2F:
187+
zktx_path = os.path.join(texturePath, zktx_path)
188+
189+
if os.path.isfile(zktx_path):
190+
with open(zktx_path, 'rb') as f:
191+
img = load_ktx(zstandard.decompress(f.read()))
192+
193+
else:
194+
raise Exception('External KTX texture {} cannot be found !'.format(zktx_path))
195+
222196
else:
223197
img = load_ktx(decompressed[i:i + fileSize])
224198
i += fileSize

System/Ktx.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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'))

docker-compose.yml

+3
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ services:
77
build:
88
context: .
99
volumes:
10+
- ./System:/System
11+
- ./Main.py:/Main.py
12+
- ./requirements.txt:/requirements.txt
1013
- ./Out-Sprites:/Out-Sprites
1114
- ./In-Compressed:/In-Compressed

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ pylzham
33
zstandard
44
colorama
55
pyliblzfse
6-
astc_decomp
6+
astc_decomp
7+
texture2ddecoder

scripts/downloader.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ shopt -s extglob # Enable extended globbing
55
if [ "$#" -eq 1 ]; then
66
fingerprint="$1"
77
else
8-
fingerprint="7dc27bbc98c5bf2818587453f966e99919e32211"
8+
fingerprint="c4e8c2976dcf42530d68dcb1fdfb61d071085abf"
99
fi
1010

1111
base_url="https://game-assets.clashofclans.com"

0 commit comments

Comments
 (0)