Files
isaac-port/scripts/fix_offsets.py
T
shweetandClaude Opus 5.5 ad8f933086 Salvage Repentance+ 1.9.7.17 decompilation toolkit, notes and name database
Ghidra 12.2 project and full dump of isaac-ng.exe v1.9.7.17, query scripts, notes
indexed by entity, anm2/rooms reimplementations, and db/ (names + fields) that
build.sh re-applies. Fixes awk numeric address comparison in find.sh/decompile.sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 13:08:19 -04:00

34 lines
1.8 KiB
Python

# REPENTOGON's struct offsets target an older exe; fields drift as the game adds members.
# Re-anchors zhl_fields.tsv using trivial getters in the decompiled corpus ("Class::GetFoo" returning *(this+N)
# anchors field "_foo" at N); every field shifts by the delta of the nearest anchor at or below it.
# Usage: fix_offsets.py all.c zhl_fields.tsv out.tsv [names.tsv: addr \t Class::Member, overrides corpus names]
import re, sys
src, fin, fout = sys.argv[1:4]
rename = dict(l.split('\t')[:2] for l in open(sys.argv[4])) if len(sys.argv) > 4 else {}
norm = lambda s: re.sub(r'^(get|is|has)', '', s.lower().lstrip('_'))
getters = {} # (class, normname) -> exe offset
name, n = None, 0
for line in open(src, errors='replace'):
if line.startswith('//@@ '): name, n = rename.get(line.split()[1], line.split()[2]), 0; continue
n += 1
m = n < 14 and name and re.search(r'return (?:\*\([\w ]+\*\)\(\w+ \+ (0x[0-9a-f]+)\)|\w+->(\w+));', line)
if m and '::' in name and m.group(1):
cls, meth = name.rsplit('::', 1)
cls = {'EntityPlayer': 'Entity_Player', 'EntityNPC': 'Entity_NPC'}.get(cls, cls)
getters[(cls, norm(meth))] = int(m.group(1), 16)
rows = [l.rstrip('\n').split('\t') for l in open(fin)]
anchors = {}
for r in rows:
if r[1] == 'base': continue
key = (r[0], norm(r[2].split()[-1]))
if key in getters: anchors.setdefault(r[0], []).append((int(r[1], 16), getters[key] - int(r[1], 16)))
with open(fout, 'w') as o:
for r in rows:
if r[1] != 'base' and r[0] in anchors:
off = int(r[1], 16)
below = [d for a, d in sorted(anchors[r[0]]) if a <= off]
r[1] = '0x%x' % (off + (below[-1] if below else 0))
o.write('\t'.join(r) + '\n')
for c, a in sorted(anchors.items()):
print(c, ' '.join('%x%+d' % x for x in sorted(a) if x[1]))