jeanbmar / sc-compression

A Node.js module to decompress and compress game assets from Supercell games
42 stars 10 forks source link
brawl-stars clash-of-clans clash-royale supercell

Sc Compression

This module is intended to compress and decompress Supercell assets.
It supports the following signatures:

signature description decompression compression
none non-compressed file ✔️ ✔️
lzma starts with bytes 0x5d0000 ✔️ ✔️
sc starts with "SC" ✔️ ✔️
sclz starts with "SC" and contains "SCLZ" ✔️ ✔️
sig starts with "Sig:" ✔️ ✔️ 🚩
sc2 starts with "SC" and contains "START" ✔️
zstd contains 0x28b52ffd ✔️

The module automatically infers the right signature when decompress is called.

Install

npm install sc-compression

API Reference

decompress(buffer)

Decompress a file buffer.

compress(buffer, signature)

Compress a file buffer.

readSignature(buffer)

Read a compressed file signature.

Example

import { readdir, readFile, writeFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { decompress } from 'sc-compression';

const files = await readdir('coc-13.0.4/logic');
for (const file of files) {
    const filepath = resolve(directory, file);
    const buffer = await readFile(filepath);
    const decompressed = await decompress(buffer);
    await writeFile(filepath, decompressed);
}

See tests for additional implementation examples.

Step by step guide for non-developers