Skip to content

Instantly share code, notes, and snippets.

@Chase-san
Created September 5, 2021 21:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Chase-san/704284e4acd841471d9836e6bc296f2f to your computer and use it in GitHub Desktop.
Save Chase-san/704284e4acd841471d9836e6bc296f2f 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)
#!/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