Skip to content

Instantly share code, notes, and snippets.

@PradyumnaKrishna
Last active August 30, 2023 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PradyumnaKrishna/0e2779f177d26186c588b79ab51e04a2 to your computer and use it in GitHub Desktop.
Save PradyumnaKrishna/0e2779f177d26186c588b79ab51e04a2 to your computer and use it in GitHub Desktop.
GTA San Andreas Save File Edit using python
import struct
# Loads the save file having name `gtasasf1.b`.
with open("gtasasf1.b", "rb") as f:
data = bytearray(f.read())
# Generate blocks for the save file.
blocks = []
for i in range(len(data)-4):
try:
if data[i:i + 1].decode("utf-8") == 'B':
if data[i:i + 5].decode("utf-8") == "BLOCK":
blocks.append(i + 5)
except:
pass
# Location for heath in the data.
health_offset = 0x24
health_loc = blocks[2] + health_offset
# print and edit the heath.
print(struct.unpack("<f", data[health_loc:health_loc+4]))
data[health_loc:health_loc+4] = struct.pack("<f", float(inf))
# generate checksum
data[-4:] = struct.pack("<I", sum(data[:-4]))
# save the file.
with open("gtasasf1.b", "wb") as out:
out.write(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment