Skip to content

Instantly share code, notes, and snippets.

@neikeq
Last active November 19, 2016 18:07
Show Gist options
  • Save neikeq/0519841d58ced642da34 to your computer and use it in GitHub Desktop.
Save neikeq/0519841d58ced642da34 to your computer and use it in GitHub Desktop.
Compress and decompress KicksOnline resources. Requires package: https://gist.github.com/neikeq/211f7826d3589a641c0b#file-bwriter-py
import zlib
from bwriter import BinaryWriter
class Compressor:
header_version = 108311
header_len = 48
header = [
0x40, 0x5C, 0x3A, 0x32, 0x47, 0x21, 0x3F, 0x33, 0x39, 0x51, 0x40, 0x56,
0x40, 0x4A, 0x40, 0x07, 0x38, 0x30, 0x49, 0x0C, 0x3A, 0x4E, 0x42, 0x45,
0x40, 0x56, 0x40, 0x4A, 0x40, 0x07, 0x38, 0x30, 0x49, 0x0C, 0xFF, 0xFF
]
def decompress(self, data):
return zlib.decompress(data[self.header_len:len(data)])
def compress(self, data):
result = zlib.compress(data)
return self.add_header(result, len(data))
def decompress_file(self, path):
with open(path, 'rb') as file:
return self.decompress(file.read())
def compress_file(self, path):
with open(path, 'rb') as file:
return self.compress(file.read())
def add_header(self, data, orig_len):
result = BinaryWriter('little')
result.write_int(self.header_version)
result.write_int(orig_len)
result.write_int(len(data))
result.write_bytes(self.header)
result.write_bytes(data)
return result.array()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment