names: CAH fill, NPC hold
This commit is contained in:
1 parent
a317ff1f22
commit
d2b8a9229a
2 files changed
+2
-33
No files matched your search
@@ -1,33 +0,0 @@
|
||||
# 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]))
|
||||
Reference in new issue
Block a user