Skip to content

Commit

Permalink
Update fingerprints and dumpsc
Browse files Browse the repository at this point in the history
  • Loading branch information
csuvajit committed Mar 30, 2024
1 parent 2622f8b commit 062c2fc
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Build and Publish

env:
FINGERPRINT: b8cb4e1c4ee7485bafc34123e4cb2b5b869b4f93
FINGERPRINT: c4e8c2976dcf42530d68dcb1fdfb61d071085abf
GAME_ASSET_URL: https://game-assets.clashofclans.com
GCP_BUCKET_NAME: game-assets-clashofclans.appspot.com

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

env:
GCP_BUCKET_NAME: game-assets-clashofclans.appspot.com
FINGERPRINT: b8cb4e1c4ee7485bafc34123e4cb2b5b869b4f93
FINGERPRINT: c4e8c2976dcf42530d68dcb1fdfb61d071085abf
GAME_ASSET_URL: https://game-assets.clashofclans.com
SC_FILE_NAME: ui_cc.sc
SC_TEX_FILE_NAME: ui_cc_tex.sc
Expand Down
3 changes: 2 additions & 1 deletion Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def extract_images():
with open(f"{input_folder}/{file}", "rb") as f:
print('')
Console.info(f"Processing {file}")
texturePath = os.path.dirname(file)
# extracting texture
images = process_sc(f"{sc_file_name}_tex", f.read(), f"{sc_output_dir}/texture/", True)
images = process_sc(texturePath, f"{sc_file_name}_tex", f.read(), f"{sc_output_dir}/texture/", True)

if sc_file not in files:
Console.warn(f"{sc_file} not found! Will skip cutting images")
Expand Down
78 changes: 26 additions & 52 deletions System/Dumpsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,7 @@
import astc_decomp
import liblzfse

def load_ktx(data):
header = data[:64]
ktx_data = data[64:]

if header[12:16] == bytes.fromhex('01020304'):
endianness = '<'

else:
endianness = '>'

if header[0:7] != b'\xabKTX 11':
raise TypeError('Unsupported or unknown KTX version: {}'.format(header[0:7]))

glInternalFormat, = struct.unpack(endianness + 'I', header[28:32])
pixelWidth, pixelHeight = struct.unpack(endianness + '2I', header[36:44])
bytesOfKeyValueData, = struct.unpack(endianness + 'I', header[60:64])

if glInternalFormat not in (0x93B0, 0x93B4, 0x93B7):
raise TypeError('Unsupported texture format: {}'.format(hex(glInternalFormat)))

if glInternalFormat == 0x93B0:
block_width, block_height = 4, 4

elif glInternalFormat == 0x93B4:
block_width, block_height = 6, 6

else:
block_width, block_height = 8, 8

key_value_data = ktx_data[:bytesOfKeyValueData]
ktx_data = ktx_data[bytesOfKeyValueData:]

if b'Compression_APPLE' in key_value_data:
if ktx_data[12:15] == b'bvx':
image_data = liblzfse.decompress(ktx_data[12:])

else:
raise ValueError('Unsupported compression type: {}'.format(
ktx_data[12:15])
)

else:
image_data = ktx_data[4:]

return Image.frombytes('RGBA', (pixelWidth, pixelHeight), image_data, 'astc', (block_width, block_height, False))

from System.Ktx import load_ktx

def convert_pixel(pixel, type):
if type in (0, 1):
Expand Down Expand Up @@ -141,7 +96,7 @@ def decompress_data(data, baseName="Unknown"):
return decompressed


def process_sc(baseName, data, path, decompress):
def process_sc(texturePath, baseName, data, path, decompress):
if decompress:
decompressed = decompress_data(data, baseName)

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

fileSize, = struct.unpack('<I', decompressed[i + 1:i + 5])
subType, = struct.unpack('<b', bytes([decompressed[i + 5]]))
width, = struct.unpack('<H', decompressed[i + 6:i + 8])
height, = struct.unpack('<H', decompressed[i + 8:i + 10])
i += 10
i += 5

