-
-
Save waryder/3951b74d8b8248dd4ae537dde5929417 to your computer and use it in GitHub Desktop.
A python script to decode the hello games no man's sky save files. (The newer compressed kind)
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
#!/usr/bin/python3 | |
import io | |
import os | |
import lz4.block | |
from glob import glob | |
FILE_PATH = os.path.dirname(os.path.realpath(__file__)) | |
def uint32(data): | |
"""Convert 4 bytes to a little endian unsigned integer.""" | |
return int.from_bytes(data, byteorder='little', signed=False) | |
def decompress(data): | |
"""Decompresses the given save bytes. If your groking this file for the important bit, this is it.""" | |
size = len(data) | |
din = io.BytesIO(data) | |
out = bytearray() | |
while din.tell() < size: | |
magic = uint32(din.read(4)) | |
if magic != 0xfeeda1e5: | |
print("Invalid Block, bad file") | |
return bytes() # some unsupported format | |
compressedSize = uint32(din.read(4)) | |
uncompressedSize = uint32(din.read(4)) | |
din.seek(4, 1) # skip 4 bytes | |
out += lz4.block.decompress(din.read(compressedSize), uncompressed_size=uncompressedSize) | |
return out | |
def findSaveGames(): | |
"""Finds all saves on windows.""" | |
return glob("C:\\Users\\*\\AppData\\Roaming\\HelloGames\\NMS\\*\\save*.hg") | |
def decodeSave(src, dst): | |
print("Decoding save: %s" % os.path.basename(src)) | |
fin = open(src, "rb") | |
data = fin.read(2) | |
if data[0] != 0x7B and data[1] != 0x22: | |
print("Decompressing file.") | |
fin.seek(0,0) # seek to start | |
data = decompress(fin.read()) | |
else: | |
fin.seek(0,0) | |
data = fin.read() | |
fin.close() | |
print("Saving to: %s" % os.path.basename(dst)) | |
fout = open(dst, "wb") | |
fout.write(data) | |
fout.close() | |
for file in findSaveGames(): | |
dst = os.path.join(FILE_PATH, "d_" + os.path.basename(file)) | |
decodeSave(file, dst) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment