I made this thing in late August/early September but I didn't post it here for some reason?!
Anyway, with this, you can pack your levels on Linux and whatnot, and they properly unpack under vanilla KS!? AMAZING!
I was too lazy to make it easy to use I guess, so you have to be in the same directory as the level you want to compress and /path/to/script level\ directory\ name
Also, it's probably pretty messy, and I'm just commenting it now, but that shouldn't be too much of a problem?!
#!/usr/bin/python
import os, sys
archive = open(sys.argv[1] + ".knytt.bin", "w") # GO GET EM
path = "" # I guess this is the path from the root (where you executed the script)
def tobytestring(data, length): # convert FILE SIZES into base-256 representation things that tell the unpacker how far the file goes
bytestring = ""
blahness = data
for i in range(length):
x = blahness % 256
bytestring += chr(x)
blahness = (blahness - x) / 256
return bytestring
def putfile(filename): # put a file into the file
global path
file = open(filename, "r")
contents = file.read()
length = len(contents)
archive.write("NF%s%s\0%s%s" % (path, filename, tobytestring(length, 4), contents)) # I'm guessing NF is NEW FILE and then that next bit is path, then filename, then a null terminator, then four bytes of size information, then file contents. Yep.
file.close()
def putdir(dirname, isroot):
global path
os.chdir(dirname)
if not isroot:
oldpath = path
path += dirname + "\\"
for file in os.listdir("."):
if os.path.isdir(file):
putdir(file, False)
else:
putfile(file)
os.chdir("..")
if not isroot:
path = oldpath
archive.write("NF%s\0BLAH" % sys.argv[1]) # I couldn't find any rhyme or reason to this size thing (the size of the level directory?! I don't even know) so I just put in BLAH and it seems to work just fine.
putdir(sys.argv[1], True)
archive.close()