Last active
August 30, 2023 10:33
-
-
Save PradyumnaKrishna/0e2779f177d26186c588b79ab51e04a2 to your computer and use it in GitHub Desktop.
GTA San Andreas Save File Edit using python
This file contains 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 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