if fileType == 0x2F:
zktx_path = decompressed[i + 1: i + 1 + decompressed[i]].decode('utf-8')
i += decompressed[i] + 1

if fileType != 0x2D:
subType, = struct.unpack('<b', bytes([decompressed[i]]))
width, = struct.unpack('<H', decompressed[i + 1:i + 3])
height, = struct.unpack('<H', decompressed[i + 3:i + 5])
i += 5

print('fileType: {}, fileSize: {}, subType: {}, width: {}, '
'height: {}'.format(fileType, fileSize, subType, width, height))

if fileType != 0x2D and fileType != 0x2F:
if subType in (0, 1):
pixelSize = 4
elif subType in (2, 3, 4, 6):
Expand Down Expand Up @@ -219,6 +183,16 @@ def process_sc(baseName, data, path, decompress):
imgl[h + (width - (width % 32)), j + (height - (height % 32))] = pixels[iSrcPix]
iSrcPix += 1

elif fileType == 0x2F:
zktx_path = os.path.join(texturePath, zktx_path)

if os.path.isfile(zktx_path):
with open(zktx_path, 'rb') as f:
img = load_ktx(zstandard.decompress(f.read()))

else:
raise Exception('External KTX texture {} cannot be found !'.format(zktx_path))

else:
img = load_ktx(decompressed[i:i + fileSize])
i += fileSize
Expand Down
53 changes: 53 additions & 0 deletions System/Ktx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import struct
import liblzfse

from PIL import Image
from texture2ddecoder import decode_astc


def load_ktx(data):
header = data[:64]
ktx_data = data[64:]

if header[12:16] == bytes.fromhex('01020304'):
endianness = '<'

else:
endianness = '>'

if header[0:7] != b'\xabKTX 11':
raise TypeError('Unsupported or unknown KTX version: {}'.format(header[0:7]))

glInternalFormat, = struct.unpack(endianness + 'I', header[28:32])
pixelWidth, pixelHeight = struct.unpack(endianness + '2I', header[36:44])
bytesOfKeyValueData, = struct.unpack(endianness + 'I', header[60:64])

if glInternalFormat not in (0x93B0, 0x93B4, 0x93B7):
raise TypeError('Unsupported texture format: {}'.format(hex(glInternalFormat)))

if glInternalFormat == 0x93B0:
block_width, block_height = 4, 4

elif glInternalFormat == 0x93B4:
block_width, block_height = 6, 6

else:
block_width, block_height = 8, 8

key_value_data = ktx_data[:bytesOfKeyValueData]
ktx_data = ktx_data[bytesOfKeyValueData:]

if b'Compression_APPLE' in key_value_data:
if ktx_data[12:15] == b'bvx':
image_data = liblzfse.decompress(ktx_data[12:])

else:
raise ValueError('Unsupported compression type: {}'.format(
ktx_data[12:15])
)

else:
image_data = ktx_data[4:]

decoded_data = decode_astc(image_data, pixelWidth, pixelHeight, block_width, block_height)
return Image.frombytes('RGBA', (pixelWidth, pixelHeight), decoded_data, 'raw', ('BGRA'))
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ services:
build:
context: .
volumes:
- ./System:/System
- ./Main.py:/Main.py
- ./requirements.txt:/requirements.txt
- ./Out-Sprites:/Out-Sprites
- ./In-Compressed:/In-Compressed
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pylzham
zstandard
colorama
pyliblzfse
astc_decomp
astc_decomp
texture2ddecoder
2 changes: 1 addition & 1 deletion scripts/downloader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ shopt -s extglob # Enable extended globbing
if [ "$#" -eq 1 ]; then
fingerprint="$1"
else
fingerprint="7dc27bbc98c5bf2818587453f966e99919e32211"
fingerprint="c4e8c2976dcf42530d68dcb1fdfb61d071085abf"
fi

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

0 comments on commit 062c2fc

Please sign in to comment.