Skip to content

Instantly share code, notes, and snippets.

@alyssadev
Last active June 28, 2025 22:13
Show Gist options
  • Save alyssadev/85f467f09bb1d9ac5d67bca1e4d57e6e to your computer and use it in GitHub Desktop.
Save alyssadev/85f467f09bb1d9ac5d67bca1e4d57e6e to your computer and use it in GitHub Desktop.
# doesn't parse correctly yet
# example save: https://s3.aly.pet/deltarune.sav
import struct
def shift(lst, n, parse=False):
out = []
for _ in range(0,n):
out.append(lst.pop(0))
if parse:
return [int(_,16) for _ in out]
return out
def parse_ds_list(inp):
inp = inp.replace(" ","") # TODO
from textwrap import wrap
_bytes = wrap(inp,2)
magic = shift(_bytes,4)
list_length = shift(_bytes,4,True)[0]
out = []
while len(_bytes) != 0:
_type = shift(_bytes,4,True)[0]
if _type == 1: # string
str_elem_len = shift(_bytes,4,True)[0]
element = "".join(chr(_) for _ in shift(_bytes,str_elem_len,True))
if _type == 0: # double?
element = str(int(struct.unpack("<d", bytes(shift(_bytes,8,True)))[0]))
out.append(element)
return out
def parse_save(data):
for line in data.split("\n"):
line = line.strip()
if line[:8] == "2F010000":
line = "\n".join(parse_ds_list(line))
yield line
def create_zip(filename, data):
import zipfile, io
buffer = io.BytesIO()
with zipfile.ZipFile(buffer, "a", zipfile.ZIP_DEFLATED, False) as zip_file:
for fn,contents in data.items():
contents = io.BytesIO(contents.encode("utf-8"))
zip_file.writestr(fn,contents.getvalue())
with open(filename,"wb") as f:
f.write(buffer.getvalue())
def main():
from json import loads
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-i", help="input filename (defaults to deltarune.sav)", default="deltarune.sav")
parser.add_argument("-o", help="output filename (defaults to deltarune.sav.zip)", default="deltarune.sav.zip")
args = parser.parse_args()
out = {}
with open(args.i) as f:
data = loads(f.read().replace("\x00","").replace("\r\n","\n"))
for fn,contents in data.items():
contents = "\n".join(line for line in parse_save(contents))
out[fn] = contents
create_zip(args.o, out)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment