Last active
December 2, 2018 22:11
-
-
Save khang06/49d0fe124025a87ba661ebcf33964ef3 to your computer and use it in GitHub Desktop.
ksacmp - .cmp tool for Kirby Star Allies written in Python 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
ksacmp v1 by Khangaroo | |
compresses and decompresses .cmp files from Kirby Star Allies | |
based on Random Talking Bush's QuickBMS script | |
""" | |
import sys | |
import lz4.frame | |
def print_help(): | |
print('Usage: ksacmp.py [mode] [input] [output]') | |
print(' [mode] - c for compress, d for decompress') | |
print(' [input] - input file path') | |
print(' [output] - output file path') | |
sys.exit() | |
pass | |
if len(sys.argv) != 4: | |
print_help() | |
if sys.argv[1] == 'c': | |
mode = 0 | |
elif sys.argv[1] == 'd': | |
mode = 1 | |
else: | |
print_help() | |
try: | |
input_file = open(sys.argv[2], 'rb') | |
except IOError: | |
print('Could not open input file!') | |
sys.exit() | |
try: | |
output_file = open(sys.argv[3], 'wb') | |
except IOError: | |
print('Could not open output file!') | |
sys.exit() | |
if mode: # decompress | |
input_file.seek(4) # first 4 bytes are the decompressed size, but we don't have to care | |
decmp_buffer = lz4.frame.decompress(input_file.read()) | |
output_file.write(decmp_buffer) | |
else: # compress | |
cmp_buffer = lz4.frame.compress(input_file.read()) | |
output_file.write(os.path.getsize(sys.argv[2]).to_bytes(4, byteorder='little')) | |
output_file.write(cmp_buffer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment