Created
January 19, 2024 08:53
-
-
Save qsniyg/8ab8ddbfff8422786b5f9dc8fd5a5848 to your computer and use it in GitHub Desktop.
Wasteland 3 Save Editor
This file contains hidden or 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
| import lzf | |
| import sys | |
| import re | |
| header_rgx = re.compile("^((?:(?:XLZF|[A-Za-z]+:=.*?)\n)+)".encode('utf-8')) | |
| datasize_rgx = re.compile("(\nDataSize:=)([0-9]+)\n".encode('utf-8')) | |
| savedatasize_rgx = re.compile("(\nSaveDataSize:=)([0-9]+)\n".encode('utf-8')) | |
| def loadfile(filename): | |
| with open(filename, mode='rb') as f: | |
| rf = f.read() | |
| matched = header_rgx.match(rf) | |
| datasize_match = datasize_rgx.search(matched[0]) | |
| content = matched[0] | |
| decoded = lzf.decompress(rf[len(matched[0]):], int(datasize_match[2])) | |
| content += decoded | |
| out = filename + '.editable' | |
| with open(out, mode='wb') as f: | |
| f.write(content) | |
| print("Unpacked to: " + out) | |
| return | |
| def savefile(filename): | |
| with open(filename, mode='rb') as f: | |
| rf = f.read() | |
| matched = header_rgx.match(rf) | |
| hdr = matched[0] | |
| unc_content = rf[len(hdr):] | |
| hdr = re.sub(datasize_rgx, ("\nDataSize:=" + str(len(unc_content)) + "\n").encode('utf-8'), hdr) | |
| com_content = lzf.compress(unc_content.decode('utf-8')) | |
| hdr = re.sub(savedatasize_rgx, ("\nSaveDataSize:=" + str(len(com_content)) + "\n").encode('utf-8'), hdr) | |
| contents = hdr + com_content | |
| out = filename.replace('.xml.editable', '.xml') | |
| with open(out, mode='wb') as f: | |
| f.write(contents) | |
| print("Repacked to: " + out) | |
| return | |
| if len(sys.argv) < 2: | |
| print("To unpack: " + sys.argv[0] + " savefile.xml") | |
| print("To repack: " + sys.argv[0] + " savefile.xml.edited") | |
| sys.exit(0) | |
| is_editable_rgx = re.compile("\\.editable$") | |
| if is_editable_rgx.search(sys.argv[1]): | |
| savefile(sys.argv[1]) | |
| else: | |
| loadfile(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment