Entity_Player::Update, RoomTransition::ChangeRoom, PlayerHUD::RenderHearts, ReviveFromTrinket, Menu_Game::Update, MenuManager::Render were on the wrong functions; real Beast and Scourge bodies found; the Lua Font table was attributed to KColor; Weapon vtable slots from the exe's RTTI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
2.1 KiB
Python
34 lines
2.1 KiB
Python
# Struct fields REPENTOGON doesn't know, from the game's own trivial Lua getters ("return *(int *)(this + 0x32c);" in
|
|
# Entity::SpawnGridIndex -> Entity 0x32c int _spawnGridIndex). Getters ICF-folded across classes are skipped, and
|
|
# pointer-returning getters only count when the name says Vector. Usage: lua_fields.py all.c lua_names.tsv lua_asm.tsv zhl_fields.tsv out.tsv
|
|
import re, sys
|
|
src, names, asm, zhl, out = sys.argv[1:6]
|
|
classes = {}
|
|
for p in (names, asm):
|
|
for l in open(p):
|
|
a, n = l.split('\t')[:2]
|
|
classes.setdefault(a, set()).add(n.split('::')[0])
|
|
known = {(r[0], int(r[1], 16)) for r in (l.split('\t') for l in open(zhl)) if r[1] != 'base'}
|
|
TYPES = {'undefined1': 'bool', 'undefined2': 'short', 'undefined4': 'int', 'undefined8': 'uint64_t'}
|
|
VECTOR = re.compile(r'Pos|Offset|Scale|Vector|Direction|Displacement|TopLeft|BottomRight|EndPoint')
|
|
CLS = lambda c: 'ANM2' if c == 'Sprite' else re.sub(r'^Entity(?=[A-Z])', 'Entity_', c) if c not in ('EntityList', 'EntityPtr', 'EntityRef') else c
|
|
rows, addr, name, n = {}, None, None, 0
|
|
for line in open(src, errors='replace'):
|
|
if line.startswith('//@@ '): addr, name, n = line.split()[1], line.split()[2], 0; continue
|
|
n += 1
|
|
if n > 16 or '::' not in name or len(classes.get(addr, ())) != 1: continue
|
|
m = re.search(r'return (?:\*\(([\w ]+) \*\)\()?(?:in_ECX|this) \+ (0x[0-9a-f]+)\)?;', line)
|
|
if not m: continue
|
|
cls, prop = name.rsplit('::', 1)
|
|
if cls == 'KColor' and prop.endswith(('LineHeight', 'BaselineHeight')): cls = 'Font' # Lua Font table mis-attributed to KColor
|
|
if prop == 'EntityRef': continue # a constructor helper, not a property
|
|
prop = re.sub(r'^Get(?=[A-Z])', '', prop)
|
|
t = TYPES.get(m.group(1), m.group(1)) if m.group(1) else 'Vector' if VECTOR.search(prop) else None
|
|
off = int(m.group(2), 16)
|
|
if t and (CLS(cls), off) not in known:
|
|
field = '_' + (prop[0].lower() + prop[1:] if t != 'bool' or prop.startswith(('Is', 'Has', 'Are')) else 'is' + prop)
|
|
rows[(CLS(cls), off)] = f'{t} {field}'
|
|
with open(out, 'w') as o:
|
|
for (c, off), f in sorted(rows.items()): o.write(f'{c}\t0x{off:x}\t{f}\n')
|
|
print(f'lua_fields: {len(rows)} fields')
|