115 lines
3.4 KiB
Python
115 lines
3.4 KiB
Python
#!/bin/env python
|
|
|
|
# Ported from https://github.com/wofsauge/IsaacSavegameReader/blob/main/Program.cs#L228
|
|
|
|
import sys
|
|
|
|
REP_ITEMSTART = 0x00000AB6 + 4
|
|
REP_NBITEMS = 732
|
|
|
|
EID_FILE = "eid_savegames.lua"
|
|
|
|
DGH_FILE1 = "saveX.dat"
|
|
|
|
def loadFromFile(filename, itemstart, nbitems):
|
|
table = []
|
|
try:
|
|
file = open(filename, "rb")
|
|
except FileNotFoundError:
|
|
print(f"File not found: {filename}", file=sys.stderr)
|
|
for i in range(nbitems):
|
|
table.append(0)
|
|
return table
|
|
data = file.read(1)
|
|
i = 0
|
|
while data:
|
|
if (i > itemstart) and i - itemstart <= nbitems:
|
|
table.append(int.from_bytes(data, byteorder='big'))
|
|
# Should be 1 (for already seen), or 0
|
|
data = file.read(1)
|
|
i += 1
|
|
file.close()
|
|
|
|
return table
|
|
|
|
|
|
def eidfile(t1, saveid):
|
|
content = "-- Auto generated from a python script\n"
|
|
content += "if EID then\n"
|
|
content += "\tEID.SaveGame = {}\n"
|
|
content += "\tEID.SaveGame.Platform = \"Steam\"\n"
|
|
content += "\tEID.SaveGame.UserID = \"0\"\n"
|
|
content += "\tEID.SaveGame.UserName = \"username\"\n"
|
|
|
|
for savefileindex in range(3):
|
|
|
|
content += f"\tEID.SaveGame[{savefileindex+1}] = {{\n"
|
|
content += "\t\tItemCollection = {\n\t\t\t"
|
|
for i, v in enumerate(table):
|
|
if savefileindex + 1 == saveid:
|
|
content += f"[{i+1}]={'true' if v==1 else 'false'}, "
|
|
else:
|
|
content += f"[{i+1}]=false, "
|
|
content += "\n\t\t},\n"
|
|
content += "\t\tItemNeedsPickup = {\n\t\t\t"
|
|
for i, v in enumerate(table):
|
|
if savefileindex + 1 == saveid:
|
|
content += f"[{i+1}]={'true' if v==0 else 'false'}, "
|
|
else:
|
|
content += f"[{i+1}]=true, "
|
|
content += "\n\t\t}\n\t}\n"
|
|
|
|
content += "end"
|
|
|
|
return content
|
|
|
|
|
|
def dghfile(table):
|
|
content = '{'
|
|
content += '"settings":{"visual":true,"eid":true,"showonmodded":true,"showonblind":false},'
|
|
content += '"seen":['
|
|
for i, v in enumerate(table):
|
|
if table[i] == 1:
|
|
content += "true"
|
|
else:
|
|
content += "false"
|
|
if i < len(table) - 1:
|
|
content += ", "
|
|
content += "],"
|
|
content += ' "seenmodded":{}}'
|
|
return content
|
|
|
|
|
|
def isHelp(args):
|
|
return ("--help" in args) or ("-h" in args)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
args = sys.argv
|
|
|
|
if len(args) < 3 or isHelp(args):
|
|
print(f"USAGE: python {args[0]} path/to/persistengamedata.dat slotnumber")
|
|
print("This will generate the following files:")
|
|
print("\t- eid_savegames.lua , used by External Items Description (to be placed in EID's script folder)")
|
|
print("\t- saveX.dat , used by Dead God Helper (to be placed in Dead God Helper data folder)")
|
|
else:
|
|
saveid = 1
|
|
error = False
|
|
try:
|
|
saveid = int(args[2])
|
|
if not (saveid <= 3 and saveid >= 1):
|
|
error = True
|
|
except ValueError:
|
|
error = True
|
|
|
|
if error:
|
|
print(f"Invalid save ID: '{args[2]}'")
|
|
print("Please retry with a number between 1 and 3!")
|
|
exit(1)
|
|
|
|
table = loadFromFile(args[1], REP_ITEMSTART, REP_NBITEMS)
|
|
with open(EID_FILE, "w") as f:
|
|
f.write(eidfile(table, saveid))
|
|
with open(DGH_FILE1.replace("X", str(saveid)), "w") as f:
|
|
f.write(dghfile(table))
|