Struct fields only where this exe confirms them; 600 verified fields; generated src/structs.hpp
REPENTOGON targets 1.9.7.12 and its offsets drift, so they are no longer trusted by themselves: scripts/zhl_fields.py (replaces fix_offsets.py) keeps a REPENTOGON field only when a getter or the game's Lua field table confirms it, or it sits between two confirmed fields with the same shift. 8 agents verified the rest against code (Game/Manager/Entity_Player shift in steps; Room, ANM2, EntityConfig unshifted). src/structs.hpp is generated from the confirmed fields with static_asserts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d2b8a9229a
commit
5d1b595294
11 files changed
+5713
-1608
No files matched your search
@@ -0,0 +1,57 @@
|
||||
# REPENTOGON's struct offsets target an older exe (1.9.7.12); fields drift as the game adds members, so they are only
|
||||
# kept where THIS exe confirms them. Evidence ("anchors"): a trivial getter in the corpus ("Class::GetFoo" returning
|
||||
# this+N anchors field "_foo" at N) or the game's Lua field table (lua_bindings.tsv: "EntityNPC State field+0xb64").
|
||||
# A field is kept when it is anchored, or lies between two anchors of its class with the same shift; everything else
|
||||
# is dropped (the decompiler then shows field_0xNNN) until db/fields.tsv confirms it. Base-class rows are always kept.
|
||||
# Usage: zhl_fields.py all.c zhl_dir lua_bindings.tsv out.tsv [names.tsv: addr \t Class::Member, overrides corpus names]
|
||||
# Prints per class: kept/total and the shifts seen.
|
||||
import collections, glob, os, re, sys
|
||||
src, zdir, lua, fout = sys.argv[1:5]
|
||||
rename = dict(l.split('\t')[:2] for l in open(sys.argv[5])) if len(sys.argv) > 5 else {}
|
||||
norm = lambda s: re.sub(r'^(get|is|has)', '', s.lower().lstrip('_'))
|
||||
cls_of = lambda c: {'Item': 'ItemConfig_Item', 'Card': 'ItemConfig_Card', 'PillEffect': 'ItemConfig_Pill', 'Costume': 'ItemConfig_Costume',
|
||||
'GridEntityDoor': 'GridEntity_Door'}.get(c, re.sub(r'^Entity(?=[A-Z])', 'Entity_', c))
|
||||
|
||||
# raw fields: "int _a : 0x0, _b : 0x4;" is two fields
|
||||
raw, bases = collections.defaultdict(list), []
|
||||
for f in sorted(glob.glob(os.path.join(zdir, '*.zhl'))):
|
||||
struct_ = None
|
||||
for l in open(f, errors='replace'):
|
||||
m = re.match(r'^\s*struct\s+(\w+)', l)
|
||||
if m:
|
||||
struct_ = m.group(1)
|
||||
b = re.search(r':\s*public\s+(\w+)', l)
|
||||
if b: bases.append((struct_, b.group(1)))
|
||||
if not (struct_ and re.match(r'^\s*([\w:<>,\s\*&]+?)\s*:\s*(0x[0-9a-fA-F]+)\s*;', l)): continue
|
||||
parts = re.findall(r'([^,:]+?)\s*:\s*(0x[0-9a-fA-F]+)', l.split(';')[0])
|
||||
ftype = parts[0][0].split()[:-1]
|
||||
for decl, off in parts:
|
||||
words = decl.split()
|
||||
raw[struct_].append((int(off, 16), ' '.join(words if len(words) > 1 else ftype + words)))
|
||||
|
||||
anchor = {} # (class, normalised member) -> offset in this exe
|
||||
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 '::' in name and re.search(r'return (?:\*\([\w ]+\*\)\((?:in_ECX|this|param_1) \+ (0x[0-9a-f]+)\)|(?:in_ECX|this|param_1) \+ (0x[0-9a-f]+));', line)
|
||||
if m:
|
||||
cls, meth = name.rsplit('::', 1)
|
||||
anchor.setdefault((cls_of(cls), norm(meth)), int(m.group(1) or m.group(2), 16))
|
||||
for l in open(lua):
|
||||
c = l.rstrip('\n').split('\t')
|
||||
m = len(c) > 2 and re.match(r'field\+(0x[0-9a-f]+)$', c[2])
|
||||
if m: anchor[(cls_of(c[0]), norm(c[1]))] = int(m.group(1), 16) # the game's own table wins over a getter guess
|
||||
|
||||
with open(fout, 'w') as o:
|
||||
for c, b in bases: o.write(f'{c}\tbase\t{b}\n')
|
||||
for c, fields in sorted(raw.items()):
|
||||
shifts = sorted((off, anchor[(c, norm(d.split()[-1]))] - off) for off, d in fields if (c, norm(d.split()[-1])) in anchor)
|
||||
kept = 0
|
||||
for off, d in fields:
|
||||
lo = [s for a, s in shifts if a <= off]; hi = [s for a, s in shifts if a >= off]
|
||||
if (c, norm(d.split()[-1])) in anchor: new = anchor[(c, norm(d.split()[-1]))]
|
||||
elif lo and hi and lo[-1] == hi[0]: new = off + lo[-1]
|
||||
else: continue
|
||||
o.write(f'{c}\t0x{new:x}\t{d}\n'); kept += 1
|
||||
if shifts: print(f'{c}: kept {kept}/{len(fields)}, shifts ' + ' '.join(f'{a:x}{s:+#x}' for a, s in shifts if s))
|
||||
Reference in new issue
Block a user