# Merges the confirmed struct fields into the one list ApplyTypes.java and source_tree.py read. # Inputs in order (later rows win at the same class and offset): zhl_fields.tsv, lua_fields.tsv, db/fields.tsv, class sizes. # Rows: "Class0x2d4type _namewhy", "ClassbaseBase", "Classsize0x2f00". # A row whose type is "- " ("Entity0x2d4- _masswhy") deletes a wrong field from the earlier files. # Usage: merge_fields.py out.tsv in.tsv... import sys out, *sources = sys.argv[1:] bases = {} sizes = {} rows = {} for path in sources: for line in open(path): if line.startswith('#') or not line.strip(): continue cols = line.rstrip('\n').split('\t') if cols[1] == 'base': bases[cols[0]] = cols[2]; continue if cols[1] == 'size': sizes[cols[0]] = int(cols[2], 0); continue key = (cols[0], int(cols[1], 16)) if cols[2].startswith('- '): rows.pop(key, None); continue rows[key] = line if line.endswith('\n') else line + '\n' with open(out, 'w') as o: o.writelines([f'{c}\tbase\t{b}\n' for c, b in bases.items()] + [f'{c}\tsize\t{n:#x}\n' for c, n in sizes.items()] + list(rows.values())) print(f'merge_fields: {len(rows)} fields, {len(bases)} bases, {len(sizes)} sizes')